Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.protocol.ssh
Class ContactSSHImpl

java.lang.Object
  extended by net.java.sip.communicator.impl.protocol.ssh.ContactSSHImpl
All Implemented Interfaces:
ContactSSH, Contact

public class ContactSSHImpl
extends Object
implements ContactSSH

A Contact of SSH Type

Author:
Shobhit Jindal

Field Summary
 
Fields inherited from interface net.java.sip.communicator.impl.protocol.ssh.ContactSSH
CONVERSATION_MESSAGE_RECEIVED, SYSTEM_MESSAGE_RECEIVED
 
Constructor Summary
ContactSSHImpl(String id, ProtocolProviderServiceSSHImpl parentProvider)
          Creates an instance of a meta contact with the specified string used as a name and identifier.
 
Method Summary
 void closeShellIO()
          Closes the readers and writer associated with shell of this contact
 boolean equals(Object obj)
          Indicates whether some other object is "equal to" this one which in terms of contacts translates to having equal ids.
 String getAddress()
          Returns a String that can be used for identifying the contact.
 String getDisplayName()
          Returns a String that could be used by any user interacting modules for referring to this contact.
 OperationSetFileTransfer getFileTransferOperationSet()
          Returns the File Transfer operation set that this contact belongs to.
 String getHostName()
          Returns the Hostname associated with this contact
 byte[] getImage()
          Returns a byte array containing an image (most often a photo or an avatar) that the contact uses as a representation.
 com.jcraft.jsch.JSch getJSch()
          Returns the JSch Stack identified associated with this contact
 int getMessageType()
          Return the type of message received from remote server
 OperationSetBasicInstantMessaging getParentBasicInstantMessagingOperationSet()
          Returns the BasicInstant Messaging operation set that this contact belongs to.
 ContactGroup getParentContactGroup()
          Returns the group that contains this contact.
 OperationSetPersistentPresence getParentPresenceOperationSet()
          Returns the persistent presence operation set that this contact belongs to.
 String getPassword()
          Returns the password associated with SSH Channel of this contact
 String getPersistentData()
          Returns persistent data of the contact.
 PresenceStatus getPresenceStatus()
          Returns the status of the contact.
 ProtocolProviderService getProtocolProvider()
          Returns a reference to the protocol provider that created the contact.
 com.jcraft.jsch.Channel getShellChannel()
          Returns the SSH Shell Channel associated with this contact
 InputStream getShellInputStream()
          Returns the Input Stream associated with SSH Channel of this contact
 OutputStream getShellOutputStream()
          Returns the Output Stream associated with SSH Channel of this contact
 InputStreamReader getShellReader()
          Returns the BufferedReader associated with SSH Channel of this contact
 PrintWriter getShellWriter()
          Returns the PrintWriter associated with SSH Channel of this contact
 SSHContactInfo getSSHConfigurationForm()
          Returns the SSHContactInfo associated with this contact
 com.jcraft.jsch.Session getSSHSession()
          Returns the SSH Session associated with this contact
 String getStatusMessage()
          Return the current status message of this contact.
 String getUserName()
          Returns the userName associated with SSH Channel of this contact
 void initializeShellIO(InputStream shellInputStream, OutputStream shellOutputStream)
          Initializes the reader and writers associated with shell of this contact
 boolean isCommandSent()
          Returns true if a command has been sent whos reply was not received yet false otherwise
 boolean isConnectionInProgress()
          Determines whether a connection to a remote server is already underway
 boolean isLocal()
          Determines whether or not this contact represents our own identity.
 boolean isPersistent()
          Determines whether or not this contact is being stored by the server.
 boolean isResolved()
          Determines whether or not this contact has been resolved against the server.
 void savePersistentDetails()
          Saves the details of contact in persistentData seperated by separator Passowrd is saved unsecurely using Base64 encoding
 void sendLine(String message)
          Sends a message a line to remote machine via the Shell Writer
 void setCommandSent(boolean commandSent)
          Set the state of commandSent variable which determines whether a reply to a command sent is awaited
 void setConnectionInProgress(boolean isConnectionInProgress)
          Sets the status of connection attempt to remote server This method is synchronized
 void setJSch(com.jcraft.jsch.JSch jsch)
          Sets the JSch Stack identified associated with this contact
 void setMessageType(int messageType)
          Sets the type of message received from remote server
 void setParentGroup(ContactGroupSSHImpl newParentGroup)
          This method is only called when the contact is added to a new ContactGroupSSHImpl by the ContactGroupSSHImpl itself.
 void setPassword(String password)
          Sets the Password associated with this contact
 void setPersistent(boolean isPersistent)
          Specifies whether or not this contact is being stored by the server.
 void setPersistentData(String persistentData)
          Stores persistent data in fields of the contact seperated by separator.
 void setPresenceStatus(PresenceStatus sshPresenceStatus)
          Sets sshPresenceStatus as the PresenceStatus that this contact is currently in.
 void setResolved(boolean resolved)
          Makes the contact resolved or unresolved.
 void setShellChannel(com.jcraft.jsch.Channel sshShellChannel)
          Sets the SSH Shell channel associated with this contact
 void setSSHSession(com.jcraft.jsch.Session sshSession)
          Sets the SSH Session associated with this contact
 void startTimerTask()
          Starts the timer and its task to periodically update the status of remote machine
 void stopTimerTask()
          Stops the timer and its task to stop updating the status of remote machine
 String toString()
          Returns a string representation of this contact, containing most of its representative details.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ContactSSHImpl

