All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.river.phoenix.common.AccessILFactory Maven / Gradle / Ivy

The newest version!
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you 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 org.apache.river.phoenix.common;

import java.lang.reflect.Method;
import java.rmi.server.ExportException;
import java.rmi.Remote;
import java.util.Collection;
import net.jini.core.constraint.InvocationConstraints;
import net.jini.jeri.BasicILFactory;
import net.jini.jeri.BasicInvocationDispatcher;
import net.jini.jeri.InvocationDispatcher;
import net.jini.jeri.ServerCapabilities;

/**
 * A basic invocation layer factory, used in exporting an
 * ActivationMonitor or ActivationInstantiator to
 * use Jini extensible remote invocation (Jini ERI), that is similar to
 * {@link BasicILFactory} except the returned invocation dispatcher only
 * accepts calls from the local host.
 *
 * @author Sun Microsystems, Inc.
 * 
 * @since 2.0
 **/
public class AccessILFactory extends BasicILFactory {

    /**
     * Creates an AccessILFactoryinstance with no server
     * constraints, no permission class, and a null class
     * loader.
     **/
    public AccessILFactory() {
    }

    /**
     * Creates an AccessILFactoryinstance with no server
     * constraints, no permission class, and the specified class loader.
     * The specified class loader is used by the {@link #createInstances
     * createInstances} method.
     *
     * @param loader the class loader, or null
     **/
    public AccessILFactory(ClassLoader loader) {
	super(null, null, loader);
    }

    /**
     * Returns an {@link AccessDispatcher} instance constructed with the
     * specified methods, the specified server capabilities, and the class
     * loader specified at construction.
     *
     * @return the {@link AccessDispatcher} instance
     * @throws NullPointerException {@inheritDoc}
     **/
    protected InvocationDispatcher
        createInvocationDispatcher(Collection methods,
				   Remote impl,
				   ServerCapabilities caps)
	throws ExportException
    {
	if (impl == null) {
	    throw new NullPointerException("impl is null");
	}
	return new AccessDispatcher(methods, caps, getClassLoader());
    }

    /**
     * A subclass of {@link BasicInvocationDispatcher} that only accepts
     * calls from the local host.
     */
    public static class AccessDispatcher extends BasicInvocationDispatcher {
	/**
	 * Constructs an invocation dispatcher for the specified methods.
	 *
	 * @param	methods a collection of {@link Method} instances
	 *		for the	remote methods
	 * @param	caps the transport capabilities of the server
	 * @param	loader the class loader, or null
	 * @throws	NullPointerException if methods is
	 *		null or if methods contains a
	 *		null elememt
	 * @throws	IllegalArgumentException if methods
	 *		contains an element that is not a Method
	 *		instance
	 * @throws ExportException doesn't throw ExportException as there are no
	 * constraints.
	 */
	public AccessDispatcher(Collection methods,
				ServerCapabilities caps,
				ClassLoader loader)
	    throws ExportException
	{
	    super(methods, caps, null, null, loader);
	}

	/**
	 * Checks that the client is calling from the local host.
	 *
	 * @throws java.security.AccessControlException if the client is not
	 * calling from the local host
	 */
	@Override
	protected void checkAccess(Remote impl,
				   Method method,
				   InvocationConstraints constraints,
				   Collection context)
	{
	    LocalAccess.check();
	}
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy