You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2005/12/01 07:04:00 UTC
svn commit: r350181 [105/198] - in
/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core: ./ depends/
depends/files/ depends/jars/ depends/libs/ depends/libs/linux.IA32/
depends/libs/win.IA32/ depends/oss/ depends/oss/linux.IA32/
depends/oss/win....
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Long.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Long.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Long.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Long.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,521 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * Integers are objects (i.e. non-base types) which represent long values.
+ */
+public final class Long extends Number implements Comparable {
+
+ static final long serialVersionUID = 4290774380558885855L;
+
+ /**
+ * The value which the receiver represents.
+ */
+ final long value;
+
+ /**
+ * Most positive and most negative possible long values.
+ */
+ public static final long MAX_VALUE = 0x7FFFFFFFFFFFFFFFl;
+
+ public static final long MIN_VALUE = 0x8000000000000000l;
+
+ /**
+ * The java.lang.Class that represents this class.
+ */
+ public static final Class TYPE = new long[0].getClass().getComponentType();
+
+ // Note: This can't be set to "long.class", since *that* is
+ // defined to be "java.lang.Long.TYPE";
+
+ /**
+ * Constructs a new instance of the receiver which represents the int valued
+ * argument.
+ *
+ * @param value
+ * the long to store in the new instance.
+ */
+ public Long(long value) {
+ this.value = value;
+ }
+
+ /**
+ * Constructs a new instance of this class given a string.
+ *
+ * @param string
+ * a string representation of an long quantity.
+ * @exception NumberFormatException
+ * if the argument could not be parsed as a long quantity.
+ */
+ public Long(String string) throws NumberFormatException {
+ this(parseLong(string));
+ }
+
+ /**
+ * Answers the byte value which the receiver represents
+ *
+ * @return byte the value of the receiver.
+ */
+ public byte byteValue() {
+ return (byte) value;
+ }
+
+ public int compareTo(Long object) {
+ return value > object.value ? 1 : (value < object.value ? -1 : 0);
+ }
+
+ public int compareTo(Object object) {
+ return compareTo((Long) object);
+ }
+
+ /**
+ * Parses the string argument as if it was a long value and returns the
+ * result. Throws NumberFormatException if the string does not represent a
+ * long quantity. The string may be a hexadecimal ("0x..."), octal ("0..."),
+ * or decimal ("...") representation of a long.
+ *
+ * @param string
+ * a string representation of an int quantity.
+ * @return Long the value represented by the argument
+ * @exception NumberFormatException
+ * if the argument could not be parsed as an int quantity.
+ */
+ public static Long decode(String string) throws NumberFormatException {
+ int length = string.length(), i = 0;
+ if (length == 0)
+ throw new NumberFormatException();
+ char firstDigit = string.charAt(i);
+ boolean negative = firstDigit == '-';
+ if (negative) {
+ if (length == 1)
+ throw new NumberFormatException(string);
+ firstDigit = string.charAt(++i);
+ }
+
+ int base = 10;
+ if (firstDigit == '0') {
+ if (++i == length)
+ return new Long(0L);
+ if ((firstDigit = string.charAt(i)) == 'x' || firstDigit == 'X') {
+ if (i == length)
+ throw new NumberFormatException(string);
+ i++;
+ base = 16;
+ } else {
+ base = 8;
+ }
+ } else if (firstDigit == '#') {
+ if (i == length)
+ throw new NumberFormatException(string);
+ i++;
+ base = 16;
+ }
+
+ long result = parse(string, i, base, negative);
+ return new Long(result);
+ }
+
+ /**
+ * Answers the double value which the receiver represents
+ *
+ * @return double the value of the receiver.
+ */
+ public double doubleValue() {
+ return value;
+ }
+
+ /**
+ * Compares the argument to the receiver, and answers true if they represent
+ * the <em>same</em> object using a class specific comparison.
+ * <p>
+ * In this case, the argument must also be an Long, and the receiver and
+ * argument must represent the same long value.
+ *
+ * @param o
+ * the object to compare with this object
+ * @return <code>true</code> if the object is the same as this object
+ * <code>false</code> if it is different from this object
+ * @see #hashCode
+ */
+ public boolean equals(Object o) {
+ return (o == this) || (o instanceof Long)
+ && (value == ((Long) o).value);
+ }
+
+ /**
+ * Answers the float value which the receiver represents
+ *
+ * @return float the value of the receiver.
+ */
+ public float floatValue() {
+ return value;
+ }
+
+ /**
+ * Answers a Long representing the long value of the property named by the
+ * argument. If the property could not be found, or its value could not be
+ * parsed as a long, answer null.
+ *
+ * @param string
+ * The name of the desired integer property.
+ * @return Long A Long representing the value of the property.
+ */
+ public static Long getLong(String string) {
+ if (string == null || string.length() == 0)
+ return null;
+ String prop = System.getProperty(string);
+ if (prop == null)
+ return null;
+ try {
+ return decode(prop);
+ } catch (NumberFormatException ex) {
+ return null;
+ }
+ }
+
+ /**
+ * Answers a Long representing the long value of the property named by the
+ * argument. If the property could not be found, or its value could not be
+ * parsed as a long, answer a Long reperesenting the second argument.
+ *
+ * @param string
+ * The name of the desired long property.
+ * @return Long An Long representing the value of the property.
+ */
+ public static Long getLong(String string, long defaultValue) {
+ if (string == null || string.length() == 0)
+ return new Long(defaultValue);
+ String prop = System.getProperty(string);
+ if (prop == null)
+ return new Long(defaultValue);
+ try {
+ return decode(prop);
+ } catch (NumberFormatException ex) {
+ return new Long(defaultValue);
+ }
+ }
+
+ /**
+ * Answers an Long representing the long value of the property named by the
+ * argument. If the property could not be found, or its value could not be
+ * parsed as an long, answer the second argument.
+ *
+ * @param string
+ * The name of the desired long property.
+ * @return Long An Long representing the value of the property.
+ */
+ public static Long getLong(String string, Long defaultValue) {
+ if (string == null || string.length() == 0)
+ return defaultValue;
+ String prop = System.getProperty(string);
+ if (prop == null)
+ return defaultValue;
+ try {
+ return decode(prop);
+ } catch (NumberFormatException ex) {
+ return defaultValue;
+ }
+ }
+
+ /**
+ * Answers an integer hash code for the receiver. Any two objects which
+ * answer <code>true</code> when passed to <code>equals</code> must
+ * answer the same value for this method.
+ *
+ * @return the receiver's hash
+ *
+ * @see #equals
+ */
+ public int hashCode() {
+ return (int) (value ^ (value >>> 32));
+ }
+
+ /**
+ * Answers the int value which the receiver represents
+ *
+ * @return int the value of the receiver.
+ */
+ public int intValue() {
+ return (int) value;
+ }
+
+ /**
+ * Answers the long value which the receiver represents
+ *
+ * @return long the value of the receiver.
+ */
+ public long longValue() {
+ return value;
+ }
+
+ /**
+ * Parses the string argument as if it was a long value and returns the
+ * result. Throws NumberFormatException if the string does not represent a
+ * long quantity.
+ *
+ * @param string
+ * a string representation of a long quantity.
+ * @return long the value represented by the argument
+ * @exception NumberFormatException
+ * if the argument could not be parsed as a long quantity.
+ */
+ public static long parseLong(String string) throws NumberFormatException {
+ return parseLong(string, 10);
+ }
+
+ /**
+ * Parses the string argument as if it was an long value and returns the
+ * result. Throws NumberFormatException if the string does not represent an
+ * long quantity. The second argument specifies the radix to use when
+ * parsing the value.
+ *
+ * @param string
+ * a string representation of an long quantity.
+ * @param radix
+ * the base to use for conversion.
+ * @return long the value represented by the argument
+ * @exception NumberFormatException
+ * if the argument could not be parsed as an long quantity.
+ */
+ public static long parseLong(String string, int radix)
+ throws NumberFormatException {
+ if (string == null || radix < Character.MIN_RADIX
+ || radix > Character.MAX_RADIX)
+ throw new NumberFormatException();
+ int length = string.length(), i = 0;
+ if (length == 0)
+ throw new NumberFormatException(string);
+ boolean negative = string.charAt(i) == '-';
+ if (negative && ++i == length)
+ throw new NumberFormatException(string);
+
+ return parse(string, i, radix, negative);
+ }
+
+ private static long parse(String string, int offset, int radix,
+ boolean negative) {
+ long max = Long.MIN_VALUE / radix;
+ long result = 0, length = string.length();
+ while (offset < length) {
+ int digit = Character.digit(string.charAt(offset++), radix);
+ if (digit == -1)
+ throw new NumberFormatException(string);
+ if (max > result)
+ throw new NumberFormatException(string);
+ long next = result * radix - digit;
+ if (next > result)
+ throw new NumberFormatException(string);
+ result = next;
+ }
+ if (!negative) {
+ result = -result;
+ if (result < 0)
+ throw new NumberFormatException(string);
+ }
+ return result;
+ }
+
+ /**
+ * Answers the short value which the receiver represents
+ *
+ * @return short the value of the receiver.
+ */
+ public short shortValue() {
+ return (short) value;
+ }
+
+ /**
+ * Answers a string containing '0' and '1' characters which describe the
+ * binary representation of the argument.
+ *
+ * @param l
+ * a long to get the binary representation of
+ * @return String the binary representation of the argument
+ */
+ public static String toBinaryString(long l) {
+ int count = 1;
+ long j = l;
+
+ if (l < 0)
+ count = 64;
+ else
+ while ((j >>= 1) != 0)
+ count++;
+
+ char[] buffer = new char[count];
+ do {
+ buffer[--count] = (char) ((l & 1) + '0');
+ l >>= 1;
+ } while (count > 0);
+ return new String(0, buffer.length, buffer);
+ }
+
+ /**
+ * Answers a string containing characters in the range 0..7, a..f which
+ * describe the hexadecimal representation of the argument.
+ *
+ * @param l
+ * a long to get the hex representation of
+ * @return String the hex representation of the argument
+ */
+ public static String toHexString(long l) {
+ int count = 1;
+ long j = l;
+
+ if (l < 0)
+ count = 16;
+ else
+ while ((j >>= 4) != 0)
+ count++;
+
+ char[] buffer = new char[count];
+ do {
+ int t = (int) (l & 15);
+ if (t > 9)
+ t = t - 10 + 'a';
+ else
+ t += '0';
+ buffer[--count] = (char) t;
+ l >>= 4;
+ } while (count > 0);
+ return new String(0, buffer.length, buffer);
+ }
+
+ /**
+ * Answers a string containing characters in the range 0..7 which describe
+ * the octal representation of the argument.
+ *
+ * @param l
+ * a long to get the octal representation of
+ * @return String the octal representation of the argument
+ */
+ public static String toOctalString(long l) {
+ int count = 1;
+ long j = l;
+
+ if (l < 0)
+ count = 22;
+ else
+ while ((j >>>= 3) != 0)
+ count++;
+
+ char[] buffer = new char[count];
+ do {
+ buffer[--count] = (char) ((l & 7) + '0');
+ l >>>= 3;
+ } while (count > 0);
+ return new String(0, buffer.length, buffer);
+ }
+
+ /**
+ * Answers a string containing a concise, human-readable description of the
+ * receiver.
+ *
+ * @return a printable representation for the receiver.
+ */
+ public String toString() {
+ return Long.toString(value);
+ }
+
+ /**
+ * Answers a string containing characters in the range 0..9 which describe
+ * the decimal representation of the argument.
+ *
+ * @param l
+ * a long to get the representation of
+ * @return String the representation of the argument
+ */
+ public static String toString(long l) {
+ return toString(l, 10);
+ }
+
+ /**
+ * Answers a string containing characters in the range 0..9, a..z (depending
+ * on the radix) which describe the representation of the argument in that
+ * radix.
+ *
+ * @param l
+ * a long to get the representation of
+ * @param radix
+ * the base to use for conversion.
+ * @return String the representation of the argument
+ */
+ public static String toString(long l, int radix) {
+ if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
+ radix = 10;
+ if (l == 0)
+ return "0";
+
+ int count = 2;
+ long j = l;
+ boolean negative = l < 0;
+ if (!negative) {
+ count = 1;
+ j = -l;
+ }
+ while ((l /= radix) != 0)
+ count++;
+
+ char[] buffer = new char[count];
+ do {
+ int ch = 0 - (int) (j % radix);
+ if (ch > 9)
+ ch = ch - 10 + 'a';
+ else
+ ch += '0';
+ buffer[--count] = (char) ch;
+ } while ((j /= radix) != 0);
+ if (negative)
+ buffer[0] = '-';
+ return new String(0, buffer.length, buffer);
+ }
+
+ /**
+ * Parses the string argument as if it was an long value and returns the
+ * result. Throws NumberFormatException if the string does not represent an
+ * long quantity.
+ *
+ * @param string
+ * a string representation of an long quantity.
+ * @return Long the value represented by the argument
+ * @exception NumberFormatException
+ * if the argument could not be parsed as an long quantity.
+ */
+ public static Long valueOf(String string) throws NumberFormatException {
+ return new Long(parseLong(string));
+ }
+
+ /**
+ * Parses the string argument as if it was an long value and returns the
+ * result. Throws NumberFormatException if the string does not represent an
+ * long quantity. The second argument specifies the radix to use when
+ * parsing the value.
+ *
+ * @param string
+ * a string representation of an long quantity.
+ * @param radix
+ * the base to use for conversion.
+ * @return Long the value represented by the argument
+ * @exception NumberFormatException
+ * if the argument could not be parsed as an long quantity.
+ */
+ public static Long valueOf(String string, int radix)
+ throws NumberFormatException {
+ return new Long(parseLong(string, radix));
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Math.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Math.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Math.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Math.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,461 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * Class math provides various floating point support routines and some standard
+ * constants.
+ */
+public final class Math {
+
+ /**
+ * Standard math constants.
+ */
+ public static final double E = 2.718281828459045;
+
+ public static final double PI = 3.141592653589793;
+
+ private static java.util.Random random;
+
+ /**
+ * Prevents this class from being instantiated.
+ */
+ private Math() {
+ }
+
+ /**
+ * Answers the absolute value of the argument.
+ *
+ * @param d
+ * the value to be converted
+ * @return the argument if it is positive, otherwise the negation of the
+ * argument.
+ */
+ public static double abs(double d) {
+ long bits = Double.doubleToLongBits(d);
+ bits &= 0x7fffffffffffffffL;
+ return Double.longBitsToDouble(bits);
+ }
+
+ /**
+ * Answers the absolute value of the argument.
+ *
+ * @param f
+ * the value to be converted
+ * @return the argument if it is positive, otherwise the negation of the
+ * argument.
+ */
+ public static float abs(float f) {
+ int bits = Float.floatToIntBits(f);
+ bits &= 0x7fffffff;
+ return Float.intBitsToFloat(bits);
+ }
+
+ /**
+ * Answers the absolute value of the argument.
+ *
+ * @param i
+ * the value to be converted
+ * @return the argument if it is positive, otherwise the negation of the
+ * argument.
+ */
+ public static int abs(int i) {
+ return i >= 0 ? i : -i;
+ }
+
+ /**
+ * Answers the absolute value of the argument.
+ *
+ * @param l
+ * the value to be converted
+ * @return the argument if it is positive, otherwise the negation of the
+ * argument.
+ */
+ public static long abs(long l) {
+ return l >= 0 ? l : -l;
+ }
+
+ /**
+ * Answers the closest double approximation of the arc cosine of the
+ * argument
+ *
+ * @param d
+ * the value to compute acos of
+ * @return the arc cosine of the argument.
+ */
+ public static native double acos(double d);
+
+ /**
+ * Answers the closest double approximation of the arc sine of the argument
+ *
+ * @param d
+ * the value to compute asin of
+ * @return the arc sine of the argument.
+ */
+ public static native double asin(double d);
+
+ /**
+ * Answers the closest double approximation of the arc tangent of the
+ * argument
+ *
+ * @param d
+ * the value to compute atan of
+ * @return the arc tangent of the argument.
+ */
+ public static native double atan(double d);
+
+ /**
+ * Answers the closest double approximation of the arc tangent of the result
+ * of dividing the first argument by the second argument.
+ *
+ * @param d1
+ * the numerator of the value to compute atan of
+ * @param d2
+ * the denominator of the value to compute atan of
+ * @return the arc tangent of d1/d2.
+ */
+ public static native double atan2(double d1, double d2);
+
+ /**
+ * Answers the double conversion of the most negative (i.e. closest to
+ * negative infinity) integer value which is greater than the argument.
+ *
+ * @param d
+ * the value to be converted
+ * @return the ceiling of the argument.
+ */
+ public static native double ceil(double d);
+
+ /**
+ * Answers the closest double approximation of the cosine of the argument
+ *
+ * @param d
+ * the value to compute cos of
+ * @return the cosine of the argument.
+ */
+ public static native double cos(double d);
+
+ /**
+ * Answers the closest double approximation of the raising "e" to the power
+ * of the argument
+ *
+ * @param d
+ * the value to compute the exponential of
+ * @return the exponential of the argument.
+ */
+ public static native double exp(double d);
+
+ /**
+ * Answers the double conversion of the most positive (i.e. closest to
+ * positive infinity) integer value which is less than the argument.
+ *
+ * @param d
+ * the value to be converted
+ * @return the ceiling of the argument.
+ */
+ public static native double floor(double d);
+
+ /**
+ * Answers the remainder of dividing the first argument by the second using
+ * the IEEE 754 rules.
+ *
+ * @param d1
+ * the numerator of the operation
+ * @param d2
+ * the denominator of the operation
+ * @return the result of d1/d2.
+ */
+ public static native double IEEEremainder(double d1, double d2);
+
+ /**
+ * Answers the closest double approximation of the natural logarithm of the
+ * argument
+ *
+ * @param d
+ * the value to compute the log of
+ * @return the natural logarithm of the argument.
+ */
+ public static native double log(double d);
+
+ /**
+ * Answers the most positive (i.e. closest to positive infinity) of the two
+ * arguments.
+ *
+ * @param d1
+ * the first argument to check
+ * @param d2
+ * the second argument
+ * @return the larger of d1 and d2.
+ */
+ public static double max(double d1, double d2) {
+ if (d1 > d2)
+ return d1;
+ if (d1 < d2)
+ return d2;
+ /* if either arg is NaN, return NaN */
+ if (d1 != d2)
+ return Double.NaN;
+ /* max( +0.0,-0.0) == +0.0 */
+ if (d1 == 0.0
+ && ((Double.doubleToLongBits(d1) & Double.doubleToLongBits(d2)) & 0x8000000000000000L) == 0)
+ return 0.0;
+ return d1;
+ }
+
+ /**
+ * Answers the most positive (i.e. closest to positive infinity) of the two
+ * arguments.
+ *
+ * @param f1
+ * the first argument to check
+ * @param f2
+ * the second argument
+ * @return the larger of f1 and f2.
+ */
+ public static float max(float f1, float f2) {
+ if (f1 > f2)
+ return f1;
+ if (f1 < f2)
+ return f2;
+ /* if either arg is NaN, return NaN */
+ if (f1 != f2)
+ return Float.NaN;
+ /* max( +0.0,-0.0) == +0.0 */
+ if (f1 == 0.0f
+ && ((Float.floatToIntBits(f1) & Float.floatToIntBits(f2)) & 0x80000000) == 0)
+ return 0.0f;
+ return f1;
+ }
+
+ /**
+ * Answers the most positive (i.e. closest to positive infinity) of the two
+ * arguments.
+ *
+ * @param i1
+ * the first argument to check
+ * @param i2
+ * the second argument
+ * @return the larger of i1 and i2.
+ */
+ public static int max(int i1, int i2) {
+ return i1 > i2 ? i1 : i2;
+ }
+
+ /**
+ * Answers the most positive (i.e. closest to positive infinity) of the two
+ * arguments.
+ *
+ * @param l1
+ * the first argument to check
+ * @param l2
+ * the second argument
+ * @return the larger of l1 and l2.
+ */
+ public static long max(long l1, long l2) {
+ return l1 > l2 ? l1 : l2;
+ }
+
+ /**
+ * Answers the most negative (i.e. closest to negative infinity) of the two
+ * arguments.
+ *
+ * @param d1
+ * the first argument to check
+ * @param d2
+ * the second argument
+ * @return the smaller of d1 and d2.
+ */
+ public static double min(double d1, double d2) {
+ if (d1 > d2)
+ return d2;
+ if (d1 < d2)
+ return d1;
+ /* if either arg is NaN, return NaN */
+ if (d1 != d2)
+ return Double.NaN;
+ /* min( +0.0,-0.0) == -0.0 */
+ if (d1 == 0.0
+ && ((Double.doubleToLongBits(d1) | Double.doubleToLongBits(d2)) & 0x8000000000000000l) != 0)
+ return 0.0 * (-1.0);
+ return d1;
+ }
+
+ /**
+ * Answers the most negative (i.e. closest to negative infinity) of the two
+ * arguments.
+ *
+ * @param f1
+ * the first argument to check
+ * @param f2
+ * the second argument
+ * @return the smaller of f1 and f2.
+ */
+ public static float min(float f1, float f2) {
+ if (f1 > f2)
+ return f2;
+ if (f1 < f2)
+ return f1;
+ /* if either arg is NaN, return NaN */
+ if (f1 != f2)
+ return Float.NaN;
+ /* min( +0.0,-0.0) == -0.0 */
+ if (f1 == 0.0f
+ && ((Float.floatToIntBits(f1) | Float.floatToIntBits(f2)) & 0x80000000) != 0)
+ return 0.0f * (-1.0f);
+ return f1;
+ }
+
+ /**
+ * Answers the most negative (i.e. closest to negative infinity) of the two
+ * arguments.
+ *
+ * @param i1
+ * the first argument to check
+ * @param i2
+ * the second argument
+ * @return the smaller of i1 and i2.
+ */
+ public static int min(int i1, int i2) {
+ return i1 < i2 ? i1 : i2;
+ }
+
+ /**
+ * Answers the most negative (i.e. closest to negative infinity) of the two
+ * arguments.
+ *
+ * @param l1
+ * the first argument to check
+ * @param l2
+ * the second argument
+ * @return the smaller of l1 and l2.
+ */
+ public static long min(long l1, long l2) {
+ return l1 < l2 ? l1 : l2;
+ }
+
+ /**
+ * Answers the closest double approximation of the result of raising the
+ * first argument to the power of the second.
+ *
+ * @param d1
+ * the base of the operation.
+ * @param d2
+ * the exponent of the operation.
+ * @return d1 to the power of d2
+ */
+ public static native double pow(double d1, double d2);
+
+ /**
+ * Answers the double conversion of the result of rounding the argument to
+ * an integer.
+ *
+ * @param d
+ * the value to be converted
+ * @return the closest integer to the argument (as a double).
+ */
+ public static native double rint(double d);
+
+ /**
+ * Answers the result of rounding the argument to an integer.
+ *
+ * @param d
+ * the value to be converted
+ * @return the closest integer to the argument.
+ */
+ public static long round(double d) {
+ // check for NaN
+ if (d != d)
+ return 0L;
+ return (long) Math.floor(d + 0.5d);
+ }
+
+ /**
+ * Answers the result of rounding the argument to an integer.
+ *
+ * @param f
+ * the value to be converted
+ * @return the closest integer to the argument.
+ */
+ public static int round(float f) {
+ // check for NaN
+ if (f != f)
+ return 0;
+ return (int) Math.floor(f + 0.5f);
+ }
+
+ /**
+ * Answers the closest double approximation of the sine of the argument
+ *
+ * @param d
+ * the value to compute sin of
+ * @return the sine of the argument.
+ */
+ public static native double sin(double d);
+
+ /**
+ * Answers the closest double approximation of the square root of the
+ * argument
+ *
+ * @param d
+ * the value to compute sqrt of
+ * @return the square root of the argument.
+ */
+ public static native double sqrt(double d);
+
+ /**
+ * Answers the closest double approximation of the tangent of the argument
+ *
+ * @param d
+ * the value to compute tan of
+ * @return the tangent of the argument.
+ */
+ public static native double tan(double d);
+
+ /**
+ * Returns a pseudo-random number between 0.0 and 1.0.
+ *
+ * @return a pseudo-random number
+ */
+ public static double random() {
+ if (random == null) {
+ random = new java.util.Random();
+ }
+ return random.nextDouble();
+ }
+
+ /**
+ * Returns the measure in radians of the supplied degree angle
+ *
+ * @param angdeg
+ * an angle in degrees
+ * @return the radian measure of the angle.
+ */
+ public static double toRadians(double angdeg) {
+ return angdeg / 180d * PI;
+ }
+
+ /**
+ * Returns the measure in degrees of the supplied radian angle
+ *
+ * @param angrad
+ * an angle in radians
+ * @return the degree measure of the angle.
+ */
+ public static double toDegrees(double angrad) {
+ return angrad * 180d / PI;
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NegativeArraySizeException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NegativeArraySizeException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NegativeArraySizeException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NegativeArraySizeException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,42 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * This runtime exception is thrown when an attempt is made to create an array
+ * whose size would be less than zero.
+ */
+public class NegativeArraySizeException extends RuntimeException {
+
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ */
+ public NegativeArraySizeException() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ * @param detailMessage
+ * String The detail message for the exception.
+ */
+ public NegativeArraySizeException(String detailMessage) {
+ super(detailMessage);
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NoClassDefFoundError.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NoClassDefFoundError.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NoClassDefFoundError.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NoClassDefFoundError.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,41 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * This error is thrown when the VM is unable to locate a class which it has
+ * been asked to load.
+ */
+public class NoClassDefFoundError extends LinkageError {
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ */
+ public NoClassDefFoundError() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ * @param detailMessage
+ * String The detail message for the exception.
+ */
+ public NoClassDefFoundError(String detailMessage) {
+ super(detailMessage);
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NoSuchFieldError.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NoSuchFieldError.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NoSuchFieldError.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NoSuchFieldError.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,44 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * This error is thrown when the VM notices that a an attempt is being made to
+ * reference a field of a class which does not exist in that class.
+ * <p>
+ * Note that this can only occur when inconsistant class files are being loaded.
+ */
+public class NoSuchFieldError extends IncompatibleClassChangeError {
+
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ */
+ public NoSuchFieldError() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ * @param detailMessage
+ * String The detail message for the exception.
+ */
+ public NoSuchFieldError(String detailMessage) {
+ super(detailMessage);
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NoSuchFieldException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NoSuchFieldException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NoSuchFieldException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NoSuchFieldException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,42 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * This exception is thrown when a program attempts to access a field which does
+ * not exist in a class
+ */
+public class NoSuchFieldException extends java.lang.Exception {
+
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ */
+ public NoSuchFieldException() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ * @param detailMessage
+ * String The detail message for the exception.
+ */
+ public NoSuchFieldException(String detailMessage) {
+ super(detailMessage);
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NoSuchMethodError.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NoSuchMethodError.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NoSuchMethodError.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NoSuchMethodError.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,43 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * This error is thrown when the VM notices that a an attempt is being made to
+ * reference a method of a class which does not exist in that class.
+ */
+public class NoSuchMethodError extends IncompatibleClassChangeError {
+
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ */
+ public NoSuchMethodError() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ * @param detailMessage
+ * String The detail message for the exception.
+ */
+ public NoSuchMethodError(String detailMessage) {
+ super(detailMessage);
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NoSuchMethodException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NoSuchMethodException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NoSuchMethodException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NoSuchMethodException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,43 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * This exception is thrown when a program attempts to access a method which
+ * does not exist in a class.
+ */
+public class NoSuchMethodException extends java.lang.Exception {
+
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ */
+ public NoSuchMethodException() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ * @param detailMessage
+ * String The detail message for the exception.
+ */
+ public NoSuchMethodException(String detailMessage) {
+ super(detailMessage);
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NullPointerException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NullPointerException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NullPointerException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NullPointerException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,44 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * This runtime exception is thrown when an attempt is made to access a field or
+ * method of an instance or an element of an array when there is no instance or
+ * array to use (i.e. the pointer is null).
+ */
+public class NullPointerException extends RuntimeException {
+
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ */
+ public NullPointerException() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ * @param detailMessage
+ * String The detail message for the exception.
+ */
+ public NullPointerException(String detailMessage) {
+ super(detailMessage);
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Number.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Number.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Number.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Number.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,78 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * Number is the abstract superclass of the classes which represent numeric base
+ * types (i.e. all but Character, Boolean, and Void).
+ */
+public abstract class Number implements java.io.Serializable {
+
+ static final long serialVersionUID = -8742448824652078965L;
+
+ /**
+ * Number constructor. Included for spec compatability.
+ */
+ public Number() {
+ }
+
+ /**
+ * Answers the byte value which the receiver represents
+ *
+ * @return byte the value of the receiver.
+ */
+ public byte byteValue() {
+ return (byte) intValue();
+ }
+
+ /**
+ * Answers the double value which the receiver represents
+ *
+ * @return double the value of the receiver.
+ */
+ public abstract double doubleValue();
+
+ /**
+ * Answers the float value which the receiver represents
+ *
+ * @return float the value of the receiver.
+ */
+ public abstract float floatValue();
+
+ /**
+ * Answers the int value which the receiver represents
+ *
+ * @return int the value of the receiver.
+ */
+ public abstract int intValue();
+
+ /**
+ * Answers the long value which the receiver represents
+ *
+ * @return long the value of the receiver.
+ */
+ public abstract long longValue();
+
+ /**
+ * Answers the short value which the receiver represents
+ *
+ * @return short the value of the receiver.
+ */
+ public short shortValue() {
+ return (short) intValue();
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NumberFormatException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NumberFormatException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NumberFormatException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/NumberFormatException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,42 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * This runtime exception is thrown when a "string to number" conversion routine
+ * is passed an invalid value.
+ */
+public class NumberFormatException extends java.lang.IllegalArgumentException {
+
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ */
+ public NumberFormatException() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ * @param detailMessage
+ * String The detail message for the exception.
+ */
+ public NumberFormatException(String detailMessage) {
+ super(detailMessage);
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/OutOfMemoryError.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/OutOfMemoryError.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/OutOfMemoryError.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/OutOfMemoryError.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,44 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * This error is thrown when a request is made for more memory either as a
+ * result of the running program, or because of the internal behavior of the
+ * virtual machine which can not be satisfied using the available platform
+ * resources.
+ */
+public class OutOfMemoryError extends java.lang.VirtualMachineError {
+
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ */
+ public OutOfMemoryError() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ * @param detailMessage
+ * String The detail message for the exception.
+ */
+ public OutOfMemoryError(String detailMessage) {
+ super(detailMessage);
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Process.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Process.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Process.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Process.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,84 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * Instances of class Process provide control of and access to platform
+ * processes.
+ */
+public abstract class Process {
+
+ /**
+ * Terimates the receiver and closes any associated streams.
+ */
+ abstract public void destroy();
+
+ /**
+ * Answers the exit value of the receiving Process. It is available only
+ * when the OS subprocess is finished.
+ *
+ * @return The exit value of the receiver.
+ *
+ * @throws IllegalThreadStateException
+ * If the receiver has not terminated.
+ */
+ abstract public int exitValue();
+
+ /**
+ * Answers the receiver's error output stream.
+ * <p>
+ * Note: This is an InputStream which allows reading of the other threads
+ * "stderr".
+ *
+ * @return The error stream associated with the receiver
+ */
+ abstract public InputStream getErrorStream();
+
+ /**
+ * Answers the receiver's standard input stream
+ * <p>
+ * Note: This is an InputStream which allows reading from the other process'
+ * "stdout".
+ *
+ * @return The receiver's process' stdin.
+ */
+ abstract public InputStream getInputStream();
+
+ /**
+ * Answers the receiver's standard output stream
+ * <p>
+ * Note: This is an OutputStream which allows writing to the other process'
+ * "stdin".
+ *
+ * @return The receiver's process' stdout.
+ */
+ abstract public OutputStream getOutputStream();
+
+ /**
+ * Causes the calling thread to wait for the process associated with the
+ * receiver to finish executing.
+ *
+ * @return The exit value of the Process being waited on
+ *
+ * @throws InterruptedException
+ * If the calling thread is interrupted
+ */
+ abstract public int waitFor() throws InterruptedException;
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Runnable.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Runnable.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Runnable.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Runnable.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,30 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * The runnable interface must be implemented by all classes which want to be
+ * run as threads.
+ *
+ * @see Thread
+ */
+public interface Runnable {
+ /**
+ * Begin doing the active part of the class' code.
+ */
+ public void run();
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/RuntimeException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/RuntimeException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/RuntimeException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/RuntimeException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,68 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * This class is the superclass of all classes which represent exceptional
+ * conditions which occur as a result of the running of the virtual machine.
+ */
+public class RuntimeException extends Exception {
+
+ static final long serialVersionUID = -7034897190745766939L;
+
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ */
+ public RuntimeException() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ * @param detailMessage
+ * String The detail message for the exception.
+ */
+ public RuntimeException(String detailMessage) {
+ super(detailMessage);
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback, message and
+ * cause filled in.
+ *
+ * @param detailMessage
+ * String The detail message for the exception.
+ * @param throwable
+ * The cause of this Throwable
+ */
+ public RuntimeException(String detailMessage, Throwable throwable) {
+ super(detailMessage, throwable);
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and cause
+ * filled in.
+ *
+ * @param throwable
+ * The cause of this Throwable
+ */
+ public RuntimeException(Throwable throwable) {
+ super(throwable);
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/RuntimePermission.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/RuntimePermission.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/RuntimePermission.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/RuntimePermission.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,97 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+import java.security.BasicPermission;
+
+/**
+ * RuntimePermission objects represent access to runtime support.
+ */
+public final class RuntimePermission extends BasicPermission {
+
+ static final long serialVersionUID = 7399184964622342223L;
+
+ /**
+ * Constants for runtime permissions used in this package.
+ */
+ static final RuntimePermission permissionToSetSecurityManager = new RuntimePermission(
+ "setSecurityManager");
+
+ static final RuntimePermission permissionToCreateSecurityManager = new RuntimePermission(
+ "createSecurityManager");
+
+ static final RuntimePermission permissionToGetProtectionDomain = new RuntimePermission(
+ "getProtectionDomain");
+
+ static final RuntimePermission permissionToGetClassLoader = new RuntimePermission(
+ "getClassLoader");
+
+ static final RuntimePermission permissionToCreateClassLoader = new RuntimePermission(
+ "createClassLoader");
+
+ static final RuntimePermission permissionToModifyThread = new RuntimePermission(
+ "modifyThread");
+
+ static final RuntimePermission permissionToModifyThreadGroup = new RuntimePermission(
+ "modifyThreadGroup");
+
+ static final RuntimePermission permissionToExitVM = new RuntimePermission(
+ "exitVM");
+
+ static final RuntimePermission permissionToReadFileDescriptor = new RuntimePermission(
+ "readFileDescriptor");
+
+ static final RuntimePermission permissionToWriteFileDescriptor = new RuntimePermission(
+ "writeFileDescriptor");
+
+ static final RuntimePermission permissionToQueuePrintJob = new RuntimePermission(
+ "queuePrintJob");
+
+ static final RuntimePermission permissionToSetFactory = new RuntimePermission(
+ "setFactory");
+
+ static final RuntimePermission permissionToSetIO = new RuntimePermission(
+ "setIO");
+
+ static final RuntimePermission permissionToStopThread = new RuntimePermission(
+ "stopThread");
+
+ /**
+ * Creates an instance of this class with the given name.
+ *
+ *
+ * @param permissionName
+ * String the name of the new permission.
+ */
+ public RuntimePermission(String permissionName) {
+ super(permissionName);
+ }
+
+ /**
+ * Creates an instance of this class with the given name and action list.
+ * The action list is ignored.
+ *
+ *
+ * @param name
+ * String the name of the new permission.
+ * @param actions
+ * String ignored.
+ */
+ public RuntimePermission(String name, String actions) {
+ super(name, actions);
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/SecurityException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/SecurityException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/SecurityException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/SecurityException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,41 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * This runtime exception is thrown when a security manager check fails.
+ */
+public class SecurityException extends java.lang.RuntimeException {
+
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ */
+ public SecurityException() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ * @param detailMessage
+ * String The detail message for the exception.
+ */
+ public SecurityException(String detailMessage) {
+ super(detailMessage);
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/SecurityManager.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/SecurityManager.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/SecurityManager.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/SecurityManager.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,730 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FilePermission;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Member;
+import java.net.InetAddress;
+import java.net.SocketPermission;
+import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.security.AllPermission;
+import java.security.Permission;
+import java.security.Security;
+import java.security.SecurityPermission;
+import java.util.PropertyPermission;
+import java.util.StringTokenizer;
+
+import com.ibm.oti.util.PriviAction;
+
+/**
+ * SecurityManager is the abstract superclass of the classes which can provide
+ * security verification for a running program.
+ */
+public class SecurityManager {
+ static String[] securePackageList = null;
+
+ /**
+ * Flag to indicate whether a security check is in progress.
+ *
+ * @deprecated Use checkPermission
+ */
+ protected boolean inCheck = false;
+
+ /**
+ * Optimization: Don't create a new PropertyPermission each time.
+ */
+ private PropertyPermission permissionToReadWriteAllProperties = new PropertyPermission(
+ "*", "read,write");
+
+ /**
+ * Constructs a new instance of this class.
+ */
+ public SecurityManager() {
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security
+ .checkPermission(RuntimePermission.permissionToCreateSecurityManager);
+ Class type = Security.class; // initialize Security properties
+ }
+
+ /**
+ * Checks whether the running program is allowed to accept socket
+ * connections.
+ *
+ * @param host
+ * the address of the host which is attempting to connect
+ * @param port
+ * the port number to check
+ */
+ public void checkAccept(String host, int port) {
+ if (host == null)
+ throw new NullPointerException();
+ checkPermission(new SocketPermission(host + ':' + port, "accept"));
+ }
+
+ /**
+ * Checks whether the running program is allowed to modify the thread.
+ *
+ * @param thread
+ * the thread we are attempting to modify
+ */
+ public void checkAccess(Thread thread) {
+ // Only worry about system threads.
+ if (thread.getThreadGroup().parent == null)
+ checkPermission(RuntimePermission.permissionToModifyThread);
+ }
+
+ /**
+ * Checks whether the running program is allowed to modify the thread group.
+ *
+ *
+ * @param group
+ * the thread group we are attempting to modify
+ */
+ public void checkAccess(ThreadGroup group) {
+ // Only worry about system threads.
+ if (group == null)
+ throw new NullPointerException();
+ if (group.parent == null)
+ checkPermission(RuntimePermission.permissionToModifyThreadGroup);
+ }
+
+ /**
+ * Checks whether the running program is allowed to establish socket
+ * connections. A -1 port indicates the caller is trying to resolve the
+ * hostname.
+ *
+ * @param host
+ * String the address of the host to connect to.
+ * @param port
+ * int the port number to check, or -1 for resolve.
+ */
+ public void checkConnect(String host, int port) {
+ if (host == null)
+ throw new NullPointerException();
+ if (port > 0)
+ checkPermission(new SocketPermission(host + ':' + port, "connect"));
+ else
+ checkPermission(new SocketPermission(host, "resolve"));
+ }
+
+ /**
+ * Checks whether the given security context is allowed to establish socket
+ * connections. A -1 port indicates the caller is trying to resolve the
+ * hostname.
+ *
+ * @param host
+ * String the address of the host to connect to.
+ * @param port
+ * int the port number to check, or -1 for resolve.
+ * @param context
+ * Object the security context to use for the check.
+ */
+ public void checkConnect(String host, int port, Object context) {
+ if (port > 0)
+ checkPermission(new SocketPermission(host + ':' + port, "connect"),
+ context);
+ else
+ checkPermission(new SocketPermission(host, "resolve"), context);
+ }
+
+ /**
+ * Checks whether the running program is allowed to create a class loader.
+ */
+ public void checkCreateClassLoader() {
+ checkPermission(RuntimePermission.permissionToCreateClassLoader);
+ }
+
+ /**
+ * Checks whether the running program is allowed to delete the file named by
+ * the argument, which should be passed in canonical form.
+ *
+ * @param file
+ * the name of the file to check
+ */
+ public void checkDelete(String file) {
+ checkPermission(new FilePermission(file, "delete"));
+ }
+
+ /**
+ * Checks whether the running program is allowed to execute the specified
+ * platform specific command.
+ *
+ * @param cmd
+ * the command line
+ */
+ public void checkExec(String cmd) {
+ checkPermission(new FilePermission(new File(cmd).isAbsolute() ? cmd
+ : "<<ALL FILES>>", "execute"));
+ }
+
+ /**
+ * Checks whether the running program is allowed to terminate itself.
+ *
+ * @param status
+ * the status to return from the exit.
+ */
+ public void checkExit(int status) {
+ checkPermission(RuntimePermission.permissionToExitVM);
+ }
+
+ /**
+ * Checks whether the running program is allowed to load the specifed native
+ * library.
+ *
+ * @param libName
+ * the name of the library to load
+ */
+ public void checkLink(String libName) {
+ if (libName == null)
+ throw new NullPointerException();
+ checkPermission(new RuntimePermission("loadLibrary." + libName));
+ }
+
+ /**
+ * Checks whether the running program is allowed to listen on the specified
+ * port.
+ *
+ * @param port
+ * int the port number to check
+ */
+ public void checkListen(int port) {
+ if (port == 0)
+ checkPermission(new SocketPermission("localhost:1024-",
+ "listen"));
+ else
+ checkPermission(new SocketPermission("localhost:" + port,
+ "listen"));
+ }
+
+ /**
+ * Checks whether the running program is allowed to access members. The
+ * default is to allow access to public members (i.e.
+ * java.lang.reflect.PUBLIC) and to classes loaded by the same loader as the
+ * original caller (i.e. the method that called the reflect API).
+ *
+ * Due to the nature of the check, overriding implementations cannot call
+ * super.checkMemberAccess() since the stack would no longer be of the
+ * expected shape.
+ *
+ * @param cls ?
+ * @param type
+ * Either java.lang.reflect.Member.PUBLIC or DECLARED
+ */
+ public void checkMemberAccess(Class cls, int type) {
+ if (cls == null)
+ throw new NullPointerException();
+ if (type == Member.PUBLIC)
+ return;
+ //
+ // Need to compare the classloaders.
+ // Stack shape is
+ // <user code> <- want this class
+ // Class.getDeclared*();
+ // Class.checkMemberAccess();
+ // SecurityManager.checkMemberAccess(); <- current frame
+ //
+ // Use getClassLoaderImpl() since getClassLoader()
+ // returns null for the bootstrap class loader.
+ if (ClassLoader.getStackClassLoader(3) == cls.getClassLoaderImpl())
+ return;
+
+ // Forward off to the permission mechanism.
+ checkPermission(new RuntimePermission("accessDeclaredMembers"));
+ }
+
+ /**
+ * Checks whether the running program is allowed to join, leave or send to a
+ * multicast address.
+ */
+ public void checkMulticast(InetAddress maddr) {
+ checkPermission(new SocketPermission(maddr.getHostAddress(),
+ "accept,connect"));
+ }
+
+ /**
+ * Checks whether the running program is allowed to join, leave or send to a
+ * multicast address.
+ *
+ * @deprecated use SecurityManager#checkMulticast(java.net.InetAddress)
+ */
+ public void checkMulticast(InetAddress maddr, byte ttl) {
+ checkPermission(new SocketPermission(maddr.getHostAddress(),
+ "accept,connect"));
+ }
+
+ /**
+ * Checks whether the running program is allowed to access the specified
+ * package.
+ *
+ * @param packageName
+ * the name of the package to be accessed.
+ */
+ public void checkPackageAccess(String packageName) {
+ if (packageName == null)
+ throw new NullPointerException();
+ if (securePackageList == null) {
+ String securePackages = getSecurityProperty("package.access");
+ if (securePackages != null) {
+ StringTokenizer tokenizer = new StringTokenizer(securePackages,
+ ", ");
+ int i = 0;
+ securePackageList = new String[tokenizer.countTokens()];
+ while (tokenizer.hasMoreTokens()) {
+ securePackageList[i++] = tokenizer.nextToken();
+ }
+ } else {
+ securePackageList = new String[0];
+ }
+ }
+ for (int i = 0; i < securePackageList.length; i++) {
+ if (packageName.startsWith(securePackageList[i])) {
+ checkPermission(new RuntimePermission("accessClassInPackage."
+ + packageName));
+ return;
+ }
+ }
+ }
+
+ /**
+ * Checks whether the running program is allowed to define new classes in
+ * the specified package.
+ *
+ * @param packageName
+ * the name of the package to add a class to.
+ */
+ public void checkPackageDefinition(String packageName) {
+ if (packageName == null)
+ throw new NullPointerException();
+ String securePackages = getSecurityProperty("package.definition");
+ if (securePackages != null) {
+ StringTokenizer tokenizer = new StringTokenizer(securePackages,
+ ", ");
+ while (tokenizer.hasMoreTokens()) {
+ if (packageName.startsWith(tokenizer.nextToken())) {
+ checkPermission(new RuntimePermission(
+ "defineClassInPackage." + packageName));
+ return;
+ }
+ }
+ }
+ }
+
+ private String getSecurityProperty(final String property) {
+ return (String) AccessController.doPrivileged(PriviAction
+ .getSecurityProperty(property));
+ }
+
+ /**
+ * Checks whether the running program is allowed to access the system
+ * properties.
+ */
+ public void checkPropertiesAccess() {
+ checkPermission(permissionToReadWriteAllProperties);
+ }
+
+ /**
+ * Checks whether the running program is allowed to access a particular
+ * system property.
+ *
+ * @param key
+ * the name of the property to be accessed.
+ */
+ public void checkPropertyAccess(String key) {
+ checkPermission(new PropertyPermission(key, "read"));
+ }
+
+ /**
+ * Checks whether the running program is allowed to read from the file whose
+ * descriptor is the argument.
+ *
+ * @param fd
+ * the file descriptor of the file to check
+ */
+ public void checkRead(FileDescriptor fd) {
+ if (fd == null)
+ throw new NullPointerException();
+ checkPermission(RuntimePermission.permissionToReadFileDescriptor);
+ }
+
+ /**
+ * Checks whether the running program is allowed to read from the file named
+ * by the argument, which should be passed in canonical form.
+ *
+ * @param file
+ * String the name of the file or directory to check.
+ */
+ public void checkRead(String file) {
+ checkPermission(new FilePermission(file, "read"));
+ }
+
+ /**
+ * Checks whether the given security context is allowed to read from the
+ * file named by the argument, which should be passed in canonical form.
+ *
+ * @param file
+ * String the name of the file or directory to check.
+ * @param context
+ * Object the security context to use for the check.
+ */
+ public void checkRead(String file, Object context) {
+ checkPermission(new FilePermission(file, "read"), context);
+ }
+
+ /**
+ * Checks whether the running program is allowed to perform the security
+ * operation named by the target.
+ *
+ * @param target
+ * String the name of the operation to perform.
+ */
+ public void checkSecurityAccess(String target) {
+ checkPermission(new SecurityPermission(target));
+ }
+
+ /**
+ * Checks whether the running program is allowed to set the net object
+ * factories.
+ */
+ public void checkSetFactory() {
+ checkPermission(RuntimePermission.permissionToSetFactory);
+ }
+
+ /**
+ * Checks whether the running program is allowed to create a top level
+ * window.
+ *
+ * @param window
+ * The non-null window for which to check access
+ */
+ public boolean checkTopLevelWindow(Object window) {
+ if (window == null)
+ throw new NullPointerException();
+ try {
+ Class awtPermission = Class.forName("java.awt.AWTPermission");
+ Class[] args = new Class[] { java.lang.String.class };
+ Constructor constructor = awtPermission.getConstructor(args);
+ Object[] constructorArgs = new Object[] { "showWindowWithoutWarningBanner" };
+ Permission perm = (Permission) constructor.newInstance(constructorArgs);
+ checkPermission(perm);
+ } catch (ClassNotFoundException e) {
+ } catch (NoSuchMethodException e) {
+ } catch (InstantiationException e) {
+ } catch (IllegalAccessException e) {
+ } catch (InvocationTargetException e) {
+ } catch (SecurityException e) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Checks whether the running program is allowed to access the system
+ * clipboard.
+ */
+ public void checkSystemClipboardAccess() {
+ try {
+ Class awtPermission = Class.forName("java.awt.AWTPermission");
+ Class[] args = new Class[] { String.class };
+ Constructor constructor = awtPermission.getConstructor(args);
+ Object[] constructorArgs = new Object[] { "accessClipboard" };
+ Permission perm = (Permission) constructor.newInstance(constructorArgs);
+ checkPermission(perm);
+ return;
+ } catch (ClassNotFoundException e) {
+ } catch (NoSuchMethodException e) {
+ } catch (InstantiationException e) {
+ } catch (IllegalAccessException e) {
+ } catch (InvocationTargetException e) {
+ }
+ throw new SecurityException();
+ }
+
+ /**
+ * Checks whether the running program is allowed to access the AWT Event
+ * queue. Since we don't support AWT, the answer is no.
+ */
+ public void checkAwtEventQueueAccess() {
+ try {
+ Class awtPermission = Class.forName("java.awt.AWTPermission");
+ Class[] ar = new Class[] { String.class };
+ Constructor constructor = awtPermission.getConstructor(ar);
+ Object[] constructorArgs = new Object[] { "accessEventQueue" };
+ Permission perm = (Permission) constructor.newInstance(constructorArgs);
+ checkPermission(perm);
+ return;
+ } catch (ClassNotFoundException e) {
+ } catch (NoSuchMethodException e) {
+ } catch (InstantiationException e) {
+ } catch (IllegalAccessException e) {
+ } catch (InvocationTargetException e) {
+ }
+ throw new SecurityException();
+ }
+
+ /**
+ * Checks whether the running program is allowed to start a new print job.
+ */
+ public void checkPrintJobAccess() {
+ checkPermission(RuntimePermission.permissionToQueuePrintJob);
+ }
+
+ /**
+ * Checks whether the running program is allowed to read from the file whose
+ * descriptor is the argument.
+ *
+ * @param fd
+ * the file descriptor of the file to check
+ */
+ public void checkWrite(FileDescriptor fd) {
+ if (fd == null)
+ throw new NullPointerException();
+ checkPermission(RuntimePermission.permissionToWriteFileDescriptor);
+ }
+
+ /**
+ * Checks whether the running program is allowed to write to the file named
+ * by the argument, which should be passed in canonical form.
+ *
+ * @param file
+ * the name of the file to check
+ */
+ public void checkWrite(String file) {
+ checkPermission(new FilePermission(file, "write"));
+ }
+
+ /**
+ * Answers true if the security manager is currently checking something.
+ *
+ * @return boolean true if we are are in a security check method.
+ *
+ * @deprecated Use checkPermission
+ */
+ public boolean getInCheck() {
+ return inCheck;
+ }
+
+ /**
+ * Answers an array containing one entry for each method in the stack. Each
+ * entry is the java.lang.Class which represents the class in which the
+ * method is defined.
+ *
+ * @return Class[] all of the classes in the stack.
+ */
+ protected Class[] getClassContext() {
+ return Class.getStackClasses(-1, false);
+ }
+
+ /**
+ * Answers the class loader of the first class in the stack whose class
+ * loader is not a system class loader.
+ *
+ * @return ClassLoader the most recent non-system class loader.
+ *
+ * @deprecated Use checkPermission
+ */
+ protected ClassLoader currentClassLoader() {
+
+ // First, check if AllPermission is allowed. If so, then we
+ // are effectively running in an unsafe environment, so just
+ // answer null (==> everything is a system class).
+ try {
+ checkPermission(new AllPermission());
+ return null;
+ } catch (SecurityException ex) {
+ }
+
+ // Now, check if there are any non-system class loaders in
+ // the stack up to the first privileged method (or the end
+ // of the stack.
+ Class[] classes = Class.getStackClasses(-1, true);
+ for (int i = 0; i < classes.length; i++) {
+ ClassLoader cl = classes[i].getClassLoaderImpl();
+ if (!cl.isSystemClassLoader())
+ return cl;
+ }
+ return null;
+ }
+
+ /**
+ * Answers the index in the stack of thee first class whose class loader is
+ * not a system class loader.
+ *
+ * @return int the frame index of the first method whose class was loaded by
+ * a non-system class loader.
+ *
+ * @deprecated Use checkPermission
+ */
+ protected int classLoaderDepth() {
+ // First, check if AllPermission is allowed. If so, then we
+ // are effectively running in an unsafe environment, so just
+ // answer -1 (==> everything is a system class).
+ try {
+ checkPermission(new AllPermission());
+ return -1;
+ } catch (SecurityException ex) {
+ }
+
+ // Now, check if there are any non-system class loaders in
+ // the stack up to the first privileged method (or the end
+ // of the stack.
+ Class[] classes = Class.getStackClasses(-1, true);
+ for (int i = 0; i < classes.length; i++) {
+ ClassLoader cl = classes[i].getClassLoaderImpl();
+ if (!cl.isSystemClassLoader())
+ return i;
+ }
+ return -1;
+ }
+
+ /**
+ * Answers the first class in the stack which was loaded by a class loader
+ * which is not a system class loader.
+ *
+ * @return Class the most recent class loaded by a non-system class loader.
+ *
+ * @deprecated Use checkPermission
+ */
+ protected Class currentLoadedClass() {
+ // First, check if AllPermission is allowed. If so, then we
+ // are effectively running in an unsafe environment, so just
+ // answer null (==> everything is a system class).
+ try {
+ checkPermission(new AllPermission());
+ return null;
+ } catch (SecurityException ex) {
+ }
+
+ // Now, check if there are any non-system class loaders in
+ // the stack up to the first privileged method (or the end
+ // of the stack.
+ Class[] classes = Class.getStackClasses(-1, true);
+ for (int i = 0; i < classes.length; i++) {
+ ClassLoader cl = classes[i].getClassLoaderImpl();
+ if (!cl.isSystemClassLoader())
+ return classes[i];
+ }
+ return null;
+ }
+
+ /**
+ * Answers the index in the stack of the first method which is contained in
+ * a class called <code>name</code>. If no methods from this class are in
+ * the stack, return -1.
+ *
+ * @param name
+ * String the name of the class to look for.
+ * @return int the depth in the stack of a the first method found.
+ *
+ * @deprecated Use checkPermission
+ */
+ protected int classDepth(String name) {
+ Class[] classes = Class.getStackClasses(-1, false);
+ for (int i = 0; i < classes.length; i++)
+ if (classes[i].getName().equals(name))
+ return i;
+ return -1;
+ }
+
+ /**
+ * Answers true if there is a method on the stack from the specified class,
+ * and false otherwise.
+ *
+ * @param name
+ * String the name of the class to look for.
+ * @return boolean true if we are running a method from the specified class.
+ *
+ * @deprecated Use checkPermission
+ */
+ protected boolean inClass(String name) {
+ return classDepth(name) != -1;
+ }
+
+ /**
+ * Answers true if there is a method on the stack from a class which was
+ * defined by a non-system classloader.
+ *
+ * @return boolean
+ *
+ * @deprecated Use checkPermission
+ */
+ protected boolean inClassLoader() {
+ return currentClassLoader() != null;
+ }
+
+ /**
+ * Answers the thread group which should be used to instantiate new threads.
+ * By default, this is the same as the thread group of the thread running
+ * this method.
+ *
+ * @return ThreadGroup The thread group to create new threads in.
+ */
+ public ThreadGroup getThreadGroup() {
+ return Thread.currentThread().getThreadGroup();
+ }
+
+ /**
+ * Answers an object which encapsulates the security state of the current
+ * point in the execution. In our case, this is an AccessControlContext.
+ */
+ public Object getSecurityContext() {
+ return AccessController.getContext();
+ }
+
+ /**
+ * Checks whether the running program is allowed to access the resource
+ * being guarded by the given Permission argument.
+ *
+ * @param permission
+ * the permission to check
+ */
+ public void checkPermission(Permission permission) {
+ try {
+ inCheck = true;
+ AccessController.checkPermission(permission);
+ } finally {
+ inCheck = false;
+ }
+ }
+
+ /**
+ * Checks whether the running program is allowed to access the resource
+ * being guarded by the given Permission argument.
+ *
+ * @param permission
+ * the permission to check
+ */
+ public void checkPermission(Permission permission, Object context) {
+ try {
+ inCheck = true;
+ // Must be an AccessControlContext. If we don't check
+ // this, then applications could pass in an arbitrary
+ // object which circumvents the security check.
+ if (context instanceof AccessControlContext)
+ ((AccessControlContext) context).checkPermission(permission);
+ else
+ throw new SecurityException();
+ } finally {
+ inCheck = false;
+ }
+ }
+}