null
if the service is unknown.
+ * @return the endpoint
+ * @throws IllegalArgumentException if the service has no endpoint in the map
+ * @throws IllegalStateException if the service endpoint cannot be returned
*/
- Listtrue
if the scope has a given {@link Type}.
+ * @param type the type
+ * @return true
if the scope has the given type, false
otherwise
+ */
+ public boolean is(Type type) {
+ return this.type.equals(type);
+ }
+
+ /**
+ * Returns the {@link Type} of the scope.
+ * @return the type
+ */
+ public Type type() {
+ return type;
+ }
+
+ /**
+ * Returns the enclosing scope, if any.
+ * @return the enclosing scope, or null
if the scope is top-level
+ */
+ public ScopeBean enclosingScope() {
+ return enclosingScope;
+ }
+
+ public ScopeBean(String scope) throws IllegalArgumentException {
+
+ String[] components=scope.split(separator);
+
+ if (components.length<2 || components.length>4)
+ throw new IllegalArgumentException("scope "+scope+" is malformed");
+
+ if(components.length>3) {
+ this.name=components[3];
+ this.enclosingScope = new ScopeBean(separator+components[1]+separator+components[2]);
+ this.type=Type.VRE;
+ }
+ else if (components.length>2) {
+ this.name=components[2];
+ this.enclosingScope=new ScopeBean(separator+components[1]);
+ this.type=Type.VO;
+ }
+ else {
+ this.name=components[1];
+ this.type=Type.INFRASTRUCTURE;
+ }
+
+ }
+
+ /**
+ * Returns the linear expression of the scope.
+ */
+ public String toString() {
+ return is(Type.INFRASTRUCTURE)?separator+name():
+ enclosingScope().toString()+separator+name();
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((enclosingScope == null) ? 0 : enclosingScope.hashCode());
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((type == null) ? 0 : type.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ScopeBean other = (ScopeBean) obj;
+ if (enclosingScope == null) {
+ if (other.enclosingScope != null)
+ return false;
+ } else if (!enclosingScope.equals(other.enclosingScope))
+ return false;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ if (type != other.type)
+ return false;
+ return true;
+ }
+
+
+}
diff --git a/src/main/java/org/gcube/common/scope/impl/ScopedServiceMap.java b/src/main/java/org/gcube/common/scope/impl/ScopedServiceMap.java
index 36cb39b..f25d08c 100644
--- a/src/main/java/org/gcube/common/scope/impl/ScopedServiceMap.java
+++ b/src/main/java/org/gcube/common/scope/impl/ScopedServiceMap.java
@@ -1,6 +1,7 @@
package org.gcube.common.scope.impl;
-import java.util.List;
+import static org.gcube.common.scope.impl.ScopeBean.Type.*;
+
import java.util.Map;
import org.gcube.common.scope.api.ScopeProvider;
@@ -8,10 +9,10 @@ import org.gcube.common.scope.api.ServiceMap;
/**
* A {@link ServiceMap} that forwards requests to {@link ServiceMap}s associated
- * with the scope of callers.
+ * with the current scope.
*
* At construction time, it configures itself with all the service maps found
- * the classpath (excluding URLs available to primordial and extension
+ * in the classpath (excluding URLs available to primordial and extension
* classloader). Recognises service maps as resources whose names match a
* {@link ServiceMapScanner#mapConfigPattern}.
*
@@ -29,18 +30,39 @@ public class ScopedServiceMap implements ServiceMap {
@Override
public String scope() {
- return ScopeProvider.instance.get();
+ return currentMap().scope();
+ }
+
+ @Override
+ public String version() {
+ return currentMap().version();
}
@Override
- public List