+ private List<Scope> parents;
+
+ private Map<String, Object> properties;
+
+ private Map<String, Object> runtimes;
+
+ private Map<ProvidedInterface, ProvidedInterfaceImplementation> provided;
+
+ private List<ProvidedInterface> externallyProvided;
+
+ /**
+ * Creates a new DefaultScope object.
+ *
+ */
+ public DefaultScope(List<ProvidedInterface> aExternallyProvided) {
+ this(aExternallyProvided.toArray(new ProvidedInterface[0]));
+ }
+
+ /**
+ * Creates a new DefaultScope object.
+ *
+ */
+ public DefaultScope(ProvidedInterface[] aExternallyProvided) {
+ this(aExternallyProvided, new ArrayList<Scope>());
+ }
+
+ /**
+ * Creates a new DefaultScope object.
+ *
+ */
+ public DefaultScope(ProvidedInterface[] aExternallyProvided, Scope aParent) {
+ this(aExternallyProvided, Arrays.asList(new Scope[] { aParent }));
+ }
+
+ /**
+ * Creates a new DefaultScope object.
+ *
+ */
+ public DefaultScope(ProvidedInterface[] aExternallyProvided,
+ List<Scope> aParent) {
+ parents = new ArrayList<Scope>(aParent);
+ properties = new HashMap<String, Object>();
+ runtimes = new HashMap<String, Object>();
+ provided = new HashMap<ProvidedInterface, ProvidedInterfaceImplementation>();
+ externallyProvided = new ArrayList<ProvidedInterface>();
+ externallyProvided.addAll(Arrays.asList(aExternallyProvided));
+ }
+
+ @Override
+ public List<ProvidedInterface> getProvidedInterfaces() {
+ return Collections.unmodifiableList(externallyProvided);
+ }
+
+ @Override
+ public Object get(String aKey) {
+ return properties.get(aKey);
+ }
+
+ @Override
+ public void put(String aKey, Object aValue) {
+ properties.put(aKey, aValue);
+ }
+
+ @Override
+ public void addRuntime(Component aComponent, Object aRuntime) {
+ runtimes.put(aComponent.getName(), aRuntime);
+ }
+
+ @Override
+ public Object getRuntime(Component aComponent) {
+ return runtimes.get(aComponent.getName());
+ }
+
+ @Override
+ public Object getRuntime(String aName) {
+ return runtimes.get(aName);
+ }
+
+ @Override
+ synchronized public void publishInterface(ProvidedInterface aInterface,
+ Object aImplementation) {
+ provided.put(aInterface, new ProvidedInterfaceImplementation(
+ aInterface, aImplementation));
+ }
+
+ @Override
+ public <T> T getInterfaceImplementation(ProvidedInterface aInterface,
+ Class<T> aType) {
+ if (aInterface == null) {
+ return null;
+ }
+
+ ProvidedInterfaceImplementation providedIntf = provided.get(aInterface);
+
+ if (providedIntf == null) {
+ for (Scope parent : parents) {
+ T impl = parent.getInterfaceImplementation(aInterface, aType);
+
+ if (impl != null) {
+ return impl;
+ }
+ }