Removed DOCUMENT ME comments that were generated and applied source code
[utils] / system / general / src / test / java / org / wamblee / system / core / StringComponent.java
1 /*
2  * Copyright 2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.wamblee.system.core;
17
18 import org.wamblee.system.core.AbstractComponent;
19 import org.wamblee.system.core.DefaultProvidedInterface;
20 import org.wamblee.system.core.ProvidedInterface;
21 import org.wamblee.system.core.RequiredInterface;
22
23 import org.wamblee.test.EventTracker;
24
25 import javax.sql.DataSource;
26
27 /**
28  * 
29  * @author $author$
30  * @version $Revision$
31  */
32 public class StringComponent extends AbstractComponent<Object> {
33     private EventTracker<String> tracker;
34
35     private double random;
36
37     /**
38      * Creates a new StringComponent object.
39      */
40     public StringComponent() {
41         this("environment");
42     }
43
44     /**
45      * Creates a new StringComponent object.
46      * 
47      */
48     public StringComponent(String aName) {
49         this(aName, "");
50     }
51
52     /**
53      * Creates a new StringComponent object.
54      * 
55      */
56     public StringComponent(String aName, String aPrefix) {
57         super(aName, provided(aPrefix), new RequiredInterface[0]);
58         random = Math.random();
59     }
60
61     /**
62      * Creates a new StringComponent object.
63      * 
64      */
65     public StringComponent(EventTracker aTracker) {
66         this();
67         tracker = aTracker;
68     }
69
70     private static final ProvidedInterface[] provided(String aPrefix) {
71         return new ProvidedInterface[] { new DefaultProvidedInterface(aPrefix +
72             "datasource", String.class) };
73     }
74
75     public Integer getInteger() {
76         return 2;
77     }
78
79     public String getString() {
80         return getName() + ".hello";
81     }
82
83     @Override
84     protected Object doStart(Scope aScope) {
85         addInterface(getProvidedInterfaces().get(0), getString(), aScope);
86         track("start." + getName());
87
88         return random;
89     }
90
91     @Override
92     protected void doStop(Object aRuntime) {
93         track("stop." + getName());
94
95         if (random != (Double) aRuntime) {
96             throw new IllegalArgumentException("Wrong runtime: expected " +
97                 random + " but got " + aRuntime);
98         }
99     }
100
101     private void track(String aString) {
102         if (tracker == null) {
103             return;
104         }
105
106         tracker.eventOccurred(aString);
107     }
108 }