de.uplanet.lucy.server.newsagent
Class NewsAgent

java.lang.Object
  extended by de.uplanet.lucy.server.newsagent.NewsAgent

@Scriptable
public final class NewsAgent
extends java.lang.Object

Handles messages that exist beyond application scope.

Users MUST call done() when finished using the agent to ensure that all resources such as SQL statements are properly closed and freed.

Version:
$Revision: 73198 $

Method Summary
static NewsAgent createInstance(de.uplanet.jdbc.JdbcConnection p_conn)
          Factory method for creating a news agent.
 Message createNewMessage()
          Create a new message.
 Message createNewMessage(java.lang.String p_strMessageId)
          Create a new message with the given message identifier.
 boolean deleteMessage(java.lang.String p_strMessageId)
          Delete the specified message.
 boolean deleteMessagesForApplication(java.lang.String p_strAppGuid)
          Delete all messages that belong to the specified application GUID.
 boolean deleteMessagesForUser(java.lang.String p_strUserId)
          Delete all messages that are addressed to the specified user.
 void done()
          Deprecated. This method must not be called anymore.
 java.lang.String dump()
          Dump this object to a String.
 int filter(IFilter p_filter)
          Filter the messages that have already being loaded.
 Message get(int p_iIndex)
          Get the message at the specified index out of the filtered collection.
 void getRichSiteSummary(java.io.Writer p_writer, java.lang.String p_strResourceUrl, java.lang.String p_strEncodingDecl, int p_iMaxCount)
          Create a Rich Site Summary containing all news for which the anonymous user is a recipient.
 java.lang.String getTarget(java.lang.String p_strAppGuid)
          Get the registered target GUID for an application.
 int load(IFilter p_filter, IOrder p_order, int p_iMaxCount)
          Load messages from the database.
 Message loadMessage(java.lang.String p_strMessageId)
          Load the specified message from the database.
 void markDeleted(java.lang.String p_strMessageId, java.lang.String p_strUserId)
          Mark a message as deleted for the specified user.
 void markRead(java.lang.String p_strMessageId, java.lang.String p_strUserId)
          Mark a message as read for the specified user.
 boolean registerTarget(java.lang.String p_strAppGuid, java.lang.String p_strTargetGuid)
          Register or re-register a link target for an application.
 boolean save(Message p_message)
          Save the message to the database.
 int size()
          Get the number of messages in the filtered collection.
 void sort(IOrder p_order)
          Sort the messages in the filtered messages collection.
 void unregisterTarget(java.lang.String p_strAppGuid)
          Unregister the link target for the given application.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createInstance

public static NewsAgent createInstance(de.uplanet.jdbc.JdbcConnection p_conn)
Factory method for creating a news agent.

Returns:
The newly generated news agent.

done

@Deprecated
public void done()
Deprecated. This method must not be called anymore.


createNewMessage

public Message createNewMessage()
Create a new message.

Returns:
The newly created message.

createNewMessage

public Message createNewMessage(java.lang.String p_strMessageId)
Create a new message with the given message identifier.

The newly created message is not inserted into the messages collection.

Returns:
The newly created message.

markRead

public void markRead(java.lang.String p_strMessageId,
                     java.lang.String p_strUserId)
Mark a message as read for the specified user.

Either of the parameters may be null, however the method does nothing in these cases.

Parameters:
p_strMessageId - The GUID of the message.
p_strUserId - The GUID of the user.

markDeleted

public void markDeleted(java.lang.String p_strMessageId,
                        java.lang.String p_strUserId)
Mark a message as deleted for the specified user.

Either of the parameters may be null, however the method does nothing in these cases.

Parameters:
p_strMessageId - The GUID of the message.
p_strUserId - The GUID of the user.

load

public int load(IFilter p_filter,
                IOrder p_order,
                int p_iMaxCount)
Load messages from the database.

