KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > wsitconf > spi > SecurityProfileRegistry


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.wsitconf.spi;
21
22 import java.util.Collections JavaDoc;
23 import java.util.Comparator JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.Set JavaDoc;
27 import java.util.TreeSet JavaDoc;
28
29 /**
30  *
31  * @author Martin Grebac
32  */

33 public class SecurityProfileRegistry {
34     
35     private static SecurityProfileRegistry instance;
36     
37     private Map JavaDoc<String JavaDoc, SecurityProfile> profiles =
38             Collections.synchronizedMap(new HashMap JavaDoc<String JavaDoc, SecurityProfile>());
39     
40     /**
41      * Creates a new instance of SecurityProfileRegistry
42      */

43     private SecurityProfileRegistry() {}
44
45     /**
46      * Returns default singleton instance of registry
47      */

48     public static SecurityProfileRegistry getDefault(){
49         if (instance == null) {
50             instance = new SecurityProfileRegistry();
51         }
52         return instance;
53     }
54     
55     /**
56      * Returns profile from list based on it's display name
57      */

58     public SecurityProfile getProfile(String JavaDoc displayName) {
59         return profiles.get(displayName);
60     }
61     
62     /**
63      * Registers profile to the list
64      */

65     public void register(SecurityProfile profile){
66         profiles.put(profile.getDisplayName(), profile);
67     }
68     
69     /**
70      * Unregisters profile from the list
71      */

72     public void unregister(SecurityProfile profile){
73         profiles.remove(profile.getDisplayName());
74     }
75     
76     public void unregister(String JavaDoc profile){
77         profiles.remove(profile);
78     }
79     
80     public Set JavaDoc<SecurityProfile> getSecurityProfiles() {
81         
82         TreeSet JavaDoc<SecurityProfile> set = new TreeSet JavaDoc(new Comparator JavaDoc() {
83             public int compare(Object JavaDoc obj1, Object JavaDoc obj2) {
84                 SecurityProfile p1 = (SecurityProfile)obj1;
85                 SecurityProfile p2 = (SecurityProfile)obj2;
86                 Integer JavaDoc i1 = p1.getId();
87                 Integer JavaDoc i2 = p2.getId();
88                 return i1.compareTo(i2);
89             }
90         });
91         set.addAll(profiles.values());
92         return Collections.synchronizedSortedSet(set);
93     }
94     
95 }
96
Popular Tags