Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.ldap
Class LdapDirectoryImpl

java.lang.Object
  extended by net.java.sip.communicator.service.ldap.event.DefaultLdapEventManager
      extended by net.java.sip.communicator.impl.ldap.LdapDirectoryImpl
All Implemented Interfaces:
Comparable<LdapDirectory>, EventListener, LdapEventManager, LdapListener, LdapConstants, LdapDirectory

public class LdapDirectoryImpl
extends DefaultLdapEventManager
implements LdapDirectory, LdapListener, LdapConstants

An LdapDirectory stores settings for one directory server and performs ldap operations (search)

Author:
Sebastien Mazy

Nested Class Summary
 class LdapDirectoryImpl.LdapQueryCancelledException
          A custom exception used internally by LdapDirectoryImpl to indicate that a query was cancelled
 
Nested classes/interfaces inherited from interface net.java.sip.communicator.service.ldap.LdapConstants
LdapConstants.Auth, LdapConstants.Encryption, LdapConstants.Scope
 
Field Summary
 
Fields inherited from class net.java.sip.communicator.service.ldap.event.DefaultLdapEventManager
ldapListeners
 
Fields inherited from interface net.java.sip.communicator.service.ldap.LdapConstants
LDAP_CONNECT_TIMEOUT, LDAP_READ_TIMEOUT
 
Constructor Summary
LdapDirectoryImpl(LdapDirectorySettings settings)
          The contructor for this class.
 
Method Summary
 int compareTo(LdapDirectory server)
          An LdapDirectory is comparable in order to display LdapDirectory(s) in alphabetic order in the UI.
 boolean equals(Object anObject)
          Two LdapDirectory(s) with the same displayed name should not exist in the same LdapDirectorySet, thus this function
(package private)  byte[] fetchPhotoForPerson(String dn)
          Tries to fetch the photo of the person with the given distinguished name in the directory
 LdapDirectorySettings getSettings()
          Returns an LdapDirectorySettings object containing a copy of the settings of this server
 int hashCode()
          We override the equals method so we also do for hashCode to keep consistent behavior
 boolean isEnabled()
          Returns the state of the enabled marker.
 void ldapEventReceived(LdapEvent event)
          Required by LdapListener.
 void overrideAttributesSearch(String attribute, List<String> names)
          Overrides attributes name for searching for a specific type (i.e mail, homePhone, ...).
 Collection<String> searchChildren(String dn)
          search the children nodes of the given dn
 void searchPerson(LdapQuery query, LdapListener caller, LdapSearchSettings searchSettings)
          Searches a person in the directory, based on a search string.
 void setEnabled(boolean enabled)
          Sets the state of the enabled marker Required by LdapDirectory interface.
 String toString()
          Turns LdapDirectoryImpl into a printable object Used for debugging purposes
 
Methods inherited from class net.java.sip.communicator.service.ldap.event.DefaultLdapEventManager
addLdapListener, fireLdapEvent, fireLdapEvent, removeLdapListener
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.java.sip.communicator.service.ldap.LdapDirectory
addLdapListener
 
Methods inherited from interface net.java.sip.communicator.service.ldap.event.LdapEventManager
fireLdapEvent, fireLdapEvent, removeLdapListener
 

Constructor Detail

LdapDirectoryImpl

public LdapDirectoryImpl(LdapDirectorySettings settings)
The contructor for this class. Since this element is immutable (otherwise it would be a real pain to use with a Set), it takes all the settings we could need to store This constructor will not modify the settings or save a reference to it, but may save a clone.

Parameters:
settings - settings for this new server
See Also:
LdapDirectorySettings
Method Detail

isEnabled

public boolean isEnabled()
Returns the state of the enabled marker. Required by LdapDirectory interface.

Specified by:
isEnabled in interface LdapDirectory
Returns:
the state of the enabled marker
See Also:
LdapDirectory.isEnabled()

setEnabled

public void setEnabled(boolean enabled)
Sets the state of the enabled marker Required by LdapDirectory interface.

Specified by:
setEnabled in interface LdapDirectory
Parameters:
enabled - whether the server is marked as enabled
See Also:
LdapDirectory.setEnabled(boolean)

getSettings

public LdapDirectorySettings getSettings()
Returns an LdapDirectorySettings object containing a copy of the settings of this server

Specified by:
getSettings in interface LdapDirectory
Returns:
a copy of this server settings
See Also:
LdapDirectorySettings, LdapDirectory.getSettings()

searchPerson

public void searchPerson(LdapQuery query,
                         LdapListener caller,
                         LdapSearchSettings searchSettings)
Searches a person in the directory, based on a search string. Since that method might take time to process, it should be implemented asynchronously and send the results (LdapPersonFound) with an LdapEvent to its listeners

Specified by:
searchPerson in interface LdapDirectory
Parameters:
query - assumed name (can be partial) of the person searched e.g. "john", "doe", "john doe"
caller - the LdapListener which called the method and will receive results.
searchSettings - custom settings for this search, null if you want to stick with the defaults
See Also:
LdapDirectory.searchPerson(net.java.sip.communicator.service.ldap.LdapQuery, net.java.sip.communicator.service.ldap.event.LdapListener, net.java.sip.communicator.service.ldap.LdapSearchSettings), LdapPersonFound, LdapEvent

toString

public String toString()
Turns LdapDirectoryImpl into a printable object Used for debugging purposes

Overrides:
toString in class Object
Returns:
a printable string

compareTo

public int compareTo(LdapDirectory server)
An LdapDirectory is comparable in order to display LdapDirectory(s) in alphabetic order in the UI.

Specified by:
compareTo in interface Comparable<LdapDirectory>
See Also:
Comparable

equals

public boolean equals(Object anObject)
Two LdapDirectory(s) with the same displayed name should not exist in the same LdapDirectorySet, thus this function

Overrides:
equals in class Object

hashCode

public int hashCode()
We override the equals method so we also do for hashCode to keep consistent behavior

Overrides:
hashCode in class Object

searchChildren

public Collection<String> searchChildren(String dn)
search the children nodes of the given dn

Specified by:
searchChildren in interface LdapDirectory
Parameters:
dn - the distinguished name of the node to search for children
Returns:
list of childrens
See Also:
LdapDirectory.searchChildren(java.lang.String)

fetchPhotoForPerson

byte[] fetchPhotoForPerson(String dn)
Tries to fetch the photo of the person with the given distinguished name in the directory

Parameters:
dn - distinguished name of the person to fetch the photo
Returns:
the bytes of the photo

ldapEventReceived

public void ldapEventReceived(LdapEvent event)
Required by LdapListener. Dispatches event received from LdapDirectory-s to real search initiators (the search dialog for example)

Specified by:
ldapEventReceived in interface LdapListener
Parameters:
event - An LdapEvent probably sent by an LdapDirectory

overrideAttributesSearch

public void overrideAttributesSearch(String attribute,
                                     List<String> names)
Overrides attributes name for searching for a specific type (i.e mail, homePhone, ...).

Specified by:
overrideAttributesSearch in interface LdapDirectory
Parameters:
attribute - name
names - list of attributes name

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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