(no commit message)
[utils] / system / general / src / main / java / org / wamblee / system / core / DefaultScope.java
index 18f26cc8d0a1e8ddaa75a3b88affd2c81422bf5b..ad4b09863418b6e7f02b47cfcdfec952f5e4b2db 100644 (file)
@@ -17,6 +17,7 @@ package org.wamblee.system.core;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -28,8 +29,12 @@ public class DefaultScope implements Scope {
        private List<Scope> _parents;
        private Map<String, Object> _properties;
        private Map<String, Object> _runtimes;
-       private Map<String, ProvidedInterfaceImplementation> _provided;
-       private ProvidedInterface[] _externallyProvided;
+       private Map<ProvidedInterface, ProvidedInterfaceImplementation> _provided;
+       private List<ProvidedInterface> _externallyProvided;
+       
+       public DefaultScope(List<ProvidedInterface>aExternallyProvided) { 
+           this(aExternallyProvided.toArray(new ProvidedInterface[0]));
+       }
 
        public DefaultScope(ProvidedInterface[] aExternallyProvided) {
                this(aExternallyProvided, new ArrayList<Scope>());
@@ -44,13 +49,14 @@ public class DefaultScope implements Scope {
                _parents = new ArrayList<Scope>(aParent);
                _properties = new HashMap<String, Object>();
                _runtimes = new HashMap<String, Object>();
-               _provided = new HashMap<String, ProvidedInterfaceImplementation>();
-               _externallyProvided = aExternallyProvided;
+               _provided = new HashMap<ProvidedInterface, ProvidedInterfaceImplementation>();
+               _externallyProvided = new ArrayList<ProvidedInterface>(); 
+               _externallyProvided.addAll(Arrays.asList(aExternallyProvided));
        }
 
        @Override
-       public ProvidedInterface[] getProvidedInterfaces() {
-               return _externallyProvided;
+       public List<ProvidedInterface> getProvidedInterfaces() {
+               return Collections.unmodifiableList(_externallyProvided);
        }
 
        @Override
@@ -81,7 +87,7 @@ public class DefaultScope implements Scope {
        @Override
        synchronized public void publishInterface(ProvidedInterface aInterface,
                        Object aImplementation) {
-               _provided.put(aInterface.getUniqueId(), new ProvidedInterfaceImplementation(aInterface,
+               _provided.put(aInterface, new ProvidedInterfaceImplementation(aInterface,
                                aImplementation));
        }
 
@@ -90,13 +96,8 @@ public class DefaultScope implements Scope {
                        Class<T> aType) {
                if ( aInterface == null ) { 
                        return null; 
-               }
-               String id = aInterface.getUniqueId(); 
-               if ( id == null ) { 
-                       // optional interface that was not published.
-                       return null;
-               }
-               ProvidedInterfaceImplementation provided = _provided.get(id);
+               } 
+               ProvidedInterfaceImplementation provided = _provided.get(aInterface);
                if (provided == null) {
                        for (Scope parent : _parents) {
                                T impl = parent.getInterfaceImplementation(aInterface, aType);