From 2f328c5252837036ec738bfa15e621fd028c67d2 Mon Sep 17 00:00:00 2001 From: erik Date: Thu, 5 Jun 2008 20:47:52 +0000 Subject: [PATCH] Now the component provides read-only access to the interfaces. --- .../wamblee/system/container/Container.java | 4 +- .../system/core/AbstractComponent.java | 20 ++-- .../org/wamblee/system/core/Component.java | 4 +- .../wamblee/system/core/NamedInterface.java | 23 ++++ .../system/core/ProvidedInterface.java | 8 +- .../system/core/ProvidedInterfaces.java | 35 ++++++ .../system/core/ReadOnlyNamedInterfaces.java | 84 ++++++++++++++ .../system/core/ReadWriteNamedInterfaces.java | 62 ++++++++++ .../core/ReadWriteProvidedInterfaces.java | 31 +++++ .../core/ReadWriteRequiredInterfaces.java | 31 +++++ .../system/core/RequiredInterface.java | 7 +- .../system/core/RequiredInterfaces.java | 31 +++++ .../wamblee/system/container/Application.java | 4 +- .../system/container/ContainerTest.java | 108 +++++++++--------- .../system/core/AbstractComponentTest.java | 4 +- .../org/wamblee/system/core/Environment.java | 4 +- .../wamblee/system/core/IntegerComponent.java | 2 +- .../wamblee/system/core/StringComponent.java | 2 +- .../system/graph/CompositeEdgeFilterTest.java | 24 ++-- ...xternalProvidedProvidedEdgeFilterTest.java | 8 +- ...uiredExternallyRequiredEdgeFilterTest.java | 24 ++-- ...ConnectRequiredProvidedEdgeFilterTest.java | 4 +- 22 files changed, 405 insertions(+), 119 deletions(-) create mode 100644 system/general/src/main/java/org/wamblee/system/core/NamedInterface.java create mode 100644 system/general/src/main/java/org/wamblee/system/core/ProvidedInterfaces.java create mode 100644 system/general/src/main/java/org/wamblee/system/core/ReadOnlyNamedInterfaces.java create mode 100644 system/general/src/main/java/org/wamblee/system/core/ReadWriteNamedInterfaces.java create mode 100644 system/general/src/main/java/org/wamblee/system/core/ReadWriteProvidedInterfaces.java create mode 100644 system/general/src/main/java/org/wamblee/system/core/ReadWriteRequiredInterfaces.java create mode 100644 system/general/src/main/java/org/wamblee/system/core/RequiredInterfaces.java diff --git a/system/general/src/main/java/org/wamblee/system/container/Container.java b/system/general/src/main/java/org/wamblee/system/container/Container.java index a69ac98e..fe744f74 100644 --- a/system/general/src/main/java/org/wamblee/system/container/Container.java +++ b/system/general/src/main/java/org/wamblee/system/container/Container.java @@ -194,7 +194,7 @@ public class Container extends AbstractComponent { * @return Scope. */ public Scope start() { - Scope scope = new DefaultScope(getProvidedInterfaces()); + Scope scope = new DefaultScope(getProvidedInterfaces().toArray()); return super.start(scope); } @@ -202,7 +202,7 @@ public class Container extends AbstractComponent { protected Scope doStart(Scope aExternalScope) { checkSealed(); validate(); - Scope scope = new DefaultScope(getProvidedInterfaces(), aExternalScope); + Scope scope = new DefaultScope(getProvidedInterfaces().toArray(), aExternalScope); ComponentGraph graph = doStartOptionalDryRun(scope, false); exposeProvidedInterfaces(graph, aExternalScope, scope); seal(); diff --git a/system/general/src/main/java/org/wamblee/system/core/AbstractComponent.java b/system/general/src/main/java/org/wamblee/system/core/AbstractComponent.java index 9000f4ae..38df3bc4 100644 --- a/system/general/src/main/java/org/wamblee/system/core/AbstractComponent.java +++ b/system/general/src/main/java/org/wamblee/system/core/AbstractComponent.java @@ -35,8 +35,8 @@ public abstract class AbstractComponent implements Component { private String _context; private String _name; - private List _provided; - private List _required; + private ReadWriteProvidedInterfaces _provided; + private ReadWriteRequiredInterfaces _required; /** * Constructs the subsystem. @@ -53,10 +53,8 @@ public abstract class AbstractComponent implements Component { _remaining = new ThreadLocal>(); _context = null; _name = aName; - _provided = new ArrayList(); - _provided.addAll(Arrays.asList(aProvided)); - _required = new ArrayList(); - _required.addAll(Arrays.asList(aRequired)); + _provided = new ReadWriteProvidedInterfaces(aProvided); + _required = new ReadWriteRequiredInterfaces(aRequired); } protected AbstractComponent(String aName) { @@ -101,20 +99,20 @@ public abstract class AbstractComponent implements Component { } @Override - public final ProvidedInterface[] getProvidedInterfaces() { - return _provided.toArray(new ProvidedInterface[0]); + public final ProvidedInterfaces getProvidedInterfaces() { + return _provided.readOnlyView(); } @Override - public final RequiredInterface[] getRequiredInterfaces() { - return _required.toArray(new RequiredInterface[0]); + public final RequiredInterfaces getRequiredInterfaces() { + return _required.readOnlyView(); } @Override public final Type start(Scope aScope) { LOG.info("Initialization starting '" + getQualifiedName() + "'"); List oldRemaining = _remaining.get(); - _remaining.set(new ArrayList(Arrays.asList(getProvidedInterfaces()))); + _remaining.set(new ArrayList(Arrays.asList(getProvidedInterfaces().toArray()))); try { Type runtime = doStart(aScope); checkNotStartedInterfaces(); diff --git a/system/general/src/main/java/org/wamblee/system/core/Component.java b/system/general/src/main/java/org/wamblee/system/core/Component.java index 37a9c84d..49ed1c7d 100644 --- a/system/general/src/main/java/org/wamblee/system/core/Component.java +++ b/system/general/src/main/java/org/wamblee/system/core/Component.java @@ -60,13 +60,13 @@ public interface Component { * Gets a description of the provided interfaces. * @return Provided interfaces. */ - ProvidedInterface[] getProvidedInterfaces(); + ProvidedInterfaces getProvidedInterfaces(); /** * Gets a description of the required interfaces. * @return Required interfaces. */ - RequiredInterface[] getRequiredInterfaces(); + RequiredInterfaces getRequiredInterfaces(); /** diff --git a/system/general/src/main/java/org/wamblee/system/core/NamedInterface.java b/system/general/src/main/java/org/wamblee/system/core/NamedInterface.java new file mode 100644 index 00000000..9800621e --- /dev/null +++ b/system/general/src/main/java/org/wamblee/system/core/NamedInterface.java @@ -0,0 +1,23 @@ +/* + * Copyright 2008 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wamblee.system.core; + +public interface NamedInterface { + /** + * Name for the interface. + */ + String getName(); +} diff --git a/system/general/src/main/java/org/wamblee/system/core/ProvidedInterface.java b/system/general/src/main/java/org/wamblee/system/core/ProvidedInterface.java index f717535c..46bf5f24 100644 --- a/system/general/src/main/java/org/wamblee/system/core/ProvidedInterface.java +++ b/system/general/src/main/java/org/wamblee/system/core/ProvidedInterface.java @@ -23,13 +23,7 @@ import java.util.Collection; * * @author Erik Brakkee */ -public interface ProvidedInterface { - - /** - * Symbolic name for the service as used by the subsystem. - * @return Service name. - */ - String getName(); +public interface ProvidedInterface extends NamedInterface { /** * Returns the service type. diff --git a/system/general/src/main/java/org/wamblee/system/core/ProvidedInterfaces.java b/system/general/src/main/java/org/wamblee/system/core/ProvidedInterfaces.java new file mode 100644 index 00000000..9fd8c06f --- /dev/null +++ b/system/general/src/main/java/org/wamblee/system/core/ProvidedInterfaces.java @@ -0,0 +1,35 @@ +/* + * Copyright 2008 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wamblee.system.core; + +import java.util.List; + +/** + * Read-only access to the provided interfaces of a component. + * + * @author Erik Brakkee. + * + */ +public class ProvidedInterfaces extends ReadOnlyNamedInterfaces { + + /** + * Constructs the provided interfaces. + * @param aInterfaces List of interfaces. + */ + public ProvidedInterfaces(List aInterfaces) { + super(ProvidedInterface.class, aInterfaces); + } +} diff --git a/system/general/src/main/java/org/wamblee/system/core/ReadOnlyNamedInterfaces.java b/system/general/src/main/java/org/wamblee/system/core/ReadOnlyNamedInterfaces.java new file mode 100644 index 00000000..4248b1db --- /dev/null +++ b/system/general/src/main/java/org/wamblee/system/core/ReadOnlyNamedInterfaces.java @@ -0,0 +1,84 @@ +/* + * Copyright 2008 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wamblee.system.core; + +import java.lang.reflect.Array; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +/** + * A set of interfaces that cannot be changed with useful added functionality. + * + * @author Erik Brakkee + * + * @param + */ +public class ReadOnlyNamedInterfaces implements Iterable { + + private Class _type; + private List _interfaces; + + public ReadOnlyNamedInterfaces(Class aType, List aInterfaces) { + _type = aType; + _interfaces = Collections.unmodifiableList(aInterfaces); + } + + /** + * @return Number of interfaces. + */ + public int size() { + return _interfaces.size(); + } + + /** + * Gets the interface at a given index. + * @param aIndex Index of the interface to return. + * @return Interface. + */ + public T get(int aIndex) { + return _interfaces.get(aIndex); + } + + /** + * Gets the interface with a specific name. + * @param aName Interface name. + * @return Interface. + */ + public T get(String aName) { + for (T intf: _interfaces) { + if ( intf.getName().equals(aName)) { + return intf; + } + } + return null; + } + + @Override + public Iterator iterator() { + return _interfaces.iterator(); + } + + /** + * Converts the interfaces to an array. + * @return List of interfaces in an array. + */ + public T[] toArray() { + T[] storage = (T[])Array.newInstance(_type, _interfaces.size()); + return _interfaces.toArray(storage); + } +} diff --git a/system/general/src/main/java/org/wamblee/system/core/ReadWriteNamedInterfaces.java b/system/general/src/main/java/org/wamblee/system/core/ReadWriteNamedInterfaces.java new file mode 100644 index 00000000..0dcd4187 --- /dev/null +++ b/system/general/src/main/java/org/wamblee/system/core/ReadWriteNamedInterfaces.java @@ -0,0 +1,62 @@ +/* + * Copyright 2008 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wamblee.system.core; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +public class ReadWriteNamedInterfaces implements Iterable { + + protected List _interfaces; + + public ReadWriteNamedInterfaces() { + _interfaces = new ArrayList(); + } + + public ReadWriteNamedInterfaces(T[] aInterfaces) { + _interfaces = new ArrayList(); + _interfaces.addAll(Arrays.asList(aInterfaces)); + } + + public int size() { + return _interfaces.size(); + } + + public T get(int aIndex) { + return _interfaces.get(aIndex); + } + + public T get(String aName) { + for (T intf: _interfaces) { + if ( intf.getName().equals(aName)) { + return intf; + } + } + return null; + } + + public void add(T aInterface) { + _interfaces.add(aInterface); + } + + @Override + public Iterator iterator() { + return _interfaces.iterator(); + } + +} diff --git a/system/general/src/main/java/org/wamblee/system/core/ReadWriteProvidedInterfaces.java b/system/general/src/main/java/org/wamblee/system/core/ReadWriteProvidedInterfaces.java new file mode 100644 index 00000000..8581c939 --- /dev/null +++ b/system/general/src/main/java/org/wamblee/system/core/ReadWriteProvidedInterfaces.java @@ -0,0 +1,31 @@ +/* + * Copyright 2008 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wamblee.system.core; + +public class ReadWriteProvidedInterfaces extends ReadWriteNamedInterfaces { + + public ReadWriteProvidedInterfaces() { + super(); + } + + public ReadWriteProvidedInterfaces(ProvidedInterface[] aInterfaces) { + super(aInterfaces); + } + + public ProvidedInterfaces readOnlyView() { + return new ProvidedInterfaces(_interfaces); + } +} diff --git a/system/general/src/main/java/org/wamblee/system/core/ReadWriteRequiredInterfaces.java b/system/general/src/main/java/org/wamblee/system/core/ReadWriteRequiredInterfaces.java new file mode 100644 index 00000000..3cdccebb --- /dev/null +++ b/system/general/src/main/java/org/wamblee/system/core/ReadWriteRequiredInterfaces.java @@ -0,0 +1,31 @@ +/* + * Copyright 2008 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wamblee.system.core; + +public class ReadWriteRequiredInterfaces extends ReadWriteNamedInterfaces { + + public ReadWriteRequiredInterfaces() { + super(); + } + + public ReadWriteRequiredInterfaces(RequiredInterface[] aInterfaces) { + super(aInterfaces); + } + + public RequiredInterfaces readOnlyView() { + return new RequiredInterfaces(_interfaces); + } +} diff --git a/system/general/src/main/java/org/wamblee/system/core/RequiredInterface.java b/system/general/src/main/java/org/wamblee/system/core/RequiredInterface.java index 74c132e0..4dd77fc7 100644 --- a/system/general/src/main/java/org/wamblee/system/core/RequiredInterface.java +++ b/system/general/src/main/java/org/wamblee/system/core/RequiredInterface.java @@ -15,12 +15,7 @@ */ package org.wamblee.system.core; -public interface RequiredInterface { - - /** - * Name for the interface. - */ - String getName(); +public interface RequiredInterface extends NamedInterface { /** * @return True iff the required interface is optional. diff --git a/system/general/src/main/java/org/wamblee/system/core/RequiredInterfaces.java b/system/general/src/main/java/org/wamblee/system/core/RequiredInterfaces.java new file mode 100644 index 00000000..bd747cd6 --- /dev/null +++ b/system/general/src/main/java/org/wamblee/system/core/RequiredInterfaces.java @@ -0,0 +1,31 @@ +/* + * Copyright 2008 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wamblee.system.core; + +import java.util.List; + +/** + * Read-only access to required interfaces of a component. + * @author Erik Brakkee + * + */ +public class RequiredInterfaces extends ReadOnlyNamedInterfaces { + + public RequiredInterfaces(List aInterfaces) { + super(RequiredInterface.class, aInterfaces); + } + +} diff --git a/system/general/src/test/java/org/wamblee/system/container/Application.java b/system/general/src/test/java/org/wamblee/system/container/Application.java index 94603767..56c267fe 100644 --- a/system/general/src/test/java/org/wamblee/system/container/Application.java +++ b/system/general/src/test/java/org/wamblee/system/container/Application.java @@ -66,8 +66,8 @@ public class Application extends AbstractComponent { @Override public Object doStart(Scope aScope) { track("start." + getName()); - _string = aScope.getInterfaceImplementation(getRequiredInterfaces()[0].getProvider(), String.class); - _integer = aScope.getInterfaceImplementation(getRequiredInterfaces()[1].getProvider(), Integer.class); + _string = aScope.getInterfaceImplementation(getRequiredInterfaces().get(0).getProvider(), String.class); + _integer = aScope.getInterfaceImplementation(getRequiredInterfaces().get(1).getProvider(), Integer.class); return _random; } diff --git a/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java b/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java index 83abf3c2..5da0f025 100644 --- a/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java +++ b/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java @@ -31,7 +31,9 @@ import org.wamblee.system.core.DefaultRequiredInterface; import org.wamblee.system.core.DefaultScope; import org.wamblee.system.core.Environment; import org.wamblee.system.core.ProvidedInterface; +import org.wamblee.system.core.ProvidedInterfaces; import org.wamblee.system.core.RequiredInterface; +import org.wamblee.system.core.RequiredInterfaces; import org.wamblee.system.core.Scope; import org.wamblee.system.core.StringComponent; import org.wamblee.system.core.SystemAssemblyException; @@ -125,10 +127,10 @@ public class ContainerTest extends TestCase { application }, new ProvidedInterface[0], new RequiredInterface[0]); Scope runtime = system.start(); - RequiredInterface[] required = system.getRequiredInterfaces(); - assertEquals(0, required.length); - ProvidedInterface[] provided = system.getProvidedInterfaces(); - assertEquals(0, provided.length); + RequiredInterfaces required = system.getRequiredInterfaces(); + assertEquals(0, required.size()); + ProvidedInterfaces provided = system.getProvidedInterfaces(); + assertEquals(0, provided.size()); AssertionUtils.assertEquals(new String[] { "start.environment", "start.application" }, _tracker.getEvents( @@ -180,13 +182,13 @@ public class ContainerTest extends TestCase { application }, new ProvidedInterface[0], new RequiredInterface[] { new DefaultRequiredInterface("float", Float.class) }); - system.getRequiredInterfaces()[0] + system.getRequiredInterfaces().get(0) .setProvider(new DefaultProvidedInterface("hallo", Float.class)); system.start(); - RequiredInterface[] required = system.getRequiredInterfaces(); - assertEquals(1, required.length); - ProvidedInterface[] provided = system.getProvidedInterfaces(); - assertEquals(0, provided.length); + RequiredInterfaces required = system.getRequiredInterfaces(); + assertEquals(1, required.size()); + ProvidedInterfaces provided = system.getProvidedInterfaces(); + assertEquals(0, provided.size()); } public void testCompositeWithExternalDependencesNotProvided() { @@ -195,7 +197,7 @@ public class ContainerTest extends TestCase { Component application = new Application(); Container system = new Container("all", new Component[] { application }, new ProvidedInterface[0], - application.getRequiredInterfaces()); + application.getRequiredInterfaces().toArray()); system.start(); } catch (SystemAssemblyException e) { return; @@ -233,18 +235,18 @@ public class ContainerTest extends TestCase { Component application = new Application(); Container system = new Container("all", new Component[] { application }, new ProvidedInterface[0], - application.getRequiredInterfaces()); + application.getRequiredInterfaces().toArray()); environment.start(new DefaultScope(new ProvidedInterface[0])); - system.getRequiredInterfaces()[0].setProvider(environment - .getProvidedInterfaces()[0]); - system.getRequiredInterfaces()[1].setProvider(environment - .getProvidedInterfaces()[1]); + system.getRequiredInterfaces().get(0).setProvider(environment + .getProvidedInterfaces().get(0)); + system.getRequiredInterfaces().get(1).setProvider(environment + .getProvidedInterfaces().get(1)); system.start(); - RequiredInterface[] required = system.getRequiredInterfaces(); - assertEquals(2, required.length); - ProvidedInterface[] provided = system.getProvidedInterfaces(); - assertEquals(0, provided.length); + RequiredInterfaces required = system.getRequiredInterfaces(); + assertEquals(2, required.size()); + ProvidedInterfaces provided = system.getProvidedInterfaces(); + assertEquals(0, provided.size()); } @@ -350,22 +352,22 @@ public class ContainerTest extends TestCase { new Component[] { application }, new ProvidedInterface[0], Application.required(true)); Environment env = new Environment(); - container.getRequiredInterfaces()[0].setProvider(env - .getProvidedInterfaces()[0]); - container.getRequiredInterfaces()[1].setProvider(env - .getProvidedInterfaces()[1]); - Scope external = new DefaultScope(env.getProvidedInterfaces()); + container.getRequiredInterfaces().get(0).setProvider(env + .getProvidedInterfaces().get(0)); + container.getRequiredInterfaces().get(1).setProvider(env + .getProvidedInterfaces().get(1)); + Scope external = new DefaultScope(env.getProvidedInterfaces().toArray()); env.start(external); container.start(external); - assertSame(env.getProvidedInterfaces()[0], container - .getRequiredInterfaces()[0].getProvider()); - assertSame(env.getProvidedInterfaces()[1], container - .getRequiredInterfaces()[1].getProvider()); - assertSame(env.getProvidedInterfaces()[0], application - .getRequiredInterfaces()[0].getProvider()); - assertSame(env.getProvidedInterfaces()[1], application - .getRequiredInterfaces()[1].getProvider()); + assertSame(env.getProvidedInterfaces().get(0), container + .getRequiredInterfaces().get(0).getProvider()); + assertSame(env.getProvidedInterfaces().get(1), container + .getRequiredInterfaces().get(1).getProvider()); + assertSame(env.getProvidedInterfaces().get(0), application + .getRequiredInterfaces().get(0).getProvider()); + assertSame(env.getProvidedInterfaces().get(1), application + .getRequiredInterfaces().get(1).getProvider()); } public void testOptionalRequiredInterfaceNotProvidedOptionalInternal() { @@ -374,18 +376,18 @@ public class ContainerTest extends TestCase { new Component[] { application }, new ProvidedInterface[0], Application.required(true)); Environment env = new Environment(); - container.getRequiredInterfaces()[0].setProvider(env - .getProvidedInterfaces()[0]); + container.getRequiredInterfaces().get(0).setProvider(env + .getProvidedInterfaces().get(0)); Scope external = new DefaultScope(new ProvidedInterface[0]); - external.publishInterface(env.getProvidedInterfaces()[0], env + external.publishInterface(env.getProvidedInterfaces().get(0), env .getString()); container.start(external); - assertSame(env.getProvidedInterfaces()[0], container - .getRequiredInterfaces()[0].getProvider()); - assertNull(container.getRequiredInterfaces()[1].getProvider()); - assertSame(env.getProvidedInterfaces()[0], application - .getRequiredInterfaces()[0].getProvider()); - assertNull(application.getRequiredInterfaces()[1].getProvider()); + assertSame(env.getProvidedInterfaces().get(0), container + .getRequiredInterfaces().get(0).getProvider()); + assertNull(container.getRequiredInterfaces().get(1).getProvider()); + assertSame(env.getProvidedInterfaces().get(0), application + .getRequiredInterfaces().get(0).getProvider()); + assertNull(application.getRequiredInterfaces().get(1).getProvider()); } public void testOptionalRequiredInterfaceProvidedMandatoryInternal() { @@ -394,10 +396,10 @@ public class ContainerTest extends TestCase { new Component[] { application }, new ProvidedInterface[0], Application.required(true)); Environment env = new Environment(); - container.getRequiredInterfaces()[0].setProvider(env - .getProvidedInterfaces()[0]); - container.getRequiredInterfaces()[1].setProvider(env - .getProvidedInterfaces()[1]); + container.getRequiredInterfaces().get(0).setProvider(env + .getProvidedInterfaces().get(0)); + container.getRequiredInterfaces().get(1).setProvider(env + .getProvidedInterfaces().get(1)); try { container.start(); } catch (SystemAssemblyException e) { @@ -480,7 +482,7 @@ public class ContainerTest extends TestCase { ProvidedInterface provided = new DefaultProvidedInterface("hallo", Integer.class); - container.getRequiredInterfaces()[0].setProvider(provided); + container.getRequiredInterfaces().get(0).setProvider(provided); Scope external = new DefaultScope(new ProvidedInterface[0]); external.publishInterface(provided, 100); @@ -547,7 +549,7 @@ public class ContainerTest extends TestCase { } }, SystemAssemblyException.class); - container.connectExternalRequired("1", app.getRequiredInterfaces()[0] + container.connectExternalRequired("1", app.getRequiredInterfaces().get(0) .getName(), "y"); ProvidedInterface i = new DefaultProvidedInterface("i", Integer.class); @@ -560,9 +562,9 @@ public class ContainerTest extends TestCase { externalScope.publishInterface(x, "x-value"); externalScope.publishInterface(y, "y-value"); - container.getRequiredInterfaces()[0].setProvider(i); - container.getRequiredInterfaces()[1].setProvider(x); - container.getRequiredInterfaces()[2].setProvider(y); + container.getRequiredInterfaces().get(0).setProvider(i); + container.getRequiredInterfaces().get(1).setProvider(x); + container.getRequiredInterfaces().get(2).setProvider(y); Scope runtime = container.start(externalScope); @@ -590,8 +592,8 @@ public class ContainerTest extends TestCase { // now choose env2 - container.connectExternalProvided(container.getProvidedInterfaces()[0] - .getName(), env2.getName(), env2.getProvidedInterfaces()[0] + container.connectExternalProvided(container.getProvidedInterfaces().get(0) + .getName(), env2.getName(), env2.getProvidedInterfaces().get(0) .getName()); Scope scope = container.start(); @@ -599,7 +601,7 @@ public class ContainerTest extends TestCase { // check the value of the provided interface of the container String value = scope.getInterfaceImplementation(container - .getProvidedInterfaces()[0], String.class); + .getProvidedInterfaces().get(0), String.class); assertNotNull(value); assertEquals(value, env2.getString()); assertFalse(value.equals(env1.getString())); diff --git a/system/general/src/test/java/org/wamblee/system/core/AbstractComponentTest.java b/system/general/src/test/java/org/wamblee/system/core/AbstractComponentTest.java index 39d7dd61..3b1b7d37 100644 --- a/system/general/src/test/java/org/wamblee/system/core/AbstractComponentTest.java +++ b/system/general/src/test/java/org/wamblee/system/core/AbstractComponentTest.java @@ -35,7 +35,7 @@ public class AbstractComponentTest extends TestCase { // Empty. } }; - component.start(new DefaultScope(component.getProvidedInterfaces())); + component.start(new DefaultScope(component.getProvidedInterfaces().toArray())); } catch (SystemAssemblyException e) { //e.printStackTrace(); return; @@ -58,7 +58,7 @@ public class AbstractComponentTest extends TestCase { // Empty. } }; - component.start(new DefaultScope(component.getProvidedInterfaces())); + component.start(new DefaultScope(component.getProvidedInterfaces().toArray())); } catch (SystemAssemblyException e) { //e.printStackTrace(); return; diff --git a/system/general/src/test/java/org/wamblee/system/core/Environment.java b/system/general/src/test/java/org/wamblee/system/core/Environment.java index c08f456d..c1e72ac4 100644 --- a/system/general/src/test/java/org/wamblee/system/core/Environment.java +++ b/system/general/src/test/java/org/wamblee/system/core/Environment.java @@ -64,8 +64,8 @@ public class Environment extends AbstractComponent { @Override protected Object doStart(Scope aScope) { - addInterface(getProvidedInterfaces()[0], getString(), aScope); - addInterface(getProvidedInterfaces()[1], getInteger(), aScope); + addInterface(getProvidedInterfaces().get(0), getString(), aScope); + addInterface(getProvidedInterfaces().get(1), getInteger(), aScope); track("start." + getName()); return _random; } diff --git a/system/general/src/test/java/org/wamblee/system/core/IntegerComponent.java b/system/general/src/test/java/org/wamblee/system/core/IntegerComponent.java index 0af4ae3d..547f831d 100644 --- a/system/general/src/test/java/org/wamblee/system/core/IntegerComponent.java +++ b/system/general/src/test/java/org/wamblee/system/core/IntegerComponent.java @@ -59,7 +59,7 @@ public class IntegerComponent extends AbstractComponent { @Override protected Object doStart(Scope aScope) { - addInterface(getProvidedInterfaces()[1], getInteger(), aScope); + addInterface(getProvidedInterfaces().get(1), getInteger(), aScope); track("start." + getName()); return _random; } diff --git a/system/general/src/test/java/org/wamblee/system/core/StringComponent.java b/system/general/src/test/java/org/wamblee/system/core/StringComponent.java index 990adaf0..c47112aa 100644 --- a/system/general/src/test/java/org/wamblee/system/core/StringComponent.java +++ b/system/general/src/test/java/org/wamblee/system/core/StringComponent.java @@ -63,7 +63,7 @@ public class StringComponent extends AbstractComponent { @Override protected Object doStart(Scope aScope) { - addInterface(getProvidedInterfaces()[0], getString(), aScope); + addInterface(getProvidedInterfaces().get(0), getString(), aScope); track("start." + getName()); return _random; } diff --git a/system/general/src/test/java/org/wamblee/system/graph/CompositeEdgeFilterTest.java b/system/general/src/test/java/org/wamblee/system/graph/CompositeEdgeFilterTest.java index 6507efa9..7889c357 100644 --- a/system/general/src/test/java/org/wamblee/system/graph/CompositeEdgeFilterTest.java +++ b/system/general/src/test/java/org/wamblee/system/graph/CompositeEdgeFilterTest.java @@ -43,8 +43,8 @@ public class CompositeEdgeFilterTest extends TestCase { public void testEmpty() { EdgeFilter restriction = new CompositeEdgeFilter(); - assertFalse(restriction.isViolated(createEdge(_app, _app.getRequiredInterfaces()[0], - _env, _env.getProvidedInterfaces()[0]))); + assertFalse(restriction.isViolated(createEdge(_app, _app.getRequiredInterfaces().get(0), + _env, _env.getProvidedInterfaces().get(0)))); } private void configureRestriction(EdgeFilter base, boolean aResult) { @@ -64,8 +64,8 @@ public class CompositeEdgeFilterTest extends TestCase { configureRestriction(base, false); control.replay(); - assertFalse(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces()[0], - _env, _env.getProvidedInterfaces()[0]))); + assertFalse(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces().get(0), + _env, _env.getProvidedInterfaces().get(0)))); control.verify(); // Second let the base return true and verify the result. @@ -73,8 +73,8 @@ public class CompositeEdgeFilterTest extends TestCase { configureRestriction(base, true); control.replay(); - assertTrue(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces()[0], - _env, _env.getProvidedInterfaces()[0]))); + assertTrue(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces().get(0), + _env, _env.getProvidedInterfaces().get(0)))); control.verify(); } @@ -94,8 +94,8 @@ public class CompositeEdgeFilterTest extends TestCase { configureRestriction(base1, false); configureRestriction(base2, false); control.replay(); - assertFalse(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces()[0], - _env, _env.getProvidedInterfaces()[0]))); + assertFalse(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces().get(0), + _env, _env.getProvidedInterfaces().get(0)))); control.verify(); control.reset(); @@ -103,8 +103,8 @@ public class CompositeEdgeFilterTest extends TestCase { configureRestriction(base1, false); configureRestriction(base2, true); control.replay(); - assertTrue(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces()[0], - _env, _env.getProvidedInterfaces()[0]))); + assertTrue(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces().get(0), + _env, _env.getProvidedInterfaces().get(0)))); control.verify(); control.reset(); @@ -112,8 +112,8 @@ public class CompositeEdgeFilterTest extends TestCase { configureRestriction(base1, true); // base 2 should not be called. control.replay(); - assertTrue(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces()[0], - _env, _env.getProvidedInterfaces()[0]))); + assertTrue(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces().get(0), + _env, _env.getProvidedInterfaces().get(0)))); control.verify(); control.reset(); } diff --git a/system/general/src/test/java/org/wamblee/system/graph/component/ConnectExternalProvidedProvidedEdgeFilterTest.java b/system/general/src/test/java/org/wamblee/system/graph/component/ConnectExternalProvidedProvidedEdgeFilterTest.java index 7d93181b..2adea27b 100644 --- a/system/general/src/test/java/org/wamblee/system/graph/component/ConnectExternalProvidedProvidedEdgeFilterTest.java +++ b/system/general/src/test/java/org/wamblee/system/graph/component/ConnectExternalProvidedProvidedEdgeFilterTest.java @@ -45,15 +45,15 @@ public class ConnectExternalProvidedProvidedEdgeFilterTest extends TestCase { String.class)); _internal = new Environment("env1"); - _externalInterfaceName = _container.getProvidedInterfaces()[0] + _externalInterfaceName = _container.getProvidedInterfaces().get(0) .getName(); _internalComponentName = _internal.getName(); - _internalInterfaceName = _internal.getProvidedInterfaces()[0].getName(); + _internalInterfaceName = _internal.getProvidedInterfaces().get(0).getName(); _edge = new DefaultEdge(new ExternalProvidedInterfaceNode(_container, - _container.getProvidedInterfaces()[0]), + _container.getProvidedInterfaces().get(0)), new ProvidedInterfaceNode(_internal, _internal - .getProvidedInterfaces()[0])); + .getProvidedInterfaces().get(0))); } public void testWrongExternal() { diff --git a/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredExternallyRequiredEdgeFilterTest.java b/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredExternallyRequiredEdgeFilterTest.java index 3fd7c61c..55d6d890 100644 --- a/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredExternallyRequiredEdgeFilterTest.java +++ b/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredExternallyRequiredEdgeFilterTest.java @@ -41,38 +41,38 @@ public class ConnectRequiredExternallyRequiredEdgeFilterTest extends TestCase { .addRequiredInterface(new DefaultRequiredInterface("x", String.class)); Node req = new RequiredInterfaceNode(_comp, _comp - .getRequiredInterfaces()[0]); + .getRequiredInterfaces().get(0)); Node external = new ExternalRequiredInterfaceNode(_container, - _container.getRequiredInterfaces()[0]); + _container.getRequiredInterfaces().get(0)); _edge = new DefaultEdge(req, external); } public void testRightComponentRightInterface() { EdgeFilter filter = new ConnectRequiredExternallyRequiredEdgeFilter( - _comp.getName(), _comp.getRequiredInterfaces()[0].getName(), - _container.getRequiredInterfaces()[0].getName()); + _comp.getName(), _comp.getRequiredInterfaces().get(0).getName(), + _container.getRequiredInterfaces().get(0).getName()); assertFalse(filter.isViolated(_edge)); } public void testWrongInterface() { EdgeFilter filter = new ConnectRequiredExternallyRequiredEdgeFilter( - _comp.getName(), _comp.getRequiredInterfaces()[0].getName() - + "xx", _container.getRequiredInterfaces()[0].getName()); + _comp.getName(), _comp.getRequiredInterfaces().get(0).getName() + + "xx", _container.getRequiredInterfaces().get(0).getName()); assertFalse(filter.isViolated(_edge)); } public void testWrongComponent() { EdgeFilter filter = new ConnectRequiredExternallyRequiredEdgeFilter( - _comp.getName() + "xx", _comp.getRequiredInterfaces()[0] - .getName(), _container.getRequiredInterfaces()[0] + _comp.getName() + "xx", _comp.getRequiredInterfaces().get(0) + .getName(), _container.getRequiredInterfaces().get(0) .getName()); assertFalse(filter.isViolated(_edge)); } public void testWrongExternalInterface() { EdgeFilter filter = new ConnectRequiredExternallyRequiredEdgeFilter( - _comp.getName(), _comp.getRequiredInterfaces()[0].getName(), - _container.getRequiredInterfaces()[0].getName() + "xx"); + _comp.getName(), _comp.getRequiredInterfaces().get(0).getName(), + _container.getRequiredInterfaces().get(0).getName() + "xx"); assertTrue(filter.isViolated(_edge)); } @@ -80,8 +80,8 @@ public class ConnectRequiredExternallyRequiredEdgeFilterTest extends TestCase { DefaultEdge edge = new DefaultEdge(new DefaultNode("x"), new DefaultNode("y")); EdgeFilter filter = new ConnectRequiredExternallyRequiredEdgeFilter( - _comp.getName(), _comp.getRequiredInterfaces()[0].getName(), - _container.getRequiredInterfaces()[0].getName()); + _comp.getName(), _comp.getRequiredInterfaces().get(0).getName(), + _container.getRequiredInterfaces().get(0).getName()); assertFalse(filter.isViolated(edge)); } } diff --git a/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredProvidedEdgeFilterTest.java b/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredProvidedEdgeFilterTest.java index d9ab61bd..ac43c9d0 100644 --- a/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredProvidedEdgeFilterTest.java +++ b/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredProvidedEdgeFilterTest.java @@ -49,9 +49,9 @@ public class ConnectRequiredProvidedEdgeFilterTest extends TestCase { for (Environment env: new Environment[] { _env1, _env2} ) { for (Application app: new Application[] { _app1, _app2} ) { Node from = new RequiredInterfaceNode( - app, app.getRequiredInterfaces()[0]); + app, app.getRequiredInterfaces().get(0)); Node to = new ProvidedInterfaceNode( - env, env.getProvidedInterfaces()[0]); + env, env.getProvidedInterfaces().get(0)); Edge edge = new DefaultEdge(from, to); result.add(aRestriction.isViolated(edge)); } -- 2.31.1