/*
- * Copyright 2007 the original author or authors.
+ * Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.wamblee.system.core.ProvidedInterface;
import org.wamblee.system.core.RequiredInterface;
import org.wamblee.system.core.Scope;
+
import org.wamblee.test.EventTracker;
-public class Application extends AbstractComponent {
- public static RequiredInterface[] required(boolean aOptional, String aPrefix) {
- return
- new RequiredInterface[] {
- new DefaultRequiredInterface(aPrefix + "string", String.class, aOptional),
- new DefaultRequiredInterface(aPrefix + "integer", Integer.class, aOptional)
- };
- }
-
- public static RequiredInterface[] required(boolean aOptional) {
- return required(aOptional, "");
+/**
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class Application extends AbstractComponent<Object> {
+ private EventTracker<String> tracker;
+
+ private String string;
+
+ private Integer integer;
+
+ private double random;
+
+ /**
+ * Creates a new Application object.
+ */
+ public Application() {
+ this("application");
}
-
-
- private EventTracker<String> _tracker;
- private String _string;
- private Integer _integer;
- private double _random;
-
- public Application() {
- this("application");
- }
-
- public Application(String aName) {
- this(aName, "");
+
+ /**
+ * Creates a new Application object.
+ *
+ */
+ public Application(String aName) {
+ this(aName, "");
}
-
- public Application(String aName, String aPrefix) {
+
+ /**
+ * Creates a new Application object.
+ *
+ */
+ public Application(String aName, String aPrefix) {
super(aName, new ProvidedInterface[0], required(false, aPrefix));
- _random = Math.random();
+ random = Math.random();
+ }
+
+ /**
+ * Creates a new Application object.
+ *
+ */
+ public Application(boolean aIsOptinal) {
+ super("application", new ProvidedInterface[0], required(true, ""));
+ }
+
+ /**
+ * Creates a new Application object.
+ *
+ */
+ public Application(EventTracker<String> aTracker) {
+ this();
+ tracker = aTracker;
+ }
+
+ public static RequiredInterface[] required(boolean aOptional, String aPrefix) {
+ return new RequiredInterface[] {
+ new DefaultRequiredInterface(aPrefix + "string", String.class,
+ aOptional),
+ new DefaultRequiredInterface(aPrefix + "integer", Integer.class,
+ aOptional) };
+ }
+
+ public static RequiredInterface[] required(boolean aOptional) {
+ return required(aOptional, "");
+ }
+
+ @Override
+ public Object doStart(Scope aScope) {
+ track("start." + getName());
+ string = aScope.getInterfaceImplementation(getRequiredInterfaces().get(
+ 0).getProvider(), String.class);
+ integer = aScope.getInterfaceImplementation(getRequiredInterfaces()
+ .get(1).getProvider(), Integer.class);
+
+ return random;
+ }
+
+ public String getString() {
+ return string;
+ }
+
+ public Integer getInteger() {
+ return integer;
+ }
+
+ @Override
+ public void doStop(Object aRuntime) {
+ track("stop." + getName());
+
+ if (random != (Double) aRuntime) {
+ throw new IllegalArgumentException("Wrong runtime: expected " +
+ random + " but got " + aRuntime);
+ }
+ }
+
+ private void track(String aString) {
+ if (tracker == null) {
+ return;
+ }
+
+ tracker.eventOccurred(aString);
}
-
- public Application(boolean aIsOptinal) {
- super("application", new ProvidedInterface[0], required(true, ""));
- }
-
- public Application(EventTracker<String> aTracker) {
- this();
- _tracker = aTracker;
- }
-
- @Override
- public Object doStart(Scope aScope) {
- track("start." + getName());
- _string = aScope.getInterfaceImplementation(getRequiredInterfaces().get(0).getProvider(), String.class);
- _integer = aScope.getInterfaceImplementation(getRequiredInterfaces().get(1).getProvider(), Integer.class);
- return _random;
- }
-
- public String getString() {
- return _string;
- }
-
- public Integer getInteger() {
- return _integer;
- }
-
- @Override
- public void doStop(Object aRuntime) {
- track("stop." + getName());
- if ( _random != (Double)aRuntime) {
- throw new IllegalArgumentException("Wrong runtime: expected " + _random + " but got " +
- aRuntime);
- }
- }
-
- private void track(String aString) {
- if ( _tracker == null ) {
- return;
- }
- _tracker.eventOccurred(aString);
- }
}