* @param detailClass one of the detail classes defined in the * ServerStoredDetails class, indicating the kind of details we're * interested in. *
* @return a java.util.Iterator over all details that are instances or
* descendants of the specified class.
*/
public
* @param detailClass one of the detail classes defined in the
* ServerStoredDetails class, indicating the kind of details we're
* interested in.
*
* @return a java.util.Iterator over all details of specified class.
*/
public Iterator
* @return a java.util.Iterator over all details currently set our account.
*/
public Iterator
* @return a java.util.Iterator over all detail classes supported by the
* implementation.
*/
public Iterator
* @param detailClass the class the support for which we'd like to
* determine.
*
* @return true if the underlying implementation supports setting details of
* this type and false otherwise.
*/
public boolean isDetailClassSupported(
Class extends GenericDetail> detailClass)
{
return supportedTypes.contains(detailClass);
}
/**
* The method returns the number of instances supported for a particular
* detail type. Some protocols offer storing multiple values for a
* particular detail type. Spoken languages are a good example.
* @param detailClass the class whose max instance number we'd like to find
* out.
*
* @return int the maximum number of detail instances.
*/
public int getMaxDetailInstances(Class extends GenericDetail> detailClass)
{
return 1;
}
/**
* Adds the specified detail to the list of details ready to be saved online
* for this account. If such a detail already exists its max instance number
* is consulted and if it allows it - a second instance is added or otherwise
* and illegal argument exception is thrown. An IllegalArgumentException is
* also thrown in case the class of the specified detail is not supported by
* the underlying implementation, i.e. its class name was not returned by the
* getSupportedDetailTypes() method.
*
* @param detail the detail that we'd like registered on the server.
*
* @throws IllegalArgumentException if such a detail already exists and its
* max instances number has been attained or if the underlying
* implementation does not support setting details of the corresponding
* class.
* @throws java.lang.ArrayIndexOutOfBoundsException if the number of
* instances currently registered by the application is already equal to the
* maximum number of supported instances (@see getMaxDetailInstances())
*/
public void addDetail(ServerStoredDetails.GenericDetail detail)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
{
if (!isDetailClassSupported(detail.getClass())) {
throw new IllegalArgumentException(
"implementation does not support such details " +
detail.getClass());
}
Iterator
* @param detail the detail to remove
* @return true if the specified detail existed and was successfully removed
* and false otherwise.
*/
public boolean removeDetail(ServerStoredDetails.GenericDetail detail)
{
return infoRetreiver.getCachedContactDetails(uin).remove(detail);
}
/**
* Replaces the currentDetailValue detail with newDetailValue and returns
* true if the operation was a success or false if currentDetailValue did
* not previously exist (in this case an additional call to addDetail is
* required).
*
* @param currentDetailValue the detail value we'd like to replace.
* @param newDetailValue the value of the detail that we'd like to replace
* currentDetailValue with.
* @return true if the operation was a success or false if
* currentDetailValue did not previously exist (in this case an additional
* call to addDetail is required).
* @throws ClassCastException if newDetailValue is not an instance of the
* same class as currentDetailValue.
*/
public boolean replaceDetail(
ServerStoredDetails.GenericDetail currentDetailValue,
ServerStoredDetails.GenericDetail newDetailValue)
throws ClassCastException
{
if (!newDetailValue.getClass().equals(currentDetailValue.getClass()))
{
throw new ClassCastException(
"New value to be replaced is not as the current one");
}
// if values are the same no change
if (currentDetailValue.equals(newDetailValue))
{
return true;
}
boolean isFound = false;
Iterator
* @throws OperationFailedException with code Network Failure if putting the
* new values back online has failed.
*/
public void save() throws OperationFailedException
{
assertConnected();
List
* @param detailClass the class whose edition we'd like to determine if it's
* possible
* @return true if the underlying implementation supports edition of this
* type of detail and false otherwise.
*/
public boolean isDetailClassEditable(
Class extends GenericDetail> detailClass)
{
if (isDetailClassSupported(detailClass)) {
return true;
}
return false;
}
/**
* Utility method throwing an exception if the jabber stack is not properly
* initialized.
* @throws java.lang.IllegalStateException if the underlying jabber stack is
* not registered and initialized.
*/
private void assertConnected() throws IllegalStateException
{
if (jabberProvider == null)
throw new IllegalStateException(
"The jabber provider must be non-null and signed on "
+"before being able to communicate.");
if (!jabberProvider.isRegistered())
throw new IllegalStateException(
"The jabber provider must be signed on before "
+"being able to communicate.");
}
}