|
From: <ls...@us...> - 2007-05-13 17:03:22
|
Revision: 3194
http://jnode.svn.sourceforge.net/jnode/?rev=3194&view=rev
Author: lsantha
Date: 2007-05-13 10:03:10 -0700 (Sun, 13 May 2007)
Log Message:
-----------
First merges of OpenJDK.
Added Paths:
-----------
trunk/core/src/openjdk/java/java/text/
trunk/core/src/openjdk/java/java/text/Normalizer.java
Added: trunk/core/src/openjdk/java/java/text/Normalizer.java
===================================================================
--- trunk/core/src/openjdk/java/java/text/Normalizer.java (rev 0)
+++ trunk/core/src/openjdk/java/java/text/Normalizer.java 2007-05-13 17:03:10 UTC (rev 3194)
@@ -0,0 +1,183 @@
+/*
+ * Portions Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ *******************************************************************************
+ * (C) Copyright IBM Corp. 1996-2005 - All Rights Reserved *
+ * *
+ * The original version of this source code and documentation is copyrighted *
+ * and owned by IBM, These materials are provided under terms of a License *
+ * Agreement between IBM and Sun. This technology is protected by multiple *
+ * US and International patents. This notice and attribution to IBM may not *
+ * to removed. *
+ *******************************************************************************
+ */
+
+package java.text;
+
+import sun.text.normalizer.NormalizerBase;
+import sun.text.normalizer.NormalizerImpl;
+
+/**
+ * This class provides the method <code>normalize</code> which transforms Unicode
+ * text into an equivalent composed or decomposed form, allowing for easier
+ * sorting and searching of text.
+ * The <code>normalize</code> method supports the standard normalization forms
+ * described in
+ * <a href="http://www.unicode.org/unicode/reports/tr15/tr15-23.html">
+ * Unicode Standard Annex #15 — Unicode Normalization Forms</a>.
+ * <p>
+ * Characters with accents or other adornments can be encoded in
+ * several different ways in Unicode. For example, take the character A-acute.
+ * In Unicode, this can be encoded as a single character (the "composed" form):
+ *
+ * <p><pre>
+ * U+00C1 LATIN CAPITAL LETTER A WITH ACUTE</pre>
+ * </p>
+ *
+ * or as two separate characters (the "decomposed" form):
+ *
+ * <p><pre>
+ * U+0041 LATIN CAPITAL LETTER A
+ * U+0301 COMBINING ACUTE ACCENT</pre>
+ * </p>
+ *
+ * To a user of your program, however, both of these sequences should be
+ * treated as the same "user-level" character "A with acute accent". When you
+ * are searching or comparing text, you must ensure that these two sequences are
+ * treated as equivalent. In addition, you must handle characters with more than
+ * one accent. Sometimes the order of a character's combining accents is
+ * significant, while in other cases accent sequences in different orders are
+ * really equivalent.
+ * <p>
+ * Similarly, the string "ffi" can be encoded as three separate letters:
+ *
+ * <p><pre>
+ * U+0066 LATIN SMALL LETTER F
+ * U+0066 LATIN SMALL LETTER F
+ * U+0069 LATIN SMALL LETTER I</pre>
+ * </p>
+ *
+ * or as the single character
+ *
+ * <p><pre>
+ * U+FB03 LATIN SMALL LIGATURE FFI</pre>
+ * </p>
+ *
+ * The ffi ligature is not a distinct semantic character, and strictly speaking
+ * it shouldn't be in Unicode at all, but it was included for compatibility
+ * with existing character sets that already provided it. The Unicode standard
+ * identifies such characters by giving them "compatibility" decompositions
+ * into the corresponding semantic characters. When sorting and searching, you
+ * will often want to use these mappings.
+ * <p>
+ * The <code>normalize</code> method helps solve these problems by transforming
+ * text into the canonical composed and decomposed forms as shown in the first
+ * example above. In addition, you can have it perform compatibility
+ * decompositions so that you can treat compatibility characters the same as
+ * their equivalents.
+ * Finally, the <code>normalize</code> method rearranges accents into the
+ * proper canonical order, so that you do not have to worry about accent
+ * rearrangement on your own.
+ * <p>
+ * The W3C generally recommends to exchange texts in NFC.
+ * Note also that most legacy character encodings use only precomposed forms and
+ * often do not encode any combining marks by themselves. For conversion to such
+ * character encodings the Unicode text needs to be normalized to NFC.
+ * For more usage examples, see the Unicode Standard Annex.
+ *
+ * @since 1.6
+ */
+public final class Normalizer {
+
+ private Normalizer() {};
+
+ /**
+ * This enum provides constants of the four Unicode normalization forms
+ * that are described in
+ * <a href="http://www.unicode.org/unicode/reports/tr15/tr15-23.html">
+ * Unicode Standard Annex #15 — Unicode Normalization Forms</a>
+ * and two methods to access them.
+ *
+ * @since 1.6
+ */
+ public static enum Form {
+
+ /**
+ * Canonical decomposition.
+ */
+ NFD,
+
+ /**
+ * Canonical decomposition, followed by canonical composition.
+ */
+ NFC,
+
+ /**
+ * Compatibility decomposition.
+ */
+ NFKD,
+
+ /**
+ * Compatibility decomposition, followed by canonical composition.
+ */
+ NFKC
+ }
+
+ /**
+ * Normalize a sequence of char values.
+ * The sequence will be normalized according to the specified normalization
+ * from.
+ * @param src The sequence of char values to normalize.
+ * @param form The normalization form; one of
+ * {@link java.text.Normalizer.Form#NFC},
+ * {@link java.text.Normalizer.Form#NFD},
+ * {@link java.text.Normalizer.Form#NFKC},
+ * {@link java.text.Normalizer.Form#NFKD}
+ * @return The normalized String
+ * @throws NullPointerException If <code>src</code> or <code>form</code>
+ * is null.
+ */
+ public static String normalize(CharSequence src, Form form) {
+ return NormalizerBase.normalize(src.toString(), form);
+ }
+
+ /**
+ * Determines if the given sequence of char values is normalized.
+ * @param src The sequence of char values to be checked.
+ * @param form The normalization form; one of
+ * {@link java.text.Normalizer.Form#NFC},
+ * {@link java.text.Normalizer.Form#NFD},
+ * {@link java.text.Normalizer.Form#NFKC},
+ * {@link java.text.Normalizer.Form#NFKD}
+ * @return true if the sequence of char values is normalized;
+ * false otherwise.
+ * @throws NullPointerException If <code>src</code> or <code>form</code>
+ * is null.
+ */
+ public static boolean isNormalized(CharSequence src, Form form) {
+ return NormalizerBase.isNormalized(src.toString(), form);
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2007-06-16 20:23:33
|
Revision: 3254
http://jnode.svn.sourceforge.net/jnode/?rev=3254&view=rev
Author: lsantha
Date: 2007-06-16 13:23:30 -0700 (Sat, 16 Jun 2007)
Log Message:
-----------
Openjdk integration.
Added Paths:
-----------
trunk/core/src/openjdk/java/java/io/
trunk/core/src/openjdk/java/java/io/IOError.java
Added: trunk/core/src/openjdk/java/java/io/IOError.java
===================================================================
--- trunk/core/src/openjdk/java/java/io/IOError.java (rev 0)
+++ trunk/core/src/openjdk/java/java/io/IOError.java 2007-06-16 20:23:30 UTC (rev 3254)
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.io;
+
+/**
+ * Thrown when a serious I/O error has occurred.
+ *
+ * @author Xueming Shen
+ * @version 1.9 05/05/07
+ * @since 1.6
+ */
+public class IOError extends Error {
+ /**
+ * Constructs a new instance of IOError with the specified cause. The
+ * IOError is created with the detail message of
+ * <tt>(cause==null ? null : cause.toString())</tt> (which typically
+ * contains the class and detail message of cause).
+ *
+ * @param cause
+ * The cause of this error, or <tt>null</tt> if the cause
+ * is not known
+ */
+ public IOError(Throwable cause) {
+ super(cause);
+ }
+
+ private static final long serialVersionUID = 67100927991680413L;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2007-06-16 20:26:18
|
Revision: 3255
http://jnode.svn.sourceforge.net/jnode/?rev=3255&view=rev
Author: lsantha
Date: 2007-06-16 13:26:16 -0700 (Sat, 16 Jun 2007)
Log Message:
-----------
Openjdk integration.
Added Paths:
-----------
trunk/core/src/openjdk/java/java/security/
trunk/core/src/openjdk/java/java/security/CodeSigner.java
trunk/core/src/openjdk/java/java/security/Timestamp.java
Added: trunk/core/src/openjdk/java/java/security/CodeSigner.java
===================================================================
--- trunk/core/src/openjdk/java/java/security/CodeSigner.java (rev 0)
+++ trunk/core/src/openjdk/java/java/security/CodeSigner.java 2007-06-16 20:26:16 UTC (rev 3255)
@@ -0,0 +1,167 @@
+/*
+ * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.security;
+
+import java.io.Serializable;
+import java.security.cert.CertPath;
+
+/**
+ * This class encapsulates information about a code signer.
+ * It is immutable.
+ *
+ * @since 1.5
+ * @version 1.11, 05/05/07
+ * @author Vincent Ryan
+ */
+
+public final class CodeSigner implements Serializable {
+
+ private static final long serialVersionUID = 6819288105193937581L;
+
+ /**
+ * The signer's certificate path.
+ *
+ * @serial
+ */
+ private CertPath signerCertPath;
+
+ /*
+ * The signature timestamp.
+ *
+ * @serial
+ */
+ private Timestamp timestamp;
+
+ /*
+ * Hash code for this code signer.
+ */
+ private transient int myhash = -1;
+
+ /**
+ * Constructs a CodeSigner object.
+ *
+ * @param signerCertPath The signer's certificate path.
+ * It must not be <code>null</code>.
+ * @param timestamp A signature timestamp.
+ * If <code>null</code> then no timestamp was generated
+ * for the signature.
+ * @throws NullPointerException if <code>signerCertPath</code> is
+ * <code>null</code>.
+ */
+ public CodeSigner(CertPath signerCertPath, Timestamp timestamp) {
+ if (signerCertPath == null) {
+ throw new NullPointerException();
+ }
+ this.signerCertPath = signerCertPath;
+ this.timestamp = timestamp;
+ }
+
+ /**
+ * Returns the signer's certificate path.
+ *
+ * @return A certificate path.
+ */
+ public CertPath getSignerCertPath() {
+ return signerCertPath;
+ }
+
+ /**
+ * Returns the signature timestamp.
+ *
+ * @return The timestamp or <code>null</code> if none is present.
+ */
+ public Timestamp getTimestamp() {
+ return timestamp;
+ }
+
+ /**
+ * Returns the hash code value for this code signer.
+ * The hash code is generated using the signer's certificate path and the
+ * timestamp, if present.
+ *
+ * @return a hash code value for this code signer.
+ */
+ public int hashCode() {
+ if (myhash == -1) {
+ if (timestamp == null) {
+ myhash = signerCertPath.hashCode();
+ } else {
+ myhash = signerCertPath.hashCode() + timestamp.hashCode();
+ }
+ }
+ return myhash;
+ }
+
+ /**
+ * Tests for equality between the specified object and this
+ * code signer. Two code signers are considered equal if their
+ * signer certificate paths are equal and if their timestamps are equal,
+ * if present in both.
+ *
+ * @param obj the object to test for equality with this object.
+ *
+ * @return true if the objects are considered equal, false otherwise.
+ */
+ public boolean equals(Object obj) {
+ if (obj == null || (!(obj instanceof CodeSigner))) {
+ return false;
+ }
+ CodeSigner that = (CodeSigner)obj;
+
+ if (this == that) {
+ return true;
+ }
+ Timestamp thatTimestamp = that.getTimestamp();
+ if (timestamp == null) {
+ if (thatTimestamp != null) {
+ return false;
+ }
+ } else {
+ if (thatTimestamp == null ||
+ (! timestamp.equals(thatTimestamp))) {
+ return false;
+ }
+ }
+ return signerCertPath.equals(that.getSignerCertPath());
+ }
+
+ /**
+ * Returns a string describing this code signer.
+ *
+ * @return A string comprising the signer's certificate and a timestamp,
+ * if present.
+ */
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("(");
+ sb.append("Signer: " + signerCertPath.getCertificates().get(0));
+ if (timestamp != null) {
+ sb.append("timestamp: " + timestamp);
+ }
+ sb.append(")");
+ return sb.toString();
+ }
+}
Added: trunk/core/src/openjdk/java/java/security/Timestamp.java
===================================================================
--- trunk/core/src/openjdk/java/java/security/Timestamp.java (rev 0)
+++ trunk/core/src/openjdk/java/java/security/Timestamp.java 2007-06-16 20:26:16 UTC (rev 3255)
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.security;
+
+import java.io.Serializable;
+import java.security.cert.CertPath;
+import java.security.cert.X509Extension;
+import java.util.Date;
+
+/**
+ * This class encapsulates information about a signed timestamp.
+ * It is immutable.
+ * It includes the timestamp's date and time as well as information about the
+ * Timestamping Authority (TSA) which generated and signed the timestamp.
+ *
+ * @since 1.5
+ * @version 1.9, 05/05/07
+ * @author Vincent Ryan
+ */
+
+public final class Timestamp implements Serializable {
+
+ private static final long serialVersionUID = -5502683707821851294L;
+
+ /**
+ * The timestamp's date and time
+ *
+ * @serial
+ */
+ private Date timestamp;
+
+ /**
+ * The TSA's certificate path.
+ *
+ * @serial
+ */
+ private CertPath signerCertPath;
+
+ /*
+ * Hash code for this timestamp.
+ */
+ private transient int myhash = -1;
+
+ /**
+ * Constructs a Timestamp.
+ *
+ * @param timestamp is the timestamp's date and time. It must not be null.
+ * @param signerCertPath is the TSA's certificate path. It must not be null.
+ * @throws NullPointerException if timestamp or signerCertPath is null.
+ */
+ public Timestamp(Date timestamp, CertPath signerCertPath) {
+ if (timestamp == null || signerCertPath == null) {
+ throw new NullPointerException();
+ }
+ this.timestamp = new Date(timestamp.getTime()); // clone
+ this.signerCertPath = signerCertPath;
+ }
+
+ /**
+ * Returns the date and time when the timestamp was generated.
+ *
+ * @return The timestamp's date and time.
+ */
+ public Date getTimestamp() {
+ return new Date(timestamp.getTime()); // clone
+ }
+
+ /**
+ * Returns the certificate path for the Timestamping Authority.
+ *
+ * @return The TSA's certificate path.
+ */
+ public CertPath getSignerCertPath() {
+ return signerCertPath;
+ }
+
+ /**
+ * Returns the hash code value for this timestamp.
+ * The hash code is generated using the date and time of the timestamp
+ * and the TSA's certificate path.
+ *
+ * @return a hash code value for this timestamp.
+ */
+ public int hashCode() {
+ if (myhash == -1) {
+ myhash = timestamp.hashCode() + signerCertPath.hashCode();
+ }
+ return myhash;
+ }
+
+ /**
+ * Tests for equality between the specified object and this
+ * timestamp. Two timestamps are considered equal if the date and time of
+ * their timestamp's and their signer's certificate paths are equal.
+ *
+ * @param obj the object to test for equality with this timestamp.
+ *
+ * @return true if the timestamp are considered equal, false otherwise.
+ */
+ public boolean equals(Object obj) {
+ if (obj == null || (!(obj instanceof Timestamp))) {
+ return false;
+ }
+ Timestamp that = (Timestamp)obj;
+
+ if (this == that) {
+ return true;
+ }
+ return (timestamp.equals(that.getTimestamp()) &&
+ signerCertPath.equals(that.getSignerCertPath()));
+ }
+
+ /**
+ * Returns a string describing this timestamp.
+ *
+ * @return A string comprising the date and time of the timestamp and
+ * its signer's certificate.
+ */
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("(");
+ sb.append("timestamp: " + timestamp);
+ sb.append("TSA: " + signerCertPath.getCertificates().get(0));
+ sb.append(")");
+ return sb.toString();
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2007-06-17 07:38:32
|
Revision: 3269
http://jnode.svn.sourceforge.net/jnode/?rev=3269&view=rev
Author: lsantha
Date: 2007-06-17 00:38:28 -0700 (Sun, 17 Jun 2007)
Log Message:
-----------
Openjdk integration.
Added Paths:
-----------
trunk/core/src/openjdk/java/java/sql/
trunk/core/src/openjdk/java/java/sql/Array.java
trunk/core/src/openjdk/java/java/sql/BatchUpdateException.java
trunk/core/src/openjdk/java/java/sql/Blob.java
trunk/core/src/openjdk/java/java/sql/CallableStatement.java
trunk/core/src/openjdk/java/java/sql/ClientInfoStatus.java
trunk/core/src/openjdk/java/java/sql/Clob.java
trunk/core/src/openjdk/java/java/sql/Connection.java
trunk/core/src/openjdk/java/java/sql/DataTruncation.java
trunk/core/src/openjdk/java/java/sql/DatabaseMetaData.java
trunk/core/src/openjdk/java/java/sql/Date.java
trunk/core/src/openjdk/java/java/sql/Driver.java
trunk/core/src/openjdk/java/java/sql/DriverManager.java
trunk/core/src/openjdk/java/java/sql/DriverPropertyInfo.java
trunk/core/src/openjdk/java/java/sql/NClob.java
trunk/core/src/openjdk/java/java/sql/ParameterMetaData.java
trunk/core/src/openjdk/java/java/sql/PreparedStatement.java
trunk/core/src/openjdk/java/java/sql/Ref.java
trunk/core/src/openjdk/java/java/sql/ResultSet.java
trunk/core/src/openjdk/java/java/sql/ResultSetMetaData.java
trunk/core/src/openjdk/java/java/sql/RowId.java
trunk/core/src/openjdk/java/java/sql/RowIdLifetime.java
trunk/core/src/openjdk/java/java/sql/SQLClientInfoException.java
trunk/core/src/openjdk/java/java/sql/SQLData.java
trunk/core/src/openjdk/java/java/sql/SQLDataException.java
trunk/core/src/openjdk/java/java/sql/SQLException.java
trunk/core/src/openjdk/java/java/sql/SQLFeatureNotSupportedException.java
trunk/core/src/openjdk/java/java/sql/SQLInput.java
trunk/core/src/openjdk/java/java/sql/SQLIntegrityConstraintViolationException.java
trunk/core/src/openjdk/java/java/sql/SQLInvalidAuthorizationSpecException.java
trunk/core/src/openjdk/java/java/sql/SQLNonTransientConnectionException.java
trunk/core/src/openjdk/java/java/sql/SQLNonTransientException.java
trunk/core/src/openjdk/java/java/sql/SQLOutput.java
trunk/core/src/openjdk/java/java/sql/SQLPermission.java
trunk/core/src/openjdk/java/java/sql/SQLRecoverableException.java
trunk/core/src/openjdk/java/java/sql/SQLSyntaxErrorException.java
trunk/core/src/openjdk/java/java/sql/SQLTimeoutException.java
trunk/core/src/openjdk/java/java/sql/SQLTransactionRollbackException.java
trunk/core/src/openjdk/java/java/sql/SQLTransientConnectionException.java
trunk/core/src/openjdk/java/java/sql/SQLTransientException.java
trunk/core/src/openjdk/java/java/sql/SQLWarning.java
trunk/core/src/openjdk/java/java/sql/SQLXML.java
trunk/core/src/openjdk/java/java/sql/Savepoint.java
trunk/core/src/openjdk/java/java/sql/Statement.java
trunk/core/src/openjdk/java/java/sql/Struct.java
trunk/core/src/openjdk/java/java/sql/Time.java
trunk/core/src/openjdk/java/java/sql/Timestamp.java
trunk/core/src/openjdk/java/java/sql/Types.java
trunk/core/src/openjdk/java/java/sql/Wrapper.java
trunk/core/src/openjdk/java/java/sql/package.html
Added: trunk/core/src/openjdk/java/java/sql/Array.java
===================================================================
--- trunk/core/src/openjdk/java/java/sql/Array.java (rev 0)
+++ trunk/core/src/openjdk/java/java/sql/Array.java 2007-06-17 07:38:28 UTC (rev 3269)
@@ -0,0 +1,368 @@
+/*
+ * Copyright 1998-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.sql;
+
+/**
+ * The mapping in the Java programming language for the SQL type
+ * <code>ARRAY</code>.
+ * By default, an <code>Array</code> value is a transaction-duration
+ * reference to an SQL <code>ARRAY</code> value. By default, an <code>Array</code>
+ * object is implemented using an SQL LOCATOR(array) internally, which
+ * means that an <code>Array</code> object contains a logical pointer
+ * to the data in the SQL <code>ARRAY</code> value rather
+ * than containing the <code>ARRAY</code> value's data.
+ * <p>
+ * The <code>Array</code> interface provides methods for bringing an SQL
+ * <code>ARRAY</code> value's data to the client as either an array or a
+ * <code>ResultSet</code> object.
+ * If the elements of the SQL <code>ARRAY</code>
+ * are a UDT, they may be custom mapped. To create a custom mapping,
+ * a programmer must do two things:
+ * <ul>
+ * <li>create a class that implements the {@link SQLData}
+ * interface for the UDT to be custom mapped.
+ * <li>make an entry in a type map that contains
+ * <ul>
+ * <li>the fully-qualified SQL type name of the UDT
+ * <li>the <code>Class</code> object for the class implementing
+ * <code>SQLData</code>
+ * </ul>
+ * </ul>
+ * <p>
+ * When a type map with an entry for
+ * the base type is supplied to the methods <code>getArray</code>
+ * and <code>getResultSet</code>, the mapping
+ * it contains will be used to map the elements of the <code>ARRAY</code> value.
+ * If no type map is supplied, which would typically be the case,
+ * the connection's type map is used by default.
+ * If the connection's type map or a type map supplied to a method has no entry
+ * for the base type, the elements are mapped according to the standard mapping.
+ * <p>
+ * All methods on the <code>Array</code> interface must be fully implemented if the
+ * JDBC driver supports the data type.
+ *
+ * @since 1.2
+ */
+
+public interface Array {
+
+ /**
+ * Retrieves the SQL type name of the elements in
+ * the array designated by this <code>Array</code> object.
+ * If the elements are a built-in type, it returns
+ * the database-specific type name of the elements.
+ * If the elements are a user-defined type (UDT),
+ * this method returns the fully-qualified SQL type name.
+ *
+ * @return a <code>String</code> that is the database-specific
+ * name for a built-in base type; or the fully-qualified SQL type
+ * name for a base type that is a UDT
+ * @exception SQLException if an error occurs while attempting
+ * to access the type name
+ * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
+ * this method
+ * @since 1.2
+ */
+ String getBaseTypeName() throws SQLException;
+
+ /**
+ * Retrieves the JDBC type of the elements in the array designated
+ * by this <code>Array</code> object.
+ *
+ * @return a constant from the class {@link java.sql.Types} that is
+ * the type code for the elements in the array designated by this
+ * <code>Array</code> object
+ * @exception SQLException if an error occurs while attempting
+ * to access the base type
+ * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
+ * this method
+ * @since 1.2
+ */
+ int getBaseType() throws SQLException;
+
+ /**
+ * Retrieves the contents of the SQL <code>ARRAY</code> value designated
+ * by this
+ * <code>Array</code> object in the form of an array in the Java
+ * programming language. This version of the method <code>getArray</code>
+ * uses the type map associated with the connection for customizations of
+ * the type mappings.
+ * <p>
+ * <strong>Note:</strong> When <code>getArray</code> is used to materialize
+ * a base type that maps to a primitive data type, then it is
+ * implementation-defined whether the array returned is an array of
+ * that primitive data type or an array of <code>Object</code>.
+ *
+ * @return an array in the Java programming language that contains
+ * the ordered elements of the SQL <code>ARRAY</code> value
+ * designated by this <code>Array</code> object
+ * @exception SQLException if an error occurs while attempting to
+ * access the array
+ * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
+ * this method
+ * @since 1.2
+ */
+ Object getArray() throws SQLException;
+
+ /**
+ * Retrieves the contents of the SQL <code>ARRAY</code> value designated by this
+ * <code>Array</code> object.
+ * This method uses
+ * the specified <code>map</code> for type map customizations
+ * unless the base type of the array does not match a user-defined
+ * type in <code>map</code>, in which case it
+ * uses the standard mapping. This version of the method
+ * <code>getArray</code> uses either the given type map or the standard mapping;
+ * it never uses the type map associated with the connection.
+ * <p>
+ * <strong>Note:</strong> When <code>getArray</code> is used to materialize
+ * a base type that maps to a primitive data type, then it is
+ * implementation-defined whether the array returned is an array of
+ * that primitive data type or an array of <code>Object</code>.
+ *
+ * @param map a <code>java.util.Map</code> object that contains mappings
+ * of SQL type names to classes in the Java programming language
+ * @return an array in the Java programming language that contains the ordered
+ * elements of the SQL array designated by this object
+ * @exception SQLException if an error occurs while attempting to
+ * access the array
+ * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
+ * this method
+ * @since 1.2
+ */
+ Object getArray(java.util.Map<String,Class<?>> map) throws SQLException;
+
+ /**
+ * Retrieves a slice of the SQL <code>ARRAY</code>
+ * value designated by this <code>Array</code> object, beginning with the
+ * specified <code>index</code> and containing up to <code>count</code>
+ * successive elements of the SQL array. This method uses the type map
+ * associated with the connection for customizations of the type mappings.
+ * <p>
+ * <strong>Note:</strong> When <code>getArray</code> is used to materialize
+ * a base type that maps to a primitive data type, then it is
+ * implementation-defined whether the array returned is an array of
+ * that primitive data type or an array of <code>Object</code>.
+ *
+ * @param index the array index of the first element to retrieve;
+ * the first element is at index 1
+ * @param count the number of successive SQL array elements to retrieve
+ * @return an array containing up to <code>count</code> consecutive elements
+ * of the SQL array, beginning with element <code>index</code>
+ * @exception SQLException if an error occurs while attempting to
+ * access the array
+ * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
+ * this method
+ * @since 1.2
+ */
+ Object getArray(long index, int count) throws SQLException;
+
+ /**
+ * Retreives a slice of the SQL <code>ARRAY</code> value
+ * designated by this <code>Array</code> object, beginning with the specified
+ * <code>index</code> and containing up to <code>count</code>
+ * successive elements of the SQL array.
+ * <P>
+ * This method uses
+ * the specified <code>map</code> for type map customizations
+ * unless the base type of the array does not match a user-defined
+ * type in <code>map</code>, in which case it
+ * uses the standard mapping. This version of the method
+ * <code>getArray</code> uses either the given type map or the standard mapping;
+ * it never uses the type map associated with the connection.
+ * <p>
+ * <strong>Note:</strong> When <code>getArray</code> is used to materialize
+ * a base type that maps to a primitive data type, then it is
+ * implementation-defined whether the array returned is an array of
+ * that primitive data type or an array of <code>Object</code>.
+ *
+ * @param index the array index of the first element to retrieve;
+ * the first element is at index 1
+ * @param count the number of successive SQL array elements to
+ * retrieve
+ * @param map a <code>java.util.Map</code> object
+ * that contains SQL type names and the classes in
+ * the Java programming language to which they are mapped
+ * @return an array containing up to <code>count</code>
+ * consecutive elements of the SQL <code>ARRAY</code> value designated by this
+ * <code>Array</code> object, beginning with element
+ * <code>index</code>
+ * @exception SQLException if an error occurs while attempting to
+ * access the array
+ * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
+ * this method
+ * @since 1.2
+ */
+ Object getArray(long index, int count, java.util.Map<String,Class<?>> map)
+ throws SQLException;
+
+ /**
+ * Retrieves a result set that contains the elements of the SQL
+ * <code>ARRAY</code> value
+ * designated by this <code>Array</code> object. If appropriate,
+ * the elements of the array are mapped using the connection's type
+ * map; otherwise, the standard mapping is used.
+ * <p>
+ * The result set contains one row for each array element, with
+ * two columns in each row. The second column stores the element
+ * value; the first column stores the index into the array for
+ * that element (with the first array element being at index 1).
+ * The rows are in ascending order corresponding to
+ * the order of the indices.
+ *
+ * @return a {@link ResultSet} object containing one row for each
+ * of the elements in the array designated by this <code>Array</code>
+ * object, with the rows in ascending order based on the indices.
+ * @exception SQLException if an error occurs while attempting to
+ * access the array
+ * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
+ * this method
+ * @since 1.2
+ */
+ ResultSet getResultSet () throws SQLException;
+
+ /**
+ * Retrieves a result set that contains the elements of the SQL
+ * <code>ARRAY</code> value designated by this <code>Array</code> object.
+ * This method uses
+ * the specified <code>map</code> for type map customizations
+ * unless the base type of the array does not match a user-defined
+ * type in <code>map</code>, in which case it
+ * uses the standard mapping. This version of the method
+ * <code>getResultSet</code> uses either the given type map or the standard mapping;
+ * it never uses the type map associated with the connection.
+ * <p>
+ * The result set contains one row for each array element, with
+ * two columns in each row. The second column stores the element
+ * value; the first column stores the index into the array for
+ * that element (with the first array element being at index 1).
+ * The rows are in ascending order corresponding to
+ * the order of the indices.
+ *
+ * @param map contains the mapping of SQL user-defined types to
+ * classes in the Java programming language
+ * @return a <code>ResultSet</code> object containing one row for each
+ * of the elements in the array designated by this <code>Array</code>
+ * object, with the rows in ascending order based on the indices.
+ * @exception SQLException if an error occurs while attempting to
+ * access the array
+ * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
+ * this method
+ * @since 1.2
+ */
+ ResultSet getResultSet (java.util.Map<String,Class<?>> map) throws SQLException;
+
+ /**
+ * Retrieves a result set holding the elements of the subarray that
+ * starts at index <code>index</code> and contains up to
+ * <code>count</code> successive elements. This method uses
+ * the connection's type map to map the elements of the array if
+ * the map contains an entry for the base type. Otherwise, the
+ * standard mapping is used.
+ * <P>
+ * The result set has one row for each element of the SQL array
+ * designated by this object, with the first row containing the
+ * element at index <code>index</code>. The result set has
+ * up to <code>count</code> rows in ascending order based on the
+ * indices. Each row has two columns: The second column stores
+ * the element value; the first column stores the index into the
+ * array for that element.
+ *
+ * @param index the array index of the first element to retrieve;
+ * the first element is at index 1
+ * @param count the number of successive SQL array elements to retrieve
+ * @return a <code>ResultSet</code> object containing up to
+ * <code>count</code> consecutive elements of the SQL array
+ * designated by this <code>Array</code> object, starting at
+ * index <code>index</code>.
+ * @exception SQLException if an error occurs while attempting to
+ * access the array
+ * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
+ * this method
+ * @since 1.2
+ */
+ ResultSet getResultSet(long index, int count) throws SQLException;
+
+ /**
+ * Retrieves a result set holding the elements of the subarray that
+ * starts at index <code>index</code> and contains up to
+ * <code>count</code> successive elements.
+ * This method uses
+ * the specified <code>map</code> for type map customizations
+ * unless the base type of the array does not match a user-defined
+ * type in <code>map</code>, in which case it
+ * uses the standard mapping. This version of the method
+ * <code>getResultSet</code> uses either the given type map or the standard mapping;
+ * it never uses the type map associated with the connection.
+ * <P>
+ * The result set has one row for each element of the SQL array
+ * designated by this object, with the first row containing the
+ * element at index <code>index</code>. The result set has
+ * up to <code>count</code> rows in ascending order based on the
+ * indices. Each row has two columns: The second column stores
+ * the element value; the first column stroes the index into the
+ * array for that element.
+ *
+ * @param index the array index of the first element to retrieve;
+ * the first element is at index 1
+ * @param count the number of successive SQL array elements to retrieve
+ * @param map the <code>Map</code> object that contains the mapping
+ * of SQL type names to classes in the Java(tm) programming language
+ * @return a <code>ResultSet</code> object containing up to
+ * <code>count</code> consecutive elements of the SQL array
+ * designated by this <code>Array</code> object, starting at
+ * index <code>index</code>.
+ * @exception SQLException if an error occurs while attempting to
+ * access the array
+ * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
+ * this method
+ * @since 1.2
+ */
+ ResultSet getResultSet (long index, int count,
+ java.util.Map<String,Class<?>> map)
+ throws SQLException;
+ /**
+ * This method frees the <code>Array</code> object and releases the resources that
+ * it holds. The object is invalid once the <code>free</code>
+ * method is called.
+ *<p>
+ * After <code>free</code> has been called, any attempt to invoke a
+ * method other than <code>free</code> will result in a <code>SQLException</code>
+ * being thrown. If <code>free</code> is called multiple times, the subsequent
+ * calls to <code>free</code> are treated as a no-op.
+ *<p>
+ *
+ * @throws SQLException if an error occurs releasing
+ * the Array's resources
+ * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
+ * this method
+ * @since 1.6
+ */
+ void free() throws SQLException;
+
+}
+
+
Added: trunk/core/src/openjdk/java/java/sql/BatchUpdateException.java
===================================================================
--- trunk/core/src/openjdk/java/java/sql/BatchUpdateException.java (rev 0)
+++ trunk/core/src/openjdk/java/java/sql/BatchUpdateException.java 2007-06-17 07:38:28 UTC (rev 3269)
@@ -0,0 +1,346 @@
+/*
+ * Copyright 1998-2005 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.sql;
+
+/**
+ * The subclass of {@link SQLException} thrown when an error
+ * occurs during a batch update operation. In addition to the
+ * information provided by {@link SQLException}, a
+ * <code>BatchUpdateException</code> provides the update
+ * counts for all commands that were executed successfully during the
+ * batch update, that is, all commands that were executed before the error
+ * occurred. The order of elements in an array of update counts
+ * corresponds to the order in which commands were added to the batch.
+ * <P>
+ * After a command in a batch update fails to execute properly
+ * and a <code>BatchUpdateException</code> is thrown, the driver
+ * may or may not continue to process the remaining commands in
+ * the batch. If the driver continues processing after a failure,
+ * the array returned by the method
+ * <code>BatchUpdateException.getUpdateCounts</code> will have
+ * an element for every command in the batch rather than only
+ * elements for the commands that executed successfully before
+ * the error. In the case where the driver continues processing
+ * commands, the array element for any command
+ * that failed is <code>Statement.EXECUTE_FAILED</code>.
+ * <P>
+ * @since 1.2
+ */
+
+public class BatchUpdateException extends SQLException {
+
+ /**
+ * Constructs a <code>BatchUpdateException</code> object initialized with a given
+ * <code>reason</code>, <code>SQLState</code>, <code>vendorCode</code> and
+ * <code>updateCounts</code>.
+ * The <code>cause</code> is not initialized, and may subsequently be
+ * initialized by a call to the
+ * {@link Throwable#initCause(java.lang.Throwable)} method.
+ * <p>
+ *
+ * @param reason a description of the error
+ * @param SQLState an XOPEN or SQL:2003 code identifying the exception
+ * @param vendorCode an exception code used by a particular
+ * database vendor
+ * @param updateCounts an array of <code>int</code>, with each element
+ * indicating the update count, <code>Statement.SUCCESS_NO_INFO</code> or
+ * <code>Statement.EXECUTE_FAILED</code> for each SQL command in
+ * the batch for JDBC drivers that continue processing
+ * after a command failure; an update count or
+ * <code>Statement.SUCCESS_NO_INFO</code> for each SQL command in the batch
+ * prior to the failure for JDBC drivers that stop processing after a command
+ * failure
+ * @since 1.2
+ */
+ public BatchUpdateException( String reason, String SQLState, int vendorCode,
+ int[] updateCounts ) {
+ super(reason, SQLState, vendorCode);
+ this.updateCounts = updateCounts;
+ }
+
+ /**
+ * Constructs a <code>BatchUpdateException</code> object initialized with a given
+ * <code>reason</code>, <code>SQLState</code> and
+ * <code>updateCounts</code>.
+ * The <code>cause</code> is not initialized, and may subsequently be
+ * initialized by a call to the
+ * {@link Throwable#initCause(java.lang.Throwable)} method. The vendor code
+ * is intialized to 0.
+ * <p>
+ *
+ * @param reason a description of the exception
+ * @param SQLState an XOPEN or SQL:2003 code identifying the exception
+ * @param updateCounts an array of <code>int</code>, with each element
+ * indicating the update count, <code>Statement.SUCCESS_NO_INFO</code> or
+ * <code>Statement.EXECUTE_FAILED</code> for each SQL command in
+ * the batch for JDBC drivers that continue processing
+ * after a command failure; an update count or
+ * <code>Statement.SUCCESS_NO_INFO</code> for each SQL command in the batch
+ * prior to the failure for JDBC drivers that stop processing after a command
+ * failure
+ * @since 1.2
+ */
+ public BatchUpdateException(String reason, String SQLState,
+ int[] updateCounts) {
+ super(reason, SQLState);
+ this.updateCounts = updateCounts;
+ }
+
+ /**
+ * Constructs a <code>BatchUpdateException</code> object initialized with a given
+ * <code>reason</code> and <code>updateCounts</code>.
+ * The <code>cause</code> is not initialized, and may subsequently be
+ * initialized by a call to the
+ * {@link Throwable#initCause(java.lang.Throwable)} method. The
+ * <code>SQLState</code> is initialized to <code>null</code>
+ * and the vender code is initialized to 0.
+ * <p>
+ *
+ *
+ * @param reason a description of the exception
+ * @param updateCounts an array of <code>int</code>, with each element
+ * indicating the update count, <code>Statement.SUCCESS_NO_INFO</code> or
+ * <code>Statement.EXECUTE_FAILED</code> for each SQL command in
+ * the batch for JDBC drivers that continue processing
+ * after a command failure; an update count or
+ * <code>Statement.SUCCESS_NO_INFO</code> for each SQL command in the batch
+ * prior to the failure for JDBC drivers that stop processing after a command
+ * failure
+ * @since 1.2
+ */
+ public BatchUpdateException(String reason, int[] updateCounts) {
+ super(reason);
+ this.updateCounts = updateCounts;
+ }
+
+ /**
+ * Constructs a <code>BatchUpdateException</code> object initialized with a given
+ * <code>updateCounts</code>.
+ * initialized by a call to the
+ * {@link Throwable#initCause(java.lang.Throwable)} method. The <code>reason</code>
+ * and <code>SQLState</code> are initialized to null and the vendor code
+ * is initialized to 0.
+ * <p>
+ *
+ * @param updateCounts an array of <code>int</code>, with each element
+ * indicating the update count, <code>Statement.SUCCESS_NO_INFO</code> or
+ * <code>Statement.EXECUTE_FAILED</code> for each SQL command in
+ * the batch for JDBC drivers that continue processing
+ * after a command failure; an update count or
+ * <code>Statement.SUCCESS_NO_INFO</code> for each SQL command in the batch
+ * prior to the failure for JDBC drivers that stop processing after a command
+ * failure
+ * @since 1.2
+ */
+ public BatchUpdateException(int[] updateCounts) {
+ super();
+ this.updateCounts = updateCounts;
+ }
+
+ /**
+ * Constructs a <code>BatchUpdateException</code> object.
+ * The <code>reason</code>, <code>SQLState</code> and <code>updateCounts</code>
+ * are initialized to <code>null</code> and the vendor code is initialized to 0.
+ * The <code>cause</code> is not initialized, and may subsequently be
+ * initialized by a call to the
+ * {@link Throwable#initCause(java.lang.Throwable)} method.
+ * <p>
+ *
+ * @since 1.2
+ */
+ public BatchUpdateException() {
+ super();
+ this.updateCounts = null;
+ }
+
+ /**
+ * Constructs a <code>BatchUpdateException</code> object initialized with
+ * a given <code>cause</code>.
+ * The <code>SQLState</code> and <code>updateCounts</code>
+ * are initialized
+ * to <code>null</code> and the vendor code is initialized to 0.
+ * The <code>reason</code> is initialized to <code>null</code> if
+ * <code>cause==null</code> or to <code>cause.toString()</code> if
+ * <code>cause!=null</code>.
+ * @param cause the underlying reason for this <code>SQLException</code>
+ * (which is saved for later retrieval by the <code>getCause()</code> method);
+ * may be null indicating the cause is non-existent or unknown.
+ * @since 1.6
+ */
+ public BatchUpdateException(Throwable cause) {
+ super(cause);
+ this.updateCounts = null;
+ }
+
+ /**
+ * Constructs a <code>BatchUpdateException</code> object initialized with a
+ * given <code>cause</code> and <code>updateCounts</code>.
+ * The <code>SQLState</code> is initialized
+ * to <code>null</code> and the vendor code is initialized to 0.
+ * The <code>reason</code> is initialized to <code>null</code> if
+ * <code>cause==null</code> or to <code>ca...
[truncated message content] |
|
From: <ls...@us...> - 2007-06-17 12:17:13
|
Revision: 3278
http://jnode.svn.sourceforge.net/jnode/?rev=3278&view=rev
Author: lsantha
Date: 2007-06-17 05:17:11 -0700 (Sun, 17 Jun 2007)
Log Message:
-----------
Openjdk integration.
Added Paths:
-----------
trunk/core/src/openjdk/java/java/math/
trunk/core/src/openjdk/java/java/math/BigDecimal.java
trunk/core/src/openjdk/java/java/math/BigInteger.java
trunk/core/src/openjdk/java/java/math/BitSieve.java
trunk/core/src/openjdk/java/java/math/MathContext.java
trunk/core/src/openjdk/java/java/math/MutableBigInteger.java
trunk/core/src/openjdk/java/java/math/RoundingMode.java
trunk/core/src/openjdk/java/java/math/SignedMutableBigInteger.java
trunk/core/src/openjdk/java/java/math/package-info.java
trunk/core/src/openjdk/java/java/util/FormatFlagsConversionMismatchException.java
trunk/core/src/openjdk/java/java/util/Formattable.java
trunk/core/src/openjdk/java/java/util/FormattableFlags.java
trunk/core/src/openjdk/java/java/util/Formatter.java
trunk/core/src/openjdk/java/java/util/FormatterClosedException.java
trunk/core/src/openjdk/java/java/util/Scanner.java
Added: trunk/core/src/openjdk/java/java/math/BigDecimal.java
===================================================================
--- trunk/core/src/openjdk/java/java/math/BigDecimal.java (rev 0)
+++ trunk/core/src/openjdk/java/java/math/BigDecimal.java 2007-06-17 12:17:11 UTC (rev 3278)
@@ -0,0 +1,3555 @@
+/*
+ * Portions Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * Portions Copyright IBM Corporation, 2001. All Rights Reserved.
+ */
+
+package java.math;
+
+/**
+ * Immutable, arbitrary-precision signed decimal numbers. A
+ * {@code BigDecimal} consists of an arbitrary precision integer
+ * <i>unscaled value</i> and a 32-bit integer <i>scale</i>. If zero
+ * or positive, the scale is the number of digits to the right of the
+ * decimal point. If negative, the unscaled value of the number is
+ * multiplied by ten to the power of the negation of the scale. The
+ * value of the number represented by the {@code BigDecimal} is
+ * therefore <tt>(unscaledValue × 10<sup>-scale</sup>)</tt>.
+ *
+ * <p>The {@code BigDecimal} class provides operations for
+ * arithmetic, scale manipulation, rounding, comparison, hashing, and
+ * format conversion. The {@link #toString} method provides a
+ * canonical representation of a {@code BigDecimal}.
+ *
+ * <p>The {@code BigDecimal} class gives its user complete control
+ * over rounding behavior. If no rounding mode is specified and the
+ * exact result cannot be represented, an exception is thrown;
+ * otherwise, calculations can be carried out to a chosen precision
+ * and rounding mode by supplying an appropriate {@link MathContext}
+ * object to the operation. In either case, eight <em>rounding
+ * modes</em> are provided for the control of rounding. Using the
+ * integer fields in this class (such as {@link #ROUND_HALF_UP}) to
+ * represent rounding mode is largely obsolete; the enumeration values
+ * of the {@code RoundingMode} {@code enum}, (such as {@link
+ * RoundingMode#HALF_UP}) should be used instead.
+ *
+ * <p>When a {@code MathContext} object is supplied with a precision
+ * setting of 0 (for example, {@link MathContext#UNLIMITED}),
+ * arithmetic operations are exact, as are the arithmetic methods
+ * which take no {@code MathContext} object. (This is the only
+ * behavior that was supported in releases prior to 5.) As a
+ * corollary of computing the exact result, the rounding mode setting
+ * of a {@code MathContext} object with a precision setting of 0 is
+ * not used and thus irrelevant. In the case of divide, the exact
+ * quotient could have an infinitely long decimal expansion; for
+ * example, 1 divided by 3. If the quotient has a nonterminating
+ * decimal expansion and the operation is specified to return an exact
+ * result, an {@code ArithmeticException} is thrown. Otherwise, the
+ * exact result of the division is returned, as done for other
+ * operations.
+ *
+ * <p>When the precision setting is not 0, the rules of
+ * {@code BigDecimal} arithmetic are broadly compatible with selected
+ * modes of operation of the arithmetic defined in ANSI X3.274-1996
+ * and ANSI X3.274-1996/AM 1-2000 (section 7.4). Unlike those
+ * standards, {@code BigDecimal} includes many rounding modes, which
+ * were mandatory for division in {@code BigDecimal} releases prior
+ * to 5. Any conflicts between these ANSI standards and the
+ * {@code BigDecimal} specification are resolved in favor of
+ * {@code BigDecimal}.
+ *
+ * <p>Since the same numerical value can have different
+ * representations (with different scales), the rules of arithmetic
+ * and rounding must specify both the numerical result and the scale
+ * used in the result's representation.
+ *
+ *
+ * <p>In general the rounding modes and precision setting determine
+ * how operations return results with a limited number of digits when
+ * the exact result has more digits (perhaps infinitely many in the
+ * case of division) than the number of digits returned.
+ *
+ * First, the
+ * total number of digits to return is specified by the
+ * {@code MathContext}'s {@code precision} setting; this determines
+ * the result's <i>precision</i>. The digit count starts from the
+ * leftmost nonzero digit of the exact result. The rounding mode
+ * determines how any discarded trailing digits affect the returned
+ * result.
+ *
+ * <p>For all arithmetic operators , the operation is carried out as
+ * though an exact intermediate result were first calculated and then
+ * rounded to the number of digits specified by the precision setting
+ * (if necessary), using the selected rounding mode. If the exact
+ * result is not returned, some digit positions of the exact result
+ * are discarded. When rounding increases the magnitude of the
+ * returned result, it is possible for a new digit position to be
+ * created by a carry propagating to a leading {@literal "9"} digit.
+ * For example, rounding the value 999.9 to three digits rounding up
+ * would be numerically equal to one thousand, represented as
+ * 100×10<sup>1</sup>. In such cases, the new {@literal "1"} is
+ * the leading digit position of the returned result.
+ *
+ * <p>Besides a logical exact result, each arithmetic operation has a
+ * preferred scale for representing a result. The preferred
+ * scale for each operation is listed in the table below.
+ *
+ * <table border>
+ * <caption top><h3>Preferred Scales for Results of Arithmetic Operations
+ * </h3></caption>
+ * <tr><th>Operation</th><th>Preferred Scale of Result</th></tr>
+ * <tr><td>Add</td><td>max(addend.scale(), augend.scale())</td>
+ * <tr><td>Subtract</td><td>max(minuend.scale(), subtrahend.scale())</td>
+ * <tr><td>Multiply</td><td>multiplier.scale() + multiplicand.scale()</td>
+ * <tr><td>Divide</td><td>dividend.scale() - divisor.scale()</td>
+ * </table>
+ *
+ * These scales are the ones used by the methods which return exact
+ * arithmetic results; except that an exact divide may have to use a
+ * larger scale since the exact result may have more digits. For
+ * example, {@code 1/32} is {@code 0.03125}.
+ *
+ * <p>Before rounding, the scale of the logical exact intermediate
+ * result is the preferred scale for that operation. If the exact
+ * numerical result cannot be represented in {@code precision}
+ * digits, rounding selects the set of digits to return and the scale
+ * of the result is reduced from the scale of the intermediate result
+ * to the least scale which can represent the {@code precision}
+ * digits actually returned. If the exact result can be represented
+ * with at most {@code precision} digits, the representation
+ * of the result with the scale closest to the preferred scale is
+ * returned. In particular, an exactly representable quotient may be
+ * represented in fewer than {@code precision} digits by removing
+ * trailing zeros and decreasing the scale. For example, rounding to
+ * three digits using the {@linkplain RoundingMode#FLOOR floor}
+ * rounding mode, <br>
+ *
+ * {@code 19/100 = 0.19 // integer=19, scale=2} <br>
+ *
+ * but<br>
+ *
+ * {@code 21/110 = 0.190 // integer=190, scale=3} <br>
+ *
+ * <p>Note that for add, subtract, and multiply, the reduction in
+ * scale will equal the number of digit positions of the exact result
+ * which are discarded. If the rounding causes a carry propagation to
+ * create a new high-order digit position, an additional digit of the
+ * result is discarded than when no new digit position is created.
+ *
+ * <p>Other methods may have slightly different rounding semantics.
+ * For example, the result of the {@code pow} method using the
+ * {@linkplain #pow(int, MathContext) specified algorithm} can
+ * occasionally differ from the rounded mathematical result by more
+ * than one unit in the last place, one <i>{@linkplain #ulp() ulp}</i>.
+ *
+ * <p>Two types of operations are provided for manipulating the scale
+ * of a {@code BigDecimal}: scaling/rounding operations and decimal
+ * point motion operations. Scaling/rounding operations ({@link
+ * #setScale setScale} and {@link #round round}) return a
+ * {@code BigDecimal} whose value is approximately (or exactly) equal
+ * to that of the operand, but whose scale or precision is the
+ * specified value; that is, they increase or decrease the precision
+ * of the stored number with minimal effect on its value. Decimal
+ * point motion operations ({@link #movePointLeft movePointLeft} and
+ * {@link #movePointRight movePointRight}) return a
+ * {@code BigDecimal} created from the operand by moving the decimal
+ * point a specified distance in the specified direction.
+ *
+ * <p>For the sake of brevity and clarity, pseudo-code is used
+ * throughout the descriptions of {@code BigDecimal} methods. The
+ * pseudo-code expression {@code (i + j)} is shorthand for "a
+ * {@code BigDecimal} whose value is that of the {@code BigDecimal}
+ * {@code i} added to that of the {@code BigDecimal}
+ * {@code j}." The pseudo-code expression {@code (i == j)} is
+ * shorthand for "{@code true} if and only if the
+ * {@code BigDecimal} {@code i} represents the same value as the
+ * {@code BigDecimal} {@code j}." Other pseudo-code expressions
+ * are interpreted similarly. Square brackets are used to represent
+ * the particular {@code BigInteger} and scale pair defining a
+ * {@code BigDecimal} value; for example [19, 2] is the
+ * {@code BigDecimal} numerically equal to 0.19 having a scale of 2.
+ *
+ * <p>Note: care should be exercised if {@code BigDecimal} objects
+ * are used as keys in a {@link java.util.SortedMap SortedMap} or
+ * elements in a {@link java.util.SortedSet SortedSet} since
+ * {@code BigDecimal}'s <i>natural ordering</i> is <i>inconsistent
+ * with equals</i>. See {@link Comparable}, {@link
+ * java.util.SortedMap} or {@link java.util.SortedSet} for more
+ * information.
+ *
+ * <p>All methods and constructors for this class throw
+ * {@code NullPointerException} when passed a {@code null} object
+ * reference for any input parameter.
+ *
+ * @see BigInteger
+ * @see MathContext
+ * @see RoundingMode
+ * @see java.util.SortedMap
+ * @see java.util.SortedSet
+ * @author Josh Bloch
+ * @author Mike Cowlishaw
+ * @author Joseph D. Darcy
+ */
+public class BigDecimal extends Number implements Comparable<BigDecimal> {
+ /**
+ * The unscaled value of this BigDecimal, as returned by {@link
+ * #unscaledValue}.
+ *
+ * @serial
+ * @see #unscaledValue
+ */
+ private volatile BigInteger intVal;
+
+ /**
+ * The scale of this BigDecimal, as returned by {@link #scale}.
+ *
+ * @serial
+ * @see #scale
+ */
+ private int scale = 0; // Note: this may have any value, so
+ // calculations must be done in longs
+ /**
+ * The number of decimal digits in this BigDecimal, or 0 if the
+ * number of digits are not known (lookaside information). If
+ * nonzero, the value is guaranteed correct. Use the precision()
+ * method to obtain and set the value if it might be 0. This
+ * field is mutable until set nonzero.
+ *
+ * @since 1.5
+ */
+ private volatile transient int precision = 0;
+
+ /**
+ * Used to store the canonical string representation, if computed.
+ */
+ private volatile transient String stringCache = null;
+
+ /**
+ * Sentinel value for {@link #intCompact} indicating the
+ * significand information is only available from {@code intVal}.
+ */
+ private static final long INFLATED = Long.MIN_VALUE;
+
+ /**
+ * If the absolute value of the significand of this BigDecimal is
+ * less than or equal to {@code Long.MAX_VALUE}, the value can be
+ * compactly stored in this field and used in computations.
+ */
+ private transient long intCompact = INFLATED;
+
+ // All 18-digit base ten strings fit into a long; not all 19-digit
+ // strings will
+ private static final int MAX_COMPACT_DIGITS = 18;
+
+ private static final int MAX_BIGINT_BITS = 62;
+
+ /* Appease the serialization gods */
+ private static final long serialVersionUID = 6108874887143696463L;
+
+ // Cache of common small BigDecimal values.
+ private static final BigDecimal zeroThroughTen[] = {
+ new BigDecimal(BigInteger.ZERO, 0, 0),
+ new BigDecimal(BigInteger.ONE, 1, 0),
+ new BigDecimal(BigInteger.valueOf(2), 2, 0),
+ new BigDecimal(BigInteger.valueOf(3), 3, 0),
+ new BigDecimal(BigInteger.valueOf(4), 4, 0),
+ new BigDecimal(BigInteger.valueOf(5), 5, 0),
+ new BigDecimal(BigInteger.valueOf(6), 6, 0),
+ new BigDecimal(BigInteger.valueOf(7), 7, 0),
+ new BigDecimal(BigInteger.valueOf(8), 8, 0),
+ new BigDecimal(BigInteger.valueOf(9), 9, 0),
+ new BigDecimal(BigInteger.TEN, 10, 0),
+ };
+
+ // Constants
+ /**
+ * The value 0, with a scale of 0.
+ *
+ * @since 1.5
+ */
+ public static final BigDecimal ZERO =
+ zeroThroughTen[0];
+
+ /**
+ * The value 1, with a scale of 0.
+ *
+ * @since 1.5
+ */
+ public static final BigDecimal ONE =
+ zeroThroughTen[1];
+
+ /**
+ * The value 10, with a scale of 0.
+ *
+ * @since 1.5
+ */
+ public static final BigDecimal TEN =
+ zeroThroughTen[10];
+
+ // Constructors
+
+ /**
+ * Translates a character array representation of a
+ * {@code BigDecimal} into a {@code BigDecimal}, accepting the
+ * same sequence of characters as the {@link #BigDecimal(String)}
+ * constructor, while allowing a sub-array to be specified.
+ *
+ * <p>Note that if the sequence of characters is already available
+ * within a character array, using this constructor is faster than
+ * converting the {@code char} array to string and using the
+ * {@code BigDecimal(String)} constructor .
+ *
+ * @param in {@code char} array that is the source of characters.
+ * @param offset first character in the array to inspect.
+ * @param len number of characters to consider.
+ * @throws NumberFormatException if {@code in} is not a valid
+ * representation of a {@code BigDecimal} or the defined subarray
+ * is not wholly within {@code in}.
+ * @since 1.5
+ */
+ public BigDecimal(char[] in, int offset, int len) {
+ // This is the primary string to BigDecimal constructor; all
+ // incoming strings end up here; it uses explicit (inline)
+ // parsing for speed and generates at most one intermediate
+ // (temporary) object (a char[] array).
+
+ // use array bounds checking to handle too-long, len == 0,
+ // bad offset, etc.
+ try {
+ // handle the sign
+ boolean isneg = false; // assume positive
+ if (in[offset] == '-') {
+ isneg = true; // leading minus means negative
+ offset++;
+ len--;
+ } else if (in[offset] == '+') { // leading + allowed
+ offset++;
+ len--;
+ }
+
+ // should now be at numeric part of the significand
+ int dotoff = -1; // '.' offset, -1 if none
+ int cfirst = offset; // record start of integer
+ long exp = 0; // exponent
+ if (len > in.length) // protect against huge length
+ throw new NumberFormatException();
+ char coeff[] = new char[len]; // integer significand array
+ char c; // work
+
+ for (; len > 0; offset++, len--) {
+ c = in[offset];
+ if ((c >= '0' && c <= '9') || Character.isDigit(c)) {
+ // have digit
+ coeff[precision] = c;
+ precision++; // count of digits
+ continue;
+ }
+ if (c == '.') {
+ // have dot
+ if (dotoff >= 0) // two dots
+ throw new NumberFormatException();
+ dotoff = offset;
+ continue;
+ }
+ // exponent expected
+ if ((c != 'e') && (c != 'E'))
+ throw new NumberFormatException();
+ offset++;
+ c = in[offset];
+ len--;
+ boolean negexp = false;
+ // optional sign
+ if (c == '-' || c == '+') {
+ negexp = (c == '-');
+ offset++;
+ c = in[offset];
+ len--;
+ }
+ if (len <= 0) // no exponent digits
+ throw new NumberFormatException();
+ // skip leading zeros in the exponent
+ while (len > 10 && Character.digit(c, 10) == 0) {
+ offset++;
+ c = in[offset];
+ len--;
+ }
+ if (len > 10) // too many nonzero exponent digits
+ throw new NumberFormatException();
+ // c now holds first digit of exponent
+ for (;; len--) {
+ int v;
+ if (c >= '0' && c <= '9') {
+ v = c - '0';
+ } else {
+ v = Character.digit(c, 10);
+ if (v < 0) // not a digit
+ throw new NumberFormatException();
+ }
+ exp = exp * 10 + v;
+ if (len == 1)
+ break; // that was final character
+ offset++;
+ c = in[offset];
+ }
+ if (negexp) // apply sign
+ exp = -exp;
+ // Next test is required for backwards compatibility
+ if ((int)exp != exp) // overflow
+ throw new NumberFormatException();
+ break; // [saves a test]
+ }
+ // here when no characters left
+ if (precision == 0) // no digits found
+ throw new NumberFormatException();
+
+ if (dotoff >= 0) { // had dot; set scale
+ scale = precision - (dotoff - cfirst);
+ // [cannot overflow]
+ }
+ if (exp != 0) { // had significant exponent
+ try {
+ scale = checkScale(-exp + scale); // adjust
+ } catch (ArithmeticException e) {
+ throw new NumberFormatException("Scale out of range.");
+ }
+ }
+
+ // Remove leading zeros from precision (digits count)
+ int first = 0;
+ for (; (coeff[first] == '0' || Character.digit(coeff[first], 10) == 0) &&
+ precision > 1;
+ first++)
+ precision--;
+
+ // Set the significand ..
+ // Copy significand to exact-sized array, with sign if
+ // negative
+ // Later use: BigInteger(coeff, first, precision) for
+ // both cases, by allowing an extra char at the front of
+ // coeff.
+ char quick[];
+ if (!isneg) {
+ quick = new char[precision];
+ System.arraycopy(coeff, first, quick, 0, precision);
+ } else {
+ quick = new char[precision+1];
+ quick[0] = '-';
+ System.arraycopy(coeff, first, quick, 1, precision);
+ }
+ if (precision <= MAX_COMPACT_DIGITS)
+ intCompact = Long.parseLong(new String(quick));
+ else
+ intVal = new BigInteger(quick);
+ // System.out.println(" new: " +intVal+" ["+scale+"] "+precision);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ throw new NumberFormatException();
+ } catch (NegativeArraySizeException e) {
+ throw new NumberFormatException();
+ }
+ }
+
+ /**
+ * Translates a character array representation of a
+ * {@code BigDecimal} into a {@code BigDecimal}, accepting the
+ * same sequence of characters as the {@link #BigDecimal(String)}
+ * constructor, while allowing a sub-array to be specified and
+ * with rounding according to the context settings.
+ *
+ * <p>Note that if the sequence of characters is already available
+ * within a character array, using this constructor is faster than
+ * converting the {@code char} array to string and using the
+ * {@code BigDecimal(String)} constructor .
+ *
+ * @param in {@code char} array that is the source of characters.
+ * @param offset first character in the array to inspect.
+ * @param len number of characters to consider..
+ * @param mc the context to use.
+ * @throws ArithmeticException if the result is inexact but the
+ * rounding mode is {@code UNNECESSARY}.
+ * @throws NumberFormatException if {@code in} is not a valid
+ * representation of a {@code BigDecimal} or the defined subarray
+ * is not wholly within {@code in}.
+ * @since 1.5
+ */
+ public BigDecimal(char[] in, int offset, int len, MathContext mc) {
+ this(in, offset, len);
+ if (mc.precision > 0)
+ roundThis(mc);
+ }
+
+ /**
+ * Translates a character array representation of a
+ * {@code BigDecimal} into a {@code BigDecimal}, accepting the
+ * same sequence of characters as the {@link #BigDecimal(String)}
+ * constructor.
+ *
+ * <p>Note that if the sequence of characters is already available
+ * as a character array, using this constructor is faster than
+ * converting the {@code char} array to string and using the
+ * {@code BigDecimal(String)} constructor .
+ *
+ * @param in {@code char} array that is the source of characters.
+ * @throws NumberFormatException if {@code in} is not a valid
+ * representation of a {@code BigDecimal}.
+ * @since 1.5
+ */
+ public BigDecimal(char[] in) {
+ this(in, 0, in.length);
+ }
+
+ /**
+ * Translates a character array representation of a
+ * {@code BigDecimal} into a {@code BigDecimal}, accepting the
+ * same sequence of characters as the {@link #BigDecimal(String)}
+ * constructor and with rounding according to the context
+ * settings.
+ *
+ * <p>Note that if the sequence of characters is already available
+ * as a character array, using this constructor is faster than
+ * converting the {@code char} array to string and using the
+ * {@code BigDecimal(String)} constructor .
+ *
+ * @param in {@code char} array that is the source of characters.
+ * @param mc the context to use.
+ * @throws ArithmeticException if the result is inexact but the
+ * rounding mode is {@code UNNECESSARY}.
+ * @throws NumberFormatException if {@code in} is not a valid
+ * representation of a {@code BigDecimal}.
+ * @since 1.5
+ */
+ public BigDecimal(char[] in, MathContext mc) {
+ this(in, 0, in.length, mc);
+ }
+
+ /**
+ * Translates the string representation of a {@code BigDecimal}
+ * into a {@code BigDecimal}. The string representation consists
+ * of an optional sign, {@code '+'} (<tt> '\u002B'</tt>) or
+ * {@code '-'} (<tt>'\u002D'</tt>), followed by a sequence of
+ * zero or more decimal digits ("the integer"), optionally
+ * followed by a fraction, optionally followed by an exponent.
+ *
+ * <p>The fraction consists of a decimal point followed by zero
+ * or more decimal digits. The string must contain at least one
+ * digit in either the integer or the fraction. The number formed
+ * by the sign, the integer and the fraction is referred to as the
+ * <i>significand</i>.
+ *
+ * <p>The exponent consists of the character {@code 'e'}
+ * (<tt>'\u0065'</tt>) or {@code 'E'} (<tt>'\u0045'</tt>)
+ * followed by one or more decimal digits. The value of the
+ * exponent must lie between -{@link Integer#MAX_VALUE} ({@link
+ * Integer#MIN_VALUE}+1) and {@link Integer#MAX_VALUE}, inclusive.
+ *
+ * <p>More formally, the strings this constructor accepts are
+ * described by the following grammar:
+ * <blockquote>
+ * <dl>
+ * <dt><i>BigDecimalString:</i>
+ * <dd><i>Sign<sub>opt</sub> Significand Exponent<sub>opt</sub></i>
+ * <p>
+ * <dt><i>Sign:</i>
+ * <dd>{@code +}
+ * <dd>{@code -}
+ * <p>
+ * <dt><i>Significand:</i>
+ * <dd><i>IntegerPart</i> {@code .} <i>FractionPart<sub>opt</sub></i>
+ * <dd>{@code .} <i>FractionPart</i>
+ * <dd><i>IntegerPart</i>
+ * <p>
+ * <dt><i>IntegerPart:
+ * <dd>Digits</i>
+ * <p>
+ * <dt><i>FractionPart:
+ * <dd>Digits</i>
+ * <p>
+ * <dt><i>Exponent:
+ * <dd>ExponentIndicator SignedInteger</i>
+ * <p>
+ * <dt><i>ExponentIndicator:</i>
+ * <dd>{@code e}
+ * <dd>{@code E}
+ * <p>
+ * <dt><i>SignedInteger:
+ * <dd>Sign<sub>opt</sub> Digits</i>
+ * <p>
+ * <dt><i>Digits:
+ * <dd>Digit
+ * <dd>Digits Digit</i>
+ * <p>
+ * <dt><i>Digit:</i>
+ * <dd>any character for which {@link Character#isDigit}
+ * returns {@code true}, including 0, 1, 2 ...
+ * </dl>
+ * </blockquote>
+ *
+ * <p>The scale of the returned {@code BigDecimal} will be the
+ * number of digits in the fraction, or zero if the string
+ * contains no decimal point, subject to adjustment for any
+ * exponent; if the string contains an exponent, the exponent is
+ * subtracted from the scale. The value of the resulting scale
+ * must lie between {@code Integer.MIN_VALUE} and
+ * {@code Integer.MAX_VALUE}, inclusive.
+ *
+ * <p>The character-to-digit mapping is provided by {@link
+ * java.lang.Character#digit} set to convert to radix 10. The
+ * String may not contain any extraneous characters (whitespace,
+ * for example).
+ *
+ * <p><b>Examples:</b><br>
+ * The value of the returned {@code BigDecimal} is equal to
+ * <i>significand</i> × 10<sup> <i>exponent</i></sup>.
+ * For each string on the left, the resulting representation
+ * [{@code BigInteger}, {@code scale}] is shown on the right.
+ * <pre>
+ * "0" [0,0]
+ * "0.00" [0,2]
+ * "123" [123,0]
+ * "-123" [-123,0]
+ * "1.23E3" [123,-1]
+ * "1.23E+3" [123,-1]
+ * "12.3E+7" [123,-6]
+ * "12.0" [120,1]
+ * "12.3" [123,1]
+ * "0.00123" [123,5]
+ * "-1.23E-12" [-123,14]
+ * "1234.5E-4" [12345,5]
+ * "0E+7" [0,-7]
+ * "-0" [0,0]
+ * </pre>
+ *
+ * <p>Note: For values other than {@code float} and
+ * {@code double} NaN and ±Infinity, this constructor is
+ * compatible with the values returned by {@link Float#toString}
+ * and {@link Double#toString}. This is generally the preferred
+ * way to convert a {@code float} or {@code double} into a
+ * BigDecimal, as it doesn't suffer from the unpredictability of
+ * the {@link #BigDecimal(double)} constructor.
+ *
+ * @param val String representation of {@code BigDecimal}.
+ *
+ * @throws NumberFormatException if {@code val} is not a valid
+ * representation of a {@code BigDecimal}.
+ */
+ public BigDecimal(String val) {
+ this(val.toCharArray(), 0, val.length());
+ }
+
+ /**
+ * Translates the string representation of a {@code BigDecimal}
+ * into a {@code BigDecimal}, accepting the same strings as the
+ * {@link #BigDecimal(String)} constructor, with rounding
+ * according to the context settings.
+ *
+ * @param val str...
[truncated message content] |
|
From: <ls...@us...> - 2007-06-25 09:50:33
|
Revision: 3306
http://jnode.svn.sourceforge.net/jnode/?rev=3306&view=rev
Author: lsantha
Date: 2007-06-25 02:32:16 -0700 (Mon, 25 Jun 2007)
Log Message:
-----------
Openjdk integration.
Added Paths:
-----------
trunk/core/src/openjdk/java/java/net/
trunk/core/src/openjdk/java/java/net/CacheRequest.java
trunk/core/src/openjdk/java/java/net/CacheResponse.java
trunk/core/src/openjdk/java/java/net/CookieHandler.java
trunk/core/src/openjdk/java/java/net/CookieManager.java
trunk/core/src/openjdk/java/java/net/CookiePolicy.java
trunk/core/src/openjdk/java/java/net/CookieStore.java
trunk/core/src/openjdk/java/java/net/HttpCookie.java
trunk/core/src/openjdk/java/java/net/HttpRetryException.java
trunk/core/src/openjdk/java/java/net/SecureCacheResponse.java
trunk/core/src/openjdk/java/java/security/AuthProvider.java
trunk/core/src/openjdk/java/java/security/KeyStore.java
trunk/core/src/openjdk/java/java/security/KeyStoreSpi.java
trunk/core/src/openjdk/java/java/security/UnrecoverableEntryException.java
trunk/core/src/openjdk/java/java/security/UnrecoverableKeyException.java
trunk/core/src/openjdk/java/java/util/LocaleISOData.java
trunk/core/src/openjdk/java/java/util/MissingResourceException.java
Added: trunk/core/src/openjdk/java/java/net/CacheRequest.java
===================================================================
--- trunk/core/src/openjdk/java/java/net/CacheRequest.java (rev 0)
+++ trunk/core/src/openjdk/java/java/net/CacheRequest.java 2007-06-25 09:32:16 UTC (rev 3306)
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.net;
+
+import java.io.OutputStream;
+import java.io.IOException;
+
+/**
+ * Represents channels for storing resources in the
+ * ResponseCache. Instances of such a class provide an
+ * OutputStream object which is called by protocol handlers to
+ * store the resource data into the cache, and also an abort() method
+ * which allows a cache store operation to be interrupted and
+ * abandoned. If an IOException is encountered while reading the
+ * response or writing to the cache, the current cache store operation
+ * will be aborted.
+ *
+ * @version 1.1, 03/09/22
+ * @author Yingxian Wang
+ * @since 1.5
+ */
+public abstract class CacheRequest {
+
+ /**
+ * Returns an OutputStream to which the response body can be
+ * written.
+ *
+ * @return an OutputStream to which the response body can
+ * be written
+ * @throws IOException if an I/O error occurs while
+ * writing the response body
+ */
+ public abstract OutputStream getBody() throws IOException;
+
+ /**
+ * Aborts the attempt to cache the response. If an IOException is
+ * encountered while reading the response or writing to the cache,
+ * the current cache store operation will be abandoned.
+ */
+ public abstract void abort();
+}
Added: trunk/core/src/openjdk/java/java/net/CacheResponse.java
===================================================================
--- trunk/core/src/openjdk/java/java/net/CacheResponse.java (rev 0)
+++ trunk/core/src/openjdk/java/java/net/CacheResponse.java 2007-06-25 09:32:16 UTC (rev 3306)
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.net;
+
+import java.io.InputStream;
+import java.util.Map;
+import java.util.List;
+import java.io.IOException;
+
+/**
+ * Represent channels for retrieving resources from the
+ * ResponseCache. Instances of such a class provide an
+ * InputStream that returns the entity body, and also a
+ * getHeaders() method which returns the associated response headers.
+ *
+ * @version 1.1, 03/09/22
+ * @author Yingxian Wang
+ * @since 1.5
+ */
+public abstract class CacheResponse {
+
+ /**
+ * Returns the response headers as a Map.
+ *
+ * @return An immutable Map from response header field names to
+ * lists of field values. The status line has null as its
+ * field name.
+ * @throws IOException if an I/O error occurs
+ * while getting the response headers
+ */
+ public abstract Map<String, List<String>> getHeaders() throws IOException;
+
+ /**
+ * Returns the response body as an InputStream.
+ *
+ * @return an InputStream from which the response body can
+ * be accessed
+ * @throws IOException if an I/O error occurs while
+ * getting the response body
+ */
+ public abstract InputStream getBody() throws IOException;
+}
Added: trunk/core/src/openjdk/java/java/net/CookieHandler.java
===================================================================
--- trunk/core/src/openjdk/java/java/net/CookieHandler.java (rev 0)
+++ trunk/core/src/openjdk/java/java/net/CookieHandler.java 2007-06-25 09:32:16 UTC (rev 3306)
@@ -0,0 +1,141 @@
+/*
+ * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.net;
+
+import java.util.Map;
+import java.util.List;
+import java.io.IOException;
+import sun.security.util.SecurityConstants;
+
+/**
+ * A CookieHandler object provides a callback mechanism to hook up a
+ * HTTP state management policy implementation into the HTTP protocol
+ * handler. The HTTP state management mechanism specifies a way to
+ * create a stateful session with HTTP requests and responses.
+ *
+ * <p>A system-wide CookieHandler that to used by the HTTP protocol
+ * handler can be registered by doing a
+ * CookieHandler.setDefault(CookieHandler). The currently registered
+ * CookieHandler can be retrieved by calling
+ * CookieHandler.getDefault().
+ *
+ * For more information on HTTP state management, see <a
+ * href="http://www.ietf.org/rfc/rfc2965.txt""><i>RFC 2965: HTTP
+ * State Management Mechanism</i></a>
+ *
+ * @version 1.4, 03/08/09
+ * @author Yingxian Wang
+ * @since 1.5
+ */
+public abstract class CookieHandler {
+ /**
+ * The system-wide cookie handler that will apply cookies to the
+ * request headers and manage cookies from the response headers.
+ *
+ * @see setDefault(CookieHandler)
+ * @see getDefault()
+ */
+ private static CookieHandler cookieHandler;
+
+ /**
+ * Gets the system-wide cookie handler.
+ *
+ * @return the system-wide cookie handler; A null return means
+ * there is no system-wide cookie handler currently set.
+ * @throws SecurityException
+ * If a security manager has been installed and it denies
+ * {@link NetPermission}<tt>("getCookieHandler")</tt>
+ * @see #setDefault(CookieHandler)
+ */
+ public synchronized static CookieHandler getDefault() {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ sm.checkPermission(SecurityConstants.GET_COOKIEHANDLER_PERMISSION);
+ }
+ return cookieHandler;
+ }
+
+ /**
+ * Sets (or unsets) the system-wide cookie handler.
+ *
+ * Note: non-standard http protocol handlers may ignore this setting.
+ *
+ * @param cHandler The HTTP cookie handler, or
+ * <code>null</code> to unset.
+ * @throws SecurityException
+ * If a security manager has been installed and it denies
+ * {@link NetPermission}<tt>("setCookieHandler")</tt>
+ * @see #getDefault()
+ */
+ public synchronized static void setDefault(CookieHandler cHandler) {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ sm.checkPermission(SecurityConstants.SET_COOKIEHANDLER_PERMISSION);
+ }
+ cookieHandler = cHandler;
+ }
+
+ /**
+ * Gets all the applicable cookies from a cookie cache for the
+ * specified uri in the request header.
+ *
+ * HTTP protocol implementers should make sure that this method is
+ * called after all request headers related to choosing cookies
+ * are added, and before the request is sent.
+ *
+ * @param uri a <code>URI</code> to send cookies to in a request
+ * @param requestHeaders - a Map from request header
+ * field names to lists of field values representing
+ * the current request headers
+ * @return an immutable map from state management headers, with
+ * field names "Cookie" or "Cookie2" to a list of
+ * cookies containing state information
+ *
+ * @throws IOException if an I/O error occurs
+ * @throws IllegalArgumentException if either argument is null
+ * @see #put(URI, Map)
+ */
+ public abstract Map<String, List<String>>
+ get(URI uri, Map<String, List<String>> requestHeaders)
+ throws IOException;
+
+ /**
+ * Sets all the applicable cookies, examples are response header
+ * fields that are named Set-Cookie2, present in the response
+ * headers into a cookie cache.
+ *
+ * @param uri a <code>URI</code> where the cookies come from
+ * @param responseHeaders an immutable map from field names to
+ * lists of field values representing the response
+ * header fields returned
+ * @throws IOException if an I/O error occurs
+ * @throws IllegalArgumentException if either argument is null
+ * @see #get(URI, Map)
+ */
+ public abstract void
+ put(URI uri, Map<String, List<String>> responseHeaders)
+ throws IOException;
+}
Added: trunk/core/src/openjdk/java/java/net/CookieManager.java
===================================================================
--- trunk/core/src/openjdk/java/java/net/CookieManager.java (rev 0)
+++ trunk/core/src/openjdk/java/java/net/CookieManager.java 2007-06-25 09:32:16 UTC (rev 3306)
@@ -0,0 +1,336 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.net;
+
+import java.util.Map;
+import java.util.List;
+import java.util.Collections;
+import java.util.Comparator;
+import java.io.IOException;
+
+/**
+ * CookieManager provides a concrete implementation of {@link CookieHandler},
+ * which separates the storage of cookies from the policy surrounding accepting
+ * and rejecting cookies. A CookieManager is initialized with a {@link CookieStore}
+ * which manages storage, and a {@link CookiePolicy} object, which makes
+ * policy decisions on cookie acceptance/rejection.
+ *
+ * <p> The HTTP cookie management in java.net package looks like:
+ * <blockquote>
+ * <pre>
+ * use
+ * CookieHandler <------- HttpURLConnection
+ * ^
+ * | impl
+ * | use
+ * CookieManager -------> CookiePolicy
+ * | use
+ * |--------> HttpCookie
+ * | ^
+ * | | use
+ * | use |
+ * |--------> CookieStore
+ * ^
+ * | impl
+ * |
+ * Internal in-memory implementation
+ * </pre>
+ * <ul>
+ * <li>
+ * CookieHandler is at the core of cookie management. User can call
+ * CookieHandler.setDefault to set a concrete CookieHanlder implementation
+ * to be used.
+ * </li>
+ * <li>
+ * CookiePolicy.shouldAccept will be called by CookieManager.put to see whether
+ * or not one cookie should be accepted and put into cookie store. User can use
+ * any of three pre-defined CookiePolicy, namely ACCEPT_ALL, ACCEPT_NONE and
+ * ACCEPT_ORIGINAL_SERVER, or user can define his own CookiePolicy implementation
+ * and tell CookieManager to use it.
+ * </li>
+ * <li>
+ * CookieStore is the place where any accepted HTTP cookie is stored in.
+ * If not specified when created, a CookieManager instance will use an internal
+ * in-memory implementation. Or user can implements one and tell CookieManager
+ * to use it.
+ * </li>
+ * <li>
+ * Currently, only CookieStore.add(URI, HttpCookie) and CookieStore.get(URI)
+ * are used by CookieManager. Others are for completeness and might be needed
+ * by a more sophisticated CookieStore implementation, e.g. a NetscapeCookieSotre.
+ * </li>
+ * </ul>
+ * </blockquote>
+ *
+ * <p>There're various ways user can hook up his own HTTP cookie management behavior, e.g.
+ * <blockquote>
+ * <ul>
+ * <li>Use CookieHandler.setDefault to set a brand new {@link CookieHandler} implementation
+ * <li>Let CookieManager be the default {@link CookieHandler} implementation,
+ * but implement user's own {@link CookieStore} and {@link CookiePolicy}
+ * and tell default CookieManager to use them:
+ * <blockquote><pre>
+ * // this should be done at the beginning of an HTTP session
+ * CookieHandler.setDefault(new CookieManager(new MyCookieStore(), new MyCookiePolicy()));
+ * </pre></blockquote>
+ * <li>Let CookieManager be the default {@link CookieHandler} implementation, but
+ * use customized {@link CookiePolicy}:
+ * <blockquote><pre>
+ * // this should be done at the beginning of an HTTP session
+ * CookieHandler.setDefault(new CookieManager());
+ * // this can be done at any point of an HTTP session
+ * ((CookieManager)CookieHandler.getDefault()).setCookiePolicy(new MyCookiePolicy());
+ * </pre></blockquote>
+ * </ul>
+ * </blockquote>
+ *
+ * <p>The implementation conforms to RFC 2965, section 3.3.
+ *
+ * @version %I%, %E%
+ * @author Edward Wang
+ * @since 1.6
+ */
+public class CookieManager extends CookieHandler
+{
+ /* ---------------- Fields -------------- */
+
+ private CookiePolicy policyCallback;
+
+
+ private CookieStore cookieJar = null;
+
+
+ /* ---------------- Ctors -------------- */
+
+ /**
+ * Create a new cookie manager.
+ *
+ * <p>This constructor will create new cookie manager with default
+ * cookie store and accept policy. The effect is same as
+ * <tt>CookieManager(null, null)</tt>.
+ */
+ public CookieManager() {
+ this(null, null);
+ }
+
+
+ /**
+ * Create a new cookie manager with specified cookie store and cookie policy.
+ *
+ * @param store a <tt>CookieStore</tt> to be used by cookie manager.
+ * if <tt>null</tt>, cookie manager will use a default one,
+ * which is an in-memory CookieStore implmentation.
+ * @param cookiePolicy a <tt>CookiePolicy</tt> instance
+ * to be used by cookie manager as policy callback.
+ * if <tt>null</tt>, ACCEPT_ORIGINAL_SERVER will
+ * be used.
+ */
+ public CookieManager(CookieStore store,
+ CookiePolicy cookiePolicy)
+ {
+ // use default cookie policy if not specify one
+ policyCallback = (cookiePolicy == null) ? CookiePolicy.ACCEPT_ORIGINAL_SERVER
+ : cookiePolicy;
+
+ // if not specify CookieStore to use, use default one
+ if (store == null) {
+ cookieJar = new sun.net.www.protocol.http.InMemoryCookieStore();
+ } else {
+ cookieJar = store;
+ }
+ }
+
+
+ /* ---------------- Public operations -------------- */
+
+ /**
+ * To set the cookie policy of this cookie manager.
+ *
+ * <p> A instance of <tt>CookieManager</tt> will have
+ * cookie policy ACCEPT_ORIGINAL_SERVER by default. Users always
+ * can call this method to set another cookie policy.
+ *
+ * @param cookiePolicy the cookie policy. Can be <tt>null</tt>, which
+ * has no effects on current cookie policy.
+ */
+ public void setCookiePolicy(CookiePolicy cookiePolicy) {
+ if (cookiePolicy != null) policyCallback = cookiePolicy;
+ }
+
+
+ /**
+ * To retrieve current cookie store.
+ *
+ * @return the cookie store currently used by cookie manager.
+ */
+ public CookieStore getCookieStore() {
+ return cookieJar;
+ }
+
+
+ public Map<String, List<String>>
+ get(URI uri, Map<String, List<String>> requestHeaders)
+ throws IOException
+ {
+ // pre-condition check
+ if (uri == null || requestHeaders == null) {
+ throw new IllegalArgumentException("Argument is null");
+ }
+
+ Map<String, List<String>> cookieMap =
+ new java.util.HashMap<String, List<String>>();
+ // if there's no default CookieStore, no way for us to get any cookie
+ if (cookieJar == null)
+ return Collections.unmodifiableMap(cookieMap);
+
+ List<HttpCookie> cookies = new java.util.ArrayList<HttpCookie>();
+ for (HttpCookie cookie : cookieJar.get(uri)) {
+ // apply path-matches rule (RFC 2965 sec. 3.3.4)
+ if (pathMatches(uri.getPath(), cookie.getPath())) {
+ cookies.add(cookie);
+ }
+ }
+
+ // apply sort rule (RFC 2965 sec. 3.3.4)
+ List<String> cookieHeader = sortByPath(cookies);
+
+ cookieMap.put("Cookie", cookieHeader);
+ return Collections.unmodifiableMap(cookieMap);
+ }
+
+
+ public void
+ put(URI uri, Map<String, List<String>> responseHeaders)
+ throws IOException
+ {
+ // pre-condition check
+ if (uri == null || responseHeaders == null) {
+ throw new IllegalArgumentException("Argument is null");
+ }
+
+
+ // if there's no default CookieStore, no need to remember any cookie
+ if (cookieJar == null)
+ return;
+
+ for (String headerKey : responseHeaders.keySet()) {
+ // RFC 2965 3.2.2, key must be 'Set-Cookie2'
+ // we also accept 'Set-Cookie' here for backward compatibility
+ if (headerKey == null
+ || !(headerKey.equalsIgnoreCase("Set-Cookie2")
+ || headerKey.equalsIgnoreCase("Set-Cookie")
+ )
+ )
+ {
+ continue;
+ }
+
+ for (String headerValue : responseHeaders.get(headerKey)) {
+ try {
+ List<HttpCookie> cookies = HttpCookie.parse(headerValue);
+ for (HttpCookie cookie : cookies) {
+ if (shouldAcceptInternal(uri, cookie)) {
+ cookieJar.add(uri, cookie);
+ }
+ }
+ } catch (IllegalArgumentException e) {
+ // invalid set-cookie header string
+ // no-op
+ }
+ }
+ }
+ }
+
+
+ /* ---------------- Private operations -------------- */
+
+ // to determine whether or not accept this cookie
+ private boolean shouldAcceptInternal(URI uri, HttpCookie cookie) {
+ try {
+ return policyCallback.shouldAccept(uri, cookie);
+ } catch (Exception ignored) { // pretect against malicious callback
+ return false;
+ }
+ }
+
+
+ /*
+ * path-matches algorithm, as defined by RFC 2965
+ */
+ private boolean pathMatches(String path, String pathToMatchWith) {
+ if (path == pathToMatchWith)
+ return true;
+ if (path == null || pathToMatchWith == null)
+ return false;
+ if (path.startsWith(pathToMatchWith))
+ return true;
+
+ return false;
+ }
+
+
+ /*
+ * sort cookies with respect to their path: those with more specific Path attributes
+ * precede those with less specific, as defined in RFC 2965 sec. 3.3.4
+ */
+ private List<String> sortByPath(List<HttpCookie> cookies) {
+ Collections.sort(cookies, new CookiePathComparator());
+
+ List<String> cookieHeader = new java.util.ArrayList<String>();
+ for (HttpCookie cookie : cookies) {
+ // Netscape cookie spec and RFC 2965 have different format of Cookie
+ // header; RFC 2965 requires a leading $Version="1" string while Netscape
+ // does not.
+ // The workaround here is to add a $Version="1" string in advance
+ if (cookies.indexOf(cookie) == 0 && cookie.getVersion() > 0) {
+ cookieHeader.add("$Version=\"1\"");
+ }
+
+ cookieHeader.add(cookie.toString());
+ }
+ return cookieHeader;
+ }
+
+
+ static class CookiePathComparator implements Comparator<HttpCookie> {
+ public int compare(HttpCookie c1, HttpCookie c2) {
+ if (c1 == c2) return 0;
+ if (c1 == null) return -1;
+ if (c2 == null) return 1;
+
+ // path rule only applies to the cookies with same name
+ if (!c1.getName().equals(c2.getName())) return 0;
+
+ // those with more specific Path attributes precede those with less specific
+ if (c1.getPath().startsWith(c2.getPath()))
+ return -1;
+ else if (c2.getPath().startsWith(c1.getPath()))
+ return 1;
+ else
+ return 0;
+ }
+ }
+}
Added: trunk/core/src/openjdk/java/java/net/CookiePolicy.java
===================================================================
--- trunk/core/src/openjdk/java/java/net/CookiePolicy.java (rev 0)
+++ trunk/core/src/openjdk/java/java/net/CookiePolicy.java 2007-06-25 09:32:16 UTC (rev 3306)
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.net;
+
+/**
+ * CookiePolicy implementations decide which cookies should be accepted
+ * and which should be rejected. Three pre-defined policy implementations
+ * are provided, namely ACCEPT_ALL, ACCEPT_NONE and ACCEPT_ORIGINAL_SERVER.
+ *
+ * <p>See RFC 2965 sec. 3.3 & 7 for more detail.
+ *
+ * @version %I%, %E%
+ * @author Edward Wang
+ * @since 1.6
+ */
+public interface CookiePolicy {
+ /**
+ * One pre-defined policy which accepts all cookies.
+ */
+ public static final CookiePolicy ACCEPT_ALL = new CookiePolicy(){
+ public boolean shouldAccept(URI uri, HttpCookie cookie) {
+ return true;
+ }
+ };
+
+ /**
+ * One pre-defined policy which accepts no cookies.
+ */
+ public static final CookiePolicy ACCEPT_NONE = new CookiePolicy(){
+ public boolean shouldAccept(URI uri, HttpCookie cookie) {
+ return false;
+ }
+ };
+
+ /**
+ * One pre-defined policy which only accepts cookies from original server.
+ */
+ public static final CookiePolicy ACCEPT_ORIGINAL_SERVER = new CookiePolicy(){
+ public boolean shouldAccept(URI uri, HttpCookie cookie) {
+ return HttpCookie.domainMatches(cookie.getDomain(), uri.getHost());
+ }
+ };
+
+
+ /**
+ * Will be called to see whether or not this cookie should be accepted.
+ *
+ * @param uri the URI to consult accept policy with
+ * @param cookie the HttpCookie object in question
+ * @return <tt>true</tt> if this cookie should be accepted;
+ * otherwise, <tt>false</tt>
+ */
+ public boolean shouldAccept(URI uri, HttpCookie cookie);
+}
+
Added: trunk/core/src/openjdk/java/java/net/CookieStore.java
===================================================================
--- trunk/core/src/openjdk/java/java/net/CookieStore.java (rev 0)
+++ trunk/core/src/openjdk/java/java/net/CookieStore.java 2007-06-25 09:32:16 UTC (rev 3306)
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE...
[truncated message content] |
|
From: <ls...@us...> - 2007-07-06 11:05:44
|
Revision: 3348
http://jnode.svn.sourceforge.net/jnode/?rev=3348&view=rev
Author: lsantha
Date: 2007-07-06 04:05:42 -0700 (Fri, 06 Jul 2007)
Log Message:
-----------
Openjdk integration.
Added Paths:
-----------
trunk/core/src/openjdk/java/java/beans/
trunk/core/src/openjdk/java/java/beans/AppletInitializer.java
trunk/core/src/openjdk/java/java/beans/BeanDescriptor.java
trunk/core/src/openjdk/java/java/beans/BeanInfo.java
trunk/core/src/openjdk/java/java/beans/Beans.java
trunk/core/src/openjdk/java/java/beans/ConstructorProperties.java
trunk/core/src/openjdk/java/java/beans/Customizer.java
trunk/core/src/openjdk/java/java/beans/DefaultPersistenceDelegate.java
trunk/core/src/openjdk/java/java/beans/DesignMode.java
trunk/core/src/openjdk/java/java/beans/Encoder.java
trunk/core/src/openjdk/java/java/beans/EventHandler.java
trunk/core/src/openjdk/java/java/beans/EventSetDescriptor.java
trunk/core/src/openjdk/java/java/beans/ExceptionListener.java
trunk/core/src/openjdk/java/java/beans/Expression.java
trunk/core/src/openjdk/java/java/beans/FeatureDescriptor.java
trunk/core/src/openjdk/java/java/beans/IndexedPropertyChangeEvent.java
trunk/core/src/openjdk/java/java/beans/IndexedPropertyDescriptor.java
trunk/core/src/openjdk/java/java/beans/IntrospectionException.java
trunk/core/src/openjdk/java/java/beans/Introspector.java
trunk/core/src/openjdk/java/java/beans/MetaData.java
trunk/core/src/openjdk/java/java/beans/MethodDescriptor.java
trunk/core/src/openjdk/java/java/beans/NameGenerator.java
trunk/core/src/openjdk/java/java/beans/ParameterDescriptor.java
trunk/core/src/openjdk/java/java/beans/PersistenceDelegate.java
trunk/core/src/openjdk/java/java/beans/PropertyChangeEvent.java
trunk/core/src/openjdk/java/java/beans/PropertyChangeListener.java
trunk/core/src/openjdk/java/java/beans/PropertyChangeListenerProxy.java
trunk/core/src/openjdk/java/java/beans/PropertyChangeSupport.java
trunk/core/src/openjdk/java/java/beans/PropertyDescriptor.java
trunk/core/src/openjdk/java/java/beans/PropertyEditor.java
trunk/core/src/openjdk/java/java/beans/PropertyEditorManager.java
trunk/core/src/openjdk/java/java/beans/PropertyEditorSupport.java
trunk/core/src/openjdk/java/java/beans/PropertyVetoException.java
trunk/core/src/openjdk/java/java/beans/ReflectionUtils.java
trunk/core/src/openjdk/java/java/beans/SimpleBeanInfo.java
trunk/core/src/openjdk/java/java/beans/Statement.java
trunk/core/src/openjdk/java/java/beans/VetoableChangeListener.java
trunk/core/src/openjdk/java/java/beans/VetoableChangeListenerProxy.java
trunk/core/src/openjdk/java/java/beans/VetoableChangeSupport.java
trunk/core/src/openjdk/java/java/beans/Visibility.java
trunk/core/src/openjdk/java/java/beans/XMLDecoder.java
trunk/core/src/openjdk/java/java/beans/XMLEncoder.java
trunk/core/src/openjdk/java/java/beans/beancontext/
trunk/core/src/openjdk/java/java/beans/beancontext/BeanContext.java
trunk/core/src/openjdk/java/java/beans/beancontext/BeanContextChild.java
trunk/core/src/openjdk/java/java/beans/beancontext/BeanContextChildComponentProxy.java
trunk/core/src/openjdk/java/java/beans/beancontext/BeanContextChildSupport.java
trunk/core/src/openjdk/java/java/beans/beancontext/BeanContextContainerProxy.java
trunk/core/src/openjdk/java/java/beans/beancontext/BeanContextEvent.java
trunk/core/src/openjdk/java/java/beans/beancontext/BeanContextMembershipEvent.java
trunk/core/src/openjdk/java/java/beans/beancontext/BeanContextMembershipListener.java
trunk/core/src/openjdk/java/java/beans/beancontext/BeanContextProxy.java
trunk/core/src/openjdk/java/java/beans/beancontext/BeanContextServiceAvailableEvent.java
trunk/core/src/openjdk/java/java/beans/beancontext/BeanContextServiceProvider.java
trunk/core/src/openjdk/java/java/beans/beancontext/BeanContextServiceProviderBeanInfo.java
trunk/core/src/openjdk/java/java/beans/beancontext/BeanContextServiceRevokedEvent.java
trunk/core/src/openjdk/java/java/beans/beancontext/BeanContextServiceRevokedListener.java
trunk/core/src/openjdk/java/java/beans/beancontext/BeanContextServices.java
trunk/core/src/openjdk/java/java/beans/beancontext/BeanContextServicesListener.java
trunk/core/src/openjdk/java/java/beans/beancontext/BeanContextServicesSupport.java
trunk/core/src/openjdk/java/java/beans/beancontext/BeanContextSupport.java
trunk/core/src/openjdk/java/java/beans/beancontext/package.html
trunk/core/src/openjdk/java/java/beans/package.html
Added: trunk/core/src/openjdk/java/java/beans/AppletInitializer.java
===================================================================
--- trunk/core/src/openjdk/java/java/beans/AppletInitializer.java (rev 0)
+++ trunk/core/src/openjdk/java/java/beans/AppletInitializer.java 2007-07-06 11:05:42 UTC (rev 3348)
@@ -0,0 +1,92 @@
+/*
+ * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.beans;
+
+import java.applet.Applet;
+
+import java.beans.beancontext.BeanContext;
+
+/**
+ * <p>
+ * This interface is designed to work in collusion with java.beans.Beans.instantiate.
+ * The interafce is intended to provide mechanism to allow the proper
+ * initialization of JavaBeans that are also Applets, during their
+ * instantiation by java.beans.Beans.instantiate().
+ * </p>
+ *
+ * @see java.beans.Beans#instantiate
+ *
+ * @version 1.19, 05/05/07
+ * @since 1.2
+ *
+ */
+
+
+public interface AppletInitializer {
+
+ /**
+ * <p>
+ * If passed to the appropriate variant of java.beans.Beans.instantiate
+ * this method will be called in order to associate the newly instantiated
+ * Applet (JavaBean) with its AppletContext, AppletStub, and Container.
+ * </p>
+ * <p>
+ * Conformant implementations shall:
+ * <ol>
+ * <li> Associate the newly instantiated Applet with the appropriate
+ * AppletContext.
+ *
+ * <li> Instantiate an AppletStub() and associate that AppletStub with
+ * the Applet via an invocation of setStub().
+ *
+ * <li> If BeanContext parameter is null, then it shall associate the
+ * Applet with its appropriate Container by adding that Applet to its
+ * Container via an invocation of add(). If the BeanContext parameter is
+ * non-null, then it is the responsibility of the BeanContext to associate
+ * the Applet with its Container during the subsequent invocation of its
+ * addChildren() method.
+ * </ol>
+ * </p>
+ *
+ * @param newAppletBean The newly instantiated JavaBean
+ * @param bCtxt The BeanContext intended for this Applet, or
+ * null.
+ */
+
+ void initialize(Applet newAppletBean, BeanContext bCtxt);
+
+ /**
+ * <p>
+ * Activate, and/or mark Applet active. Implementors of this interface
+ * shall mark this Applet as active, and optionally invoke its start()
+ * method.
+ * </p>
+ *
+ * @param newApplet The newly instantiated JavaBean
+ */
+
+ void activate(Applet newApplet);
+}
Added: trunk/core/src/openjdk/java/java/beans/BeanDescriptor.java
===================================================================
--- trunk/core/src/openjdk/java/java/beans/BeanDescriptor.java (rev 0)
+++ trunk/core/src/openjdk/java/java/beans/BeanDescriptor.java 2007-07-06 11:05:42 UTC (rev 3348)
@@ -0,0 +1,100 @@
+/*
+ * Copyright 1996-2004 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.beans;
+
+import java.lang.ref.Reference;
+
+/**
+ * A BeanDescriptor provides global information about a "bean",
+ * including its Java class, its displayName, etc.
+ * <p>
+ * This is one of the kinds of descriptor returned by a BeanInfo object,
+ * which also returns descriptors for properties, method, and events.
+ */
+
+public class BeanDescriptor extends FeatureDescriptor {
+
+ private Reference beanClassRef;
+ private Reference customizerClassRef;
+
+ /**
+ * Create a BeanDescriptor for a bean that doesn't have a customizer.
+ *
+ * @param beanClass The Class object of the Java class that implements
+ * the bean. For example sun.beans.OurButton.class.
+ */
+ public BeanDescriptor(Class<?> beanClass) {
+ this(beanClass, null);
+ }
+
+ /**
+ * Create a BeanDescriptor for a bean that has a customizer.
+ *
+ * @param beanClass The Class object of the Java class that implements
+ * the bean. For example sun.beans.OurButton.class.
+ * @param customizerClass The Class object of the Java class that implements
+ * the bean's Customizer. For example sun.beans.OurButtonCustomizer.class.
+ */
+ public BeanDescriptor(Class<?> beanClass, Class<?> customizerClass) {
+ beanClassRef = createReference(beanClass);
+ customizerClassRef = createReference(customizerClass);
+
+ String name = beanClass.getName();
+ while (name.indexOf('.') >= 0) {
+ name = name.substring(name.indexOf('.')+1);
+ }
+ setName(name);
+ }
+
+ /**
+ * Gets the bean's Class object.
+ *
+ * @return The Class object for the bean.
+ */
+ public Class<?> getBeanClass() {
+ return (Class)getObject(beanClassRef);
+ }
+
+ /**
+ * Gets the Class object for the bean's customizer.
+ *
+ * @return The Class object for the bean's customizer. This may
+ * be null if the bean doesn't have a customizer.
+ */
+ public Class<?> getCustomizerClass() {
+ return (Class)getObject(customizerClassRef);
+ }
+
+ /*
+ * Package-private dup constructor
+ * This must isolate the new object from any changes to the old object.
+ */
+ BeanDescriptor(BeanDescriptor old) {
+ super(old);
+ beanClassRef = old.beanClassRef;
+ customizerClassRef = old.customizerClassRef;
+ }
+}
Added: trunk/core/src/openjdk/java/java/beans/BeanInfo.java
===================================================================
--- trunk/core/src/openjdk/java/java/beans/BeanInfo.java (rev 0)
+++ trunk/core/src/openjdk/java/java/beans/BeanInfo.java 2007-07-06 11:05:42 UTC (rev 3348)
@@ -0,0 +1,171 @@
+/*
+ * Copyright 1996-1999 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.beans;
+
+/**
+ * A bean implementor who wishes to provide explicit information about
+ * their bean may provide a BeanInfo class that implements this BeanInfo
+ * interface and provides explicit information about the methods,
+ * properties, events, etc, of their bean.
+ * <p>
+ * A bean implementor doesn't need to provide a complete set of
+ * explicit information. You can pick and choose which information
+ * you want to provide and the rest will be obtained by automatic
+ * analysis using low-level reflection of the bean classes' methods
+ * and applying standard design patterns.
+ * <p>
+ * You get the opportunity to provide lots and lots of different
+ * information as part of the various XyZDescriptor classes. But
+ * don't panic, you only really need to provide the minimal core
+ * information required by the various constructors.
+ * <P>
+ * See also the SimpleBeanInfo class which provides a convenient
+ * "noop" base class for BeanInfo classes, which you can override
+ * for those specific places where you want to return explicit info.
+ * <P>
+ * To learn about all the behaviour of a bean see the Introspector class.
+ */
+
+public interface BeanInfo {
+
+ /**
+ * Gets the beans <code>BeanDescriptor</code>.
+ *
+ * @return A BeanDescriptor providing overall information about
+ * the bean, such as its displayName, its customizer, etc. May
+ * return null if the information should be obtained by automatic
+ * analysis.
+ */
+ BeanDescriptor getBeanDescriptor();
+
+ /**
+ * Gets the beans <code>EventSetDescriptor</code>s.
+ *
+ * @return An array of EventSetDescriptors describing the kinds of
+ * events fired by this bean. May return null if the information
+ * should be obtained by automatic analysis.
+ */
+ EventSetDescriptor[] getEventSetDescriptors();
+
+ /**
+ * A bean may have a "default" event that is the event that will
+ * mostly commonly be used by humans when using the bean.
+ * @return Index of default event in the EventSetDescriptor array
+ * returned by getEventSetDescriptors.
+ * <P> Returns -1 if there is no default event.
+ */
+ int getDefaultEventIndex();
+
+ /**
+ * Gets the beans <code>PropertyDescriptor</code>s.
+ *
+ * @return An array of PropertyDescriptors describing the editable
+ * properties supported by this bean. May return null if the
+ * information should be obtained by automatic analysis.
+ * <p>
+ * If a property is indexed, then its entry in the result array will
+ * belong to the IndexedPropertyDescriptor subclass of PropertyDescriptor.
+ * A client of getPropertyDescriptors can use "instanceof" to check
+ * if a given PropertyDescriptor is an IndexedPropertyDescriptor.
+ */
+ PropertyDescriptor[] getPropertyDescriptors();
+
+ /**
+ * A bean may have a "default" property that is the property that will
+ * mostly commonly be initially chosen for update by human's who are
+ * customizing the bean.
+ * @return Index of default property in the PropertyDescriptor array
+ * returned by getPropertyDescriptors.
+ * <P> Returns -1 if there is no default property.
+ */
+ int getDefaultPropertyIndex();
+
+ /**
+ * Gets the beans <code>MethodDescriptor</code>s.
+ *
+ * @return An array of MethodDescriptors describing the externally
+ * visible methods supported by this bean. May return null if
+ * the information should be obtained by automatic analysis.
+ */
+ MethodDescriptor[] getMethodDescriptors();
+
+ /**
+ * This method allows a BeanInfo object to return an arbitrary collection
+ * of other BeanInfo objects that provide additional information on the
+ * current bean.
+ * <P>
+ * If there are conflicts or overlaps between the information provided
+ * by different BeanInfo objects, then the current BeanInfo takes precedence
+ * over the getAdditionalBeanInfo objects, and later elements in the array
+ * take precedence over earlier ones.
+ *
+ * @return an array of BeanInfo objects. May return null.
+ */
+ BeanInfo[] getAdditionalBeanInfo();
+
+ /**
+ * This method returns an image object that can be used to
+ * represent the bean in toolboxes, toolbars, etc. Icon images
+ * will typically be GIFs, but may in future include other formats.
+ * <p>
+ * Beans aren't required to provide icons and may return null from
+ * this method.
+ * <p>
+ * There are four possible flavors of icons (16x16 color,
+ * 32x32 color, 16x16 mono, 32x32 mono). If a bean choses to only
+ * support a single icon we recommend supporting 16x16 color.
+ * <p>
+ * We recommend that icons have a "transparent" background
+ * so they can be rendered onto an existing background.
+ *
+ * @param iconKind The kind of icon requested. This should be
+ * one of the constant values ICON_COLOR_16x16, ICON_COLOR_32x32,
+ * ICON_MONO_16x16, or ICON_MONO_32x32.
+ * @return An image object representing the requested icon. May
+ * return null if no suitable icon is available.
+ */
+ java.awt.Image getIcon(int iconKind);
+
+ /**
+ * Constant to indicate a 16 x 16 color icon.
+ */
+ final static int ICON_COLOR_16x16 = 1;
+
+ /**
+ * Constant to indicate a 32 x 32 color icon.
+ */
+ final static int ICON_COLOR_32x32 = 2;
+
+ /**
+ * Constant to indicate a 16 x 16 monochrome icon.
+ */
+ final static int ICON_MONO_16x16 = 3;
+
+ /**
+ * Constant to indicate a 32 x 32 monochrome icon.
+ */
+ final static int ICON_MONO_32x32 = 4;
+}
Added: trunk/core/src/openjdk/java/java/beans/Beans.java
===================================================================
--- trunk/core/src/openjdk/java/java/beans/Beans.java (rev 0)
+++ trunk/core/src/openjdk/java/java/beans/Beans.java 2007-07-06 11:05:42 UTC (rev 3348)
@@ -0,0 +1,627 @@
+/*
+ * Copyright 1996-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.beans;
+
+import com.sun.beans.finder.ClassFinder;
+
+import java.applet.*;
+
+import java.awt.*;
+
+import java.beans.AppletInitializer;
+
+import java.beans.beancontext.BeanContext;
+
+import java.io.*;
+
+import java.lang.reflect.Constructor;
+
+import java.net.URL;
+import java.lang.reflect.Array;
+
+/**
+ * This class provides some general purpose beans control methods.
+ */
+
+public class Beans {
+
+ /**
+ * <p>
+ * Instantiate a JavaBean.
+ * </p>
+ *
+ * @param cls the class-loader from which we should create
+ * the bean. If this is null, then the system
+ * class-loader is used.
+ * @param beanName the name of the bean within the class-loader.
+ * For example "sun.beanbox.foobah"
+ *
+ * @exception java.lang.ClassNotFoundException if the class of a serialized
+ * object could not be found.
+ * @exception java.io.IOException if an I/O error occurs.
+ */
+
+ public static Object instantiate(ClassLoader cls, String beanName) throws java.io.IOException, ClassNotFoundException {
+ return Beans.instantiate(cls, beanName, null, null);
+ }
+
+ /**
+ * <p>
+ * Instantiate a JavaBean.
+ * </p>
+ *
+ * @param cls the class-loader from which we should create
+ * the bean. If this is null, then the system
+ * class-loader is used.
+ * @param beanName the name of the bean within the class-loader.
+ * For example "sun.beanbox.foobah"
+ * @param beanContext The BeanContext in which to nest the new bean
+ *
+ * @exception java.lang.ClassNotFoundException if the class of a serialized
+ * object could not be found.
+ * @exception java.io.IOException if an I/O error occurs.
+ */
+
+ public static Object instantiate(ClassLoader cls, String beanName, BeanContext beanContext) throws java.io.IOException, ClassNotFoundException {
+ return Beans.instantiate(cls, beanName, beanContext, null);
+ }
+
+ /**
+ * Instantiate a bean.
+ * <p>
+ * The bean is created based on a name relative to a class-loader.
+ * This name should be a dot-separated name such as "a.b.c".
+ * <p>
+ * In Beans 1.0 the given name can indicate either a serialized object
+ * or a class. Other mechanisms may be added in the future. In
+ * beans 1.0 we first try to treat the beanName as a serialized object
+ * name then as a class name.
+ * <p>
+ * When using the beanName as a serialized object name we convert the
+ * given beanName to a resource pathname and add a trailing ".ser" suffix.
+ * We then try to load a serialized object from that resource.
+ * <p>
+ * For example, given a beanName of "x.y", Beans.instantiate would first
+ * try to read a serialized object from the resource "x/y.ser" and if
+ * that failed it would try to load the class "x.y" and create an
+ * instance of that class.
+ * <p>
+ * If the bean is a subtype of java.applet.Applet, then it is given
+ * some special initialization. First, it is supplied with a default
+ * AppletStub and AppletContext. Second, if it was instantiated from
+ * a classname the applet's "init" method is called. (If the bean was
+ * deserialized this step is skipped.)
+ * <p>
+ * Note that for beans which are applets, it is the caller's responsiblity
+ * to call "start" on the applet. For correct behaviour, this should be done
+ * after the applet has been added into a visible AWT container.
+ * <p>
+ * Note that applets created via beans.instantiate run in a slightly
+ * different environment than applets running inside browsers. In
+ * particular, bean applets have no access to "parameters", so they may
+ * wish to provide property get/set methods to set parameter values. We
+ * advise bean-applet developers to test their bean-applets against both
+ * the JDK appletviewer (for a reference browser environment) and the
+ * BDK BeanBox (for a reference bean container).
+ *
+ * @param cls the class-loader from which we should create
+ * the bean. If this is null, then the system
+ * class-loader is used.
+ * @param beanName the name of the bean within the class-loader.
+ * For example "sun.beanbox.foobah"
+ * @param beanContext The BeanContext in which to nest the new bean
+ * @param initializer The AppletInitializer for the new bean
+ *
+ * @exception java.lang.ClassNotFoundException if the class of a serialized
+ * object could not be found.
+ * @exception java.io.IOException if an I/O error occurs.
+ */
+
+ public static Object instantiate(ClassLoader cls, String beanName, BeanContext beanContext, AppletInitializer initializer)
+ throws java.io.IOException, ClassNotFoundException {
+
+ java.io.InputStream ins;
+ java.io.ObjectInputStream oins = null;
+ Object result = null;
+ boolean serialized = false;
+ java.io.IOException serex = null;
+
+ // If the given classloader is null, we check if an
+ // system classloader is available and (if so)
+ // use that instead.
+ // Note that calls on the system class loader will
+ // look in the bootstrap class loader first.
+ if (cls == null) {
+ try {
+ cls = ClassLoader.getSystemClassLoader();
+ } catch (SecurityException ex) {
+ // We're not allowed to access the system class loader.
+ // Drop through.
+ }
+ }
+
+ // Try to find a serialized object with this name
+ final String serName = beanName.replace('.','/').concat(".ser");
+ final ClassLoader loader = cls;
+ ins = (InputStream)java.security.AccessController.doPrivileged
+ (new java.security.PrivilegedAction() {
+ public Object run() {
+ if (loader == null)
+ return ClassLoader.getSystemResourceAsStream(serName);
+ else
+ return loader.getResourceAsStream(serName);
+ }
+ });
+ if (ins != null) {
+ try {
+ if (cls == null) {
+ oins = new ObjectInputStream(ins);
+ } else {
+ oins = new ObjectInputStreamWithLoader(ins, cls);
+ }
+ result = oins.readObject();
+ serialized = true;
+ oins.close();
+ } catch (java.io.IOException ex) {
+ ins.close();
+ // Drop through and try opening the class. But remember
+ // the exception in case we can't find the class either.
+ serex = ex;
+ } catch (ClassNotFoundException ex) {
+ ins.close();
+ throw ex;
+ }
+ }
+
+ if (result == null) {
+ // No serialized object, try just instantiating the class
+ Class cl;
+
+ try {
+ cl = ClassFinder.findClass(beanName, cls);
+ } catch (ClassNotFoundException ex) {
+ // There is no appropriate class. If we earlier tried to
+ // deserialize an object and got an IO exception, throw that,
+ // otherwise rethrow the ClassNotFoundException.
+ if (serex != null) {
+ throw serex;
+ }
+ throw ex;
+ }
+
+ /*
+ * Try to instantiate the class.
+ */
+
+ try {
+ result = cl.newInstance();
+ } catch (Exception ex) {
+ // We have to remap the exception to one in our signature.
+ // But we pass extra information in the detail message.
+ throw new ClassNotFoundException("" + cl + " : " + ex, ex);
+ }
+ }
+
+ if (result != null) {
+
+ // Ok, if the result is an applet initialize it.
+
+ AppletStub stub = null;
+
+ if (result instanceof Applet) {
+ Applet applet = (Applet) result;
+ boolean needDummies = initializer == null;
+
+ if (needDummies) {
+
+ // Figure our the codebase and docbase URLs. We do this
+ // by locating the URL for a known resource, and then
+ // massaging the URL.
+
+ // First find the "resource name" corresponding to the bean
+ // itself. So a serialzied bean "a.b.c" would imply a
+ // resource name of "a/b/c.ser" and a classname of "x.y"
+ // would imply a resource name of "x/y.class".
+
+ final String resourceName;
+
+ if (serialized) {
+ // Serialized bean
+ resourceName = beanName.replace('.','/').concat(".ser");
+ } else {
+ // Regular class
+ resourceName = beanName.replace('.','/').concat(".class");
+ }
+
+ URL objectUrl = null;
+ URL codeBase = null;
+ URL docBase = null;
+
+ // Now get the URL correponding to the resource name.
+
+ final ClassLoader cloader = cls;
+ objectUrl = (URL)
+ java.security.AccessController.doPrivileged
+ (new java.security.PrivilegedAction() {
+ public Object run() {
+ if (cloader == null)
+ return ClassLoader.getSystemResource
+ (resourceName);
+ else
+ return cloader.getResource(resourceName);
+ }
+ });
+
+ // If we found a URL, we try to locate the docbase by taking
+ // of the final path name co...
[truncated message content] |