+/**
+* Copyright (C) 2014 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
package eu.etaxonomy.cdm.remote;
-import org.springframework.remoting.RemoteConnectFailureException;
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
import eu.etaxonomy.cdm.api.service.IDatabaseService;
import eu.etaxonomy.cdm.config.CdmSourceException;
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
+/**
+ * Base class representing a CDM remote source.
+ * This class handles all the configuration relating to the remoting aspect of
+ * a CDM source.
+ *
+ */
public class CdmRemoteSourceBase extends CdmSource implements ICdmRemoteSource {
private String contextPath;
private IDatabaseService databaseService;
+ /**
+ * Constructs a CdmRemoteSourceBase
+ *
+ * @param name
+ * @param server
+ * @param port
+ * @param contextPath
+ * @param nomenclaturalCode
+ */
protected CdmRemoteSourceBase(String name, String server, int port, String contextPath, NomenclaturalCode nomenclaturalCode) {
setName(name);
setServer(server);
} else {
setBaseUrl("http://" + server + ":" + String.valueOf(port) + "/" + contextPath);
}
+ // the database service needs to be initialised (before the spring
+ // application context initialsation) since it is required to
+ // to make queries related to the source database
HttpInvokerProxyFactoryBean proxy = new HttpInvokerProxyFactoryBean();
proxy.setServiceInterface(IDatabaseService.class);
proxy.setServiceUrl(getBaseUrl() + "/remoting/database.service");
databaseService = (IDatabaseService) proxy.getObject();
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.remote.ICdmRemoteSource#getBaseUrl()
+ */
@Override
public String getBaseUrl() {
return baseUrl;
}
+ /**
+ * Sets the base url for the http-invoker services as listed in
+ * httpInvokerServicesClients.xml.
+ * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the
+ * base url would be 'http://127.0.0.1:8080/col'
+ *
+ * @param baseUrl
+ */
public void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.remote.ICdmRemoteSource#getContextPath()
+ */
@Override
public String getContextPath() {
return contextPath;
}
+ /**
+ * Sets the context path.
+ * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the
+ * context path would be 'col'
+ *
+ * @param contextPath
+ */
public void setContextPath(String contextPath) {
this.contextPath = contextPath;
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.config.CdmSource#getDbSchemaVersion()
+ */
@Override
public String getDbSchemaVersion() throws CdmSourceException {
return databaseService.getDbSchemaVersion();
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.config.CdmSource#isDbEmpty()
+ */
@Override
public boolean isDbEmpty() throws CdmSourceException {
return databaseService.isDbEmpty();
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.config.CdmSource#checkConnection()
+ */
@Override
public boolean checkConnection() throws CdmSourceException {
// assuming that database service works implies
// the connection is up
// if no exception is thrown then we assume that the
// connection is up
-
+ // FIXME:Remoting is this really correct?
databaseService.getDbSchemaVersion();
return true;
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.config.CdmSource#getConnectionMessage()
+ */
@Override
public String getConnectionMessage() {
return "Conncting to Remote CDM Server " + getName();