View Javadoc

1   /*
2    *   Copyright 2004 The Apache Software Foundation
3    *
4    *   Licensed under the Apache License, Version 2.0 (the "License");
5    *   you may not use this file except in compliance with the License.
6    *   You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *   Unless required by applicable law or agreed to in writing, software
11   *   distributed under the License is distributed on an "AS IS" BASIS,
12   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *   See the License for the specific language governing permissions and
14   *   limitations under the License.
15   *
16   */
17  package org.apache.ldap.server.invocation;
18  
19  
20  import java.util.ArrayList;
21  import java.util.Collections;
22  import java.util.List;
23  import java.util.Collection;
24  
25  import javax.naming.Context;
26  
27  import org.apache.ldap.server.partition.DirectoryPartitionNexus;
28  import org.apache.ldap.server.partition.DirectoryPartitionNexusProxy;
29  
30  
31  /***
32   * Represents a call from JNDI {@link Context} to {@link DirectoryPartitionNexus}.
33   *
34   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
35   * @version $Rev: 326026 $, $Date: 2005-10-18 00:35:27 -0400 (Tue, 18 Oct 2005) $
36   */
37  public class Invocation
38  {
39      private final Context caller;
40      private final String name;
41      private final List parameters;
42      private final Collection bypassed;
43      private final DirectoryPartitionNexusProxy proxy;
44  
45  
46      /***
47       * Creates a new instance that represents an invocation without parameters.
48       * 
49       * @param caller the JNDI {@link Context} that made this invocation
50       * @param name the name of the called method
51       */
52      public Invocation( DirectoryPartitionNexusProxy proxy, Context caller, String name )
53      {
54          this( proxy, caller, name, null, Collections.EMPTY_SET );
55      }
56  
57  
58      /***
59       * Creates a new instance.
60       *
61       * @param caller the JNDI {@link Context} that made this invocation
62       * @param name the name of the called method
63       * @param parameters the array of parameters passed to the called method
64       */
65      public Invocation( DirectoryPartitionNexusProxy proxy, Context caller, String name, Object[] parameters )
66      {
67          this( proxy, caller, name, parameters, Collections.EMPTY_SET );
68      }
69  
70  
71      /***
72       * Creates a new instance.
73       * 
74       * @param caller the JNDI {@link Context} that made this invocation
75       * @param name the name of the called method
76       * @param parameters the array of parameters passed to the called method
77       * @param bypassed the set of bypassed Interceptor names
78       */
79      public Invocation( DirectoryPartitionNexusProxy proxy, Context caller, String name, Object[] parameters,
80                         Collection bypassed )
81      {
82          if( proxy == null )
83          {
84              throw new NullPointerException( "proxy" );
85          }
86          if( caller == null )
87          {
88              throw new NullPointerException( "caller" );
89          }
90          if( name == null )
91          {
92              throw new NullPointerException( "name" );
93          }
94  
95          if( parameters == null )
96          {
97              parameters = new Object[ 0 ];
98          }
99  
100         if ( bypassed == null )
101         {
102             this.bypassed = Collections.EMPTY_SET;
103         }
104         else
105         {
106             this.bypassed = Collections.unmodifiableCollection( bypassed );
107         }
108 
109         this.proxy = proxy;
110         this.caller = caller;
111         this.name = name;
112 
113         List paramList = new ArrayList();
114         for( int i = 0; i < parameters.length; i++ )
115         {
116             paramList.add( parameters[ i ] );
117         }
118 
119         this.parameters = Collections.unmodifiableList( paramList );
120     }
121 
122 
123     /***
124      * Returns the proxy object to the {@link DirectoryPartitionNexus}.
125      */
126     public DirectoryPartitionNexusProxy getProxy()
127     {
128         return proxy;
129     }
130 
131 
132     /***
133      * Returns the JNDI {@link Context} which made this invocation.
134      */
135     public Context getCaller()
136     {
137         return caller;
138     }
139 
140 
141     /***
142      * Returns the name of the called method.
143      */
144     public String getName()
145     {
146         return name;
147     }
148 
149 
150     /***
151      * Returns the list of parameters parameters passed to the called method.
152      */
153     public List getParameters()
154     {
155         return parameters;
156     }
157 
158 
159     /***
160      * Checks to see if an interceptor is bypassed.
161      *
162      * @param interceptorName the interceptorName of the interceptor to check for bypass
163      * @return true if the interceptor should be bypassed, false otherwise
164      */
165     public boolean isBypassed( String interceptorName )
166     {
167         return bypassed.contains( interceptorName );
168     }
169 
170 
171     /***
172      * Checks to see if any interceptors are bypassed by this Invocation.
173      *
174      * @return true if at least one bypass exists
175      */
176     public boolean hasBypass()
177     {
178         return !bypassed.isEmpty();
179     }
180 }