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 eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationRemoteConfiguration
;
14 import eu
.etaxonomy
.cdm
.api
.service
.IMetadataService
;
15 import eu
.etaxonomy
.cdm
.config
.CdmSource
;
16 import eu
.etaxonomy
.cdm
.config
.CdmSourceException
;
17 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmMetaData
.MetaDataPropertyName
;
18 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
21 * Base class representing a CDM remote source.
22 * This class handles all the configuration relating to the remoting aspect of
26 public class CdmRemoteSourceBase
extends CdmSource
implements ICdmRemoteSource
{
28 protected static final String DEFAULT_NAME
= "default";
29 protected static final String DEFAULT_SERVER
= "127.0.0.1";
30 protected static final int DEFAULT_PORT
= 8080;
31 protected static final String DEFAULT_CONTEXT_PATH
= "";
32 protected static final NomenclaturalCode DEFAULT_NOMENCLATURAL_CODE
= NomenclaturalCode
.ICNAFP
;
33 private String contextPath
;
34 private String baseUrl
;
36 private IMetadataService metadataService
;
39 * Constructs a CdmRemoteSourceBase object with default values.
42 protected CdmRemoteSourceBase() {
43 setName(DEFAULT_NAME
);
44 setServer(DEFAULT_SERVER
);
45 setPort(DEFAULT_PORT
);
46 setContextPath(DEFAULT_CONTEXT_PATH
);
47 setNomenclaturalCode(DEFAULT_NOMENCLATURAL_CODE
);
51 * Constructs a CdmRemoteSourceBase
57 * @param nomenclaturalCode
59 public CdmRemoteSourceBase(String name
, String server
, int port
, String contextPath
, NomenclaturalCode nomenclaturalCode
) {
63 setContextPath(contextPath
);
64 setNomenclaturalCode(nomenclaturalCode
);
65 metadataService
= CdmApplicationRemoteConfiguration
.getMetadataService(this);
70 * @see eu.etaxonomy.cdm.remote.ICdmRemoteSource#getBaseUrl()
73 public String
getBaseUrl() {
78 * Sets the base url for the http-invoker services as listed in
79 * httpInvokerServicesClients.xml.
80 * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the
81 * base url would be 'http://127.0.0.1:8080/col'
85 public void setBaseUrl(String baseUrl
) {
86 this.baseUrl
= baseUrl
;
90 * @see eu.etaxonomy.cdm.remote.ICdmRemoteSource#getContextPath()
93 public String
getContextPath() {
98 * Sets the context path.
99 * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the
100 * context path would be 'col'
104 public void setContextPath(String contextPath
) {
105 this.contextPath
= contextPath
;
109 * @see eu.etaxonomy.cdm.config.CdmSource#getDbSchemaVersion()
112 public String
getDbSchemaVersion() throws CdmSourceException
{
113 return metadataService
.getDbSchemaVersion();
118 * @see eu.etaxonomy.cdm.config.CdmSource#isDbEmpty()
121 public boolean isDbEmpty() throws CdmSourceException
{
122 return metadataService
.isDbEmpty();
127 * @see eu.etaxonomy.cdm.config.CdmSource#checkConnection()
130 public boolean checkConnection() throws CdmSourceException
{
131 // assuming that database service works implies
132 // the connection is up
133 // if no exception is thrown then we assume that the
135 // FIXME:Remoting is this really correct?
136 metadataService
.getDbSchemaVersion();
142 * @see eu.etaxonomy.cdm.config.CdmSource#getConnectionMessage()
145 public String
getConnectionMessage() {
146 return "Connecting to Remote CDM Instance " + getName() + ":" + getPort() + "/" + getContextPath();
151 public Map
<MetaDataPropertyName
, String
> getMetaDataMap() throws CdmSourceException
{
152 return metadataService
.getCdmMetadataMap();