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.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;
33 public class Application extends AbstractComponent<Object> {
37 private EventTracker<String> tracker;
42 private String string;
47 private Integer integer;
52 private double random;
55 * Creates a new Application object.
57 public Application() {
62 * Creates a new Application object.
64 * @param aName DOCUMENT ME!
66 public Application(String aName) {
71 * Creates a new Application object.
73 * @param aName DOCUMENT ME!
74 * @param aPrefix DOCUMENT ME!
76 public Application(String aName, String aPrefix) {
77 super(aName, new ProvidedInterface[0], required(false, aPrefix));
78 random = Math.random();
82 * Creates a new Application object.
84 * @param aIsOptinal DOCUMENT ME!
86 public Application(boolean aIsOptinal) {
87 super("application", new ProvidedInterface[0], required(true, ""));
91 * Creates a new Application object.
93 * @param aTracker DOCUMENT ME!
95 public Application(EventTracker<String> aTracker) {
103 * @param aOptional DOCUMENT ME!
104 * @param aPrefix DOCUMENT ME!
106 * @return DOCUMENT ME!
108 public static RequiredInterface[] required(boolean aOptional, String aPrefix) {
109 return new RequiredInterface[] {
110 new DefaultRequiredInterface(aPrefix + "string", String.class,
112 new DefaultRequiredInterface(aPrefix + "integer", Integer.class,
120 * @param aOptional DOCUMENT ME!
122 * @return DOCUMENT ME!
124 public static RequiredInterface[] required(boolean aOptional) {
125 return required(aOptional, "");
131 * @param aScope DOCUMENT ME!
133 * @return DOCUMENT ME!
136 public Object doStart(Scope aScope) {
137 track("start." + getName());
138 string = aScope.getInterfaceImplementation(getRequiredInterfaces()
139 .get(0).getProvider(), String.class);
140 integer = aScope.getInterfaceImplementation(getRequiredInterfaces()
141 .get(1).getProvider(), Integer.class);
149 * @return DOCUMENT ME!
151 public String getString() {
158 * @return DOCUMENT ME!
160 public Integer getInteger() {
167 * @param aRuntime DOCUMENT ME!
170 public void doStop(Object aRuntime) {
171 track("stop." + getName());
173 if (random != (Double) aRuntime) {
174 throw new IllegalArgumentException("Wrong runtime: expected "
175 + random + " but got " + aRuntime);
182 * @param aString DOCUMENT ME!
184 private void track(String aString) {
185 if (tracker == null) {
189 tracker.eventOccurred(aString);