merged from trunk
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/common/common-gcore-clients/2.0@83968 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e5d4b034d7
commit
491552e1e8
|
@ -8,7 +8,10 @@
|
||||||
<Changeset component="common-gcore-clients-2.0.1" date="2012-11-30">
|
<Changeset component="common-gcore-clients-2.0.1" date="2012-11-30">
|
||||||
<Change>Fixed W3CEndpointReference->EndpointReferenceType conversion util</Change>
|
<Change>Fixed W3CEndpointReference->EndpointReferenceType conversion util</Change>
|
||||||
</Changeset>
|
</Changeset>
|
||||||
<Changeset component="${build.finalName}" date="2013-01-11">
|
<Changeset component="common-gcore-clients-2.1.0" date="2013-01-11">
|
||||||
<Change>Aligns with gCF 1.6.0+ and eliminates dependencies on legacy scope handling mechanisms</Change>
|
<Change>Aligns with gCF 1.6.0+ and eliminates dependencies on legacy scope handling mechanisms</Change>
|
||||||
</Changeset>
|
</Changeset>
|
||||||
|
<Changeset component="${build.finalName}" date="2013-10-10">
|
||||||
|
<Change>internal refactoring</Change>
|
||||||
|
</Changeset>
|
||||||
</ReleaseNotes>
|
</ReleaseNotes>
|
2
pom.xml
2
pom.xml
|
@ -10,7 +10,7 @@
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>common-gcore-clients</artifactId>
|
<artifactId>common-gcore-clients</artifactId>
|
||||||
|
|
||||||
<version>2.1.0-SNAPSHOT</version>
|
<version>2.2.0-SNAPSHOT</version>
|
||||||
<name>GCore Clients</name>
|
<name>GCore Clients</name>
|
||||||
|
|
||||||
<description>A framework for client APIs that invoke GCore services</description>
|
<description>A framework for client APIs that invoke GCore services</description>
|
||||||
|
|
|
@ -13,15 +13,10 @@ import org.gcube.common.clients.delegates.ProxyPlugin;
|
||||||
*/
|
*/
|
||||||
public interface Plugin<S,P> extends ProxyPlugin<EndpointReferenceType, S,P> {
|
public interface Plugin<S,P> extends ProxyPlugin<EndpointReferenceType, S,P> {
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the gCube name of the service.
|
|
||||||
* @return the name
|
|
||||||
*/
|
|
||||||
String serviceClass();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the gCube class of the service.
|
* Returns the namespace of the service
|
||||||
* @return the class
|
* @return the namespace
|
||||||
*/
|
*/
|
||||||
String serviceName();;
|
String namespace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,19 @@
|
||||||
package org.gcube.common.clients.gcore.queries;
|
package org.gcube.common.clients.gcore.queries;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.axis.message.addressing.EndpointReferenceType;
|
import org.apache.axis.message.addressing.EndpointReferenceType;
|
||||||
import org.gcube.common.clients.cache.DefaultEndpointCache;
|
import org.gcube.common.clients.cache.DefaultEndpointCache;
|
||||||
import org.gcube.common.clients.cache.EndpointCache;
|
import org.gcube.common.clients.cache.EndpointCache;
|
||||||
|
import org.gcube.common.clients.delegates.ProxyPlugin;
|
||||||
|
import org.gcube.common.clients.exceptions.DiscoveryException;
|
||||||
import org.gcube.common.clients.gcore.plugins.Plugin;
|
import org.gcube.common.clients.gcore.plugins.Plugin;
|
||||||
import org.gcube.common.clients.gcore.plugins.PluginAdapter;
|
import org.gcube.common.clients.gcore.plugins.PluginAdapter;
|
||||||
import org.gcube.common.clients.queries.AbstractQuery;
|
|
||||||
import org.gcube.common.clients.queries.Query;
|
import org.gcube.common.clients.queries.Query;
|
||||||
|
import org.gcube.common.clients.queries.ResultMatcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Partial implementation of {@link Query}s for gCore services.
|
* Partial implementation of {@link Query}s for gCore services.
|
||||||
|
@ -15,10 +22,15 @@ import org.gcube.common.clients.queries.Query;
|
||||||
*
|
*
|
||||||
* @param <R> the type of query results
|
* @param <R> the type of query results
|
||||||
*/
|
*/
|
||||||
public abstract class GCoreQuery<R> extends AbstractQuery<EndpointReferenceType, R> {
|
public abstract class GCoreQuery<R> implements Query<EndpointReferenceType> {
|
||||||
|
|
||||||
|
|
||||||
|
private final ProxyPlugin<EndpointReferenceType,?,?> plugin;
|
||||||
|
|
||||||
public static EndpointCache<EndpointReferenceType> globalCache = new DefaultEndpointCache<EndpointReferenceType>();
|
public static EndpointCache<EndpointReferenceType> globalCache = new DefaultEndpointCache<EndpointReferenceType>();
|
||||||
|
|
||||||
|
private final Map<String,String> conditions = new HashMap<String, String>();
|
||||||
|
|
||||||
private final ISFacade facade;
|
private final ISFacade facade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,8 +40,7 @@ public abstract class GCoreQuery<R> extends AbstractQuery<EndpointReferenceType,
|
||||||
* @param queryClass the query type
|
* @param queryClass the query type
|
||||||
*/
|
*/
|
||||||
protected GCoreQuery(ISFacade facade, Plugin<?,?> plugin) {
|
protected GCoreQuery(ISFacade facade, Plugin<?,?> plugin) {
|
||||||
super(plugin);
|
this.plugin = plugin;
|
||||||
|
|
||||||
this.facade=facade;
|
this.facade=facade;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,4 +51,106 @@ public abstract class GCoreQuery<R> extends AbstractQuery<EndpointReferenceType,
|
||||||
protected ISFacade facade() {
|
protected ISFacade facade() {
|
||||||
return facade;
|
return facade;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//default matcher does not filter out any result
|
||||||
|
private ResultMatcher<R> matcher = new ResultMatcher<R>() {
|
||||||
|
@Override public boolean match(R doc) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a condition to the query.
|
||||||
|
* @param property an expression that identifies a property of service endpoints
|
||||||
|
* @param value the value of the property
|
||||||
|
*/
|
||||||
|
public void addCondition(String property, String value) {
|
||||||
|
this.conditions.put(property,value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets an {@link ResultMatcher} for the query.
|
||||||
|
* @param matcher the matcher.
|
||||||
|
*/
|
||||||
|
public void setMatcher(ResultMatcher<R> matcher) {
|
||||||
|
this.matcher=matcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final List<EndpointReferenceType> fire() throws DiscoveryException {
|
||||||
|
|
||||||
|
//delegate actual execution to subclass-specific mechanisms
|
||||||
|
List<R> results = fire(conditions);
|
||||||
|
|
||||||
|
//from results to addresses
|
||||||
|
List<EndpointReferenceType> endpoints = new ArrayList<EndpointReferenceType>();
|
||||||
|
|
||||||
|
for (R result : results)
|
||||||
|
try {
|
||||||
|
if (matcher.match(result)) //should we include this? ask matcher
|
||||||
|
endpoints.add(address(result)); //extract address
|
||||||
|
}
|
||||||
|
catch(IllegalArgumentException e) {
|
||||||
|
//skip result, this is just a signal from subclasses
|
||||||
|
};
|
||||||
|
|
||||||
|
return endpoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the query through implementation-specific means.
|
||||||
|
* @param conditions the conditions to apply on the query prior to its execution
|
||||||
|
* @return the query results
|
||||||
|
* @throws DiscoveryException if the query could not be executed
|
||||||
|
*/
|
||||||
|
protected abstract List<R> fire(Map<String,String> conditions) throws DiscoveryException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an endpoint address from a query result.
|
||||||
|
* @param result the result
|
||||||
|
* @return the address
|
||||||
|
* @throws IllegalArgumentException if an address cannot be derived from the result
|
||||||
|
*/
|
||||||
|
protected abstract EndpointReferenceType address(R result) throws IllegalArgumentException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the {@link ProxyPlugin}.
|
||||||
|
* @return the plugin
|
||||||
|
*/
|
||||||
|
protected ProxyPlugin<EndpointReferenceType,?,?> plugin() {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
//queries are value objects based on properties
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
GCoreQuery<?> other = (GCoreQuery<?>) obj;
|
||||||
|
if (conditions == null) {
|
||||||
|
if (other.conditions != null)
|
||||||
|
return false;
|
||||||
|
} else if (!conditions.equals(other.conditions))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((conditions == null) ? 0 : conditions.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final String toString() {
|
||||||
|
return conditions.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue