KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > interceptor > InterceptorFactory


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * InterceptorFactory.java
20  *
21  * This class is responsible for returning interceptors constructed with
22  * reference to the coadunation internals. So that incoming threads can be
23  * boot strapped appropriatly.
24  */

25
26 // package path
27
package com.rift.coad.lib.interceptor;
28
29 // coadunation imports
30
import com.rift.coad.lib.security.ThreadsPermissionContainer;
31 import com.rift.coad.lib.security.user.UserSessionManager;
32 import com.rift.coad.lib.security.user.UserStoreManager;
33
34 /**
35  * This class is responsible for returning interceptors constructed with
36  * reference to the coadunation internals. So that incoming threads can be
37  * boot strapped appropriatly.
38  *
39  * @author Brett Chaldecott
40  */

41 public class InterceptorFactory {
42     
43     // private member variables
44
private static InterceptorFactory singleton = null;
45     private ClientInterceptor clientInterceptor = null;
46     private ServerInterceptor serverInterceptor = null;
47     
48     /**
49      * Creates a new instance of InterceptorFactory
50      */

51     private InterceptorFactory(ThreadsPermissionContainer permissionContainer,
52             UserSessionManager userSessionManager, UserStoreManager
53             userStoreManger) {
54         serverInterceptor = new ServerInterceptor(permissionContainer,
55                 userSessionManager, userStoreManger);
56         clientInterceptor = new ClientInterceptor(permissionContainer);
57     }
58     
59     
60     /**
61      * This method instanciates the rmi interceptor factory
62      *
63      *
64      * @return The reference to the RMI interceptor factory.
65      * @param permissionContainer The reference to the permission container.
66      * @exception InterceptorException
67      */

68     public static synchronized InterceptorFactory init(
69             ThreadsPermissionContainer permissionContainer, UserSessionManager
70             userSessionManager, UserStoreManager userStoreManger) throws
71             InterceptorException {
72         if (singleton == null) {
73             return singleton = new InterceptorFactory(permissionContainer,
74                     userSessionManager,userStoreManger);
75         }
76         throw new InterceptorException("The interceptor factory has already " +
77                 "been initialized.");
78     }
79     
80     
81     /**
82      * This method returns a reference to the rmi interceptor factory singleton.
83      *
84      *
85      * @return The reference to the RMI interceptor factory.
86      * @exception InterceptorException
87      */

88     protected static synchronized InterceptorFactory getInstance() throws
89             InterceptorException {
90         if (singleton == null) {
91             throw new InterceptorException("The interceptor factory has not " +
92                 "been initialized.");
93         }
94         return singleton;
95     }
96     
97     
98     /**
99      * This method returns a reference to the client interceptor.
100      *
101      * @return A reference to the client intercpetor.
102      * @exception InterceptorException
103      */

104     protected ClientInterceptor getClientInterceptor() throws
105             InterceptorException {
106         return clientInterceptor;
107     }
108     
109     
110     /**
111      * This method returns a reference to the server interceptor.
112      *
113      * @return A reference to the server interceptor.
114      * @exception InterceptorException
115      */

116     protected ServerInterceptor getServerInterceptor() throws
117             InterceptorException {
118         return serverInterceptor;
119     }
120 }
121
Popular Tags