2 * Copyright (C) 2014 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.remote
;
11 import org
.springframework
.remoting
.httpinvoker
.HttpInvokerProxyFactoryBean
;
13 import eu
.etaxonomy
.cdm
.api
.service
.IDatabaseService
;
14 import eu
.etaxonomy
.cdm
.config
.CdmSource
;
15 import eu
.etaxonomy
.cdm
.config
.CdmSourceException
;
16 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
19 * Base class representing a CDM remote source.
20 * This class handles all the configuration relating to the remoting aspect of
24 public class CdmRemoteSourceBase
extends CdmSource
implements ICdmRemoteSource
{
26 private String contextPath
;
27 private String baseUrl
;
29 private IDatabaseService databaseService
;
32 * Constructs a CdmRemoteSourceBase object with default values.
35 protected CdmRemoteSourceBase() {
37 setServer("127.0.0.1");
40 setNomenclaturalCode(NomenclaturalCode
.ICNAFP
);
44 * Constructs a CdmRemoteSourceBase
50 * @param nomenclaturalCode
52 protected CdmRemoteSourceBase(String name
, String server
, int port
, String contextPath
, NomenclaturalCode nomenclaturalCode
) {
56 setContextPath(contextPath
);
57 setNomenclaturalCode(nomenclaturalCode
);
58 if(contextPath
== null || contextPath
.equals("")) {
59 setBaseUrl("http://" + server
+ ":" + String
.valueOf(port
));
61 setBaseUrl("http://" + server
+ ":" + String
.valueOf(port
) + "/" + contextPath
);
63 // the database service needs to be initialised (before the spring
64 // application context initialsation) since it is required to
65 // to make queries related to the source database
66 HttpInvokerProxyFactoryBean proxy
= new HttpInvokerProxyFactoryBean();
67 proxy
.setServiceInterface(IDatabaseService
.class);
68 proxy
.setServiceUrl(getBaseUrl() + "/remoting/database.service");
69 proxy
.afterPropertiesSet();
70 databaseService
= (IDatabaseService
) proxy
.getObject();
74 * @see eu.etaxonomy.cdm.remote.ICdmRemoteSource#getBaseUrl()
77 public String
getBaseUrl() {
82 * Sets the base url for the http-invoker services as listed in
83 * httpInvokerServicesClients.xml.
84 * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the
85 * base url would be 'http://127.0.0.1:8080/col'
89 public void setBaseUrl(String baseUrl
) {
90 this.baseUrl
= baseUrl
;
94 * @see eu.etaxonomy.cdm.remote.ICdmRemoteSource#getContextPath()
97 public String
getContextPath() {
102 * Sets the context path.
103 * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the
104 * context path would be 'col'
108 public void setContextPath(String contextPath
) {
109 this.contextPath
= contextPath
;
113 * @see eu.etaxonomy.cdm.config.CdmSource#getDbSchemaVersion()
116 public String
getDbSchemaVersion() throws CdmSourceException
{
117 return databaseService
.getDbSchemaVersion();
122 * @see eu.etaxonomy.cdm.config.CdmSource#isDbEmpty()
125 public boolean isDbEmpty() throws CdmSourceException
{
126 return databaseService
.isDbEmpty();
131 * @see eu.etaxonomy.cdm.config.CdmSource#checkConnection()
134 public boolean checkConnection() throws CdmSourceException
{
135 // assuming that database service works implies
136 // the connection is up
137 // if no exception is thrown then we assume that the
139 // FIXME:Remoting is this really correct?
140 databaseService
.getDbSchemaVersion();
146 * @see eu.etaxonomy.cdm.config.CdmSource#getConnectionMessage()
149 public String
getConnectionMessage() {
150 return "Conncting to Remote CDM Server " + getName();