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
.taxeditor
.remoting
.source
;
13 import org
.springframework
.remoting
.RemoteAccessException
;
15 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationRemoteConfiguration
;
16 import eu
.etaxonomy
.cdm
.api
.service
.IMetadataService
;
17 import eu
.etaxonomy
.cdm
.config
.CdmSource
;
18 import eu
.etaxonomy
.cdm
.config
.CdmSourceException
;
19 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmMetaData
.MetaDataPropertyName
;
20 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
23 * Base class representing a CDM remote source.
24 * This class handles all the configuration relating to the remoting aspect of
28 public class CdmRemoteSourceBase
extends CdmSource
implements ICdmRemoteSource
{
30 protected static final String DEFAULT_NAME
= "default";
31 protected static final String DEFAULT_SERVER
= "127.0.0.1";
32 protected static final int DEFAULT_PORT
= 8080;
33 protected static final String DEFAULT_CONTEXT_PATH
= "";
34 protected static final NomenclaturalCode DEFAULT_NOMENCLATURAL_CODE
= NomenclaturalCode
.ICNAFP
;
35 private String contextPath
;
36 private String baseUrl
;
38 private IMetadataService metadataService
;
41 * Constructs a CdmRemoteSourceBase object with default values.
44 protected CdmRemoteSourceBase() {
45 setName(DEFAULT_NAME
);
46 setServer(DEFAULT_SERVER
);
47 setPort(DEFAULT_PORT
);
48 setContextPath(DEFAULT_CONTEXT_PATH
);
49 setNomenclaturalCode(DEFAULT_NOMENCLATURAL_CODE
);
53 * Constructs a CdmRemoteSourceBase
59 * @param nomenclaturalCode
61 public CdmRemoteSourceBase(String name
, String server
, int port
, String contextPath
, NomenclaturalCode nomenclaturalCode
) {
65 setContextPath(contextPath
);
66 setNomenclaturalCode(nomenclaturalCode
);
67 metadataService
= CdmApplicationRemoteConfiguration
.getMetadataService(this);
72 * @see eu.etaxonomy.cdm.remote.ICdmRemoteSource#getBaseUrl()
75 public String
getBaseUrl() {
80 * Sets the base url for the http-invoker services as listed in
81 * httpInvokerServicesClients.xml.
82 * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the
83 * base url would be 'http://127.0.0.1:8080/col'
87 public void setBaseUrl(String baseUrl
) {
88 this.baseUrl
= baseUrl
;
92 * @see eu.etaxonomy.cdm.remote.ICdmRemoteSource#getContextPath()
95 public String
getContextPath() {
100 * Sets the context path.
101 * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the
102 * context path would be 'col'
106 public void setContextPath(String contextPath
) {
107 this.contextPath
= contextPath
;
111 * @see eu.etaxonomy.cdm.config.CdmSource#getDbSchemaVersion()
114 public String
getDbSchemaVersion() throws CdmSourceException
{
115 return metadataService
.getDbSchemaVersion();
120 * @see eu.etaxonomy.cdm.config.CdmSource#isDbEmpty()
123 public boolean isDbEmpty() throws CdmSourceException
{
124 return metadataService
.isDbEmpty();
129 * @see eu.etaxonomy.cdm.config.CdmSource#checkConnection()
132 public boolean checkConnection() throws CdmSourceException
{
133 // assuming that database service works implies
134 // the connection is up
135 // if no exception is thrown then we assume that the
138 metadataService
.getDbSchemaVersion();
139 } catch (RemoteAccessException e
) {
140 throw new CdmSourceException("RemoteAccessException: " + e
.getMessage());
147 * @see eu.etaxonomy.cdm.config.CdmSource#getConnectionMessage()
150 public String
getConnectionMessage() {
151 return "Connecting to Remote CDM Instance " + getName() + ":" + getPort() + "/" + getContextPath();
156 public Map
<MetaDataPropertyName
, String
> getMetaDataMap() throws CdmSourceException
{
157 return metadataService
.getCdmMetadataMap();