(no commit message)
[utils] / system / general / src / test / java / org / wamblee / system / Environment.java
1 package org.wamblee.system;
2
3 import javax.sql.DataSource;
4
5 import org.wamblee.test.EventTracker;
6
7
8 public class Environment extends AbstractComponent {
9         
10         private static final ProvidedInterface[] provided() { 
11                 return new ProvidedInterface[] { 
12                         new DefaultProvidedInterface("datasource", DataSource.class), 
13                         new DefaultProvidedInterface("integer", Integer.class)
14         };
15         }
16         
17         private EventTracker<String> _tracker; 
18         
19         public Environment() { 
20                 super("environment", provided(), new RequiredInterface[0]);
21         }
22         
23         public Environment(EventTracker aTracker) { 
24                 this();
25                 _tracker = aTracker; 
26         }
27         
28         @Override
29         protected void doStart(String aContext) {
30             addService(aContext, getProvidedServices()[0], new Integer(1));
31             addService(aContext, getProvidedServices()[1], new Integer(2));
32             track("start." + getName());
33         }
34
35         @Override
36         protected void doStop() {
37                 track("stop." + getName());
38         }
39         
40         private void track(String aString) {
41                 if ( _tracker == null ) { 
42                         return; 
43                 }
44                 _tracker.eventOccurred(aString);
45         }
46 }