/*
 * 
 * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
 * 
 * The contents of this file are subject to the Sun Community Source
 * License v3.0/Jini Technology Specific Attachment v 1.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://wwws.sun.com/software/jini/licensing/SCSL3_JiniTSA1.html.
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific language governing rights and limitations
 * under the License.
 * 
 * The Reference Code is Jini Technology Core Platform code, v2.0. The
 * Developer of the Reference Code is Sun Microsystems, Inc.
 * 
 * Contributor(s): Sun Microsystems, Inc.
 * 
 * The contents of this file comply with the Jini Technology Core
 * Platform Compatibility Kit, v2.0A.
 * 
 * Tester(s): Sun Microsystems, Inc.
 * 
 * Test Platform(s):
 * Java 2 SDK, Standard Edition, Version 1.4.2_03 for Solaris(TM)SPARC/x86
 * Java 2 SDK, Standard Edition, Version 1.4.2_03 for Linux (Intel x86)
 * Java 2 SDK, Standard Edition, Version 1.4.2_03 for Windows (Intel Platform)
 * 
 */
package com.sun.jini.fiddler;

import java.lang.reflect.Method;

/**
 * Convenience class that contains a package protected static utility method
 * used by the proxy classes of this package in proxy trust verification
 * process.
 *
 * Note that this class cannot be instantiated.
 *
 * @author Sun Microsystems, Inc.
 */
class ProxyUtil {

    /** This class cannot be instantiated. */
    private ProxyUtil() {
	throw new AssertionError("class cannot be instantiated");
    }//end constructor

    /**
     * Returns the public method for the specified <code>Class</code> type,
     * method name, and array of parameter types.
     * <p>
     * This method is typically used in place of {@link Class#getMethod
     * Class.getMethod} to get a method that should definitely be defined;
     * thus, this method throws an error instead of an exception if the
     * given method is missing.
     * <p>
     * This method is convenient for the initialization of a static
     * variable for use as the <code>mappings</code> argument to 
     * {@link com.sun.jini.proxy.ConstrainableProxyUtil#translateConstraints 
     * ConstrainableProxyUtil.translateConstraints}.
     *
     * @param type           the <code>Class</code> type that defines the
     *                       method of interest
     * @param name           <code>String</code> containing the name of the
     *                       method of interest
     * @param parameterTypes the <code>Class</code> types of the parameters
     *                       to the method of interest
     *
     * @return a <code>Method</code> object that provides information about,
     *         and access to, the method of interest
     *
     * @throws <code>NoSuchMethodError</code> if the method of interest cannot
     *         be found
     * @throws <code>NullPointerException</code> if <code>type</code> or
     *         <code>name</code> is <code>null</code> 
     */
    static Method getMethod(Class type,
				   String name,
				   Class[] parameterTypes)
    {
        try {
            return type.getMethod(name, parameterTypes);
        } catch (NoSuchMethodException e) {
            throw (Error)(new NoSuchMethodError(e.getMessage()).initCause(e));
        }
    }//end getMethod
}//end class ProxyUtil