public ContactSSHImpl(String id,
                      ProtocolProviderServiceSSHImpl parentProvider)
Creates an instance of a meta contact with the specified string used as a name and identifier.

Parameters:
id - the identifier of this contact (also used as a name).
parentProvider - the provider that created us.
Method Detail

initializeShellIO

public void initializeShellIO(InputStream shellInputStream,
                              OutputStream shellOutputStream)
Initializes the reader and writers associated with shell of this contact

Specified by:
initializeShellIO in interface ContactSSH
Parameters:
shellInputStream - The InputStream of stack
shellOutputStream - The OutputStream of stack

closeShellIO

public void closeShellIO()
Closes the readers and writer associated with shell of this contact

Specified by:
closeShellIO in interface ContactSSH

sendLine

public void sendLine(String message)
              throws IOException
Sends a message a line to remote machine via the Shell Writer

Specified by:
sendLine in interface ContactSSH
Parameters:
message - to be sent
Throws:
IOException - if message failed to be sent

startTimerTask

public void startTimerTask()
Starts the timer and its task to periodically update the status of remote machine

Specified by:
startTimerTask in interface ContactSSH

stopTimerTask

public void stopTimerTask()
Stops the timer and its task to stop updating the status of remote machine

Specified by:
stopTimerTask in interface ContactSSH

savePersistentDetails

public void savePersistentDetails()
Saves the details of contact in persistentData seperated by separator Passowrd is saved unsecurely using Base64 encoding

Specified by:
savePersistentDetails in interface ContactSSH

setPersistentData

public void setPersistentData(String persistentData)
Stores persistent data in fields of the contact seperated by separator.

Specified by:
setPersistentData in interface ContactSSH
Parameters:
persistentData - of the contact

isConnectionInProgress

public boolean isConnectionInProgress()
Determines whether a connection to a remote server is already underway

Specified by:
isConnectionInProgress in interface ContactSSH
Returns:
isConnectionInProgress

setConnectionInProgress

public void setConnectionInProgress(boolean isConnectionInProgress)
Sets the status of connection attempt to remote server This method is synchronized

Specified by:
setConnectionInProgress in interface ContactSSH
Parameters:
isConnectionInProgress -

getSSHConfigurationForm

public SSHContactInfo getSSHConfigurationForm()
Returns the SSHContactInfo associated with this contact

Specified by:
getSSHConfigurationForm in interface ContactSSH
Returns:
sshConfigurationForm

getJSch

public com.jcraft.jsch.JSch getJSch()
Returns the JSch Stack identified associated with this contact

Specified by:
getJSch in interface ContactSSH
Returns:
jsch

setJSch

public void setJSch(com.jcraft.jsch.JSch jsch)
Sets the JSch Stack identified associated with this contact

Specified by:
setJSch in interface ContactSSH
Parameters:
jsch - to be associated

setParentGroup

public void setParentGroup(ContactGroupSSHImpl newParentGroup)
This method is only called when the contact is added to a new ContactGroupSSHImpl by the ContactGroupSSHImpl itself.

