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 Environment extends AbstractComponent<Object> {
26 private static int COUNT = 0;
28 private EventTracker<String> tracker;
30 private double random;
35 * Creates a new Environment object.
37 public Environment() {
42 * Creates a new Environment object.
45 public Environment(String aName) {
50 * Creates a new Environment object.
53 public Environment(String aName, String aPrefix) {
54 super(aName, provided(aPrefix), new RequiredInterface[0]);
55 random = Math.random();
60 * Creates a new Environment object.
63 public Environment(EventTracker aTracker) {
68 private static final ProvidedInterface[] provided(String aPrefix) {
69 return new ProvidedInterface[] {
70 new DefaultProvidedInterface(aPrefix + "datasource", String.class),
71 new DefaultProvidedInterface(aPrefix + "integer", Integer.class) };
74 public Integer getInteger() {
78 public String getString() {
79 return getName() + ".hello";
83 protected Object doStart(Scope aScope) {
84 addInterface(getProvidedInterfaces().get(0), getString(), aScope);
85 addInterface(getProvidedInterfaces().get(1), getInteger(), 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);