KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > security > jacc > provider > JPolicyConfigurationKeeper


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: JPolicyConfigurationKeeper.java 1121 2006-09-27 08:51:06Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.security.jacc.provider;
27
28 import java.util.HashMap JavaDoc;
29 import java.util.Map JavaDoc;
30
31 import javax.security.jacc.PolicyContextException JavaDoc;
32
33 /**
34  * This class keep the JPolicyConfiguration. This is used when
35  * JPolicyConfigurationFactory is used as a delegate factory.
36  * @author Florent Benoit
37  */

38 public final class JPolicyConfigurationKeeper {
39
40     /**
41      * Internal list of JPolicyConfiguration objects.
42      */

43     private static Map JavaDoc<String JavaDoc, JPolicyConfiguration> policyConfigurations = new HashMap JavaDoc<String JavaDoc, JPolicyConfiguration>();
44
45     /**
46      * Utility class, no constructor.
47      */

48     private JPolicyConfigurationKeeper() {
49     }
50
51     /**
52      * Add a EasyBeans policy configuration.
53      * @param config policy configuration object to add
54      */

55     public static void addConfiguration(final JPolicyConfiguration config) {
56         try {
57             policyConfigurations.put(config.getContextID(), config);
58         } catch (PolicyContextException JavaDoc pce) {
59             throw new RuntimeException JavaDoc("Cannot add the policy configuration object '" + config + "'");
60         }
61     }
62
63     /**
64      * Remove a EasyBeans policy configuration.
65      * @param config policy configuration object to remove
66      */

67     public static void removeConfiguration(final JPolicyConfiguration config) {
68         try {
69             if (policyConfigurations.containsKey(config.getContextID())) {
70                 policyConfigurations.remove(config.getContextID());
71             }
72         } catch (PolicyContextException JavaDoc pce) {
73             throw new RuntimeException JavaDoc("Cannot remove the policy configuration object '" + config + "'");
74         }
75     }
76
77     /**
78      * Gets the EasyBeans policy configuration by its contextId.
79      * @param contextId given ID to retrieve policy configuration object
80      * @return the EasyBeans policy configuration specified by its contextId
81      */

82     public static JPolicyConfiguration getConfiguration(final String JavaDoc contextId) {
83         return policyConfigurations.get(contextId);
84     }
85 }
86
Popular Tags