Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6417cffb08288c6b60156372e92dd514f6f01793 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*******************************************************************************
 * Copyright (c) 2007 JCraft,Inc. and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Atsuhiko Yamanaka, JCraft,Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.jsch.internal.core;

import org.eclipse.core.runtime.*;
import org.eclipse.jsch.core.IJSchLocation;
import org.eclipse.jsch.core.IPasswordStore;

/**
 * This class implements IJSchLocation interface.
 * @since 1.1
 */
public class JSchLocation extends PlatformObject implements IJSchLocation{
  /**
   * port value which indicates to a connection method to use the default port
   */
  private static int DEFAULT_PORT=22;

  private String user;
  private String password;
  private String host;
  private int port=DEFAULT_PORT;
  private boolean userFixed=true;
  private String comment=null;
  private IPasswordStore passwordStore=null;

  /*
   * Create a JSchLocation from its composite parts.
   */
  public JSchLocation(String user, String host, int port){
    this.user=user;
    this.host=host;
    this.port=port;
  }

  public JSchLocation(String user, String host){
    this(user, host, DEFAULT_PORT);
  }

  /**
   * @see IJSchLocation#getHost()
   */
  public String getHost(){
    return host;
  }

  /**
   * @see IJSchLocation#getPort()
   */
  public int getPort(){
    return port;
  }

  /*
   * @see IJSchLocation#setUsername(String)
   */
  public void setUsername(String user){
    if(userFixed)
      throw new UnsupportedOperationException();
    this.user=user;
  }

  /**
   * @see IJSchLocation#getUsername()
   */
  public String getUsername(){
    return user==null ? "" : user; //$NON-NLS-1$
  }

  /**
   * @see IJSchLocation#setPassword(String)
   */
  public void setPassword(String password){
    if(password!=null)
      this.password=password;
  }

  /**
   * @see IJSchLocation#getPassword()
   */
  public String getPassword(){
    return password;
  }

  /**
   * @see IJSchLocation#setComment(String comment)
   */
  public void setComment(String comment){
    this.comment=comment;
  }

  /**
   * @see IJSchLocation#getComment()
   */
  public String getComment(){
    return comment;
  }

  /**
   * @see IJSchLocation#setPasswordStore(IPasswordStore store)
   */
  public void setPasswordStore(IPasswordStore store){
    this.passwordStore=store;
  }

  /**
   * @see IJSchLocation#getPasswordStore()
   */
  public IPasswordStore getPasswordStore(){
    return passwordStore;
  }

  /**
   * Implementation of inherited toString()
   */
  public String toString(){
    return user
        +"@"+host+((port==DEFAULT_PORT) ? "" : ":"+(Integer.valueOf(port).toString())); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
  }
}

Back to the top