Plugin Manager
This commit is contained in:
parent
a09b47a379
commit
c85122a5a3
|
@ -0,0 +1,39 @@
|
|||
package org.gcube.spatial.data.clients;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class SDIClientManager {
|
||||
|
||||
private Collection<SDIGenericClient> clients=new ArrayList<SDIGenericClient>();
|
||||
|
||||
public SDIClientManager() {
|
||||
ServiceLoader.load(SDIGenericClient.class).forEach((SDIGenericClient c)->{clients.add(c);});
|
||||
log.info("Loaded {} clients ",clients.size());
|
||||
clients.forEach((SDIGenericClient c)->{
|
||||
log.debug("Loaded "+c.getInfo());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the implementation for the target engine. Null if no suitable plugin is found
|
||||
*
|
||||
* @param engine
|
||||
* @param version
|
||||
* @return
|
||||
*/
|
||||
public SDIGenericClient get(String engine,String version) {
|
||||
log.info("Looking for clients [target : {} {} ] ",engine,version);
|
||||
for(SDIGenericClient c:clients) {
|
||||
if(c.getInfo().getSupportedEngine().getEngineUniqueString().equals(engine)
|
||||
&& c.getInfo().getSupportedEngine().getRange().supports(version))
|
||||
return c;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package org.gcube.spatial.data.clients;
|
||||
|
||||
public class SDIClientValidator {
|
||||
|
||||
}
|
|
@ -3,8 +3,7 @@ package org.gcube.spatial.data.sdi;
|
|||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.gcube.spatial.data.clients.model.ClientInfo;
|
||||
import org.gcube.spatial.data.clients.model.engine.Engine;
|
||||
import org.gcube.spatial.data.clients.SDIClientManager;
|
||||
import org.gcube.spatial.data.clients.model.engine.Range;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -12,8 +11,7 @@ public class Clients {
|
|||
|
||||
@Test
|
||||
public void testRanges() {
|
||||
ClientInfo gnClient=new ClientInfo("gn2-client","GeoNetwork 2","Client to communicate with GN 2","org.gcube.sdi.some.clients.Client",
|
||||
new Engine(Engine.GN_ENGINE,"",new Range("1.1.0",null)));
|
||||
|
||||
|
||||
|
||||
assertFalse(new Range("1.1.0",null).supports("0.0.1"));
|
||||
|
@ -27,4 +25,9 @@ public class Clients {
|
|||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testLoading() {
|
||||
System.out.println(new SDIClientManager().get("dumb-gn", "1.5.7rc").getInfo());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package org.gcube.spatial.data.sdi;
|
||||
|
||||
import org.gcube.spatial.data.clients.SDIGenericClient;
|
||||
import org.gcube.spatial.data.clients.model.ClientInfo;
|
||||
import org.gcube.spatial.data.clients.model.ConnectionDescriptor;
|
||||
import org.gcube.spatial.data.clients.model.engine.Engine;
|
||||
import org.gcube.spatial.data.clients.model.engine.Range;
|
||||
|
||||
public class DumbGNClient implements SDIGenericClient{
|
||||
|
||||
|
||||
ClientInfo gnClient=new ClientInfo("dumb-gn","GeoNetwork 2","Client to communicate with GN 2","org.gcube.sdi.some.clients.Client",
|
||||
new Engine("dumb-gn","",new Range("1.1.0","2.20")));
|
||||
|
||||
@Override
|
||||
public ClientInfo getInfo() {
|
||||
return gnClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRESTClient(ConnectionDescriptor conn) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
org.gcube.spatial.data.sdi.DumbGNClient
|
Loading…
Reference in New Issue