harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r350181 [107/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....
Date Thu, 01 Dec 2005 06:04:00 GMT
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/Member.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/Member.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/Member.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/Member.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,55 @@
+/* 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.reflect;
+
+
+/**
+ * Implementors of this interface model a class member.
+ * 
+ * @see Field
+ * @see Constructor
+ * @see Method
+ */
+public interface Member {
+	
+	public static final int PUBLIC = 0;
+
+	public static final int DECLARED = 1;
+
+	/**
+	 * Return the java.lang.Class associated with the class that defined this
+	 * member.
+	 * 
+	 * @return the declaring class
+	 */
+	public abstract Class getDeclaringClass();
+
+	/**
+	 * Return the modifiers for the member. The Modifier class should be used to
+	 * decode the result.
+	 * 
+	 * @return the modifiers
+	 * @see java.lang.reflect.Modifier
+	 */
+	public abstract int getModifiers();
+
+	/**
+	 * Return the name of the member.
+	 * 
+	 * @return the name
+	 */
+	public abstract String getName();
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/Modifier.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/Modifier.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/Modifier.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/Modifier.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,244 @@
+/* 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.reflect;
+
+
+/**
+ * This class provides methods to decode class and member modifiers.
+ * 
+ * @see java.lang.Class#getModifiers()
+ * @see java.lang.reflect.Member#getModifiers()
+ */
+public class Modifier {
+
+	public static final int PUBLIC = 0x1;
+
+	public static final int PRIVATE = 0x2;
+
+	public static final int PROTECTED = 0x4;
+
+	public static final int STATIC = 0x8;
+
+	public static final int FINAL = 0x10;
+
+	public static final int SYNCHRONIZED = 0x20;
+
+	public static final int VOLATILE = 0x40;
+
+	public static final int TRANSIENT = 0x80;
+
+	public static final int NATIVE = 0x100;
+
+	public static final int INTERFACE = 0x200;
+
+	public static final int ABSTRACT = 0x400;
+
+	public static final int STRICT = 0x800;
+
+	public Modifier() {
+	}
+
+	/**
+	 * Return true if the specified modifiers contain the <code>abstract</code>
+	 * modifier, false otherwise.
+	 * 
+	 * @param modifiers
+	 *            the modifiers to test
+	 * @return if the modifiers contain the abstract modifier
+	 */
+	public static boolean isAbstract(int modifiers) {
+		return ((modifiers & ABSTRACT) != 0);
+	}
+
+	/**
+	 * Return true if the specified modifiers contain the <code>final</code>
+	 * modifier, false otherwise.
+	 * 
+	 * @param modifiers
+	 *            the modifiers to test
+	 * @return if the modifiers contain the final modifier
+	 */
+	public static boolean isFinal(int modifiers) {
+		return ((modifiers & FINAL) != 0);
+	}
+
+	/**
+	 * Return true if the specified modifiers contain the <code>interface</code>
+	 * modifier, false otherwise.
+	 * 
+	 * @param modifiers
+	 *            the modifiers to test
+	 * @return if the modifiers contain the interface modifier
+	 */
+	public static boolean isInterface(int modifiers) {
+		return ((modifiers & INTERFACE) != 0);
+	}
+
+	/**
+	 * Return true if the specified modifiers contain the <code>native</code>
+	 * modifier, false otherwise.
+	 * 
+	 * @param modifiers
+	 *            the modifiers to test
+	 * @return if the modifiers contain the native modifier
+	 */
+	public static boolean isNative(int modifiers) {
+		return ((modifiers & NATIVE) != 0);
+	}
+
+	/**
+	 * Return true if the specified modifiers contain the <code>private</code>
+	 * modifier, false otherwise.
+	 * 
+	 * @param modifiers
+	 *            the modifiers to test
+	 * @return if the modifiers contain the private modifier
+	 */
+	public static boolean isPrivate(int modifiers) {
+		return ((modifiers & PRIVATE) != 0);
+	}
+
+	/**
+	 * Return true if the specified modifiers contain the <code>protected</code>
+	 * modifier, false otherwise.
+	 * 
+	 * @param modifiers
+	 *            the modifiers to test
+	 * @return if the modifiers contain the protected modifier
+	 */
+	public static boolean isProtected(int modifiers) {
+		return ((modifiers & PROTECTED) != 0);
+	}
+
+	/**
+	 * Return true if the specified modifiers contain the <code>public</code>
+	 * modifier, false otherwise.
+	 * 
+	 * @param modifiers
+	 *            the modifiers to test
+	 * @return if the modifiers contain the abstract modifier
+	 */
+	public static boolean isPublic(int modifiers) {
+		return ((modifiers & PUBLIC) != 0);
+	}
+
+	/**
+	 * Return true if the specified modifiers contain the <code>static</code>
+	 * modifier, false otherwise.
+	 * 
+	 * @param modifiers
+	 *            the modifiers to test
+	 * @return if the modifiers contain the static modifier
+	 */
+	public static boolean isStatic(int modifiers) {
+		return ((modifiers & STATIC) != 0);
+	}
+
+	/**
+	 * Return true if the specified modifiers contain the <code>strict</code>
+	 * modifier, false otherwise.
+	 * 
+	 * @param modifiers
+	 *            the modifiers to test
+	 * @return if the modifiers contain the strict modifier
+	 */
+	public static boolean isStrict(int modifiers) {
+		return ((modifiers & STRICT) != 0);
+	}
+
+	/**
+	 * Return true if the specified modifiers contain the
+	 * <code>synchronized</code> modifier, false otherwise.
+	 * 
+	 * @param modifiers
+	 *            the modifiers to test
+	 * @return if the modifiers contain the synchronized modifier
+	 */
+	public static boolean isSynchronized(int modifiers) {
+		return ((modifiers & SYNCHRONIZED) != 0);
+	}
+
+	/**
+	 * Return true if the specified modifiers contain the <code>transient</code>
+	 * modifier, false otherwise.
+	 * 
+	 * @param modifiers
+	 *            the modifiers to test
+	 * @return if the modifiers contain the transient modifier
+	 */
+	public static boolean isTransient(int modifiers) {
+		return ((modifiers & TRANSIENT) != 0);
+	}
+
+	/**
+	 * Return true if the specified modifiers contain the <code>volatile</code>
+	 * modifier, false otherwise.
+	 * 
+	 * @param modifiers
+	 *            the modifiers to test
+	 * @return if the modifiers contain the volatile modifier
+	 */
+	public static boolean isVolatile(int modifiers) {
+		return ((modifiers & VOLATILE) != 0);
+	}
+
+	/**
+	 * Answers a string containing the string representation of all modifiers
+	 * present in the specified modifiers.
+	 * 
+	 * Modifiers appear in the order specified by the Java Language
+	 * Specification:
+	 * <code>public private protected abstract static final transient volatile native synchronized interface strict</code>
+	 * 
+	 * @param modifiers
+	 *            the modifiers to print
+	 * @return a printable representation of the modifiers
+	 */
+	public static java.lang.String toString(int modifiers) {
+		StringBuffer buf;
+
+		buf = new StringBuffer();
+
+		if (isPublic(modifiers))
+			buf.append("public ");
+		if (isProtected(modifiers))
+			buf.append("protected ");
+		if (isPrivate(modifiers))
+			buf.append("private ");
+		if (isAbstract(modifiers))
+			buf.append("abstract ");
+		if (isStatic(modifiers))
+			buf.append("static ");
+		if (isFinal(modifiers))
+			buf.append("final ");
+		if (isTransient(modifiers))
+			buf.append("transient ");
+		if (isVolatile(modifiers))
+			buf.append("volatile ");
+		if (isSynchronized(modifiers))
+			buf.append("synchronized ");
+		if (isNative(modifiers))
+			buf.append("native ");
+		if (isStrict(modifiers))
+			buf.append("strictfp ");
+		if (isInterface(modifiers))
+			buf.append("interface ");
+		if (buf.length() == 0)
+			return "";
+		buf.setLength(buf.length() - 1);
+		return buf.toString();
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/Proxy.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/Proxy.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/Proxy.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/Proxy.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,233 @@
+/* Copyright 2001, 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.reflect;
+
+
+import java.lang.ref.WeakReference;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import com.ibm.oti.lang.reflect.ProxyClassFile;
+import com.ibm.oti.util.Msg;
+
+/**
+ * This class provides methods to creating dynamic proxy classes and instances.
+ * 
+ * @see java.lang.reflect.InvocationHandler
+ */
+public class Proxy implements java.io.Serializable {
+
+	static final long serialVersionUID = -2222568056686623797L;
+
+	// maps class loaders to created classes by interface names
+	private static Map loaderCache = new WeakHashMap();
+
+	// to find previously created types
+	private static Map proxyCache = new WeakHashMap();
+
+	private static int NextClassNameIndex = 0;
+
+	protected InvocationHandler h;
+
+	private Proxy() {
+	}
+
+	protected Proxy(InvocationHandler h) {
+		this.h = h;
+	}
+
+	/**
+	 * Return the dynamically build class for the given interfaces, build a new
+	 * one when necessary. The order of the interfaces is important.
+	 * 
+	 * The interfaces must be visible from the supplied class loader; no
+	 * duplicates are permitted. All non-public interfaces must be defined in
+	 * the same package.
+	 * 
+	 * @param loader
+	 *            the class loader that will define the proxy class.
+	 * @param interfaces
+	 *            an array of <code>Class</code> objects, each one identifying
+	 *            an interface that the new proxy must implement
+	 * @return a proxy class that implements all of the interfaces referred to
+	 *         in the contents of <code>interfaces</code>.
+	 * @exception IllegalArgumentException
+	 * @exception NullPointerException
+	 *                if either <code>interfaces</code> or any of its elements
+	 *                are <code>null</code>.
+	 */
+	public static Class getProxyClass(ClassLoader loader, Class[] interfaces)
+			throws IllegalArgumentException {
+		// check that interfaces are a valid array of visible interfaces
+		if (interfaces == null)
+			throw new NullPointerException();
+		String commonPackageName = null;
+		for (int i = 0, length = interfaces.length; i < length; i++) {
+			Class next = interfaces[i];
+			if (next == null)
+				throw new NullPointerException();
+			String name = next.getName();
+			if (!next.isInterface())
+				throw new IllegalArgumentException(Msg.getString("K00ed", name));
+			if (loader != next.getClassLoader()) {
+				try {
+					if (next != Class.forName(name, false, loader))
+						throw new IllegalArgumentException(Msg.getString(
+								"K00ee", name));
+				} catch (ClassNotFoundException ex) {
+					throw new IllegalArgumentException(Msg.getString("K00ee",
+							name));
+				}
+			}
+			for (int j = i + 1; j < length; j++)
+				if (next == interfaces[j])
+					throw new IllegalArgumentException(Msg.getString("K00ef",
+							name));
+			if (!Modifier.isPublic(next.getModifiers())) {
+				int last = name.lastIndexOf('.');
+				String p = last == -1 ? "" : name.substring(0, last);
+				if (commonPackageName == null)
+					commonPackageName = p;
+				else if (!commonPackageName.equals(p))
+					throw new IllegalArgumentException(Msg.getString("K00f0"));
+			}
+		}
+
+		// search cache for matching proxy class using the class loader
+		synchronized (loaderCache) {
+			Map interfaceCache = (Map) loaderCache.get(loader);
+			if (interfaceCache == null)
+				loaderCache.put(loader, (interfaceCache = new HashMap()));
+
+			String interfaceKey = "";
+			if (interfaces.length == 1) {
+				interfaceKey = interfaces[0].getName();
+			} else {
+				StringBuffer names = new StringBuffer();
+				for (int i = 0, length = interfaces.length; i < length; i++) {
+					names.append(interfaces[i].getName());
+					names.append(' ');
+				}
+				interfaceKey = names.toString();
+			}
+
+			Class newClass;
+			WeakReference ref = (WeakReference) interfaceCache
+					.get(interfaceKey);
+			if (ref == null) {
+				String nextClassName = "$Proxy" + NextClassNameIndex++;
+				if (commonPackageName != null)
+					nextClassName = commonPackageName + "." + nextClassName;
+				byte[] classFileBytes = ProxyClassFile.generateBytes(
+						nextClassName, interfaces);
+				if (loader == null)
+					loader = ClassLoader.getSystemClassLoader();
+				newClass = defineClassImpl(loader, nextClassName.replace('.',
+						'/'), classFileBytes);
+				// Need a weak reference to the class so it can
+				// be unloaded if the class loader is discarded
+				interfaceCache.put(interfaceKey, new WeakReference(newClass));
+				synchronized (proxyCache) {
+					proxyCache.put(newClass, ""); // the value is unused
+				}
+			} else {
+				newClass = (Class) ref.get();
+			}
+			return newClass;
+		}
+	}
+
+	/**
+	 * Return an instance of the dynamically build class for the given
+	 * interfaces that forwards methods to the specified invocation handler.
+	 * 
+	 * The interfaces must be visible from the supplied class loader; no
+	 * duplicates are permitted. All non-public interfaces must be defined in
+	 * the same package.
+	 * 
+	 * @param loader
+	 *            the class loader that will define the proxy class.
+	 * @param interfaces
+	 *            the list of interfaces to implement.
+	 * @param h
+	 *            the invocation handler for the forwarded methods.
+	 * @return a new proxy object that delegates to the handler <code>h</code>
+	 * @exception IllegalArgumentException
+	 * @exception NullPointerException
+	 *                if the interfaces or any of its elements are null.
+	 */
+	public static Object newProxyInstance(ClassLoader loader,
+			Class[] interfaces, InvocationHandler h)
+			throws IllegalArgumentException {
+		if (h != null) {
+			try {
+				return getProxyClass(loader, interfaces).getConstructor(
+						new Class[] { InvocationHandler.class }).newInstance(
+						new Object[] { h });
+			} catch (NoSuchMethodException ex) {
+				throw new InternalError(ex.toString());
+			} catch (IllegalAccessException ex) {
+				throw new InternalError(ex.toString());
+			} catch (InstantiationException ex) {
+				throw new InternalError(ex.toString());
+			} catch (InvocationTargetException ex) {
+				throw new InternalError(ex.getTargetException().toString());
+			}
+		}
+		throw new NullPointerException();
+	}
+
+	/**
+	 * Return whether the supplied class is a dynamically generated proxy class.
+	 * 
+	 * @param cl
+	 *            the class.
+	 * @return true if the class is a proxy class and false otherwise.
+	 * @exception NullPointerException
+	 *                if the class is null.
+	 */
+	public static boolean isProxyClass(Class cl) {
+		if (cl != null) {
+			synchronized (proxyCache) {
+				return proxyCache.containsKey(cl);
+			}
+		}
+		throw new NullPointerException();
+	}
+
+	/**
+	 * Return the proxy instance's invocation handler.
+	 * 
+	 * @param proxy
+	 *            the proxy instance.
+	 * @return the proxy's invocation handler object
+	 * @exception IllegalArgumentException
+	 *                if the supplied <code>proxy</code> is not a proxy
+	 *                object.
+	 */
+	public static InvocationHandler getInvocationHandler(Object proxy)
+			throws IllegalArgumentException {
+		if (isProxyClass(proxy.getClass()))
+			return ((Proxy) proxy).h;
+
+		throw new IllegalArgumentException(Msg.getString("K00f1"));
+	}
+
+	private static native Class defineClassImpl(ClassLoader classLoader,
+			String className, byte[] classFileBytes);
+
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/ReflectPermission.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/ReflectPermission.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/ReflectPermission.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/ReflectPermission.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,49 @@
+/* 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.reflect;
+
+
+import java.security.BasicPermission;
+
+/**
+ * ReflectPermission objects represent permission to access dangerous operations
+ * in the reflection layer.
+ */
+public final class ReflectPermission extends BasicPermission {
+
+	/**
+	 * Creates an instance of this class with given name.
+	 * 
+	 * @param permissionName
+	 *            String the name of the new permission.
+	 */
+	public ReflectPermission(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 ReflectPermission(String name, String actions) {
+		super(name, actions);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/UndeclaredThrowableException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/UndeclaredThrowableException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/UndeclaredThrowableException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/UndeclaredThrowableException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,77 @@
+/* Copyright 2001, 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.reflect;
+
+
+/**
+ * This class provides a wrapper for an unexpected exception thrown by an
+ * InvocationHandler
+ * 
+ * @see java.lang.reflect.InvocationHandler#invoke
+ */
+
+public class UndeclaredThrowableException extends RuntimeException {
+
+	static final long serialVersionUID = 330127114055056639L;
+
+	private Throwable undeclaredThrowable;
+
+	/**
+	 * Constructs a new instance of this class with its walkback and target
+	 * exception filled in.
+	 * 
+	 * @param exception
+	 *            The exception which occurred while loading the class.
+	 */
+	public UndeclaredThrowableException(Throwable exception) {
+		super();
+		this.undeclaredThrowable = exception;
+		initCause(exception);
+	}
+
+	/**
+	 * Constructs a new instance of this class with its walkback, target
+	 * exception and message filled in.
+	 * 
+	 * @param detailMessage
+	 *            String The detail message for the exception.
+	 * @param exception
+	 *            Throwable The exception which occurred while loading the
+	 *            class.
+	 */
+	public UndeclaredThrowableException(Throwable exception,
+			String detailMessage) {
+		super(detailMessage);
+		this.undeclaredThrowable = exception;
+		initCause(exception);
+	}
+
+	/**
+	 * Answers the exception which caused the receiver to be thrown.
+	 */
+	public Throwable getUndeclaredThrowable() {
+		return undeclaredThrowable;
+	}
+
+	/**
+	 * Answers the cause of this Throwable, or null if there is no cause.
+	 * 
+	 * @return Throwable The receiver's cause.
+	 */
+	public Throwable getCause() {
+		return undeclaredThrowable;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/Authenticator.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/Authenticator.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/Authenticator.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/Authenticator.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,233 @@
+/* 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.net;
+
+
+/**
+ * This class is able to obtain authentication info for an connection, usually
+ * from user. First the application has to set the default authenticator which
+ * extends <code>Authenticator</code> by
+ * <code>setDefault(Authenticator a)</code>.
+ * <p>
+ * It should overide <code>getPasswordAuthentication()</code> which dictates
+ * how the authentication info should be obtained.
+ * 
+ * @see java.net.Authenticator.setDefault(java.net.ConnectionAuthenticator),
+ * @see java.net.getPasswordAuthentication()
+ */
+public abstract class Authenticator {
+
+	// the default authenticator that needs to be set
+	private static Authenticator thisAuthenticator;
+
+	private static final NetPermission requestPasswordAuthenticationPermission = new NetPermission(
+			"requestPasswordAuthentication");
+
+	private static final NetPermission setDefaultAuthenticatorPermission = new NetPermission(
+			"setDefaultAuthenticator");
+
+	// the requester connection info
+	private String host;
+
+	private InetAddress addr;
+
+	private int port;
+
+	private String protocol;
+
+	private String prompt;
+
+	private String scheme;
+
+	/**
+	 * This method is responsible for retrieving the username and password for
+	 * the sender. The implementation varies. The subclass has to overwrites
+	 * this.
+	 * <p>
+	 * It answers null by default.
+	 * 
+	 * @return java.net.PasswordAuthentication The password authenticaiton that
+	 *         it obtains
+	 */
+	protected PasswordAuthentication getPasswordAuthentication() {
+		return null;
+	}
+
+	/**
+	 * Answers the port of the connection that requests authorization.
+	 * 
+	 * @return int the port of the connection
+	 */
+	protected final int getRequestingPort() {
+		return this.port;
+	}
+
+	/**
+	 * Answers the address of the connection that requests authorization or null
+	 * if unknown.
+	 * 
+	 * @return InetAddress the address of the connection
+	 */
+	protected final InetAddress getRequestingSite() {
+		return this.addr;
+	}
+
+	/**
+	 * Answers the realm (prompt string) of the connection that requires
+	 * authorization.
+	 * 
+	 * @return java.lang.String the prompt string of the connection
+	 */
+	protected final String getRequestingPrompt() {
+		return this.prompt;
+	}
+
+	/**
+	 * Answers the protocol of the connection that requests authorization.
+	 * 
+	 * @return java.lang.String the protocol of connection
+	 */
+	protected final String getRequestingProtocol() {
+		return this.protocol;
+	}
+
+	/**
+	 * Answers the scheme of the connection that requires authorization. Eg.
+	 * Basic
+	 * 
+	 * @return java.lang.String the scheme of the connection
+	 */
+	protected final String getRequestingScheme() {
+		return this.scheme;
+	}
+
+	/**
+	 * If the permission check of the security manager does not result in a
+	 * security exception, this method invokes the methods of the registered
+	 * authenticator to get the authentication info.
+	 * 
+	 * @return java.net.PasswordAuthentication the authentication info
+	 * 
+	 * @param rAddr
+	 *            java.net.InetAddress the address of the connection that
+	 *            requests authentication
+	 * @param rPort
+	 *            int the port of the siconnectionte that requests
+	 *            authentication
+	 * @param rProtocol
+	 *            java.lang.String the protocol of the connection that requests
+	 *            authentication
+	 * @param rPrompt
+	 *            java.lang.String the realm of the connection that requests
+	 *            authentication
+	 * @param rScheme
+	 *            java.lang.String the scheme of the connection that requests
+	 *            authentication
+	 */
+	public static synchronized PasswordAuthentication requestPasswordAuthentication(
+			InetAddress rAddr, int rPort, String rProtocol, String rPrompt,
+			String rScheme) {
+		SecurityManager sm = System.getSecurityManager();
+		if (sm != null)
+			sm.checkPermission(requestPasswordAuthenticationPermission);
+		if (thisAuthenticator == null)
+			return null;
+		// set the requester info so it knows what it is requesting
+		// authentication for
+		thisAuthenticator.addr = rAddr;
+		thisAuthenticator.port = rPort;
+		thisAuthenticator.protocol = rProtocol;
+		thisAuthenticator.prompt = rPrompt;
+		thisAuthenticator.scheme = rScheme;
+
+		// returns the authentication info obtained by the registered
+		// Authenticator
+		return thisAuthenticator.getPasswordAuthentication();
+	}
+
+	/**
+	 * This method sets <code>a</code> to be the default authenticator. It
+	 * will be called whenever the realm that the URL is pointing to requires
+	 * authorization. If there is already an authenticator installed before or
+	 * <code>a</code> is null, it will simply do nothing.
+	 * 
+	 * @param a
+	 *            java.net.Authenticator The authenticator to be set.
+	 */
+	public static void setDefault(Authenticator a) {
+		SecurityManager sm = System.getSecurityManager();
+		if (sm != null)
+			sm.checkPermission(setDefaultAuthenticatorPermission);
+		if ((thisAuthenticator == null) && (a != null))
+			thisAuthenticator = a;
+	}
+
+	/**
+	 * If the permission check of the security manager does not result in a
+	 * security exception, this method invokes the methods of the registered
+	 * authenticator to get the authentication info.
+	 * 
+	 * @return java.net.PasswordAuthentication the authentication info
+	 * 
+	 * @param rHost
+	 *            java.lang.String the host name of the connection that requests
+	 *            authentication
+	 * @param rAddr
+	 *            java.net.InetAddress the address of the connection that
+	 *            requests authentication
+	 * @param rPort
+	 *            int the port of the siconnectionte that requests
+	 *            authentication
+	 * @param rProtocol
+	 *            java.lang.String the protocol of the connection that requests
+	 *            authentication
+	 * @param rPrompt
+	 *            java.lang.String the realm of the connection that requests
+	 *            authentication
+	 * @param rScheme
+	 *            java.lang.String the scheme of the connection that requests
+	 *            authentication
+	 */
+	public static synchronized PasswordAuthentication requestPasswordAuthentication(
+			String rHost, InetAddress rAddr, int rPort, String rProtocol,
+			String rPrompt, String rScheme) {
+		SecurityManager sm = System.getSecurityManager();
+		if (sm != null)
+			sm.checkPermission(requestPasswordAuthenticationPermission);
+		if (thisAuthenticator == null)
+			return null;
+		// set the requester info so it knows what it is requesting
+		// authentication for
+		thisAuthenticator.host = rHost;
+		thisAuthenticator.addr = rAddr;
+		thisAuthenticator.port = rPort;
+		thisAuthenticator.protocol = rProtocol;
+		thisAuthenticator.prompt = rPrompt;
+		thisAuthenticator.scheme = rScheme;
+
+		// returns the authentication info obtained by the registered
+		// Authenticator
+		return thisAuthenticator.getPasswordAuthentication();
+	}
+
+	/**
+	 * Return the host name of the connection that requests authentication, or
+	 * null if unknown.
+	 */
+	protected final String getRequestingHost() {
+		return host;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/BindException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/BindException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/BindException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/BindException.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.net;
+
+
+/**
+ * A BindException is thrown when a process cannot bind a local address/port,
+ * either because it is already bound or reserved by the OS.
+ */
+public class BindException extends SocketException {
+
+	/**
+	 * Constructs a new instance of this class with its walkback filled in.
+	 */
+	public BindException() {
+		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 BindException(String detailMessage) {
+		super(detailMessage);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/ConnectException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/ConnectException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/ConnectException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/ConnectException.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.net;
+
+
+/**
+ * This ConnectException is thrown when a connection cannot be established to a
+ * remote host/port, because for instance a server was not listening.
+ */
+public class ConnectException extends SocketException {
+
+	/**
+	 * Constructs a new instance of this class with its walkback filled in.
+	 */
+	public ConnectException() {
+		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 ConnectException(String detailMessage) {
+		super(detailMessage);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/ContentHandler.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/ContentHandler.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/ContentHandler.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/ContentHandler.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,71 @@
+/* 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.net;
+
+
+import java.io.IOException;
+
+/**
+ * This class converts the content of a certain format into a Java type Object.
+ * It is implemented differently for each content type in each platform. It is
+ * created by <code>ContentHandlerFactory</code>
+ * 
+ * @see ContentHandlerFactory
+ * @see URL
+ * @see URLConnection#getContent()
+ */
+abstract public class ContentHandler {
+	/**
+	 * Answers the object pointed by the specified URL Connection
+	 * <code>uConn</code>.
+	 * 
+	 * @return java.lang.Object the object refered by <code>uConn</code>
+	 * @param uConn
+	 *            java.net.URLConnection the url connection that points to the
+	 *            desired object
+	 * @exception java.io.IOException
+	 *                thrown if an IO error occurs during the retrieval of the
+	 *                object
+	 */
+	public abstract Object getContent(URLConnection uConn) throws IOException;
+
+	/**
+	 * Answers the object pointed by the specified URL Connection
+	 * <code>uConn</code>.
+	 * 
+	 * @param uConn
+	 *            java.net.URLConnection the url connection that points to the
+	 *            desired object
+	 * @param types
+	 *            The list of acceptable content types
+	 * @return Object The object of the resource pointed by this URL, or null if
+	 *         the content does not match a specified content type.
+	 * 
+	 * @exception IOException
+	 *                If an error occured obtaining the content.
+	 */
+	public Object getContent(URLConnection uConn, Class[] types)
+			throws IOException {
+		Object content = getContent(uConn);
+		Class cl = content.getClass();
+		for (int i = 0; i < types.length; i++) {
+			if (cl == types[i]) {
+				return content;
+			}
+		}
+		return null;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/ContentHandlerFactory.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/ContentHandlerFactory.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/ContentHandlerFactory.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/ContentHandlerFactory.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,31 @@
+/* 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.net;
+
+
+/**
+ * Defines a factory which is reponsible for creating a ContentHandler
+ */
+public interface ContentHandlerFactory {
+	/**
+	 * Creates a content handler to handle <code>contentType</code>
+	 * 
+	 * @return java.net.ContentHandler
+	 * @param contentType
+	 *            java.lang.String
+	 */
+	ContentHandler createContentHandler(String contentType);
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/DatagramPacket.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/DatagramPacket.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/DatagramPacket.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/DatagramPacket.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,288 @@
+/* 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.net;
+
+import com.ibm.oti.util.Msg;
+
+
+/**
+ * This class models a datagram packet to be sent or received. The
+ * DatagramPacket(byte[], int, InetAddress, int) constructor is used for packets
+ * to be sent, while the DatagramPacket(byte[], int) constructor is used for
+ * received packets.
+ * 
+ * @see DatagramSocket
+ */
+public final class DatagramPacket {
+	
+	byte[] data;
+
+	int length;
+
+	InetAddress address;
+
+	int port;
+
+	int offset = 0;
+
+	/**
+	 * Constructs a new <code>DatagramPacket</code> suitable for receiving
+	 * datagram packets of length up to <code>length</code>.
+	 * 
+	 * @param data
+	 *            byte array to store the read characters
+	 * @param length
+	 *            length of the data buffer
+	 */
+	public DatagramPacket(byte[] data, int length) {
+		this(data, 0, length);
+	}
+
+	/**
+	 * Constructs a new <code>DatagramPacket</code> suitable for receiving
+	 * datagram packets of length up to <code>length</code>, with an offset
+	 * into the buffer <code>offset</code>.
+	 * 
+	 * @param data
+	 *            byte array to store the read characters
+	 * @param offset
+	 *            the offset into the byte array
+	 * @param length
+	 *            length of the data buffer
+	 */
+	public DatagramPacket(byte[] data, int offset, int length) {
+		super();
+		setData(data, offset, length);
+	}
+
+	/**
+	 * Constructs a new <code>DatagramPacket</code> suitable for sending
+	 * packets to the nominated host/port. The <code>length</code> must be
+	 * less than or equal to the size of <code>data</code>.
+	 * 
+	 * @param data
+	 *            byte array to store the read characters
+	 * @param offset
+	 *            the offset in to read/write from
+	 * @param length
+	 *            length of the data buffer
+	 * @param host
+	 *            address of the target host
+	 * @param aPort
+	 *            target host port
+	 */
+
+	public DatagramPacket(byte[] data, int offset, int length,
+			InetAddress host, int aPort) {
+		this(data, offset, length);
+		setPort(aPort);
+		address = host;
+	}
+
+	/**
+	 * Constructs a new <code>DatagramPacket</code> suitable for sending
+	 * packets to the nominated host/port. The <code>length</code> must be
+	 * less than or equal to the size of <code>data</code>.
+	 * 
+	 * @param data
+	 *            byte array to store the read characters
+	 * @param length
+	 *            length of the data buffer
+	 * @param host
+	 *            address of the target host
+	 * @param port
+	 *            target host port
+	 */
+	public DatagramPacket(byte[] data, int length, InetAddress host, int port) {
+		this(data, 0, length, host, port);
+	}
+
+	/**
+	 * Answer the IP address of the machine that is the target or sender of this
+	 * datagram.
+	 * 
+	 * @return InetAddress the target host address
+	 */
+	public synchronized InetAddress getAddress() {
+		return address;
+	}
+
+	/**
+	 * Answer the data sent or received in this datagram.
+	 * 
+	 * @return byte[] the data sent/received
+	 */
+	public synchronized byte[] getData() {
+		return data;
+	}
+
+	/**
+	 * Answer the length of the data sent or received in this datagram.
+	 * 
+	 * @return int the length of the sent/received data
+	 */
+	public synchronized int getLength() {
+		return length;
+	}
+
+	/**
+	 * Answer the offset of the data sent or received in this datagram buffer.
+	 * 
+	 * @return int the offset of the start of the sent/received data
+	 */
+	public synchronized int getOffset() {
+		return offset;
+	}
+
+	/**
+	 * Answer the port number of the target or sender machine of this datagram.
+	 * 
+	 * @return int for received packets, the sender address and for sent
+	 *         packets, the target host
+	 */
+
+	public synchronized int getPort() {
+		return port;
+	}
+
+	/**
+	 * Set the IP address of the machine that is the target of this datagram.
+	 * 
+	 * @param addr
+	 *            the target host address
+	 */
+	public synchronized void setAddress(InetAddress addr) {
+		address = addr;
+	}
+
+	/**
+	 * Set the data buffer for this datagram.
+	 * 
+	 * @param buf
+	 *            the data to be sent
+	 * @param anOffset
+	 *            the offset into the data
+	 * @param aLength
+	 *            the length of the data to be sent
+	 */
+	public synchronized void setData(byte[] buf, int anOffset, int aLength) {
+		if (0 > anOffset || anOffset > buf.length || 0 > aLength
+				|| aLength > buf.length - anOffset)
+			throw new IllegalArgumentException(com.ibm.oti.util.Msg
+					.getString("K002f"));
+		data = buf;
+		offset = anOffset;
+		length = aLength;
+	}
+
+	/**
+	 * Set the data sent in this datagram.
+	 * 
+	 * @param buf
+	 *            the data to be sent
+	 */
+	public synchronized void setData(byte[] buf) {
+		length = buf.length; // This will check for null
+		data = buf;
+		offset = 0;
+	}
+
+	/**
+	 * Set the length of the data sent in this datagram.
+	 * 
+	 * @param len
+	 *            the length of the data to be sent
+	 */
+	public synchronized void setLength(int len) {
+		if (0 > len || offset + len > data.length) {
+			throw new IllegalArgumentException(Msg.getString("K002f"));
+		}
+		length = len;
+	}
+
+	/**
+	 * Set the port number of the target machine of this datagram.
+	 * 
+	 * @param aPort
+	 *            the target host port
+	 */
+	public synchronized void setPort(int aPort) {
+		if (aPort < 0 || aPort > 65535) {
+			throw new IllegalArgumentException(Msg.getString("K0325", aPort));
+		}
+		port = aPort;
+	}
+
+	/**
+	 * Constructs a new <code>DatagramPacket</code> suitable for sending
+	 * packets to the nominated host/port. The <code>length</code> must be
+	 * less than or equal to the size of <code>data</code>.
+	 * 
+	 * @param data
+	 *            byte array to store the read characters
+	 * @param length
+	 *            length of the data buffer
+	 * @param sockAddr
+	 *            the machine address and port
+	 */
+	public DatagramPacket(byte[] data, int length, SocketAddress sockAddr) {
+		this(data, 0, length);
+		setSocketAddress(sockAddr);
+	}
+
+	/**
+	 * Constructs a new <code>DatagramPacket</code> suitable for sending
+	 * packets to the nominated host/port. The <code>length</code> must be
+	 * less than or equal to the size of <code>data</code>.
+	 * 
+	 * @param data
+	 *            byte array to store the read characters
+	 * @param offset
+	 *            the offset in to read/write from
+	 * @param length
+	 *            length of the data buffer
+	 * @param sockAddr
+	 *            the machine address and port
+	 */
+	public DatagramPacket(byte[] data, int offset, int length,
+			SocketAddress sockAddr) {
+		this(data, offset, length);
+		setSocketAddress(sockAddr);
+	}
+
+	/**
+	 * Answer the SocketAddress for this packet.
+	 */
+	public SocketAddress getSocketAddress() {
+		return new InetSocketAddress(getAddress(), getPort());
+	}
+
+	/**
+	 * Set the SocketAddress for this packet.
+	 * 
+	 * @param sockAddr
+	 *            the machine address and port
+	 */
+	public void setSocketAddress(SocketAddress sockAddr) {
+		if (!(sockAddr instanceof InetSocketAddress)) {
+			throw new IllegalArgumentException(Msg.getString(
+					"K0316", sockAddr == null ? null : sockAddr.getClass())); //$NON-NLS-1$
+		}
+		InetSocketAddress inetAddr = (InetSocketAddress) sockAddr;
+		port = inetAddr.getPort();
+		address = inetAddr.getAddress();
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/DatagramSocket.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/DatagramSocket.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/DatagramSocket.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/DatagramSocket.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,811 @@
+/* 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.net;
+
+
+import java.io.IOException;
+import java.security.AccessController;
+
+import com.ibm.oti.util.Msg;
+import com.ibm.oti.util.PriviAction;
+
+/**
+ * This class models a socket for sending & receiving datagram packets.
+ * 
+ * @see DatagramPacket
+ */
+public class DatagramSocket {
+
+	DatagramSocketImpl impl;
+
+	InetAddress address;
+
+	int port = -1;
+
+	static DatagramSocketImplFactory factory;
+
+	boolean isBound = false;
+
+	private boolean isConnected = false;
+
+	private boolean isClosed = false;
+
+	Object lock = new Object();
+
+	/**
+	 * Constructs a datagram socket, bound to any available port on the
+	 * localhost.
+	 * 
+	 * @throws SocketException
+	 *             if a problem occurs creating or binding the socket
+	 */
+	public DatagramSocket() throws SocketException {
+		this(0);
+	}
+
+	/**
+	 * Answers a datagram socket, bound to the nominated port on the localhost.
+	 * 
+	 * @param aPort
+	 *            the port to bind on the localhost
+	 * 
+	 * @throws SocketException
+	 *             if a problem occurs creating or binding the socket
+	 */
+	public DatagramSocket(int aPort) throws SocketException {
+		super();
+		checkListen(aPort);
+		createSocket(aPort, InetAddress.ANY);
+	}
+
+	/**
+	 * Constructs a datagram socket, bound to the nominated localhost/port.
+	 * 
+	 * @param aPort
+	 *            the port on the localhost to bind
+	 * @param addr
+	 *            the address on the multihomed localhost to bind
+	 * 
+	 * @throws SocketException
+	 *             if a problem occurs creating or binding the socket
+	 */
+	public DatagramSocket(int aPort, InetAddress addr) throws SocketException {
+		super();
+		checkListen(aPort);
+		createSocket(aPort, null == addr ? InetAddress.ANY : addr);
+	}
+
+	/**
+	 * Sent prior to attempting to bind the socket, check that the port is
+	 * within the valid port range and verify with the security manager that the
+	 * port may be bound by the current context.
+	 * 
+	 * @param aPort
+	 *            the port on the localhost that is to be bound
+	 */
+	void checkListen(int aPort) {
+		if (aPort < 0 || aPort > 65535)
+			throw new IllegalArgumentException(Msg.getString("K0325", aPort));
+		SecurityManager security = System.getSecurityManager();
+		if (security != null)
+			security.checkListen(aPort);
+	}
+
+	/**
+	 * Close the socket.
+	 */
+	// In the documentation jdk1.1.7a/guide/net/miscNet.html, this method is
+	// noted as not
+	// being synchronized.
+	public void close() {
+		isClosed = true;
+		impl.close();
+	}
+
+	/**
+	 * Connect the datagram socket to a remote host and port. The host and port
+	 * are validated, thereafter the only validation on send() and receive() is
+	 * that the packet address/port matches the connected target.
+	 * 
+	 * @param anAddress
+	 *            the target address
+	 * @param aPort
+	 *            the target port
+	 */
+	public void connect(InetAddress anAddress, int aPort) {
+		if (anAddress == null || aPort < 0 || aPort > 65535)
+			throw new IllegalArgumentException(Msg.getString("K0032"));
+
+		synchronized (lock) {
+
+			if (isClosed())
+				return;
+			try {
+				checkClosedAndBind(true);
+			} catch (SocketException e) {
+			}
+
+			SecurityManager security = System.getSecurityManager();
+			if (security != null) {
+				if (anAddress.isMulticastAddress())
+					security.checkMulticast(anAddress);
+				else
+					security.checkConnect(anAddress.getHostName(), aPort);
+			}
+
+			try {
+				impl.connect(anAddress, aPort);
+			} catch (SocketException e) {
+				// not connected at the native level just do what we did before
+			}
+			address = anAddress;
+			port = aPort;
+			isConnected = true;
+		}
+	}
+
+	/**
+	 * 'Disconnect' the datagram socket from a remote host and port. This method
+	 * may be called on an unconnected socket.
+	 */
+	public void disconnect() {
+		if (isClosed() || !isConnected())
+			return;
+		impl.disconnect();
+		address = null;
+		port = -1;
+		isConnected = false;
+	}
+
+	synchronized void createSocket(int aPort, InetAddress addr)
+			throws SocketException {
+		impl = factory != null ? factory.createDatagramSocketImpl()
+				: createSocketImpl();
+		impl.create();
+		try {
+			impl.bind(aPort, addr);
+			isBound = true;
+		} catch (SocketException e) {
+			close();
+			throw e;
+		}
+	}
+
+	/**
+	 * Answer a concrete instance of DatagramSocketImpl, either as declared in
+	 * the system properties or the default, PlainDatagramSocketImpl. The latter
+	 * does not support security checks.
+	 * 
+	 * @return DatagramSocketImpl the concrete instance
+	 * 
+	 * @exception SocketException
+	 *                if an error occurs during the instantiation of a type
+	 *                declared in the system properties
+	 */
+	DatagramSocketImpl createSocketImpl() throws SocketException {
+		Object socketImpl = null;
+		String prefix;
+		prefix = (String) AccessController.doPrivileged(new PriviAction(
+				"impl.prefix", "Plain"));
+		try {
+			Class aClass = Class.forName("java.net." + prefix
+					+ "DatagramSocketImpl");
+			socketImpl = aClass.newInstance();
+		} catch (Exception e) {
+			throw new SocketException(Msg.getString("K0033"));
+		}
+		return (DatagramSocketImpl) socketImpl;
+	}
+
+	/**
+	 * Returns an {@link InetAddress} instance representing the address this
+	 * socket has connected to.
+	 * 
+	 * @return if this socket is connected, the address it is connected to. A
+	 *         <code>null</code> return signifies no connection has been made.
+	 */
+	public InetAddress getInetAddress() {
+		return address;
+	}
+
+	/**
+	 * Returns an {@link InetAddress} instance representing the <i>local</i>
+	 * address this socket is bound to.
+	 * 
+	 * @return the local address to which the socket is bound
+	 */
+	public InetAddress getLocalAddress() {
+		if (isClosed()) {
+			return null;
+		}
+		if (!isBound()) {
+			return InetAddress.ANY;
+		}
+		InetAddress anAddr = impl.getLocalAddress();
+		try {
+			SecurityManager security = System.getSecurityManager();
+			if (security != null)
+				security.checkConnect(anAddr.getHostName(), -1);
+		} catch (SecurityException e) {
+			return InetAddress.ANY;
+		}
+		return anAddr;
+	}
+
+	/**
+	 * Answer the local port to which the socket is bound.
+	 * 
+	 * @return int local port to which the socket is bound
+	 */
+	public int getLocalPort() {
+		if (isClosed()) {
+			return -1;
+		}
+		if (!isBound()) {
+			return 0;
+		}
+		return impl.getLocalPort();
+	}
+
+	/**
+	 * Returns the number of the remote port this socket is connected to.
+	 * 
+	 * @return int the remote port number that this socket has connected to. A
+	 *         return of <code>-1</code> indicates that there is no connection
+	 *         in place.
+	 */
+	public int getPort() {
+		return port;
+	}
+
+	boolean isMulticastSocket() {
+		return false;
+	}
+
+	/**
+	 * Answer the socket receive buffer size (SO_RCVBUF).
+	 * 
+	 * @return int socket receive buffer size
+	 * 
+	 * @exception SocketException
+	 *                when an error occurs
+	 */
+	public synchronized int getReceiveBufferSize() throws SocketException {
+		checkClosedAndBind(false);
+		return ((Integer) impl.getOption(SocketOptions.SO_RCVBUF)).intValue();
+	}
+
+	/**
+	 * Answer the socket send buffer size (SO_SNDBUF).
+	 * 
+	 * @return int socket send buffer size
+	 * 
+	 * @exception SocketException
+	 *                when an error occurs
+	 */
+	public synchronized int getSendBufferSize() throws SocketException {
+		checkClosedAndBind(false);
+		return ((Integer) impl.getOption(SocketOptions.SO_SNDBUF)).intValue();
+	}
+
+	/**
+	 * Answer the socket receive timeout (SO_RCVTIMEOUT), in milliseconds. Zero
+	 * implies the timeout is disabled.
+	 * 
+	 * @return int socket receive timeout
+	 * 
+	 * @exception SocketException
+	 *                when an error occurs
+	 */
+	public synchronized int getSoTimeout() throws SocketException {
+		checkClosedAndBind(false);
+		return ((Integer) impl.getOption(SocketOptions.SO_TIMEOUT)).intValue();
+	}
+
+	/**
+	 * Receive on this socket into the packet argument. This method blocks until
+	 * a packet is received or, if a timeout has been defined, the timeout
+	 * period expires. If this is a connected socket, the packet host/port are
+	 * compared to the connection host/port otherwise the security manager if
+	 * present is queried whether the packet host/port is acceptable. Any
+	 * packets from unacceptable origins will be silently discarded. The packet
+	 * fields are set according to the data received. If the received data is
+	 * longer than the packet buffer, it is truncated.
+	 * 
+	 * @param pack
+	 *            the DatagramPacket to receive data into
+	 * 
+	 * @exception java.io.IOException
+	 *                If a receive error occurs.
+	 */
+	public synchronized void receive(DatagramPacket pack) throws IOException {
+		checkClosedAndBind(true);
+
+		boolean secure = true;
+
+		InetAddress senderAddr = null;
+
+		int senderPort = 0;
+		DatagramPacket tempPack = new DatagramPacket(new byte[1], 1);
+		boolean copy = false;
+
+		SecurityManager security = System.getSecurityManager();
+		if (address != null || security != null) { // The socket is connected
+			// Check pack before peeking
+			if (pack == null)
+				throw new NullPointerException();
+			secure = false;
+			while (!secure) {
+				copy = false;
+				try {
+					senderPort = impl.peekData(tempPack);
+					senderAddr = tempPack.getAddress();
+				} catch (SocketException e) {
+					if (e.getMessage().equals(
+							"The socket does not support the operation")) {
+						tempPack = new DatagramPacket(new byte[pack.length],
+								pack.getLength());
+						impl.receive(tempPack);
+						senderAddr = tempPack.getAddress();
+						senderPort = tempPack.getPort();
+						copy = true;
+					} else
+						throw e;
+				}
+				if (address == null) {
+					try {
+						security.checkAccept(senderAddr.getHostName(),
+								senderPort);
+						if (!copy)
+							secure = true;
+						break;
+					} catch (SecurityException e) {
+						if (!copy) {
+							if (tempPack == null)
+								tempPack = new DatagramPacket(
+										new byte[pack.length], pack.length);
+							impl.receive(tempPack);
+						}
+					}
+				} else if (port == senderPort && address.equals(senderAddr)) {
+					if (!copy)
+						secure = true;
+					break;
+				} else if (!copy) {
+					if (tempPack == null)
+						tempPack = new DatagramPacket(new byte[pack.length],
+								pack.length);
+					impl.receive(tempPack);
+				}
+			}
+		}
+		if (copy) {
+			System.arraycopy(tempPack.getData(), 0, pack.getData(), pack
+					.getOffset(), tempPack.getLength());
+			pack.setLength(tempPack.getLength());
+			pack.setAddress(tempPack.getAddress());
+			pack.setPort(tempPack.getPort());
+		}
+		if (secure) {
+			impl.receive(pack);
+		}
+	}
+
+	/**
+	 * Send the packet on this socket. The packet must satisfy the security
+	 * policy before it may be sent.
+	 * 
+	 * @param pack
+	 *            the DatagramPacket to send
+	 * 
+	 * @exception java.io.IOException
+	 *                If a send error occurs.
+	 */
+	public void send(DatagramPacket pack) throws IOException {
+		checkClosedAndBind(true);
+
+		InetAddress packAddr = pack.getAddress();
+		if (address != null) { // The socket is connected
+			if (packAddr != null) {
+				if (!address.equals(packAddr) || port != pack.getPort())
+					throw new IllegalArgumentException(Msg.getString("K0034"));
+			} else {
+				pack.setAddress(address);
+				pack.setPort(port);
+			}
+		} else {
+			// not connected so the target address cannot be null
+			if (packAddr == null) {
+				throw new NullPointerException(Msg.getString("K0331"));
+			}
+			SecurityManager security = System.getSecurityManager();
+			if (security != null) {
+				if (packAddr.isMulticastAddress())
+					security.checkMulticast(packAddr);
+				else
+					security.checkConnect(packAddr.getHostName(), pack
+							.getPort());
+			}
+		}
+		impl.send(pack);
+	}
+
+	/**
+	 * Set the socket send buffer size.
+	 * 
+	 * @param size
+	 *            the buffer size, in bytes
+	 * 
+	 * @exception java.net.SocketException
+	 *                If an error occurs while setting the size or the size is
+	 *                invalid.
+	 */
+	public synchronized void setSendBufferSize(int size) throws SocketException {
+		if (size >= 1) {
+			checkClosedAndBind(false);
+			impl.setOption(SocketOptions.SO_SNDBUF, new Integer(size));
+		} else
+			throw new IllegalArgumentException(Msg.getString("K0035"));
+	}
+
+	/**
+	 * Set the socket receive buffer size.
+	 * 
+	 * @param size
+	 *            the buffer size, in bytes
+	 * 
+	 * @exception java.net.SocketException
+	 *                If an error occurs while setting the size or the size is
+	 *                invalid.
+	 */
+	public synchronized void setReceiveBufferSize(int size)
+			throws SocketException {
+		if (size >= 1) {
+			checkClosedAndBind(false);
+			impl.setOption(SocketOptions.SO_RCVBUF, new Integer(size));
+		} else
+			throw new IllegalArgumentException(Msg.getString("K0035"));
+	}
+
+	/**
+	 * Set the SO_RCVTIMEOUT to <code>timeout</code>, in milliseconds. The
+	 * receive timeout defines the period a socket will block waiting to receive
+	 * data, before throwing an InterruptedIOException.
+	 * 
+	 * @param timeout
+	 *            the timeout period, in milliseconds
+	 * 
+	 * @exception java.net.SocketException
+	 *                If an error occurs while setting the timeout or the period
+	 *                is invalid.
+	 */
+	public synchronized void setSoTimeout(int timeout) throws SocketException {
+		if (timeout >= 0) {
+			checkClosedAndBind(false);
+			impl.setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout));
+		} else
+			throw new IllegalArgumentException(Msg.getString("K0036"));
+	}
+
+	/**
+	 * Specifies the application's socket implementation factory. This may only
+	 * be invoked once over the lifetime of the application.
+	 * 
+	 * @param fac
+	 *            the socket factory to set
+	 * @exception IOException
+	 *                thrown if the factory has already been set
+	 */
+	public static synchronized void setDatagramSocketImplFactory(
+			DatagramSocketImplFactory fac) throws IOException {
+		SecurityManager security = System.getSecurityManager();
+		if (security != null)
+			security.checkSetFactory();
+		if (factory == null)
+			factory = fac;
+		else
+			throw new SocketException(Msg.getString("K0044"));
+	}
+
+	/**
+	 * Constructs a DatagramSocket using the specified DatagramSocketImpl. The
+	 * DatagramSocket is not bound.
+	 * 
+	 * @param socketImpl
+	 *            the DatagramSocketImpl to use
+	 */
+	protected DatagramSocket(DatagramSocketImpl socketImpl) {
+		impl = socketImpl;
+	}
+
+	/**
+	 * Constructs a DatagramSocket bound to the host/port specified by the
+	 * SocketAddress, or an unbound DatagramSocket if the SocketAddress is null.
+	 * 
+	 * @param localAddr
+	 *            the local machine address and port to bind to
+	 * 
+	 * @throws IllegalArgumentException
+	 *             if the SocketAddress is not supported
+	 * @throws SocketException
+	 *             if a problem occurs creating or binding the socket
+	 */
+	public DatagramSocket(SocketAddress localAddr) throws SocketException {
+		if (localAddr != null) {
+			if (!(localAddr instanceof InetSocketAddress))
+				throw new IllegalArgumentException(Msg.getString(
+						"K0316", localAddr.getClass())); //$NON-NLS-1$
+			checkListen(((InetSocketAddress) localAddr).getPort());
+		}
+		impl = factory != null ? factory.createDatagramSocketImpl()
+				: createSocketImpl();
+		impl.create();
+		if (localAddr != null) {
+			try {
+				bind(localAddr);
+			} catch (SocketException e) {
+				close();
+				throw e;
+			}
+		}
+	}
+
+	void checkClosedAndBind(boolean bind) throws SocketException {
+		if (isClosed()) {
+			throw new SocketException(Msg.getString("K003d"));
+		}
+		if (bind && !isBound()) {
+			checkListen(0);
+			impl.bind(0, InetAddress.ANY);
+			isBound = true;
+		}
+	}
+
+	/**
+	 * Bind the DatagramSocket to the nominated local host/port.
+	 * 
+	 * @param localAddr
+	 *            the local machine address and port to bind on
+	 * 
+	 * @throws IllegalArgumentException
+	 *             if the SocketAddress is not supported
+	 * @throws SocketException
+	 *             if the socket is already bound, or a problem occurs during
+	 *             the bind
+	 */
+	public void bind(SocketAddress localAddr) throws SocketException {
+		checkClosedAndBind(false);
+		int localPort = 0;
+		InetAddress addr = InetAddress.ANY;
+		if (localAddr != null) {
+			if (!(localAddr instanceof InetSocketAddress))
+				throw new IllegalArgumentException(Msg.getString(
+						"K0316", localAddr.getClass())); //$NON-NLS-1$
+			InetSocketAddress inetAddr = (InetSocketAddress) localAddr;
+			addr = inetAddr.getAddress();
+			if (addr == null)
+				throw new SocketException(Msg.getString(
+						"K0317", inetAddr.getHostName())); //$NON-NLS-1$
+			localPort = inetAddr.getPort();
+			checkListen(localPort);
+		}
+		impl.bind(localPort, addr);
+		isBound = true;
+	}
+
+	/**
+	 * Connect the datagram socket to a remote host and port. The host and port
+	 * are validated, thereafter the only validation on send() and receive() is
+	 * that the packet address/port matches the connected target.
+	 * 
+	 * @param remoteAddr
+	 *            the target address and port
+	 * 
+	 * @exception SocketException
+	 *                if a problem occurs during the connect
+	 */
+	public void connect(SocketAddress remoteAddr) throws SocketException {
+		if (remoteAddr == null) {
+			throw new IllegalArgumentException(Msg.getString("K0318"));
+		}
+
+		if (!(remoteAddr instanceof InetSocketAddress)) {
+			throw new IllegalArgumentException(Msg.getString(
+					"K0316", remoteAddr.getClass())); //$NON-NLS-1$
+		}
+
+		InetSocketAddress inetAddr = (InetSocketAddress) remoteAddr;
+		if (inetAddr.getAddress() == null) {
+			throw new SocketException(Msg.getString(
+					"K0317", inetAddr.getHostName())); //$NON-NLS-1$
+		}
+
+		synchronized (lock) {
+			// make sure the socket is open
+			checkClosedAndBind(true);
+
+			SecurityManager security = System.getSecurityManager();
+			if (security != null) {
+				if (inetAddr.getAddress().isMulticastAddress()) {
+					security.checkMulticast(inetAddr.getAddress());
+				} else {
+					security.checkConnect(inetAddr.getAddress().getHostName(),
+							inetAddr.getPort());
+				}
+			}
+
+			// now try to do the connection at the native level. To be
+			// compatible for the case
+			// when the address is inaddr_any we just
+			// eat the exception an act as if we are connected at the java level
+			try {
+				impl.connect(inetAddr.getAddress(), inetAddr.getPort());
+			} catch (Exception e) {
+				// not connected at the native level just do what we did before
+			}
+
+			// if we get here then we connected ok
+			address = inetAddr.getAddress();
+			port = inetAddr.getPort();
+			isConnected = true;
+		}
+	}
+
+	/**
+	 * Return if the socket is bound to a local address and port.
+	 * 
+	 * @return <code>true</code> if the socket is bound to a local address,
+	 *         <code>false</code> otherwise.
+	 */
+	public boolean isBound() {
+		return isBound;
+	}
+
+	/**
+	 * Return if the socket is connected.
+	 * 
+	 * @return <code>true</code> if the socket is connected,
+	 *         <code>false</code> otherwise.
+	 */
+	public boolean isConnected() {
+		return isConnected;
+	}
+
+	/**
+	 * Answer the remote SocketAddress for this socket, or null if the socket is
+	 * not connected.
+	 * 
+	 * @return the remote socket address
+	 */
+	public SocketAddress getRemoteSocketAddress() {
+		if (!isConnected())
+			return null;
+		return new InetSocketAddress(getInetAddress(), getPort());
+	}
+
+	/**
+	 * Answer the local SocketAddress for this socket, or null if the socket is
+	 * not bound.
+	 * <p>
+	 * This is useful on multihomed hosts.
+	 * 
+	 * @return the local socket address
+	 */
+	public SocketAddress getLocalSocketAddress() {
+		if (!isBound())
+			return null;
+		return new InetSocketAddress(getLocalAddress(), getLocalPort());
+	}
+
+	/**
+	 * Set the SO_REUSEADDR socket option.
+	 * 
+	 * @param reuse
+	 *            the socket SO_REUSEADDR option setting
+	 * 
+	 * @throws SocketException
+	 *             if the socket is closed or the option is invalid.
+	 */
+	public void setReuseAddress(boolean reuse) throws SocketException {
+		checkClosedAndBind(false);
+		impl.setOption(SocketOptions.SO_REUSEADDR, reuse ? Boolean.TRUE
+				: Boolean.FALSE);
+	}
+
+	/**
+	 * Get the state of the SO_REUSEADDR socket option.
+	 * 
+	 * @return <code>true</code> if the SO_REUSEADDR is enabled,
+	 *         <code>false</code> otherwise.
+	 * 
+	 * @throws SocketException
+	 *             if the socket is closed or the option is invalid.
+	 */
+	public boolean getReuseAddress() throws SocketException {
+		checkClosedAndBind(false);
+		return ((Boolean) impl.getOption(SocketOptions.SO_REUSEADDR))
+				.booleanValue();
+	}
+
+	/**
+	 * Set the SO_BROADCAST socket option.
+	 * 
+	 * @param broadcast
+	 *            the socket SO_BROADCAST option setting
+	 * 
+	 * @throws SocketException
+	 *             if the socket is closed or the option is invalid.
+	 */
+	public void setBroadcast(boolean broadcast) throws SocketException {
+		checkClosedAndBind(false);
+		impl.setOption(SocketOptions.SO_BROADCAST, broadcast ? Boolean.TRUE
+				: Boolean.FALSE);
+	}
+
+	/**
+	 * Get the state of the SO_BROADCAST socket option.
+	 * 
+	 * @return <code>true</code> if the SO_BROADCAST is enabled,
+	 *         <code>false</code> otherwise.
+	 * 
+	 * @throws SocketException
+	 *             if the socket is closed or the option is invalid.
+	 */
+	public boolean getBroadcast() throws SocketException {
+		checkClosedAndBind(false);
+		return ((Boolean) impl.getOption(SocketOptions.SO_BROADCAST))
+				.booleanValue();
+	}
+
+	/**
+	 * Set the IP_TOS socket option.
+	 * 
+	 * @param value
+	 *            the socket IP_TOS setting
+	 * 
+	 * @throws SocketException
+	 *             if the socket is closed or the option is invalid.
+	 */
+	public void setTrafficClass(int value) throws SocketException {
+		checkClosedAndBind(false);
+		if (value < 0 || value > 255)
+			throw new IllegalArgumentException();
+		impl.setOption(SocketOptions.IP_TOS, new Integer(value));
+	}
+
+	/**
+	 * Get the IP_TOS socket option.
+	 * 
+	 * @return the IP_TOS socket option value
+	 * 
+	 * @throws SocketException
+	 *             if the option is invalid
+	 */
+	public int getTrafficClass() throws SocketException {
+		checkClosedAndBind(false);
+		return ((Number) impl.getOption(SocketOptions.IP_TOS)).intValue();
+	}
+
+	/**
+	 * Return if the socket is closed.
+	 * 
+	 * @return <code>true</code> if the socket is closed, <code>false</code>
+	 *         otherwise.
+	 */
+	public boolean isClosed() {
+		return isClosed;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/DatagramSocketImpl.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/DatagramSocketImpl.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/DatagramSocketImpl.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/DatagramSocketImpl.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,292 @@
+/* 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.net;
+
+
+import java.io.FileDescriptor;
+import java.io.IOException;
+
+/**
+ * The abstract superclass of datagram & multicast socket implementatations.
+ */
+public abstract class DatagramSocketImpl implements SocketOptions {
+
+	protected FileDescriptor fd;
+
+	protected int localPort;
+
+	int receiveTimeout;
+
+	/**
+	 * Constructs an unbound datagram socket implementation.
+	 */
+	public DatagramSocketImpl() {
+		initializeSocket();
+	}
+
+	/**
+	 * Bind the datagram socket to the nominated localhost/port. Sockets must be
+	 * bound prior to attempting to send or receive data.
+	 * 
+	 * @param port
+	 *            the port on the localhost to bind
+	 * @param addr
+	 *            the address on the multihomed localhost to bind
+	 * 
+	 * @exception SocketException
+	 *                if an error occured during bind, such as if the port was
+	 *                already bound
+	 */
+	protected abstract void bind(int port, InetAddress addr)
+			throws SocketException;
+
+	/**
+	 * Close the socket.
+	 */
+	protected abstract void close();
+
+	/**
+	 * This method allocates the socket descriptor in the underlying operating
+	 * system.
+	 */
+	protected abstract void create() throws SocketException;
+
+	/**
+	 * Answer the FileDescriptor, which will be invalid if the socket is closed
+	 * or not bound.
+	 * 
+	 * @return FileDescriptor the socket file descriptor
+	 */
+	protected FileDescriptor getFileDescriptor() {
+		return fd;
+	}
+
+	/**
+	 * Answer the local address to which the socket is bound.
+	 * 
+	 * @return InetAddress the local address to which the socket is bound.
+	 */
+	abstract InetAddress getLocalAddress();
+
+	/**
+	 * Answer the local port. If the socket was bound to any available port, as
+	 * flagged by a <code>localPort</code> value of -1, query the IP stack.
+	 * 
+	 * @return int the local port to which the socket is bound.
+	 */
+	protected int getLocalPort() {
+		return localPort;
+	}
+
+	/**
+	 * Answer the nominated socket option.
+	 * 
+	 * @param optID
+	 *            the socket option to retrieve
+	 * @return Object the option value
+	 * @exception SocketException
+	 *                thrown if an error occurs while accessing the option
+	 */
+	public abstract Object getOption(int optID) throws SocketException;
+
+	/**
+	 * Answer the time-to-live (TTL) for multicast packets sent on this socket.
+	 * 
+	 * @return java.net.InetAddress
+	 * @exception java.io.IOException
+	 *                The exception description.
+	 * @deprecated Replaced by getTimeToLive
+	 * @see #getTimeToLive()
+	 */
+	protected abstract byte getTTL() throws IOException;
+
+	/**
+	 * Answer the time-to-live (TTL) for multicast packets sent on this socket.
+	 * 
+	 * @return int
+	 * @exception java.io.IOException
+	 *                The exception description.
+	 */
+	protected abstract int getTimeToLive() throws IOException;
+
+	/**
+	 * Allocate a FileDescriptor and flag the localPort, so that a lookup to the
+	 * IP stack is forced in <code>getLocalPort</code>.
+	 */
+	void initializeSocket() {
+		fd = new FileDescriptor();
+		localPort = -1;
+		receiveTimeout = 0;
+	}
+
+	/**
+	 * Add this socket to the multicast group. A socket must join a group before
+	 * data may be received. A socket may be a member of multiple groups but may
+	 * join any group once.
+	 * 
+	 * @param addr
+	 *            the multicast group to be joined
+	 * @exception java.io.IOException
+	 *                may be thrown while joining a group
+	 */
+	protected abstract void join(InetAddress addr) throws IOException;
+
+	/**
+	 * Add this socket to the multicast group. A socket must join a group before
+	 * data may be received. A socket may be a member of multiple groups but may
+	 * join any group once.
+	 * 
+	 * @param addr
+	 *            the multicast group to be joined
+	 * @param netInterface
+	 *            the network interface on which the addresses should be dropped
+	 * @exception java.io.IOException
+	 *                may be thrown while joining a group
+	 */
+	protected abstract void joinGroup(SocketAddress addr,
+			NetworkInterface netInterface) throws IOException;
+
+	/**
+	 * Remove the socket from the multicast group.
+	 * 
+	 * @param addr
+	 *            the multicast group to be left
+	 * @exception java.io.IOException
+	 *                May be thrown while leaving the group
+	 */
+	protected abstract void leave(InetAddress addr) throws IOException;
+
+	/**
+	 * Remove the socket from the multicast group.
+	 * 
+	 * @param addr
+	 *            the multicast group to be left
+	 * @param netInterface
+	 *            the network interface on which the addresses should be dropped
+	 * @exception java.io.IOException
+	 *                May be thrown while leaving the group
+	 */
+	protected abstract void leaveGroup(SocketAddress addr,
+			NetworkInterface netInterface) throws IOException;
+
+	/**
+	 * Peek at the incoming packet to this socket and answer the sender's
+	 * address into <code>sender</code>. The method will block until a packet
+	 * is received or timeout expires and returns the sender's port.
+	 * 
+	 * @exception IOException
+	 *                if a read error or timeout occurs
+	 */
+	protected abstract int peek(InetAddress sender) throws IOException;
+
+	/**
+	 * Receive data into the supplied datagram packet. This call will block
+	 * until either data is received or, if a timeout is set, the timeout
+	 * expires. If the timeout expires, the InterruptedIOException is thrown.
+	 * 
+	 * @exception IOException
+	 *                if a read error or timeout occurs
+	 */
+	protected abstract void receive(DatagramPacket pack) throws IOException;
+
+	/**
+	 * Sends the supplied datagram packet. The packet contains the destination
+	 * host & port.
+	 * 
+	 * @param pack
+	 *            DatagramPacket to send
+	 * 
+	 * @exception IOException
+	 *                if a write error occurs
+	 */
+	protected abstract void send(DatagramPacket pack) throws IOException;
+
+	/**
+	 * Set the nominated socket option.
+	 * 
+	 * @param optID
+	 *            the socket option to set
+	 * @param val
+	 *            the option value
+	 * @exception SocketException
+	 *                thrown if an error occurs while setting the option
+	 */
+	public abstract void setOption(int optID, Object val)
+			throws SocketException;
+
+	/**
+	 * Set the time-to-live (TTL) for multicast packets sent on this socket.
+	 * 
+	 * @param ttl
+	 *            the time-to-live, 0<ttl<= 255
+	 * @exception java.io.IOException
+	 *                The exception thrown while setting the TTL
+	 */
+	protected abstract void setTimeToLive(int ttl) throws IOException;
+
+	/**
+	 * Set the time-to-live (TTL) for multicast packets sent on this socket.
+	 * 
+	 * @param ttl
+	 *            the time-to-live, 0<ttl<= 255
+	 * @exception java.io.IOException
+	 *                The exception thrown while setting the TTL
+	 * @deprecated Replaced by setTimeToLive
+	 * @see #setTimeToLive(int)
+	 */
+	protected abstract void setTTL(byte ttl) throws IOException;
+
+	/**
+	 * Connect the socket to the specified remote address and port.
+	 * 
+	 * @param inetAddr
+	 *            the remote address
+	 * @param port
+	 *            the remote port
+	 * 
+	 * @exception SocketException
+	 *                possibly thrown, if the datagram socket cannot be
+	 *                connected to the specified remote address and port
+	 */
+	protected void connect(InetAddress inetAddr, int port)
+			throws SocketException {
+		// do nothing
+	}
+
+	/**
+	 * Disconnect the socket from the remote address and port.
+	 */
+	protected void disconnect() {
+		// do nothing
+	}
+
+	/**
+	 * Receive data into the supplied datagram packet by peeking. The data is
+	 * not removed and will be received by another peekData() or receive() call.
+	 * 
+	 * This call will block until either data is received or, if a timeout is
+	 * set, the timeout expires.
+	 * 
+	 * @param pack
+	 *            the DatagramPacket used to store the data
+	 * 
+	 * @return the port the packet was received from
+	 * 
+	 * @exception IOException
+	 *                if an error occurs
+	 */
+	protected abstract int peekData(DatagramPacket pack) throws IOException;
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/DatagramSocketImplFactory.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/DatagramSocketImplFactory.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/DatagramSocketImplFactory.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/DatagramSocketImplFactory.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,31 @@
+/* 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.net;
+
+
+/**
+ * This interface defines a factory for datagram socket implementations. It is
+ * used by the class <code>DatagramSocket</code> to create datagram socket
+ * implementations.
+ */
+public interface DatagramSocketImplFactory {
+	/**
+	 * Creates a new <code>SocketImpl</code> instance.
+	 * 
+	 * @return SocketImpl
+	 */
+	DatagramSocketImpl createDatagramSocketImpl();
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/FileNameMap.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/FileNameMap.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/FileNameMap.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/FileNameMap.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,39 @@
+/* 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.net;
+
+
+/**
+ * Defines a scheme for mapping a filename type to a MIME content type. Mainly
+ * used by <code>URLStreamHandler</code> for determining the right content
+ * handler to handle the resource.
+ * 
+ * @see ContentHandler
+ * @see URLConnection#getFileNameMap()
+ * @see URLConnection#guessContentTypeFromName(String)
+ * @see URLStreamHandler
+ */
+public interface FileNameMap {
+	/**
+	 * Determines the MIME types for a file <code>fileName</code> of a
+	 * <code>URL</code>.
+	 * 
+	 * @return java.lang.String
+	 * @param fileName
+	 *            java.lang.String
+	 */
+	public String getContentTypeFor(String fileName);
+}



Mime
View raw message