comparison src/org/tmatesoft/hg/internal/remote/RemoteConnectorDescriptor.java @ 699:a483b2b68a2e

Provisional APIs and respective implementation for http, https and ssh remote repositories
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 08 Aug 2013 19:18:50 +0200
parents 822f3a83ff57
children 992fa84e7885
comparison
equal deleted inserted replaced
698:822f3a83ff57 699:a483b2b68a2e
20 import java.util.HashMap; 20 import java.util.HashMap;
21 import java.util.Map; 21 import java.util.Map;
22 22
23 import org.tmatesoft.hg.core.HgBadArgumentException; 23 import org.tmatesoft.hg.core.HgBadArgumentException;
24 import org.tmatesoft.hg.core.SessionContext; 24 import org.tmatesoft.hg.core.SessionContext;
25 import org.tmatesoft.hg.repo.HgLookup.Authenticator;
26 import org.tmatesoft.hg.repo.HgLookup.RemoteDescriptor;
27 import org.tmatesoft.hg.repo.HgRemoteRepository; 25 import org.tmatesoft.hg.repo.HgRemoteRepository;
28 import org.tmatesoft.hg.util.Pair; 26 import org.tmatesoft.hg.util.Pair;
29 27
30 /** 28 /**
31 * Connector-aware descriptor of remote repository, i.e. descriptor that uses 29 * Connector-aware descriptor of remote repository, i.e. descriptor that uses
36 * 34 *
37 * 35 *
38 * @author Artem Tikhomirov 36 * @author Artem Tikhomirov
39 * @author TMate Software Ltd. 37 * @author TMate Software Ltd.
40 */ 38 */
41 public class RemoteConnectorDescriptor implements RemoteDescriptor { 39 public class RemoteConnectorDescriptor implements HgRemoteRepository.RemoteDescriptor {
42 40
43 private Map<String, Pair<ClassLoader, String>> connFactory; 41 private Map<String, Pair<ClassLoader, String>> connFactory;
44 private final URI uri; 42 private final URI uri;
45 43
46 public RemoteConnectorDescriptor(Map<String,Pair<ClassLoader, String>> scheme2connectorMap, URI uriRemote) { 44 public RemoteConnectorDescriptor(Map<String,Pair<ClassLoader, String>> scheme2connectorMap, URI uriRemote) {
52 uri = uriRemote; 50 uri = uriRemote;
53 } 51 }
54 52
55 public URI getURI() { 53 public URI getURI() {
56 return uri; 54 return uri;
57 }
58
59 public Authenticator getAuth() {
60 // TODO Auto-generated method stub
61 return null;
62 } 55 }
63 56
64 public Connector createConnector() throws HgBadArgumentException { 57 public Connector createConnector() throws HgBadArgumentException {
65 Pair<ClassLoader, String> connectorToBe = connFactory.get(uri.getScheme()); 58 Pair<ClassLoader, String> connectorToBe = connFactory.get(uri.getScheme());
66 if (connectorToBe == null || connectorToBe.second() == null) { 59 if (connectorToBe == null || connectorToBe.second() == null) {
93 knownConnectors.put("https", new Pair<ClassLoader, String>(cl, HttpConnector.class.getName())); 86 knownConnectors.put("https", new Pair<ClassLoader, String>(cl, HttpConnector.class.getName()));
94 // FIXME replace SshConnector.class with fqn string to avoid dependency from the trilead library in runtime 87 // FIXME replace SshConnector.class with fqn string to avoid dependency from the trilead library in runtime
95 knownConnectors.put("ssh", new Pair<ClassLoader, String>(cl, SshConnector.class.getName())); 88 knownConnectors.put("ssh", new Pair<ClassLoader, String>(cl, SshConnector.class.getName()));
96 } 89 }
97 90
98 public RemoteDescriptor get(SessionContext ctx, URI uri) { 91 public HgRemoteRepository.RemoteDescriptor get(SessionContext ctx, URI uri) {
99 if (knownConnectors.containsKey(uri.getScheme())) { 92 if (knownConnectors.containsKey(uri.getScheme())) {
100 return new RemoteConnectorDescriptor(knownConnectors, uri); 93 return new RemoteConnectorDescriptor(knownConnectors, uri);
101 } 94 }
102 return null; 95 return null;
103 } 96 }