Specified by:
setParentGroup in interface ContactSSH
Parameters:
newParentGroup - the ContactGroupSSHImpl that is now parent of this ContactSSHImpl

getHostName

public String getHostName()
Returns the Hostname associated with this contact

Specified by:
getHostName in interface ContactSSH
Returns:
hostName

getAddress

public String getAddress()
Returns a String that can be used for identifying the contact.

Specified by:
getAddress in interface Contact
Returns:
a String id representing and uniquely identifying the contact.

getDisplayName

public String getDisplayName()
Returns a String that could be used by any user interacting modules for referring to this contact.

Specified by:
getDisplayName in interface Contact
Returns:
a String that can be used for referring to this contact when interacting with the user.

getImage

public byte[] getImage()
Returns a byte array containing an image (most often a photo or an avatar) that the contact uses as a representation.

Specified by:
getImage in interface Contact
Returns:
byte[] an image representing the contact.

isCommandSent

public boolean isCommandSent()
Returns true if a command has been sent whos reply was not received yet false otherwise

Specified by:
isCommandSent in interface ContactSSH
Returns:
commandSent

setCommandSent

public void setCommandSent(boolean commandSent)
Set the state of commandSent variable which determines whether a reply to a command sent is awaited

Specified by:
setCommandSent in interface ContactSSH

getMessageType

public int getMessageType()
Return the type of message received from remote server

Specified by:
getMessageType in interface ContactSSH
Returns:
messageType

setMessageType

public void setMessageType(int messageType)
Sets the type of message received from remote server

Specified by:
setMessageType in interface ContactSSH
Parameters:
messageType -

getPresenceStatus

public PresenceStatus getPresenceStatus()
Returns the status of the contact.

Specified by:
getPresenceStatus in interface Contact
Returns:
presenceStatus

setPresenceStatus

public void setPresenceStatus(PresenceStatus sshPresenceStatus)
Sets sshPresenceStatus as the PresenceStatus that this contact is currently in.

Specified by:
setPresenceStatus in interface ContactSSH
Parameters:
sshPresenceStatus - the SSHPresenceStatus currently valid for this contact.

getProtocolProvider

public ProtocolProviderService getProtocolProvider()
Returns a reference to the protocol provider that created the contact.

Specified by:
getProtocolProvider in interface Contact
Returns:
a refererence to an instance of the ProtocolProviderService

isLocal

public boolean isLocal()
Determines whether or not this contact represents our own identity.

Returns:
true

getParentContactGroup

public ContactGroup getParentContactGroup()
Returns the group that contains this contact.

Specified by:
getParentContactGroup in interface Contact
Returns:
a reference to the ContactGroupSSHImpl that contains this contact.

toString

public String toString()
Returns a string representation of this contact, containing most of its representative details.

Overrides:
toString in class Object
Returns:
a string representation of this contact.

isPersistent

public boolean isPersistent()
Determines whether or not this contact is being stored by the server. Non persistent contacts are common in the case of simple, non-persistent presence operation sets. They could however also be seen in persistent presence operation sets when for example we have received an event from someone not on our contact list. Non persistent contacts are volatile even when coming from a persistent presence op. set. They would only exist until the application is closed and will not be there next time it is loaded.

Specified by:
isPersistent in interface Contact
Returns:
true if the contact is persistent and false otherwise.

setPersistent

public void setPersistent(boolean isPersistent)
Specifies whether or not this contact is being stored by the server. Non persistent contacts are common in the case of simple, non-persistent presence operation sets. They could however also be seen in persistent presence operation sets when for example we have received an event from someone not on our contact list. Non persistent contacts are volatile even when coming from a persistent presence op. set. They would only exist until the application is closed and will not be there next time it is loaded.

Specified by:
setPersistent in interface ContactSSH
Parameters:
isPersistent - true if the contact is persistent and false otherwise.

getPersistentData

public String getPersistentData()
Returns persistent data of the contact.

Specified by:
getPersistentData in interface Contact
Returns:
persistentData of the contact

isResolved

public boolean isResolved()
Determines whether or not this contact has been resolved against the server. Unresolved contacts are used when initially loading a contact list that has been stored in a local file until the presence operation set has managed to retrieve all the contact list from the server and has properly mapped contacts to their on-line buddies.

