2 * Copyright 2005-2010 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.test.EventTracker;
25 public class StringComponent extends AbstractComponent<Object> {
26 private EventTracker<String> tracker;
28 private double random;
31 * Creates a new StringComponent object.
33 public StringComponent() {
38 * Creates a new StringComponent object.
41 public StringComponent(String aName) {
46 * Creates a new StringComponent object.
49 public StringComponent(String aName, String aPrefix) {
50 super(aName, provided(aPrefix), new RequiredInterface[0]);
51 random = Math.random();
55 * Creates a new StringComponent object.
58 public StringComponent(EventTracker aTracker) {
63 private static final ProvidedInterface[] provided(String aPrefix) {
64 return new ProvidedInterface[] { new DefaultProvidedInterface(aPrefix +
65 "datasource", String.class) };
68 public Integer getInteger() {
72 public String getString() {
73 return getName() + ".hello";
77 protected Object doStart(Scope aScope) {
78 addInterface(getProvidedInterfaces().get(0), getString(), aScope);
79 track("start." + getName());
85 protected void doStop(Object aRuntime) {
86 track("stop." + getName());
88 if (random != (Double) aRuntime) {
89 throw new IllegalArgumentException("Wrong runtime: expected " +
90 random + " but got " + aRuntime);
94 private void track(String aString) {
95 if (tracker == null) {
99 tracker.eventOccurred(aString);