1 12 13 package org.ejtools.jmx.browser.model.service; 14 15 16 17 import java.beans.beancontext.BeanContextServices ; 18 19 import java.util.Arrays ; 20 21 import java.util.Collection ; 22 23 import java.util.Iterator ; 24 25 import java.util.Vector ; 26 27 28 29 import org.apache.log4j.Logger; 30 31 import org.ejtools.beans.beancontext.CustomBeanContextServiceProvider; 32 33 import org.ejtools.jmx.browser.mbean.CustomViewDeployer; 34 35 import org.ejtools.jmx.browser.mbean.View; 36 37 import org.ejtools.jmx.browser.model.Resource; 38 39 40 41 58 59 public class CustomizationServiceProvider extends CustomBeanContextServiceProvider implements CustomizationService 60 61 { 62 63 64 65 protected CustomizationService service = null; 66 67 68 69 private static Logger logger = Logger.getLogger(CustomizationServiceProvider.class); 70 71 72 73 74 75 76 77 public CustomizationServiceProvider() 78 79 { 80 81 this.service = this; 82 83 } 84 85 86 87 88 89 102 103 public Iterator getCurrentServiceSelectors(BeanContextServices bcs, java.lang.Class serviceClass) 104 105 { 106 107 return (new Vector ()).iterator(); 108 109 } 110 111 112 113 114 115 132 133 public Object getService(BeanContextServices bcs, java.lang.Object requestor, java.lang.Class serviceClass, java.lang.Object serviceSelector) 134 135 { 136 137 return service; 138 139 } 140 141 142 143 144 145 156 157 public View getView(int index) 158 159 { 160 161 logger.debug("Getting view by index=" + index); 162 163 164 165 BeanContextServices context = (BeanContextServices ) getBeanContext(); 166 167 168 169 View result = null; 170 171 172 173 if (context.hasService(ConnectionService.class) && context.hasService(CacheService.class)) 174 175 { 176 177 logger.debug("Using service ConnectionService and CacheService..."); 178 179 try 180 181 { 182 183 ConnectionService service = (ConnectionService) context.getService(this, this, ConnectionService.class, this, this); 184 185 CacheService cache = (CacheService) context.getService(this, this, CacheService.class, this, this); 186 187 188 189 Resource resource = (Resource) cache.get(CacheService.RESOURCE_TYPE, CustomViewDeployer.OBJECT_NAME); 190 191 if (resource != null) 192 193 { 194 195 result = (View) resource.invoke("getView", new Object []{new Integer (index)}, new String []{"int"}); 196 197 } 198 199 200 201 context.releaseService(this, this, CacheService.class); 202 203 context.releaseService(this, this, ConnectionService.class); 204 205 } 206 207 catch (Exception e) 208 209 { 210 211 e.printStackTrace(); 212 213 logger.error("Error during utilisation of service ConnectionService or CacheService (" + e.getMessage() + ")"); 214 215 } 216 217 } 218 219 220 221 return result; 222 223 } 224 225 226 227 228 229 238 239 public Collection getViews() 240 241 { 242 243 logger.debug("Getting views"); 244 245 246 247 BeanContextServices context = (BeanContextServices ) getBeanContext(); 248 249 250 251 Collection result = new Vector (); 252 253 254 255 if (context.hasService(ConnectionService.class) && context.hasService(CacheService.class)) 256 257 { 258 259 logger.debug("Using service ConnectionService and CacheService..."); 260 261 try 262 263 { 264 265 ConnectionService service = (ConnectionService) context.getService(this, this, ConnectionService.class, this, this); 266 267 CacheService cache = (CacheService) context.getService(this, this, CacheService.class, this, this); 268 269 270 271 Resource resource = (Resource) cache.get(CacheService.RESOURCE_TYPE, CustomViewDeployer.OBJECT_NAME); 272 273 if (resource != null) 274 275 { 276 277 View[] views = (View[]) resource.getAttribute("Views"); 278 279 if (views != null) 280 281 { 282 283 result.addAll(Arrays.asList(views)); 284 285 } 286 287 } 288 289 290 291 context.releaseService(this, this, CacheService.class); 292 293 context.releaseService(this, this, ConnectionService.class); 294 295 } 296 297 catch (Exception e) 298 299 { 300 301 e.printStackTrace(); 302 303 logger.error("Error during utilisation of service ConnectionService or CacheService (" + e.getMessage() + ")"); 304 305 } 306 307 } 308 309 310 311 return result; 312 313 } 314 315 316 317 318 319 332 333 public void releaseService(BeanContextServices bcs, java.lang.Object requestor, java.lang.Object service) { } 334 335 336 337 338 339 344 345 protected Class [] getServiceClass() 346 347 { 348 349 return new Class []{CustomizationService.class}; 350 351 } 352 353 } 354 355 | Popular Tags |