+ 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);