1 23 package com.sun.enterprise.admin.wsmgmt.filter.spi; 24 25 import java.util.List ; 26 import java.util.ArrayList ; 27 import java.util.ListIterator ; 28 import java.util.Iterator ; 29 import java.util.Map ; 30 import java.util.HashMap ; 31 32 36 public class FilterRegistry { 37 38 public synchronized void registerFilter(String stage, String endpoint, 39 Filter filter) { 40 41 List fl = (List ) filters.get( stage + DELIM + endpoint); 42 if ( fl == null ) { 43 fl = new ArrayList (); 44 } 45 fl.add(filter); 46 filters.put(stage + DELIM + endpoint, fl); 47 setManaged(endpoint); 48 } 49 50 public void unregisterFilter(String stage, String endpoint, Filter filter) { 51 List fl = (List ) filters.get( stage + DELIM + endpoint); 52 if ( fl == null ) { 53 throw new IllegalArgumentException (" No registration exists for " + 54 stage + DELIM + endpoint ); 55 } 56 fl.remove(filter); 57 if ( fl.size() == 0 ) { 58 setUnManaged(endpoint); 60 } 61 } 62 63 public void unregisterFilterByName(String stage, String endpoint, 64 String filtername) { 65 66 List fl = (List ) filters.get( stage + DELIM + endpoint); 67 if ( fl == null ) { 68 throw new IllegalArgumentException (" No registration exists for " + 69 stage + DELIM + endpoint ); 70 } 71 Iterator 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 setUnManaged(endpoint); 83 } 84 } 85 86 public void unregisterAllFilters(String endpoint) { 87 Iterator itr = filters.keySet().iterator(); 88 while ( itr.hasNext()) { 89 String key = (String ) itr.next(); 90 if ( key.contains( DELIM+endpoint) ) { 91 itr.remove(); 92 } 93 } 94 } 95 96 public List getFilters(String stage, String endpoint) { 97 return (List ) filters.get(stage + DELIM + endpoint); 98 } 99 100 public FilterRegistration[] getFilters(String endpoint) { 102 return null; 103 } 104 105 public boolean isManaged(String endpoint) { 106 if ( managedEndpoints == null) 107 return false; 108 else { 109 Object 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 endpoint) { 119 managedEndpoints.put(endpoint, new Boolean (true)); 120 } 121 122 public void setUnManaged(String 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 (); 132 } 133 if ( filters == null ) { 134 filters = new HashMap (); 135 } 136 return fm; 137 } 138 139 private static FilterRegistry fm = null; 140 141 private FilterRegistry() {} 142 143 private static HashMap managedEndpoints = null; 144 145 private static HashMap filters = null; 146 147 public static final String DELIM = ":"; 148 } 149 | Popular Tags |