Specified by:
isResolved in interface Contact
Returns:
true if the contact has been resolved (mapped against a buddy) and false otherwise.

setResolved

public void setResolved(boolean resolved)
Makes the contact resolved or unresolved.

Specified by:
setResolved in interface ContactSSH
Parameters:
resolved - true to make the contact resolved; false to make it unresolved

equals

public boolean equals(Object obj)
Indicates whether some other object is "equal to" this one which in terms of contacts translates to having equal ids. The resolved status of the contacts deliberately ignored so that contacts would be declared equal even if it differs.

Overrides:
equals in class Object
Parameters:
obj - the reference object with which to compare.
Returns:
true if this contact has the same id as that of the obj argument.

getParentPresenceOperationSet

public OperationSetPersistentPresence getParentPresenceOperationSet()
Returns the persistent presence operation set that this contact belongs to.

Specified by:
getParentPresenceOperationSet in interface ContactSSH
Returns:
the OperationSetPersistentPresenceSSHImpl that this contact belongs to.

getParentBasicInstantMessagingOperationSet

public OperationSetBasicInstantMessaging getParentBasicInstantMessagingOperationSet()
Returns the BasicInstant Messaging operation set that this contact belongs to.

Specified by:
getParentBasicInstantMessagingOperationSet in interface ContactSSH
Returns:
the OperationSetBasicInstantMessagingSSHImpl that this contact belongs to.

getFileTransferOperationSet

public OperationSetFileTransfer getFileTransferOperationSet()
Returns the File Transfer operation set that this contact belongs to.

Specified by:
getFileTransferOperationSet in interface ContactSSH
Returns:
the OperationSetFileTransferSSHImpl that this contact belongs to.

getSSHSession

public com.jcraft.jsch.Session getSSHSession()
Returns the SSH Session associated with this contact

Specified by:
getSSHSession in interface ContactSSH
Returns:
sshSession

setSSHSession

public void setSSHSession(com.jcraft.jsch.Session sshSession)
Sets the SSH Session associated with this contact

Specified by:
setSSHSession in interface ContactSSH
Parameters:
sshSession - the newly created SSH Session to be associated

getShellChannel

public com.jcraft.jsch.Channel getShellChannel()
Returns the SSH Shell Channel associated with this contact

Specified by:
getShellChannel in interface ContactSSH
Returns:
sshShellChannel

setShellChannel

public void setShellChannel(com.jcraft.jsch.Channel sshShellChannel)
Sets the SSH Shell channel associated with this contact

Specified by:
setShellChannel in interface ContactSSH
Parameters:
sshShellChannel - to be associated with SSH Session of this contact

getShellInputStream

public InputStream getShellInputStream()
Returns the Input Stream associated with SSH Channel of this contact

Specified by:
getShellInputStream in interface ContactSSH
Returns:
shellInputStream associated with SSH Channel of this contact

getShellOutputStream

public OutputStream getShellOutputStream()
Returns the Output Stream associated with SSH Channel of this contact

Specified by:
getShellOutputStream in interface ContactSSH
Returns:
shellOutputStream associated with SSH Channel of this contact

getShellReader

public InputStreamReader getShellReader()
Returns the BufferedReader associated with SSH Channel of this contact

Specified by:
getShellReader in interface ContactSSH
Returns:
shellReader associated with SSH Channel of this contact

getShellWriter

public PrintWriter getShellWriter()
Returns the PrintWriter associated with SSH Channel of this contact

Specified by:
getShellWriter in interface ContactSSH
Returns:
shellWriter associated with SSH Channel of this contact

getUserName

public String getUserName()
Returns the userName associated with SSH Channel of this contact

Specified by:
getUserName in interface ContactSSH
Returns:
userName associated with SSH Channel of this contact

getPassword

public String getPassword()
Returns the password associated with SSH Channel of this contact

Specified by:
getPassword in interface ContactSSH
Returns:
password associated with SSH Channel of this contact

setPassword

public void setPassword(String password)
Sets the Password associated with this contact

Specified by:
setPassword in interface ContactSSH
Parameters:
password -

getStatusMessage

public String getStatusMessage()
Return the current status message of this contact.

Specified by:
getStatusMessage in interface Contact
Returns:
the current status message

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.