1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 package org.apache.river.phoenix.common;
20
21 import java.lang.reflect.Method;
22 import java.rmi.server.ExportException;
23 import java.rmi.Remote;
24 import java.util.Collection;
25 import net.jini.core.constraint.InvocationConstraints;
26 import net.jini.jeri.BasicILFactory;
27 import net.jini.jeri.BasicInvocationDispatcher;
28 import net.jini.jeri.InvocationDispatcher;
29 import net.jini.jeri.ServerCapabilities;
30
31 /**
32 * A basic invocation layer factory, used in exporting an
33 * <code>ActivationMonitor</code> or <code>ActivationInstantiator</code> to
34 * use Jini extensible remote invocation (Jini ERI), that is similar to
35 * {@link BasicILFactory} except the returned invocation dispatcher only
36 * accepts calls from the local host.
37 *
38 * @author Sun Microsystems, Inc.
39 *
40 * @since 2.0
41 **/
42 public class AccessILFactory extends BasicILFactory {
43
44 /**
45 * Creates an <code>AccessILFactory</code>instance with no server
46 * constraints, no permission class, and a <code>null</code> class
47 * loader.
48 **/
49 public AccessILFactory() {
50 }
51
52 /**
53 * Creates an <code>AccessILFactory</code>instance with no server
54 * constraints, no permission class, and the specified class loader.
55 * The specified class loader is used by the {@link #createInstances
56 * createInstances} method.
57 *
58 * @param loader the class loader, or <code>null</code>
59 **/
60 public AccessILFactory(ClassLoader loader) {
61 super(null, null, loader);
62 }
63
64 /**
65 * Returns an {@link AccessDispatcher} instance constructed with the
66 * specified methods, the specified server capabilities, and the class
67 * loader specified at construction.
68 *
69 * @return the {@link AccessDispatcher} instance
70 * @throws NullPointerException {@inheritDoc}
71 **/
72 protected InvocationDispatcher
73 createInvocationDispatcher(Collection methods,
74 Remote impl,
75 ServerCapabilities caps)
76 throws ExportException
77 {
78 if (impl == null) {
79 throw new NullPointerException("impl is null");
80 }
81 return new AccessDispatcher(methods, caps, getClassLoader());
82 }
83
84 /**
85 * A subclass of {@link BasicInvocationDispatcher} that only accepts
86 * calls from the local host.
87 */
88 public static class AccessDispatcher extends BasicInvocationDispatcher {
89 /**
90 * Constructs an invocation dispatcher for the specified methods.
91 *
92 * @param methods a collection of {@link Method} instances
93 * for the remote methods
94 * @param caps the transport capabilities of the server
95 * @param loader the class loader, or <code>null</code>
96 * @throws NullPointerException if <code>methods</code> is
97 * <code>null</code> or if <code>methods</code> contains a
98 * <code>null</code> elememt
99 * @throws IllegalArgumentException if <code>methods</code>
100 * contains an element that is not a <code>Method</code>
101 * instance
102 * @throws ExportException doesn't throw ExportException as there are no
103 * constraints.
104 */
105 public AccessDispatcher(Collection methods,
106 ServerCapabilities caps,
107 ClassLoader loader)
108 throws ExportException
109 {
110 super(methods, caps, null, null, loader);
111 }
112
113 /**
114 * Checks that the client is calling from the local host.
115 *
116 * @throws java.security.AccessControlException if the client is not
117 * calling from the local host
118 */
119 @Override
120 protected void checkAccess(Remote impl,
121 Method method,
122 InvocationConstraints constraints,
123 Collection context)
124 {
125 LocalAccess.check();
126 }
127 }
128 }