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.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;
32 public class StringComponent extends AbstractComponent<Object> {
33 private EventTracker<String> tracker;
35 private double random;
38 * Creates a new StringComponent object.
40 public StringComponent() {
45 * Creates a new StringComponent object.
48 public StringComponent(String aName) {
53 * Creates a new StringComponent object.
56 public StringComponent(String aName, String aPrefix) {
57 super(aName, provided(aPrefix), new RequiredInterface[0]);
58 random = Math.random();
62 * Creates a new StringComponent object.
65 public StringComponent(EventTracker aTracker) {
70 private static final ProvidedInterface[] provided(String aPrefix) {
71 return new ProvidedInterface[] { new DefaultProvidedInterface(aPrefix +
72 "datasource", String.class) };
75 public Integer getInteger() {
79 public String getString() {
80 return getName() + ".hello";
84 protected Object doStart(Scope aScope) {
85 addInterface(getProvidedInterfaces().get(0), getString(), aScope);
86 track("start." + getName());
92 protected void doStop(Object aRuntime) {
93 track("stop." + getName());
95 if (random != (Double) aRuntime) {
96 throw new IllegalArgumentException("Wrong runtime: expected " +
97 random + " but got " + aRuntime);
101 private void track(String aString) {
102 if (tracker == null) {
106 tracker.eventOccurred(aString);