org.eclipse.jgit.transport

## Class TransportProtocol

- java.lang.Object
- - org.eclipse.jgit.transport.TransportProtocol

    public abstract class TransportProtocol
    extends Object

Describes a way to connect to another Git repository.

Implementations of this class are typically immutable singletons held by static class members, for example:

     package com.example.my_transport;

     class MyTransport extends Transport {
            public static final TransportProtocol PROTO = new TransportProtocol() {
                    public String getName() {
                            return "My Protocol";
                    }
            };
     }

Applications may register additional protocols for use by JGit by calling `Transport.register(TransportProtocol)`. Because that API holds onto the protocol object by a WeakReference, applications must ensure their own ClassLoader retains the TransportProtocol for the life of the application. Using a static singleton pattern as above will ensure the protocol is valid so long as the ClassLoader that defines it remains valid.

Applications may automatically register additional protocols by filling in the names of their TransportProtocol defining classes using the services file `META-INF/services/org.eclipse.jgit.transport.Transport`. For each class name listed in the services file, any static fields of type `TransportProtocol` will be automatically registered. For the above example the string `com.example.my_transport.MyTransport` should be listed in the file, as that is the name of the class that defines the static PROTO singleton.

### Nested Class Summary

Nested Classes
`static class` `TransportProtocol.URIishField` Fields within a `URIish` that a transport uses.

### Constructor Summary

Constructors
Constructor and Description
`TransportProtocol()`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`boolean` `canHandle(URIish uri)` Determine if this protocol can handle a particular URI.
`boolean` `canHandle(URIish uri, Repository local, String remoteName)` Determine if this protocol can handle a particular URI.
`int` `getDefaultPort()`
`abstract String` `getName()`
`Set<TransportProtocol.URIishField>` `getOptionalFields()`
`Set<TransportProtocol.URIishField>` `getRequiredFields()`
`Set<String>` `getSchemes()`
`Transport` `open(URIish uri)` Open a new transport instance to the remote repository.
`abstract Transport` `open(URIish uri, Repository local, String remoteName)` Open a Transport instance to the other repository.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### TransportProtocol

    public TransportProtocol()

### Method Detail

#### getName

    public abstract String getName()

Returns:
  text name of the protocol suitable for display to a user.

#### getSchemes

    public Set<String> getSchemes()

Returns:
  immutable set of schemes supported by this protocol.

#### getRequiredFields

    public Set<TransportProtocol.URIishField> getRequiredFields()

Returns:
  immutable set of URIishFields that must be filled in.

#### getOptionalFields

    public Set<TransportProtocol.URIishField> getOptionalFields()

Returns:
  immutable set of URIishFields that may be filled in.

#### getDefaultPort

    public int getDefaultPort()

Returns:
  if a port is supported, the default port, else -1.

#### canHandle

    public boolean canHandle(URIish uri)

Determine if this protocol can handle a particular URI.

Implementations should try to avoid looking at the local filesystem, but may look at implementation specific configuration options in the remote block of `local.getConfig()` using `remoteName` if the name is non-null.

The default implementation of this method matches the scheme against `getSchemes()`, required fields against `getRequiredFields()`, and optional fields against `getOptionalFields()`, returning true only if all of the fields match the specification.

Parameters:
  `uri` - address of the Git repository; never null.
Returns:
  true if this protocol can handle this URI; false otherwise.

#### canHandle

    public boolean canHandle(URIish uri,
                             Repository local,
                             String remoteName)

Determine if this protocol can handle a particular URI.

Implementations should try to avoid looking at the local filesystem, but may look at implementation specific configuration options in the remote block of `local.getConfig()` using `remoteName` if the name is non-null.

The default implementation of this method matches the scheme against `getSchemes()`, required fields against `getRequiredFields()`, and optional fields against `getOptionalFields()`, returning true only if all of the fields match the specification.

Parameters:
  `uri` - address of the Git repository; never null.
  `local` - the local repository that will communicate with the other Git repository. May be null if the caller is only asking about a specific URI and does not have a local Repository.
  `remoteName` - name of the remote, if the remote as configured in `local`; otherwise null.
Returns:
  true if this protocol can handle this URI; false otherwise.

#### open

    public abstract Transport open(URIish uri,
                                   Repository local,
                                   String remoteName)
                            throws NotSupportedException,
                                   TransportException

Open a Transport instance to the other repository.

Implementations should avoid making remote connections until an operation on the returned Transport is invoked, however they may fail fast here if they know a connection is impossible, such as when using the local filesystem and the target path does not exist.

Implementations may access implementation-specific configuration options within `local.getConfig()` using the remote block named by the `remoteName`, if the name is non-null.

Parameters:
  `uri` - address of the Git repository.
  `local` - the local repository that will communicate with the other Git repository.
  `remoteName` - name of the remote, if the remote as configured in `local`; otherwise null.
Returns:
  the transport.
Throws:
  `NotSupportedException` - this protocol does not support the URI.
  `TransportException` - the transport cannot open this URI.

#### open

    public Transport open(URIish uri)
                   throws NotSupportedException,
                          TransportException

Open a new transport instance to the remote repository. Use default configuration instead of reading from configuration files.

Parameters:
  `uri` -
Returns:
  new Transport
Throws:
  `NotSupportedException`
  `TransportException`