KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > wsmgmt > filter > spi > FilterRegistry


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.admin.wsmgmt.filter.spi;
24
25 import java.util.List JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.ListIterator JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.Map JavaDoc;
30 import java.util.HashMap JavaDoc;
31
32 /**
33  * This class interacts with JAX RPC Monitoring SPI and registers Global
34  * Listener to get callbacks.
35  */

36 public class FilterRegistry {
37
38     public synchronized void registerFilter(String JavaDoc stage, String JavaDoc endpoint,
39         Filter filter) {
40
41         List JavaDoc fl = (List JavaDoc) filters.get( stage + DELIM + endpoint);
42         if ( fl == null ) {
43             fl = new ArrayList JavaDoc();
44         }
45         fl.add(filter);
46         filters.put(stage + DELIM + endpoint, fl);
47         setManaged(endpoint);
48     }
49
50     public void unregisterFilter(String JavaDoc stage, String JavaDoc endpoint, Filter filter) {
51         List JavaDoc fl = (List JavaDoc) filters.get( stage + DELIM + endpoint);
52         if ( fl == null ) {
53             throw new IllegalArgumentException JavaDoc(" No registration exists for " +
54                 stage + DELIM + endpoint );
55         }
56         fl.remove(filter);
57         if ( fl.size() == 0 ) {
58             // this is the last filter, set this web service as un-managed
59
setUnManaged(endpoint);
60         }
61     }
62
63     public void unregisterFilterByName(String JavaDoc stage, String JavaDoc endpoint,
64         String JavaDoc filtername) {
65
66         List JavaDoc fl = (List JavaDoc) filters.get( stage + DELIM + endpoint);
67         if ( fl == null ) {
68             throw new IllegalArgumentException JavaDoc(" No registration exists for " +
69                 stage + DELIM + endpoint );
70         }
71         Iterator JavaDoc fli = fl.iterator();
72         while (fli.hasNext()) {
73             Filter f = (Filter) fli.next();
74             if (f.getName().equals(filtername)) {
75                 fli.remove();
76                 continue;
77             }
78         }
79
80         if ( fl.size() == 0 ) {
81             // this is the last filter, set this web service as un-managed
82
setUnManaged(endpoint);
83         }
84     }
85
86     public void unregisterAllFilters(String JavaDoc endpoint) {
87         Iterator JavaDoc itr = filters.keySet().iterator();
88         while ( itr.hasNext()) {
89             String JavaDoc key = (String JavaDoc) itr.next();
90             if ( key.contains( DELIM+endpoint) ) {
91                 itr.remove();
92             }
93         }
94     }
95
96     public List JavaDoc getFilters(String JavaDoc stage, String JavaDoc endpoint) {
97         return (List JavaDoc) filters.get(stage + DELIM + endpoint);
98     }
99
100     // Is this method needed???
101
public FilterRegistration[] getFilters(String JavaDoc endpoint) {
102         return null;
103     }
104
105     public boolean isManaged(String JavaDoc endpoint) {
106         if ( managedEndpoints == null)
107             return false;
108         else {
109              Object JavaDoc o = managedEndpoints.get(endpoint);
110              if ( o != null) {
111                 return true;
112              } else {
113                 return false;
114              }
115         }
116     }
117
118     public void setManaged(String JavaDoc endpoint) {
119         managedEndpoints.put(endpoint, new Boolean JavaDoc(true));
120     }
121
122     public void setUnManaged(String JavaDoc endpoint) {
123         managedEndpoints.remove(endpoint);
124     }
125
126     public static synchronized FilterRegistry getInstance() {
127         if ( fm == null) {
128             fm = new FilterRegistry();
129         }
130         if ( managedEndpoints == null ) {
131             managedEndpoints = new HashMap JavaDoc();
132         }
133         if ( filters == null ) {
134             filters = new HashMap JavaDoc();
135         }
136         return fm;
137     }
138
139     private static FilterRegistry fm = null;
140
141     private FilterRegistry() {}
142
143     private static HashMap JavaDoc managedEndpoints = null;
144
145     private static HashMap JavaDoc filters = null;
146
147     public static final String JavaDoc DELIM = ":";
148 }
149
Popular Tags