diff --git a/src/main/java/uniresolver/driver/did/sov/DidSovDriver.java b/src/main/java/uniresolver/driver/did/sov/DidSovDriver.java index aabab26..9c59f73 100644 --- a/src/main/java/uniresolver/driver/did/sov/DidSovDriver.java +++ b/src/main/java/uniresolver/driver/did/sov/DidSovDriver.java @@ -36,16 +36,44 @@ public class DidSovDriver implements Driver { private boolean openParallel; private IndyConnector indyConnector; - public DidSovDriver(Map properties) { + public DidSovDriver(LibIndyInitializer libIndyInitializer, boolean openParallel, IndyConnector indyConnector) throws IndyConnectionException{ + + this.setLibIndyInitializer(libIndyInitializer); + this.setOpenParallel(openParallel); + this.setIndyConnector(indyConnector); + + this.initializeIndy(); + } + + public DidSovDriver(Map properties) throws IndyConnectionException{ this.setProperties(properties); + + this.initializeIndy(); } - public DidSovDriver() { + public DidSovDriver() throws IndyConnectionException { this(getPropertiesFromEnvironment()); } + private void initializeIndy() throws IndyConnectionException { + + // init libindy + + if (this.getLibIndyInitializer() != null && ! this.getLibIndyInitializer().isInitialized()) { + this.getLibIndyInitializer().initializeLibIndy(); + if (log.isInfoEnabled()) log.info("Successfully initialized libindy."); + } + + // open indy connections + + if (this.getIndyConnector() != null && ! this.getIndyConnector().isOpened()) { + this.getIndyConnector().openIndyConnections(true, false, this.getOpenParallel()); + if (log.isInfoEnabled()) log.info("Successfully opened Indy connections."); + } + } + private static Map getPropertiesFromEnvironment() { if (log.isDebugEnabled()) log.debug("Loading from environment: " + System.getenv()); @@ -109,22 +137,10 @@ private void configureFromProperties() { @Override public ResolveDataModelResult resolve(DID did, Map resolveOptions) throws ResolutionException { - // init - - if (!this.getLibIndyInitializer().isInitialized()) { - this.getLibIndyInitializer().initializeLibIndy(); - if (log.isInfoEnabled()) log.info("Successfully initialized libindy."); - } - - // open indy connections + // check if Indy connections are open if (! this.getIndyConnector().isOpened()) { - try { - this.getIndyConnector().openIndyConnections(true, false, this.getOpenParallel()); - if (log.isInfoEnabled()) log.info("Successfully opened Indy connections."); - } catch (IndyConnectionException ex) { - throw new ResolutionException("Cannot open Indy connections: " + ex.getMessage(), ex); - } + throw new ResolutionException("Indy connections are not opened"); } // parse identifier