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.container;
18 import org.wamblee.system.core.AbstractComponent;
19 import org.wamblee.system.core.DefaultRequiredInterface;
20 import org.wamblee.system.core.ProvidedInterface;
21 import org.wamblee.system.core.RequiredInterface;
22 import org.wamblee.system.core.Scope;
24 import org.wamblee.test.EventTracker;
31 public class Application extends AbstractComponent<Object> {
32 private EventTracker<String> tracker;
34 private String string;
36 private Integer integer;
38 private double random;
41 * Creates a new Application object.
43 public Application() {
48 * Creates a new Application object.
51 public Application(String aName) {
56 * Creates a new Application object.
59 public Application(String aName, String aPrefix) {
60 super(aName, new ProvidedInterface[0], required(false, aPrefix));
61 random = Math.random();
65 * Creates a new Application object.
68 public Application(boolean aIsOptinal) {
69 super("application", new ProvidedInterface[0], required(true, ""));
73 * Creates a new Application object.
76 public Application(EventTracker<String> aTracker) {
81 public static RequiredInterface[] required(boolean aOptional, String aPrefix) {
82 return new RequiredInterface[] {
83 new DefaultRequiredInterface(aPrefix + "string", String.class,
85 new DefaultRequiredInterface(aPrefix + "integer", Integer.class,
89 public static RequiredInterface[] required(boolean aOptional) {
90 return required(aOptional, "");
94 public Object doStart(Scope aScope) {
95 track("start." + getName());
96 string = aScope.getInterfaceImplementation(getRequiredInterfaces().get(
97 0).getProvider(), String.class);
98 integer = aScope.getInterfaceImplementation(getRequiredInterfaces()
99 .get(1).getProvider(), Integer.class);
104 public String getString() {
108 public Integer getInteger() {
113 public void doStop(Object aRuntime) {
114 track("stop." + getName());
116 if (random != (Double) aRuntime) {
117 throw new IllegalArgumentException("Wrong runtime: expected " +
118 random + " but got " + aRuntime);
122 private void track(String aString) {
123 if (tracker == null) {
127 tracker.eventOccurred(aString);