View Javadoc

1   package org.jmonit.web;
2   
3   import java.util.Collection;
4   import java.util.HashMap;
5   import java.util.Map;
6   
7   import org.jmonit.Monitor;
8   import org.jmonit.reporting.Visitable;
9   import org.jmonit.reporting.Visitor;
10  
11  /**
12   * @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
13   */
14  final class VisitableMonitor
15      implements Visitable
16  {
17      /**
18       *
19       */
20      private final Monitor monitor;
21  
22      private final Collection<Class> features;
23  
24      /**
25       * @param monitor
26       */
27      VisitableMonitor( Monitor monitor, Collection<Class> features )
28      {
29          this.monitor = monitor;
30          this.features = features;
31      }
32  
33      public void accept( Visitor visitor )
34      {
35          Map<String, Object> attributes = new HashMap<String, Object>();
36          attributes.put( "name", monitor.getName() );
37          attributes.put( "tags", monitor.getTags().toArray() );
38          if ( features != null )
39          {
40              for ( Class feature : features )
41              {
42                  Object obj = monitor.getFeature( feature );
43                  if ( obj instanceof Visitable )
44                  {
45                      // getSimpleName not supported on java 1.3
46                      String path = feature.getName();
47                      path = path.substring( path.lastIndexOf( "." ) + 1 );
48                      attributes.put( path, obj );
49                  }
50              }
51          }
52          visitor.visit( attributes );
53      }
54  }