Parameters:
p_filter - The filter to be applied when loading.
p_order - The order in which the messages should be loaded.
p_iMaxCount - The maximum number of messages to be loaded or -1 if all messages should be loaded.
Returns:
The number of messages that where actually loaded.

loadMessage

public Message loadMessage(java.lang.String p_strMessageId)
Load the specified message from the database.

The internal state of the news agent is not affected by calling this method. In particular, the content of the messages collection and of the filtered messages collection is not changed.

Parameters:
p_strMessageId - The GUID of the message to be loaded.
Returns:
The message or null if the message could not be found.

save

public boolean save(Message p_message)
Save the message to the database.

Parameters:
p_message - The message to save.
Returns:
true if the message was saved, false otherwise.
Throws:
java.sql.SQLException
de.uplanet.jdbc.sqlhelper.SqlHelperException
java.io.IOException
To Do:
Implement recipient update.

registerTarget

public boolean registerTarget(java.lang.String p_strAppGuid,
                              java.lang.String p_strTargetGuid)
Register or re-register a link target for an application.

Parameters:
p_strAppGuid - The application for which the target should be registered.
p_strTargetGuid - The identifier of the link target.

unregisterTarget

public void unregisterTarget(java.lang.String p_strAppGuid)
Unregister the link target for the given application.

Call this method whenever an application is deleted.

Parameters:
p_strAppGuid - The GUID of the application.

getTarget

public java.lang.String getTarget(java.lang.String p_strAppGuid)
Get the registered target GUID for an application.

Parameters:
p_strAppGuid - The application GUID.
Returns:
The registered target identifier.

deleteMessage

public boolean deleteMessage(java.lang.String p_strMessageId)
Delete the specified message.

Parameters:
p_strMessageId - The GUID of the message that should be deleted.
Returns:
true if the message could be deleted, false otherwise.

deleteMessagesForApplication

public boolean deleteMessagesForApplication(java.lang.String p_strAppGuid)
Delete all messages that belong to the specified application GUID.

Parameters:
p_strAppGuid - The application GUID for which the messages should be deleted.
Returns:
true if the the messages could be deleted, false otherwise.

deleteMessagesForUser

public boolean deleteMessagesForUser(java.lang.String p_strUserId)
Delete all messages that are addressed to the specified user.

Parameters:
p_strUserId - The GUID of the user for whom the messages should be deleted.
Returns:
true if the the messages could be deleted, false otherwise.
To Do:
Implement this method.

sort

public void sort(IOrder p_order)
Sort the messages in the filtered messages collection.

Parameters:
p_order - The sorting criterion.

filter

public int filter(IFilter p_filter)
Filter the messages that have already being loaded.

Parameters:
p_filter - The filter criterion.
Returns:
The number of messages in the filtered collection, i.e. the value of size().

size

public int size()
Get the number of messages in the filtered collection.

Returns:
The number of messages in the filtered collection.

get

public Message get(int p_iIndex)
Get the message at the specified index out of the filtered collection.

Parameters:
p_iIndex - The index of the message.
Returns:
The message with the specified index or null if there are no filtered messages available or an error occurred.

getRichSiteSummary

public void getRichSiteSummary(java.io.Writer p_writer,
                               java.lang.String p_strResourceUrl,
                               java.lang.String p_strEncodingDecl,
                               int p_iMaxCount)
Create a Rich Site Summary containing all news for which the anonymous user is a recipient.

Calling this method does not affect the internal state of this object.

Parameters:
p_writer - The stream where to write the data to.
p_strResourceUrl - The URL for this resource (rdf:about).
p_strEncodingDecl - The encoding declaration to be used in the XML text declaration.
p_iMaxCount - The maximum number of news to be contained in the summary. -1 indicates that this count is unlimited.

dump

public java.lang.String dump()
Dump this object to a String.

Warning:
This method is provided for debugging purposes only.


Last updated: 2011-08-11 10-04
Copyright © 2000-2011 United Planet. All Rights Reserved.