tikhomirov@699: /* tikhomirov@699: * Copyright (c) 2013 TMate Software Ltd tikhomirov@699: * tikhomirov@699: * This program is free software; you can redistribute it and/or modify tikhomirov@699: * it under the terms of the GNU General Public License as published by tikhomirov@699: * the Free Software Foundation; version 2 of the License. tikhomirov@699: * tikhomirov@699: * This program is distributed in the hope that it will be useful, tikhomirov@699: * but WITHOUT ANY WARRANTY; without even the implied warranty of tikhomirov@699: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the tikhomirov@699: * GNU General Public License for more details. tikhomirov@699: * tikhomirov@699: * For information on how to redistribute this software under tikhomirov@699: * the terms of a license other than GNU General Public License tikhomirov@699: * contact TMate Software at support@hg4j.com tikhomirov@699: */ tikhomirov@699: package org.tmatesoft.hg.internal.remote; tikhomirov@699: tikhomirov@699: import java.io.InputStream; tikhomirov@699: import java.io.OutputStream; tikhomirov@699: import java.net.URI; tikhomirov@699: import java.util.Collection; tikhomirov@699: import java.util.List; tikhomirov@699: tikhomirov@699: import org.tmatesoft.hg.auth.HgAuthFailedException; tikhomirov@699: import org.tmatesoft.hg.core.HgRemoteConnectionException; tikhomirov@699: import org.tmatesoft.hg.core.Nodeid; tikhomirov@699: import org.tmatesoft.hg.core.SessionContext; tikhomirov@699: import org.tmatesoft.hg.repo.HgRemoteRepository.RemoteDescriptor; tikhomirov@699: import org.tmatesoft.hg.repo.HgRuntimeException; tikhomirov@699: import org.tmatesoft.hg.repo.HgRemoteRepository.Range; tikhomirov@699: tikhomirov@699: /** tikhomirov@699: * An abstract base class for {@link Connector} implementations, tikhomirov@699: * to keep binary compatibility once {@link Connector} interface changes. tikhomirov@699: * tikhomirov@699: *
Provides default implementation for {@link #getServerLocation()} that hides user credentials from uri, if any tikhomirov@699: * tikhomirov@699: *
Present method implementations are not expected to be invoked and do nothing, this may change in future to return
tikhomirov@699: * reasonable error objects. New methods, added to {@link Connector}, will get default implementation in this class as well.
tikhomirov@699: *
tikhomirov@699: * @author Artem Tikhomirov
tikhomirov@699: * @author TMate Software Ltd.
tikhomirov@699: */
tikhomirov@699: public abstract class ConnectorBase implements Connector {
tikhomirov@699: protected URI uri;
tikhomirov@699:
tikhomirov@699: protected ConnectorBase() {
tikhomirov@699: }
tikhomirov@699:
tikhomirov@699: protected void setURI(URI uri) {
tikhomirov@699: this.uri = uri;
tikhomirov@699: }
tikhomirov@699:
tikhomirov@699: // clients may invoke this method, or call #setURI(URI) directly
tikhomirov@699: public void init(RemoteDescriptor remote, SessionContext sessionContext, Object globalConfig) throws HgRuntimeException {
tikhomirov@699: setURI(remote.getURI());
tikhomirov@699: }
tikhomirov@699:
tikhomirov@699: public String getServerLocation() {
tikhomirov@699: if (uri == null) {
tikhomirov@699: return "";
tikhomirov@699: }
tikhomirov@699: if (uri.getUserInfo() == null) {
tikhomirov@699: return uri.toString();
tikhomirov@699: }
tikhomirov@699: if (uri.getPort() != -1) {
tikhomirov@699: return String.format("%s://%s:%d%s", uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath());
tikhomirov@699: } else {
tikhomirov@699: return String.format("%s://%s%s", uri.getScheme(), uri.getHost(), uri.getPath());
tikhomirov@699: }
tikhomirov@699: }
tikhomirov@699:
tikhomirov@699: public void connect() throws HgAuthFailedException, HgRemoteConnectionException, HgRuntimeException {
tikhomirov@699: }
tikhomirov@699:
tikhomirov@699: public void disconnect() throws HgRemoteConnectionException, HgRuntimeException {
tikhomirov@699: }
tikhomirov@699:
tikhomirov@699: public void sessionBegin() throws HgRemoteConnectionException, HgRuntimeException {
tikhomirov@699: }
tikhomirov@699:
tikhomirov@699: public void sessionEnd() throws HgRemoteConnectionException, HgRuntimeException {
tikhomirov@699: }
tikhomirov@699:
tikhomirov@699: public String getCapabilities() throws HgRemoteConnectionException, HgRuntimeException {
tikhomirov@699: return null;
tikhomirov@699: }
tikhomirov@699:
tikhomirov@699: public InputStream heads() throws HgRemoteConnectionException, HgRuntimeException {
tikhomirov@699: return null;
tikhomirov@699: }
tikhomirov@699:
tikhomirov@699: public InputStream between(Collection