2 * Copyright 2007 the original author or authors.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.wamblee.system.core;
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;
23 import org.wamblee.test.EventTracker;
25 import javax.sql.DataSource;
34 public class StringComponent extends AbstractComponent<Object> {
38 private EventTracker<String> tracker;
43 private double random;
46 * Creates a new StringComponent object.
48 public StringComponent() {
53 * Creates a new StringComponent object.
55 * @param aName DOCUMENT ME!
57 public StringComponent(String aName) {
62 * Creates a new StringComponent object.
64 * @param aName DOCUMENT ME!
65 * @param aPrefix DOCUMENT ME!
67 public StringComponent(String aName, String aPrefix) {
68 super(aName, provided(aPrefix), new RequiredInterface[0]);
69 random = Math.random();
73 * Creates a new StringComponent object.
75 * @param aTracker DOCUMENT ME!
77 public StringComponent(EventTracker aTracker) {
85 * @param aPrefix DOCUMENT ME!
87 * @return DOCUMENT ME!
89 private static final ProvidedInterface[] provided(String aPrefix) {
90 return new ProvidedInterface[] {
91 new DefaultProvidedInterface(aPrefix + "datasource", String.class)
98 * @return DOCUMENT ME!
100 public Integer getInteger() {
107 * @return DOCUMENT ME!
109 public String getString() {
110 return getName() + ".hello";
116 * @param aScope DOCUMENT ME!
118 * @return DOCUMENT ME!
121 protected Object doStart(Scope aScope) {
122 addInterface(getProvidedInterfaces().get(0), getString(), aScope);
123 track("start." + getName());
131 * @param aRuntime DOCUMENT ME!
134 protected void doStop(Object aRuntime) {
135 track("stop." + getName());
137 if (random != (Double) aRuntime) {
138 throw new IllegalArgumentException("Wrong runtime: expected "
139 + random + " but got " + aRuntime);
146 * @param aString DOCUMENT ME!
148 private void track(String aString) {
149 if (tracker == null) {
153 tracker.eventOccurred(aString);