harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ghar...@apache.org
Subject svn commit: r407625 [7/16] - in /incubator/harmony/enhanced/classlib/trunk/modules/rmi3: ./ doc/ make/ src/ src/common/ src/common/javasrc/ src/common/javasrc/java/ src/common/javasrc/java/rmi/ src/common/javasrc/java/rmi/activation/ src/common/javasrc...
Date Thu, 18 May 2006 20:01:30 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/ClassList.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/ClassList.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/ClassList.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/ClassList.java Thu May 18 13:01:22 2006
@@ -0,0 +1,323 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.2 $
+ */
+package org.apache.harmony.rmi.common;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Vector;
+
+
+/**
+ * Stores list of classes ({@link Class} instances), making sure
+ * no duplicates are stored, and taking inheritance into account.
+ *
+ * The classes are stores in order they were added, so that no class
+ * in the list inherits any other class in the list. When each new class
+ * is added to the list, all its superclasses (or subclasses, if
+ * <em>inverse</em> flag was set in constructor) are removed from the list.
+ *
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.2 $
+ */
+public final class ClassList {
+
+    /**
+     * Storage vector.
+     */
+    private Vector vector;
+
+    /**
+     * Inverse flag.
+     */
+    private boolean inverse;
+
+    /**
+     * Creates empty list, equivalent to
+     * {@link #ClassList(boolean) ClassList(false)}.
+     */
+    public ClassList() {
+        this(false);
+    }
+
+    /**
+     * Creates empty list.
+     *
+     * @param   inverse
+     *          Inverse flag, see {@linkplain ClassList class description}.
+     */
+    public ClassList(boolean inverse) {
+        this.inverse = inverse;
+        vector = new Vector();
+    }
+
+    /**
+     * Creates list and all the elements from the specified array, equivalent to
+     * {@link #ClassList(Class[], boolean) ClassList(Class[], false)}.
+     *
+     * @param   classes
+     *          Initial classes to put to the list.
+     */
+    public ClassList(Class[] classes) {
+        this(false);
+        addAll(classes);
+    }
+
+    /**
+     * Creates list and all the elements from the specified array.
+     *
+     * @param   classes
+     *          Initial classes to put to the list.
+     *
+     * @param   inverse
+     *          Inverse flag, see {@linkplain ClassList class description}.
+     */
+    public ClassList(Class[] classes, boolean inverse) {
+        this(inverse);
+        addAll(classes);
+    }
+
+    /**
+     * Creates list and all the elements from the specified collection,
+     * equivalent to
+     * {@link #ClassList(Collection, boolean) ClassList(Collection, false)}.
+     *
+     * @param   classes
+     *          Initial classes to put to the list.
+     */
+    public ClassList(Collection classes) {
+        this(false);
+        addAll(classes);
+    }
+
+    /**
+     * Creates list and all the elements from the specified collection.
+     *
+     * @param   classes
+     *          Initial classes to put to the list.
+     *
+     * @param   inverse
+     *          Inverse flag, see {@linkplain ClassList class description}.
+     */
+    public ClassList(Collection classes, boolean inverse) {
+        this(inverse);
+        addAll(classes);
+    }
+
+    /**
+     * Creates list and all the elements from the specified list, equivalent to
+     * {@link #ClassList(ClassList, boolean) ClassList(ClassList, false)}.
+     *
+     * @param   classes
+     *          Initial classes to put to the list.
+     */
+    public ClassList(ClassList classes) {
+        this(false);
+        addAll(classes);
+    }
+
+    /**
+     * Creates list and all the elements from the specified list.
+     *
+     * @param   classes
+     *          Initial classes to put to the list.
+     *
+     * @param   inverse
+     *          Inverse flag, see {@linkplain ClassList class description}.
+     */
+    public ClassList(ClassList classes, boolean inverse) {
+        this(inverse);
+        addAll(classes);
+    }
+
+    /**
+     * Return <code>true</code>
+     * if <code>cls2</code> is assignable from <code>cls1</code>
+     * and {@linkplain ClassList inverse flag} is <code>true</code>
+     * or if <code>cls1</code> is assignable from <code>cls2</code>
+     * and {@linkplain ClassList inverse flag} is <code>false</code>,
+     * <code>false</code> otherwise.
+     *
+     * @param   cls1
+     *          Class to check.
+     *
+     * @param   cls2
+     *          Class to check.
+     *
+     * @return  <code>true</code> if <code>cls2</code> is assignable from
+     *          <code>cls1</code> and {@linkplain ClassList inverse flag}
+     *          is <code>true</code> or if <code>cls1</code> is assignable
+     *          from <code>cls2</code> and {@linkplain ClassList inverse flag}
+     *          is <code>false</code>, <code>false</code> otherwise.
+     */
+    private boolean checkAssign(Class cls1, Class cls2) {
+        return (inverse
+                ? cls2.isAssignableFrom(cls1)
+                : cls1.isAssignableFrom(cls2));
+    }
+
+    /**
+     * Returns <code>true</code> if the list contains the specified
+     * class or any of its subclasses/superclasses (depending on
+     * {@linkplain ClassList inverse flag}), <code>false</code> otherwise.
+     *
+     * @param   cls
+     *          Class to check.
+     *
+     * @return  <code>true</code> if the list contains the specified
+     *          class or any of its subclasses/superclasses (depending
+     *          on {@linkplain ClassList inverse flag}), <code>false</code>
+     *          otherwise.
+     */
+    public boolean contains(Class cls) {
+        int size = vector.size();
+
+        for (int i = 0; i < size; i++) {
+            if (checkAssign(cls, (Class) vector.elementAt(i))) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Adds the specified class to the end of the list. All its
+     * superclasses/subclasses
+     * (depending on {@linkplain ClassList inverse flag}),
+     * if present, are removed. If class itself or any of its
+     * subclasses/superclasses is already present, nothing is done.
+     *
+     * @param   cls
+     *          Class to add.
+     */
+    public void add(Class cls) {
+        boolean exist = false;
+
+        // Do not pre-caclculate size, it will change.
+        for (int i = 0; i < vector.size(); i++) {
+            Class element = (Class) vector.elementAt(i);
+
+            // If subclass/superclass is present, do nothing, return.
+            if (checkAssign(cls, element)) {
+                return;
+            }
+
+            // If superclass/subclass is present, make sure class is present,
+            // remove any other other superclasses/subclasses.
+            if (checkAssign(element, cls)) {
+                if (!exist) {
+                    vector.setElementAt(cls, i);
+                    exist = true;
+                } else {
+                    vector.removeElementAt(i);
+                }
+            }
+        }
+
+        if (!exist) {
+            vector.addElement(cls);
+        }
+    }
+
+    /**
+     * Adds the all classes in the specified array to the list.
+     * See {@link #add(Class)} for details.
+     *
+     * @param   classes
+     *          Classes to add.
+     */
+    public void addAll(Class[] classes) {
+        for (int i = 0; i < classes.length; i++) {
+            add(classes[i]);
+        }
+    }
+
+    /**
+     * Adds the all classes in the specified collection to the list.
+     * See {@link #add(Class)} for details.
+     *
+     * @param   classes
+     *          Classes to add.
+     */
+    public void addAll(Collection classes) {
+        for (Iterator i = classes.iterator(); i.hasNext(); ) {
+            add((Class) i.next());
+        }
+    }
+
+    /**
+     * Adds the all classes in the specified list to this list.
+     * See {@link #add(Class)} for details.
+     *
+     * @param   classes
+     *          Classes to add.
+     */
+    public void addAll(ClassList classes) {
+        addAll(classes.vector);
+    }
+
+    /**
+     * Removes the specified class from the list.
+     * If class itself is not present, but its superclasses/subclasses
+     * (depending on {@linkplain ClassList inverse flag}) are, they are removed.
+     *
+     * @param   cls
+     *          Class to remove.
+     */
+    public void remove(Class cls) {
+        boolean changed = false;
+
+        // Do not pre-caclculate size, it will change.
+        for (int i = 0; i < vector.size(); i++) {
+            Class element = (Class) vector.elementAt(i);
+
+            // If superclass/subclass is found, remove it.
+            if (checkAssign(element, cls)) {
+                vector.removeElementAt(i);
+
+                // If class itself is found, return.
+                if (cls == element) {
+                    return;
+                }
+            }
+        }
+    }
+
+    /**
+     * Returns an iterator over the elements
+     * in this list in proper sequence.
+     *
+     * @return  Iterator over the elements in this list
+     *          in proper sequence.
+     */
+    public Iterator iterator() {
+        return vector.iterator();
+    }
+
+    /**
+     * Returns string representation of this list.
+     *
+     * @return  String representation of this list.
+     */
+    public String toString() {
+        return vector.toString();
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/ClassList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/CreateThreadAction.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/CreateThreadAction.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/CreateThreadAction.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/CreateThreadAction.java Thu May 18 13:01:22 2006
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Mikhail A. Markov
+ * @version $Revision: 1.1.2.2 $
+ */
+package org.apache.harmony.rmi.common;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+
+/**
+ * Action for privileged Threads creation.
+ * There are 2 ThreadGroups used in RMI runtime:
+ *   1) System ThreadGroup, i.e. the topmost non-null ThreadGroup. All RMI
+ *      internal threads are created in this group
+ *   2) Non-system ThreadGroup, i.e. the child of the system ThreadGroup. There
+ *      are 2 cases when the thread is created in this group:
+ *        a) When the remote call is accepted on the server side
+ *        b) When the unreferenced thread is started
+ *
+ * There are 2 reasons why 2 threads are needed:
+ *   1) If we create all threads in the system ThreadGroup than if the
+ *      implementation of remote method has the code starting the new thread,
+ *      we'll get AccessControllException requiring
+ *      java.lang.RuntimePermission("modifyThreadGroup") and
+ *      java.lang.RuntimePermission("modifyThread") permissions because it's not
+ *      allowed by default to create a new thread in the system group
+ *   2) If we create all threads (including RMI internal ones) in non-system
+ *      ThreadGroup then the malicious code could potentially interrupt RMI
+ *      internal threads by using Thread.enumerate() static method.
+ *
+ * @author  Mikhail A. Markov
+ * @version $Revision: 1.1.2.2 $
+ */
+public class CreateThreadAction implements PrivilegedAction {
+    /*
+     * System ThreadGroup, i.e. the topmost non-null ThreadGroup.
+     */
+    private static final ThreadGroup systemGroup = (ThreadGroup)
+            AccessController.doPrivileged(new PrivilegedAction() {
+                public Object run() {
+                    ThreadGroup tg =
+                            Thread.currentThread().getThreadGroup();
+                    ThreadGroup tg1 = tg.getParent();
+
+                    while (tg1 != null) {
+                        tg = tg1;
+                        tg1 = tg.getParent();
+                    }
+                    return tg;
+                }
+            });
+
+    /*
+     * Non-system ThreadGroup: child of the system ThreadGroup.
+     */
+    private static final ThreadGroup nonSystemGroup = (ThreadGroup)
+            AccessController.doPrivileged(new PrivilegedAction() {
+                public Object run() {
+                    return new ThreadGroup(systemGroup, "RMI Group");
+                }
+            });
+
+    // Runnable object for Thread creation.
+    private Runnable r;
+
+    // The name of thread to be created.
+    private String name;
+
+    // True if thread to be created should be a daemon.
+    private boolean isDaemon;
+
+    // True if thread to be created should be in the system ThreadGroup.
+    private boolean isSystem;
+
+    /**
+     * Constructs CreateThreadAction to create a new Thread in the system
+     * ThreadGroup.
+     *
+     * @param r Runnable object for Thread creation
+     * @param name name of thread to be created
+     * @param isDaemon true if thread to be created should be a daemon
+     */
+    public CreateThreadAction(Runnable r, String name, boolean isDaemon) {
+        this(r, name, isDaemon, true);
+    }
+
+    /**
+     * Constructs CreateThreadAction to create Thread.
+     *
+     * @param r Runnable object for Thread creation
+     * @param name name of thread to be created
+     * @param isDaemon true if thread to be created should be a daemon
+     * @param isSystem true if system ThreadGroup should be used and false
+     *        otherwise
+     */
+    public CreateThreadAction(Runnable r,
+                              String name,
+                              boolean isDaemon,
+                              boolean isSystem) {
+        this.r = r;
+        this.name = name;
+        this.isDaemon = isDaemon;
+        this.isSystem = isSystem;
+    }
+
+    /**
+     * Creates the thread.
+     *
+     * @return started thread
+     */
+    public Object run() {
+        Thread t = new Thread(isSystem ? systemGroup : nonSystemGroup, r, name);
+        t.setContextClassLoader(ClassLoader.getSystemClassLoader());
+        t.setDaemon(isDaemon);
+        return t;
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/CreateThreadAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/EclipseJavaCompiler.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/EclipseJavaCompiler.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/EclipseJavaCompiler.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/EclipseJavaCompiler.java Thu May 18 13:01:22 2006
@@ -0,0 +1,152 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.2 $
+ */
+package org.apache.harmony.rmi.common;
+
+import java.lang.reflect.InvocationTargetException;
+
+
+/**
+ * This class represents an Eclipse Java Compiler
+ * executed with a simple Java call.
+ *
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.2 $
+ */
+public class EclipseJavaCompiler extends MethodJavaCompiler {
+
+    /**
+     * Eclipse Compiler class name.
+     */
+    public static final String ECLIPSE_COMPILER_CLASS_NAME =
+            "org.eclipse.jdt.internal.compiler.batch.Main";
+
+    /**
+     * Eclipse Compiler method name.
+     */
+    protected final static String ECLIPSE_COMPILER_METHOD_NAME = "compile";
+
+    /**
+     * Eclipse Compiler method signature.
+     */
+    protected static final Class[] ECLIPSE_COMPILER_METHOD_SIGNATURE =
+            new Class[] { String.class };
+
+    /**
+     * Name of the environment variable specifying the Eclipse location.
+     */
+    public static final String ECLIPSE_HOME_VARIABLE = "ECLIPSE_HOME";
+
+    /**
+     * Path from {@link #ECLIPSE_HOME_VARIABLE ECLIPSE_HOME}
+     * to {@linkplain #ECLIPSE_JAR_PATTERN Eclipse Compiler JAR}.
+     */
+    public static final String ECLIPSE_JAR_PATH = "plugins";
+
+    /**
+     * File name pattern describing Eclipse Compiler JAR file name.
+     */
+    public static final String ECLIPSE_JAR_PATTERN =
+            "^org.eclipse.jdt.core_.+\\.jar$";
+
+    /**
+     * Creates instance of this class, equivalent to
+     * {@link #EclipseJavaCompiler(ClassLoader) EclipseJavaCompiler(null)}.
+     *
+     * @throws  JavaCompilerException
+     *          If error occurs while finding or loading
+     *          the Eclipse Compiler class or method.
+     */
+    public EclipseJavaCompiler() throws JavaCompilerException {
+        this(null);
+    }
+
+    /**
+     * Creates instance of this class by trying to load the
+     * {@linkplain #ECLIPSE_COMPILER_CLASS_NAME Eclipse Compiler class}
+     * with the specified class loader.
+     *
+     * If the specified class loader is <code>null</code>, tries to load
+     * with the default class loader, and if failed, tries to load
+     * from {@link #ECLIPSE_HOME_VARIABLE ECLIPSE_HOME} location.
+     *
+     * @param   classLoader
+     *          Class loader to use to load the compiler class.
+     *          Can be <code>null</code>.
+     *
+     * @throws  JavaCompilerException
+     *          If error occurs while finding or loading
+     *          the Eclipse Compiler class or method.
+     */
+    public EclipseJavaCompiler(ClassLoader classLoader)
+            throws JavaCompilerException {
+        Class compilerClass = null;
+
+        try {
+            compilerClass = getClass(ECLIPSE_COMPILER_CLASS_NAME, classLoader);
+        } catch (JavaCompilerException e) {
+            if (classLoader != null) {
+                throw e;
+            }
+        }
+
+        if (compilerClass == null) {
+            compilerClass = getClass(ECLIPSE_COMPILER_CLASS_NAME,
+                    getClassLoaderFromJarFile(
+                    getFileFromVariable(ECLIPSE_HOME_VARIABLE,
+                            ECLIPSE_JAR_PATH, ECLIPSE_JAR_PATTERN,
+                            "Eclipse Compiler JAR")));
+        }
+
+        compilerMethod = getMethod(compilerClass, ECLIPSE_COMPILER_METHOD_NAME,
+                ECLIPSE_COMPILER_METHOD_SIGNATURE);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int compile(String commandString) throws JavaCompilerException {
+        try {
+            Object ret = compilerMethod.invoke(null,
+                    new Object[] { commandString });
+            return (((Boolean) ret).booleanValue() ? 0 : -1);
+        } catch (IllegalAccessException e) {
+            throw new JavaCompilerException(e);
+        } catch (InvocationTargetException e) {
+            throw new JavaCompilerException(e.getCause());
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected int run(String[] args) throws JavaCompilerException {
+        StringBuffer buffer = new StringBuffer();
+
+        for (int i = 0; i < args.length; i++) {
+            if (i > 0) {
+                buffer.append(' ');
+            }
+            buffer.append(args[i]);
+        }
+        return compile(buffer.toString());
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/EclipseJavaCompiler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/ExecJavaCompiler.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/ExecJavaCompiler.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/ExecJavaCompiler.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/ExecJavaCompiler.java Thu May 18 13:01:22 2006
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.3 $
+ */
+package org.apache.harmony.rmi.common;
+
+import java.io.IOException;
+
+
+/**
+ * This class represents a Java Compiler executed as an external program.
+ *
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.3 $
+ */
+public class ExecJavaCompiler extends JavaCompiler {
+
+    /**
+     * Default name of a program to execute.
+     */
+    public static final String DEFAULT_COMPILER_PROGRAM = "javac";
+
+    /**
+     * Name of the system variable specifying the Java location.
+     */
+    public static final String JAVA_HOME_VARIABLE = "JAVA_HOME";
+
+    /**
+     * Path from {@link #JAVA_HOME_VARIABLE JAVA_HOME}
+     * to {@linkplain #JAVA_COMPILER_PATTERN Javac executable}.
+     */
+    public static final String JAVA_COMPILER_PATH = "bin";
+
+    /**
+     * File name pattern describing Javac executable file name.
+     */
+    public static final String JAVA_COMPILER_PATTERN =
+            "((javac)|(JAVAC))(|(\\.(exe|EXE)))";
+
+    /**
+     * Creates uninitialized instance of this class.
+     * Note that using this constructor in most cases
+     * requires overriding {@link #run(String[])} method.
+     */
+    protected ExecJavaCompiler() {}
+
+    /**
+     * Configures this class to use the
+     * {@linkplain #DEFAULT_COMPILER_PROGRAM default program name} to compile.
+     *
+     * @param   search
+     *          If <code>true</code> the constructor tries to locate the Javac
+     *          executable at {@link #JAVA_HOME_VARIABLE JAVA_HOME} location,
+     *          this is equivalent to {@link #ExecJavaCompiler(String)
+     *          ExecJavaCompiler(null)}.
+     *          Otherwise, the {@linkplain #DEFAULT_COMPILER_PROGRAM}
+     *          is used in hope that it would be found in system path,
+     *          this is equivalent to {@link #ExecJavaCompiler(String)
+     *          ExecJavaCompiler(DEFAULT_COMPILER_PROGRAM)}.
+     *
+     * @throws  JavaCompilerException
+     *          If error occurs during searching for executable
+     *          at {@link #JAVA_HOME_VARIABLE}.
+     */
+    public ExecJavaCompiler(boolean search) throws JavaCompilerException {
+        this(search ? null : DEFAULT_COMPILER_PROGRAM);
+    }
+
+    /**
+     * Configures this class to use the specified program to compile.
+     * If <code>programName</code> is <code>null</code>, tries to locate
+     * the Javac executable at {@link #JAVA_HOME_VARIABLE JAVA_HOME} location.
+     *
+     * @param   programName
+     *          Name of the program to execute. Can be <code>null</code>.
+     *
+     * @throws  JavaCompilerException
+     *          If <code>programName</code> is <code>null</code>
+     *          and error occurs during searching for Javac executable
+     *          at {@link #JAVA_HOME_VARIABLE}.
+     */
+    public ExecJavaCompiler(String programName) throws JavaCompilerException {
+        compilerOptions = new String[] { (programName == null)
+                ? getFileFromVariable(JAVA_HOME_VARIABLE, JAVA_COMPILER_PATH,
+                        JAVA_COMPILER_PATTERN, "Java compiler").getPath()
+                : programName };
+    }
+
+    /**
+     * Runs the compilation process with the specified arguments.
+     *
+     * @param   args
+     *          Full arguments list.
+     *
+     * @return  Java Compiler return value.
+     *
+     * @throws  JavaCompilerException
+     *          If execution failed for some reason.
+     */
+    protected int run(String[] args) throws JavaCompilerException {
+        try {
+            // @ToDo: Rewrite with ProcessBuilder for Java 5.0.
+            return new SubProcess(args, System.out, null, System.err).waitFor();
+        } catch (IOException e) {
+            throw new JavaCompilerException(e);
+        }
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/ExecJavaCompiler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/GetBooleanPropAction.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/GetBooleanPropAction.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/GetBooleanPropAction.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/GetBooleanPropAction.java Thu May 18 13:01:22 2006
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Mikhail A. Markov
+ * @version $Revision: 1.1.2.2 $
+ */
+package org.apache.harmony.rmi.common;
+
+import java.security.PrivilegedAction;
+
+
+/**
+ * Action for obtaining boolean value from properties.
+ *
+ * @author  Mikhail A. Markov
+ * @version $Revision: 1.1.2.2 $
+ */
+public class GetBooleanPropAction implements PrivilegedAction {
+
+    // the name of the property to be obtained
+    private String propName;
+
+    // default value for the property
+    private Boolean defaultVal;
+
+    /**
+     * Constructs GetBooleanPropAction to read property with the given name.
+     *
+     * @param propName the name of the property to be read
+     */
+    public GetBooleanPropAction(String propName) {
+        this.propName = propName;
+        defaultVal = new Boolean(false);
+    }
+
+    /**
+     * Constructs GetBooleanPropAction to read property with the given name
+     * and the specified default value.
+     *
+     * @param propName the name of the property to be read
+     * @param defaultVal default value for the property
+     */
+    public GetBooleanPropAction(String propName, boolean defaultVal) {
+        this.propName = propName;
+        this.defaultVal = new Boolean(defaultVal);
+    }
+
+    /**
+     * Obtains boolean value from the property with the name specified in
+     * constructor and returns it as a result (if this property does not
+     * exist - the default value will be returned).
+     *
+     * @return value read or the default value if property to be read is not set
+     */
+    public Object run() {
+        String propVal = System.getProperty(propName);
+        return (propVal == null) ? defaultVal : Boolean.valueOf(propVal);
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/GetBooleanPropAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/GetLongPropAction.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/GetLongPropAction.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/GetLongPropAction.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/GetLongPropAction.java Thu May 18 13:01:22 2006
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Mikhail A. Markov
+ * @version $Revision: 1.1.2.3 $
+ */
+package org.apache.harmony.rmi.common;
+
+import java.security.PrivilegedAction;
+
+
+/**
+ * Action for obtaining properties holding long values.
+ *
+ * @author  Mikhail A. Markov
+ * @version $Revision: 1.1.2.3 $
+ */
+public class GetLongPropAction implements PrivilegedAction {
+
+    // the name of the property to be obtained
+    private String propName;
+
+    // default value for the property
+    private long defaultVal;
+
+    /**
+     * Constructs GetLongPropAction to read property with the given name.
+     *
+     * @param propName the name of the property to be read
+     */
+    public GetLongPropAction(String propName) {
+        this(propName, 0);
+    }
+
+    /**
+     * Constructs GetLongPropAction to read property with the given name.
+     * and specified default value.
+     *
+     * @param propName the name of the property to be read
+     * @param defaultVal default value for the property
+     */
+    public GetLongPropAction(String propName, long defaultVal) {
+        this.propName = propName;
+        this.defaultVal = defaultVal;
+    }
+
+    /**
+     * Reads the property with the name specified in constructor and returns it
+     * as a result; if value read is null, then default value will be returned.
+     *
+     * @return property read or defaultValue if read property is null
+     */
+    public Object run() {
+        return Long.getLong(propName, defaultVal);
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/GetLongPropAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/GetStringPropAction.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/GetStringPropAction.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/GetStringPropAction.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/GetStringPropAction.java Thu May 18 13:01:22 2006
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Mikhail A. Markov
+ * @version $Revision: 1.1.2.3 $
+ */
+package org.apache.harmony.rmi.common;
+
+import java.security.PrivilegedAction;
+
+
+/**
+ * Action for obtaining properties holding string values.
+ *
+ * @author  Mikhail A. Markov
+ * @version $Revision: 1.1.2.3 $
+ */
+public class GetStringPropAction implements PrivilegedAction {
+
+    // the name of the property to be obtained
+    private String propName;
+
+    // default value for the property
+    private String defaultVal;
+
+    /**
+     * Constructs GetStringPropAction to read property with the given name.
+     *
+     * @param propName the name of the property to be read
+     */
+    public GetStringPropAction(String propName) {
+        this(propName, null);
+    }
+
+    /**
+     * Constructs GetStringPropAction to read property with the given name
+     * and the specified default value.
+     *
+     * @param propName the name of the property to be read
+     * @param defaultVal default value for the property
+     */
+    public GetStringPropAction(String propName, String defaultVal) {
+        this.propName = propName;
+        this.defaultVal = defaultVal;
+    }
+
+    /**
+     * Reads the property with the name specified in constructor and returns it
+     * as a result; if value read is null, then default value (possibly
+     * null) will be returned.
+     *
+     * @return property read or defaultValue if property read is null
+     */
+    public Object run() {
+        return System.getProperty(propName, defaultVal);
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/GetStringPropAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/InterruptThreadAction.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/InterruptThreadAction.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/InterruptThreadAction.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/InterruptThreadAction.java Thu May 18 13:01:22 2006
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Mikhail A. Markov
+ * @version $Revision: 1.1.2.2 $
+ */
+package org.apache.harmony.rmi.common;
+
+import java.security.PrivilegedAction;
+
+
+/**
+ * Action for privileged Threads interruption.
+ *
+ * @author  Mikhail A. Markov
+ * @version $Revision: 1.1.2.2 $
+ */
+public class InterruptThreadAction implements PrivilegedAction {
+
+    // Thread for interruption.
+    private Thread t;
+
+    /**
+     * Constructs InterruptThreadAction to create Thread.
+     *
+     * @param t Thread for interruption
+     */
+    public InterruptThreadAction(Thread t) {
+        this.t = t;
+    }
+
+    /**
+     * Interrupts the thread.
+     *
+     * @return null
+     */
+    public Object run() {
+        t.interrupt();
+        return null;
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/InterruptThreadAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/JavaCompiler.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/JavaCompiler.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/JavaCompiler.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/JavaCompiler.java Thu May 18 13:01:22 2006
@@ -0,0 +1,333 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.6 $
+ */
+package org.apache.harmony.rmi.common;
+
+import java.io.File;
+import java.io.FilenameFilter;
+
+
+/**
+ * Representation of a Java Compiler.
+ *
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.6 $
+ */
+public abstract class JavaCompiler implements RMIProperties {
+
+    /**
+     * Compiler-specific options, may be re-initialized by subclasses.
+     */
+    protected String[] compilerOptions = new String[0];
+
+    /**
+     * Compiles the files specified (together with options)
+     * with a command line.
+     *
+     * @param   commandLine
+     *          Command line. Can be <code>null</code>.
+     *
+     * @return  Java Compiler return value.
+     *
+     * @throws  JavaCompilerException
+     *          If some error occurs.
+     */
+    public int compile(String commandLine) throws JavaCompilerException {
+        return compile((commandLine != null)
+                ? commandLine.trim().split("\\s") : new String[0]);
+    }
+
+    /**
+     * Compiles the files specified in parameters (together with options).
+     *
+     * @param   args
+     *          Java Compiler options and source files to compile.
+     *          Can be <code>null</code>.
+     *
+     * @return  Java Compiler return value.
+     *
+     * @throws  JavaCompilerException
+     *          If some error occurs.
+     */
+    public int compile(String[] args) throws JavaCompilerException {
+        return compile(args, (String[]) null);
+    }
+
+    /**
+     * Compiles the specified files with specified options.
+     *
+     * @param   options
+     *          Java Compiler options. Can be <code>null</code>.
+     *
+     * @param   files
+     *          Source files to compile. Can be <code>null</code>.
+     *
+     * @return  Java Compiler return value.
+     *
+     * @throws  JavaCompilerException
+     *          If some error occurs.
+     */
+    public int compile(String[] options, File[] files)
+            throws JavaCompilerException {
+        int length = ((files != null) ? files.length : 0);
+        String[] fileNames = new String[length];
+
+        for (int i = 0; i < length; i++) {
+            fileNames[i] = files[i].getPath();
+        }
+        return compile(options, fileNames);
+    }
+
+    /**
+     * Compiles the specified files with specified options.
+     *
+     * @param   options
+     *          Java Compiler options. Can be <code>null</code>.
+     *
+     * @param   fileNames
+     *          Source files to compile. Can be <code>null</code>.
+     *
+     * @return  Java Compiler return value.
+     *
+     * @throws  JavaCompilerException
+     *          If some error occurs.
+     */
+    public int compile(String[] options, String[] fileNames)
+            throws JavaCompilerException {
+        int optionsLength = ((options != null) ? options.length : 0);
+        int fileNamesLength = ((fileNames != null) ? fileNames.length : 0);
+        int compilerOptionsLength =
+                ((compilerOptions != null) ? compilerOptions.length : 0);
+        String[] args;
+
+        if ((fileNamesLength == 0) && (compilerOptionsLength == 0)) {
+            args = ((options != null) ? options : new String[0]);
+        } else {
+            args = new String[
+                    compilerOptionsLength + optionsLength + fileNamesLength];
+
+            if (compilerOptionsLength != 0) {
+                System.arraycopy(compilerOptions, 0, args,
+                        0, compilerOptionsLength);
+            }
+
+            if (optionsLength != 0) {
+                System.arraycopy(options, 0, args,
+                        compilerOptionsLength, optionsLength);
+            }
+
+            if (fileNamesLength != 0) {
+                System.arraycopy(fileNames, 0, args,
+                        compilerOptionsLength + optionsLength, fileNamesLength);
+            }
+        }
+        return run(args);
+    }
+
+    /**
+     * Runs the compilation process with the specified arguments.
+     *
+     * This method must be overridden by the subclasses.
+     *
+     * @param   args
+     *          Full non-<code>null</code> arguments list. Can be empty.
+     *
+     * @return  Java Compiler return value.
+     *
+     * @throws  JavaCompilerException
+     *          If some error occurs.
+     *
+     * @throws  NullPointerException
+     *          If args is <code>null</code>.
+     */
+    protected abstract int run(String[] args) throws JavaCompilerException;
+
+    /**
+     * Locates the file from the given environment
+     * variable using the specified parameters.
+     *
+     * @param   variableName
+     *          Name of the environment variable to use.
+     *
+     * @param   path
+     *          Path from the directory designated by the specified environment
+     *          variable to the directory, containing the file needed.
+     *
+     * @param   pattern
+     *          Pattern (regular expression)
+     *          describing the file that has to be retutned.
+     *          The first file matching this pattern would be returned.
+     *
+     * @param   name
+     *          Descriptive name of the file being searched for,
+     *          to be mentioned in exception message if error occurs.
+     *
+     * @return  The first file matching the
+     *          <code>$variableName/path/pattern</code>.
+     *
+     * @throws  JavaCompilerException
+     *          If no matching file is found.
+     */
+    protected static File getFileFromVariable(String variableName, String path,
+            final String pattern, String name) throws JavaCompilerException {
+        String parent;
+
+        try {
+            parent = System.getenv(variableName);
+        } catch (Error e) {
+            // TODO
+            // Workaround until System.getenv() is implemented.
+            parent = System.getProperty(variableName);
+        }
+
+        if (parent == null) {
+            throw new JavaCompilerException(
+                    variableName + " variable not found");
+        }
+
+        File[] files = new File(parent, path).listFiles(
+                new FilenameFilter() {
+                    public boolean accept(File dir, String name) {
+                        // Ignoring dir.
+                        return (name.matches(pattern));
+                    }
+                });
+
+        if ((files == null) || (files.length < 1)) {
+            throw new JavaCompilerException(name + " not found");
+        }
+        return files[0];
+    }
+
+    /**
+     * Locates Java Compiler using the following algorithm:
+     *
+     * 1. Check if {@link #JAVA_COMPILER_CLASS_PROPERTY} system property is set.
+     *    If set, configure the returned compiler to use the specified class.
+     *    Also check {@link #JAVA_COMPILER_METHOD_PROPERTY} system property,
+     *    if set, configure the returned compiler to use the specified method,
+     *    otherwise, the
+     *    {@linkplain MethodJavaCompiler#DEFAULT_COMPILER_METHOD default method}
+     *    is used.
+     *
+     * 2. Check if {@link #JAVA_COMPILER_EXECUTABLE_PROPERTY} system property
+     *    is set. If found, configure the returned compiler to use the specified
+     *    executable.
+     *
+     * 3. Check if the Eclipse Compiler class
+     *    ({@link EclipseJavaCompiler#ECLIPSE_COMPILER_CLASS_NAME})
+     *    is accessible via classpath, if so, use it to compile.
+     *
+     * 4. Check if
+     *    {@link EclipseJavaCompiler#ECLIPSE_HOME_VARIABLE ECLIPSE_HOME}
+     *    environment variable is set. If set, locate Eclipse compiler JAR
+     *    ({@link EclipseJavaCompiler#ECLIPSE_HOME_VARIABLE
+     *    $ECLIPSE_HOME}<code>/</code>{@link
+     *    EclipseJavaCompiler#ECLIPSE_JAR_PATH plugins}<code>/</code>{@link
+     *    EclipseJavaCompiler#ECLIPSE_JAR_PATTERN org.eclipse.jdt.core_*.jar}),
+     *    load ({@link EclipseJavaCompiler#ECLIPSE_COMPILER_CLASS_NAME
+     *    Eclipse Compiler class}) from it and use it to compile.
+     *
+     * 5. Check if {@link ExecJavaCompiler#JAVA_HOME_VARIABLE JAVA_HOME}
+     *    environment variable is set. If set, search if
+     *    {@link ExecJavaCompiler#JAVA_HOME_VARIABLE
+     *    $JAVA_HOME}<code>/</code>{@link ExecJavaCompiler#JAVA_COMPILER_PATH
+     *    bin}<code>/</code>{@link ExecJavaCompiler#JAVA_COMPILER_PATTERN
+     *    javac} executable, if found, execute it to compile.
+     *
+     * 6. If nothing found, just execute
+     *    {@link ExecJavaCompiler#DEFAULT_COMPILER_PROGRAM javac}
+     *    hoping it would be found in the system path.
+     *
+     * @param   verbose
+     *          If notes and warnings should be printed to {@link System#err}.
+     *
+     * @return  Configured {@link JavaCompiler} implementation.
+     *
+     * @throws  JavaCompilerException
+     *          If compiler could not be found of configured.
+     */
+    public static final JavaCompiler locateJavaCompiler(boolean verbose)
+            throws JavaCompilerException {
+
+        // Checking JAVA_COMPILER_CLASS_PROPERTY.
+        String compilerClassName =
+                System.getProperty(JAVA_COMPILER_CLASS_PROPERTY);
+
+        if (compilerClassName != null) {
+            String compilerMethodName =
+                    System.getProperty(JAVA_COMPILER_METHOD_PROPERTY);
+
+            if (verbose) {
+                System.err.println("NOTE: Using compiler class: " +
+                        compilerClassName + ((compilerMethodName != null)
+                                ? (", method: " + compilerMethodName) : ""));
+            }
+            return new MethodJavaCompiler(
+                    compilerClassName, compilerMethodName);
+        }
+
+        // Checking JAVA_COMPILER_EXECUTABLE_PROPERTY.
+        String executableName =
+            System.getProperty(JAVA_COMPILER_EXECUTABLE_PROPERTY);
+
+        if (executableName != null) {
+            if (verbose) {
+                System.err.println("NOTE: Using compiler executable: " +
+                        executableName);
+            }
+            return new ExecJavaCompiler(executableName);
+        }
+
+        // Trying to run Eclipse Compiler.
+        try {
+            JavaCompiler compiler = new EclipseJavaCompiler();
+
+            if (verbose) {
+                System.err.println("NOTE: Using Eclipse Compiler");
+            }
+            return compiler;
+        } catch (JavaCompilerException e) {
+            if (verbose) {
+                System.err.println(
+                        "NOTE: Eclipse Compiler class not found: " + e);
+            }
+        }
+
+        // Trying to run Javac executable from JAVA_HOME.
+        try {
+            JavaCompiler compiler = new ExecJavaCompiler(true);
+
+            if (verbose) {
+                System.err.println("NOTE: Using JAVA_HOME Javac compiler");
+            }
+            return compiler;
+        } catch (JavaCompilerException e) {
+            if (verbose) {
+                System.err.println(
+                        "NOTE: JAVA_HOME Javac compiler not found: " + e);
+            }
+        }
+
+        // Trying to run Javac executable from system path, as a last resort.
+        return new ExecJavaCompiler(false);
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/JavaCompiler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/JavaCompilerException.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/JavaCompilerException.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/JavaCompilerException.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/JavaCompilerException.java Thu May 18 13:01:22 2006
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.3 $
+ */
+package org.apache.harmony.rmi.common;
+
+
+/**
+ * General exception for Java Compiler classes.
+ *
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.3 $
+ */
+public class JavaCompilerException extends Exception {
+
+    /**
+     * serialVersionUID
+     */
+    private static final long serialVersionUID = 3632651458880391763L;
+
+    /**
+     * Creates this exception with <code>null</code> message and cause.
+     */
+    public JavaCompilerException() {
+        super();
+    }
+
+    /**
+     * Creates this exception with the specified message
+     * and <code>null</code> cause.
+     *
+     * @param   message
+     *          Detail message.
+     */
+    public JavaCompilerException(String message) {
+        super(message);
+    }
+
+    /**
+     * Creates this exception with the specified message and cause.
+     *
+     * @param   message
+     *          Detail message.
+     *
+     * @param   cause
+     *          Cause.
+     */
+    public JavaCompilerException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * Creates this exception with the specified cause
+     * and message equal to the cause's message.
+     *
+     * @param   cause
+     *          Cause.
+     */
+    public JavaCompilerException(Throwable cause) {
+        super(cause);
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/JavaCompilerException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/MethodJavaCompiler.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/MethodJavaCompiler.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/MethodJavaCompiler.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/MethodJavaCompiler.java Thu May 18 13:01:22 2006
@@ -0,0 +1,355 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.3 $
+ */
+package org.apache.harmony.rmi.common;
+
+import java.io.File;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+
+
+/**
+ * This class represents a Java Compiler executed with a simple Java call.
+ * The class provides multiple constructors to allow flexible specification
+ * of what class and method must be used.
+ *
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.3 $
+ */
+public class MethodJavaCompiler extends JavaCompiler {
+
+    /**
+     * Default name of a method to call in a compiler class.
+     */
+    public static final String DEFAULT_COMPILER_METHOD = "main";
+
+    /**
+     * Compiler method signature.
+     */
+    protected static final Class[] COMPILER_METHOD_SIGNATURE =
+            new Class[] { String[].class };
+
+    /**
+     * Compiler instance.
+     */
+    protected Object compilerInstance;
+
+    /**
+     * Compiler method.
+     */
+    protected Method compilerMethod;
+
+    /**
+     * Creates uninitialized instance of this class.
+     * Note that using this constructor in most cases
+     * requires overriding {@link #run(String[])} method.
+     */
+    protected MethodJavaCompiler() {}
+
+    /**
+     * Configures this class to use {@link #DEFAULT_COMPILER_METHOD} method
+     * of the specified class to compile.
+     *
+     * Equivalent to {@link #MethodJavaCompiler(String, ClassLoader, String)
+     * MethodJavaCompiler(className, null, null)}.
+     *
+     * @param   className
+     *          Name of the compiler class to use.
+     *
+     * @throws  JavaCompilerException
+     *          If error occurs while finding or loading
+     *          the compiler class or method.
+     */
+    public MethodJavaCompiler(String className) throws JavaCompilerException  {
+        this(className, null, null);
+    }
+
+    /**
+     * Configures this class to use {@link #DEFAULT_COMPILER_METHOD} method
+     * of the specified class (loaded by the specified class loader) to compile.
+     *
+     * Equivalent to {@link #MethodJavaCompiler(String, ClassLoader, String)
+     * MethodJavaCompiler(className, classLoader, null)}.
+     *
+     * @param   className
+     *          Name of the compiler class to use.
+     *
+     * @param   classLoader
+     *          Class loader to use to instantiate the specified class.
+     *          Can be <code>null</code>, in this case
+     *          the default class loader is used.
+     *
+     * @throws  JavaCompilerException
+     *          If error occurs while finding or loading
+     *          the compiler class or method.
+     */
+    public MethodJavaCompiler(String className, ClassLoader classLoader)
+            throws JavaCompilerException {
+        this(className, classLoader, null);
+    }
+
+    /**
+     * Configures this class to use the specified class and method to compile.
+     *
+     * Equivalent to {@link #MethodJavaCompiler(String, ClassLoader, String)
+     * MethodJavaCompiler(className, null, methodName)}.
+     *
+     * @param   className
+     *          Name of the compiler class to use.
+     *
+     * @param   methodName
+     *          Name of the method to use.
+     *          Can be <code>null</code>, in this case the
+     *          {@linkplain #DEFAULT_COMPILER_METHOD default method name}
+     *          is used.
+     *
+     * @throws  JavaCompilerException
+     *          If error occurs while finding or loading
+     *          the compiler class or method.
+     */
+    public MethodJavaCompiler(String className, String methodName)
+            throws JavaCompilerException {
+        this(className, null, methodName);
+    }
+
+    /**
+     * Configures this class to use the specified class
+     * (loaded by the specified class loader) and method to compile.
+     *
+     * Equivalent to {@link #MethodJavaCompiler(Class, String)
+     * MethodJavaCompiler(Class.forName(className, true, classLoader),
+     * methodName)}.
+     *
+     * @param   className
+     *          Name of the compiler class to use.
+     *
+     * @param   classLoader
+     *          Class loader to use to instantiate the specified class.
+     *          Can be <code>null</code>, in this case
+     *          the default class loader is used.
+     *
+     * @param   methodName
+     *          Name of the method to use.
+     *          Can be <code>null</code>, in this case the
+     *          {@linkplain #DEFAULT_COMPILER_METHOD default method name}
+     *          is used.
+     *
+     * @throws  JavaCompilerException
+     *          If error occurs while finding or loading
+     *          the compiler class or method.
+     */
+    public MethodJavaCompiler(
+            String className, ClassLoader classLoader, String methodName)
+            throws JavaCompilerException {
+        this(getClass(className, classLoader), methodName);
+    }
+
+    /**
+     * Configures this class to use method
+     * {@link #DEFAULT_COMPILER_METHOD}<code>(String[])</code>
+     * of the specified class to compile.
+     *
+     * Equivalent to {@link #MethodJavaCompiler(Class, String)
+     * MethodJavaCompiler(c, null)}.
+     *
+     * @param   c
+     *          Compiler class to use.
+     *
+     * @throws  JavaCompilerException
+     *          If error occurs while finding or loading
+     *          the compiler method.
+     */
+    public MethodJavaCompiler(Class c) throws JavaCompilerException {
+        this(c, null);
+    }
+
+    /**
+     * Configures this class to use the specified class and method to compile.
+     *
+     * @param   c
+     *          Compiler class to use.
+     *
+     * @param   methodName
+     *          Name of the method to use.
+     *          Can be <code>null</code>, in this case the
+     *          {@linkplain #DEFAULT_COMPILER_METHOD default method name}
+     *          is used.
+     *
+     * @throws  JavaCompilerException
+     *          If error occurs while finding or loading
+     *          the compiler method.
+     */
+    public MethodJavaCompiler(Class c, String methodName)
+            throws JavaCompilerException {
+        this(getMethod(c, ((methodName != null)
+                ? methodName : DEFAULT_COMPILER_METHOD)));
+    }
+
+    /**
+     * Configures this class to use the specified method to compile.
+     *
+     * @param   method
+     *          Compiler method to use.
+     *
+     * @throws  JavaCompilerException
+     *          If specified method is an instance method,
+     *          and the compiler class cannot be instantiated.
+     */
+    public MethodJavaCompiler(Method method) throws JavaCompilerException {
+        try {
+            compilerInstance = (Modifier.isStatic(method.getModifiers())
+                    ? null : method.getDeclaringClass().newInstance());
+        } catch (InstantiationException e) {
+            throw new JavaCompilerException(e);
+        } catch (IllegalAccessException e) {
+            throw new JavaCompilerException(e);
+        } catch (ExceptionInInitializerError e) {
+            throw new JavaCompilerException(e);
+        }
+        compilerMethod = method;
+    }
+
+    /**
+     * Runs the compilation process with the specified arguments.
+     *
+     * @param   args
+     *          Full arguments list.
+     *
+     * @return  Java Compiler return value.
+     *          For this particular implementation, always <code>0</code>,
+     *          unless exception is thrown.
+     *
+     * @throws  JavaCompilerException
+     *          If some error occurs during invocation.
+     */
+    protected int run(String[] args) throws JavaCompilerException {
+        try {
+            compilerMethod.invoke(compilerInstance, new Object[] { args });
+            return 0;
+        } catch (IllegalAccessException e) {
+            throw new JavaCompilerException(e);
+        } catch (InvocationTargetException e) {
+            throw new JavaCompilerException(e.getCause());
+        }
+    }
+
+    /**
+     * Tries to create a class loader for the specified JAR file.
+     *
+     * @param   jar
+     *          Jar file to create class loader for.
+     *
+     * @return  Class loader for the specified JAR file.
+     *
+     * @throws  JavaCompilerException
+     *          If file name parsing failed.
+     */
+    protected static ClassLoader getClassLoaderFromJarFile(File jar)
+            throws JavaCompilerException {
+        try {
+            return new URLClassLoader(new URL[] { jar.toURI().toURL() });
+        } catch (MalformedURLException e) {
+            throw new JavaCompilerException(e);
+        }
+    }
+
+    /**
+     * Loads the specified class with the specified class loader.
+     * Wraps the possible exceptions to {@link JavaCompilerException}.
+     *
+     * @param   className
+     *          Name of the class to get.
+     *
+     * @param   classLoader
+     *          Class loader to use to instantiate the specified class.
+     *          Can be <code>null</code>, in this case
+     *          the default class loader is used.
+     *
+     * @return  The loaded class.
+     *
+     * @throws  JavaCompilerException
+     *          If error occurs while trying to load the class.
+     */
+    protected static Class getClass(String className, ClassLoader classLoader)
+            throws JavaCompilerException {
+        try {
+            return Class.forName(className, true, classLoader);
+        } catch (ClassNotFoundException e) {
+            throw new JavaCompilerException(e);
+        } catch (LinkageError e) {
+            throw new JavaCompilerException(e);
+        }
+    }
+
+    /**
+     * Returns the specified compiler method for the specified class.
+     * Wraps the possible exceptions to {@link JavaCompilerException}.
+     *
+     * @param   c
+     *          Class to get method for.
+     *
+     * @param   methodName
+     *          Name of the method to get.
+     *
+     * @return  The resulting {@link Method} object.
+     *
+     * @throws  JavaCompilerException
+     *          If method is not found.
+     */
+    protected static Method getMethod(Class c, String methodName)
+            throws JavaCompilerException {
+        return getMethod(c, methodName, COMPILER_METHOD_SIGNATURE);
+    }
+
+    /**
+     * Returns the specified method for the specified class.
+     * Wraps the possible exceptions to {@link JavaCompilerException}.
+     *
+     * @param   c
+     *          Class to get method for.
+     *
+     * @param   methodName
+     *          Name of the method to get.
+     *
+     * @param   methodSignature
+     *          Signature of the method to get.
+     *
+     * @return  The resulting {@link Method} object.
+     *
+     * @throws  JavaCompilerException
+     *          If method is not found.
+     */
+    protected static Method getMethod(
+            Class c, String methodName, Class[] methodSignature)
+            throws JavaCompilerException {
+        try {
+            return c.getMethod(methodName, methodSignature);
+        } catch (NoSuchMethodException e) {
+            throw new JavaCompilerException(e);
+        }
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/MethodJavaCompiler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/RMIConstants.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/RMIConstants.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/RMIConstants.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/RMIConstants.java Thu May 18 13:01:22 2006
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Victor A. Martynov
+ * @version $Revision: 1.1.2.5 $
+ */
+package org.apache.harmony.rmi.common;
+
+
+/**
+ * The constants of the RMI and Activation framework.
+ * @author  Victor A. Martynov
+ * @version $Revision: 1.1.2.5 $
+ */
+public interface RMIConstants {
+    /*
+     * -------------------------------------------------------------------------
+     * proxy constants
+     * -------------------------------------------------------------------------
+     */
+
+    /**
+     * Default HTTP proxy port number to use
+     * if {@link RMIProperties#PROXY_PORT_PROP} is not set.
+     */
+    public static final int HTTP_DEFAULT_PORT = 80;
+
+    /*
+     * ************************************************************************
+     * Default values for RMI Activation.
+     * ************************************************************************
+     */
+    /**
+     * The default filename to store snapshots of the RMID's state.
+     */
+    public static final String DEFAULT_SNAPSHOT_FILE = "snapshot.rmid";
+
+    /**
+     * The default filename to store deltas of the RMID's state between snapshots.
+     */
+    public static final String DEFAULT_DELTA_FILE = "delta.rmid";
+
+    /**
+     * The default folder to store rmid log (snapshot and delta).
+     */
+    public static final String DEFAULT_LOG_FOLDER = "log";
+    /**
+     * "Well-Known" ObjID for Activation System.
+     */
+    public static final int ACTIVATION_SYSTEM_ID = 4;
+
+    /**
+     * The usage of RMID tool.
+     */
+    public static final String RMID_USAGE =
+        "\nUsage: rmid <options>"+
+        "\n\nwhere <options> include:"+
+        "\n-port <port>        Specify port for rmid to use"+
+        "\n-log <directory>    Specify directory in which rmid writes log"+
+        "\n-stop               Stop current invocation of rmid (for specified port)"+
+        "\n-C<runtime flag>    Pass argument to each child process (activation group)"+
+        "\n-J<runtime flag>    Pass argument to the java interpreter"+
+        "\n-help               Prints this help message"+
+        "\n------------------ Nonstandard options ------------------"+
+        "\n-monitor            Starts rmid with monitoring on";
+
+    /**
+     * The default timeout that is given to the ActivationGroup VM to
+     * start(milliseconds).
+     */
+    public static final long DEFAULT_ACTIVATION_EXECTIMEOUT = 30000;
+
+    /**
+     * The state of RMID (as a database for ActivationGroups and
+     * ActivatableObjects) is saved on the harddrive and this operation is
+     * known as "snapshot". This variable represents the interval between
+     * the snapshots of the RMID current state.
+     */
+    public static final long DEFAULT_SNAPSHOTINTERVAL = 200;
+
+    /**
+     * The amount of activation groups that may be started concurrently.
+     */
+    public static final long MAX_CONCURRENT_STARTING_GROUPS = 3;
+
+    /**
+     * The default class name of the RMID monitor.
+     *
+     * @see org.apache.harmony.rmi.common.RMIProperties#ACTIVATION_MONITOR_CLASS_NAME_PROP
+     * @see org.apache.harmony.rmi.activation.RmidMonitorAdapter
+     */
+    public static final String DEFAULT_ACTIVATION_MONITOR_CLASS_NAME =
+        "org.apache.harmony.rmi.activation.RmidMonitorAdapter";
+
+    /**
+     * The default value of the activation group VM executable.
+     *
+     * @see RMIProperties#ACTIVATION_VM_EXECUTABLE_PROP
+     */
+    public static final String DEFAULT_ACTIVATION_VM_EXECUTABLE = "java";
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/RMIConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/RMIHash.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/RMIHash.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/RMIHash.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/RMIHash.java Thu May 18 13:01:22 2006
@@ -0,0 +1,221 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.2 $
+ */
+package org.apache.harmony.rmi.common;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import java.lang.reflect.Method;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+import java.util.Iterator;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+
+/**
+ * Generates class and method hash codes neccessary for RMI.
+ *
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.2 $
+ */
+public final class RMIHash {
+
+    /**
+     * This class cannot be instantiated.
+     */
+    private RMIHash() {}
+
+    /**
+     * Calculates RMI method hash
+     * as specified in Chapter 8.3 of RMI Specification.
+     *
+     * @param   method
+     *          Method to calculate RMI hash for.
+     *
+     * @return  RMI hash for the specified method.
+     *
+     * @throws  RMIHashException
+     *          If some error occurs.
+     */
+    public static long getMethodHash(Method method) throws RMIHashException {
+        try {
+            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+            DataOutputStream dataStream = new DataOutputStream(buffer);
+
+            dataStream.writeUTF(RMIUtil.getExtendedMethodDescriptor(method));
+            dataStream.close();
+
+            return getHash(buffer.toByteArray());
+        } catch (IOException e) {
+            throw new RMIHashException("Failed to calculate hash for method "
+                    + method, e);
+        } catch (NoSuchAlgorithmException e) {
+            throw new RMIHashException("Failed to calculate hash for method "
+                    + method, e);
+        }
+    }
+
+    /**
+     * Calculates RMI interface hash
+     * as specified in Chapter 8.3 of RMI Specification.
+     *
+     * @param   cls
+     *          Class to calculate RMI hash for.
+     *
+     * @return  RMI hash for the specified class.
+     *
+     * @throws  RMIHashException
+     *          If some error occurs.
+     */
+    public static long getInterfaceHash(Class cls) throws RMIHashException {
+        try {
+            return getInterfaceHash(getSortedMethodMap(cls.getMethods()));
+        } catch (RMIHashException e) {
+            throw new RMIHashException("Failed to calculate interface hash "
+                    + "for class" + cls, e.getCause());
+        }
+    }
+
+    /**
+     * Calculates RMI interface hash
+     * as specified in Chapter 8.3 of RMI Specification.
+     *
+     * @param   methodMap
+     *          Map containing methods of the class to calculate hash for.
+     *
+     * @return  RMI hash for the specified interface.
+     *
+     * @throws  RMIHashException
+     *          If some error occurs.
+     */
+    public static long getInterfaceHash(SortedMap methodMap)
+            throws RMIHashException {
+        try {
+            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+            DataOutputStream dataStream = new DataOutputStream(buffer);
+
+            dataStream.writeInt(1);
+
+            for (Iterator i = methodMap.values().iterator(); i.hasNext(); ) {
+                Method method = (Method) i.next();
+
+                dataStream.writeUTF(method.getName());
+                dataStream.writeUTF(RMIUtil.getMethodDescriptor(method));
+
+                Class[] exceptions = method.getExceptionTypes();
+                TreeSet exceptionSet = new TreeSet();
+
+                for (int j = 0; j < exceptions.length; j++) {
+                    exceptionSet.add(exceptions[j].getName());
+                }
+
+                for (Iterator k = exceptionSet.iterator(); k.hasNext(); ) {
+                    dataStream.writeUTF((String) k.next());
+                }
+            }
+
+            dataStream.close();
+
+            return getHash(buffer.toByteArray());
+        } catch (IOException e) {
+            throw new RMIHashException("Failed to calculate interface hash "
+                    + "for specified set of methods", e);
+        } catch (NoSuchAlgorithmException e) {
+            throw new RMIHashException("Failed to calculate interface hash "
+                    + "for specified set of methods", e);
+        }
+    }
+
+    /**
+     * Moves methods from the specified array to the newly created map
+     * sorting them properly for RMI interface hash calculation.
+     *
+     * @param   methods
+     *          Methods to sort.
+     *
+     * @return  The created method map.
+     */
+    public static SortedMap getSortedMethodMap(Method[] methods) {
+        return getSortedMethodMap(null, methods);
+    }
+
+    /**
+     * Adds methods from the specified array to the specified map
+     * sorting them properly for RMI interface hash calculation.
+     *
+     * @param   methodMap
+     *          Map to store sorted methods to.
+     *
+     * @param   methods
+     *          Methods to sort.
+     *
+     * @return  The updated method map.
+     */
+    public static SortedMap getSortedMethodMap(
+            SortedMap methodMap, Method[] methods) {
+        if (methodMap == null) {
+            methodMap = new TreeMap();
+        }
+
+        for (int i = 0; i < methods.length; i++) {
+            Method method = methods[i];
+            methodMap.put(RMIUtil.getExtendedMethodDescriptor(method), method);
+        }
+
+        return methodMap;
+    }
+
+    /**
+     * Calculates RMI hash value for the specified byte array,
+     * as specified in Chapter 8.3 of RMI Specification.
+     *
+     * @param   buffer
+     *          Byte array to calculate RMI hash for.
+     *
+     * @return  RMI hash value for the specified byte array.
+     *
+     * @throws  NoSuchAlgorithmException
+     *          Should never occur.
+     */
+    private static long getHash(byte[] buffer) throws NoSuchAlgorithmException {
+        byte[] digest = MessageDigest.getInstance("SHA-1").digest(buffer);
+
+        long hash = 0;
+
+        int length = digest.length;
+
+        if (length > 8) {
+            length = 8;
+        }
+
+        for (int i = 0; i < length; i++) {
+            hash += ((long) (digest[i] & 0xff)) << (i * 8);
+        }
+
+        return hash;
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/RMIHash.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/RMIHashException.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/RMIHashException.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/RMIHashException.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/RMIHashException.java Thu May 18 13:01:22 2006
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.2 $
+ */
+package org.apache.harmony.rmi.common;
+
+
+/**
+ * This exception is used if {@link RMIHash} fails to compute
+ * RMI hash for some class or method.
+ *
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.2 $
+ */
+public class RMIHashException extends Exception {
+
+    /**
+     * serialVersionUID
+     */
+    private static final long serialVersionUID = -7107015868027717508L;
+
+    /**
+     * Constructs a new exception with <code>null</code> message.
+     */
+    public RMIHashException() {
+        super();
+    }
+
+    /**
+     * Constructs a new exception with the specified message.
+     *
+     * @param   message
+     *          Message of this exception.
+     */
+    public RMIHashException(String message) {
+        super(message);
+    }
+
+    /**
+     * Constructs a new exception with the specified cause and message
+     * equal to the specified cause.
+     *
+     * @param   cause
+     *          Cause of this exception.
+     */
+    public RMIHashException(Throwable cause) {
+        super(cause);
+    }
+
+    /**
+     * Constructs a new exception with the specified message and cause.
+     *
+     * @param   message
+     *          Message of this exception.
+     *
+     * @param   cause
+     *          Cause of this exception.
+     */
+    public RMIHashException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/common/RMIHashException.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message