NamedPayloads

public abstract class NamedPayloads

A Named payloads is a kind of payload (file attachment) that use it’s filename to provide some informations for the system. It is a proxy design pattern that control the behavior of the actual files. In SFRM plugin, the default style of named payload is shown on the below:

  • Outgoing Payload Repository - <service>$<message_id>$timestamp>
  • Packaged Payload Repository - <service>$<message_id>
  • Incoming Payload Repository - <service>$<message_id>

Creation Date: 6/10/2006.

Author:Twinsen Tsang

Fields

decodeDelimiters

protected static final String decodeDelimiters

The delimitier used for decoding.

filenameEndBracket

protected static final String filenameEndBracket

The end bracket to enclose the filename of the single file, not packed payload

filenameStartBracket

protected static final String filenameStartBracket

The start bracket to enclose the filename of the single file, not packed payload

processedPrefix

protected static final String processedPrefix

The prefix of uploading payload.

processingPrefix

protected static final String processingPrefix

The prefix of processing payload.

uploadingPrefix

protected static final String uploadingPrefix

The prefix of uploading payload.

Constructors

NamedPayloads

public NamedPayloads(String payloadsName, int initialState, PayloadsRepository owner)

Explicit Constructor. This constructor is mainly used for creating a new payload proxy including the physical file and the proxy object. NOTE: The physical file is not created until it is necessary.

Parameters:
  • payloadsName – The name of the newly created payload.
  • initialState – The initialState of the payloads, see PayloadsState for details.
  • owner – The owner of the payloads.
Throws:
  • NullPointerException – if the owner is null
  • IllegalArgumentException – if the payloadsName is null or the initialState is not invalid.

See also: hk.hku.cecid.edi.sfrm.com.PayloadsRepostory, hk.hku.cecid.edi.sfrm.com.PayloadsState

NamedPayloads

public NamedPayloads(File payloads, PayloadsRepository owner)

Explicit Constructor. The constructor is mainly used for creating the new payload proxy object only.

Parameters:
  • payloads – The file payload object.
  • owner – The owner of the payloads.

See also: hk.hku.cecid.edi.sfrm.PayloadsRepostory

Methods

clearPayloadCache

public void clearPayloadCache()

Clear / Delete the payload cache to free some space.

clearTokens

public void clearTokens()

Clear the tokens to free some memory.

decode

protected abstract void decode()

Decode the payload root to become some useful information.

Throws:

encode

protected abstract void encode()

Encode the payload root back to a filename.

getContentType

public String getContentType()
Returns:the contentType

getExtension

public String getExtension()
Returns:the extension

getOriginalRootname

public String getOriginalRootname()
Returns:the original file name of the payload root.

getOwner

public PayloadsRepository getOwner()
Returns:get the owner of this payload.

getRoot

public File getRoot()
Returns:the directory of this payload set.

getSize

public long getSize()
Returns:get the size of the payload, return 0 if the payload does not exist.

getStateForm

public static String getStateForm(int state)

Get the state form string according to the specified state.

Parameters:
  • state – The state you want to retrieve.
Throws:

getTokens

protected List getTokens()
Returns:a list of token under the decode delimiters.

isProcessed

public boolean isProcessed()
Returns:true if the payload’s name is starting with processed prefix.

isProcessing

public boolean isProcessing()
Returns:true if the payload’s name is startting with processing prefix.

isUploading

public boolean isUploading()
Returns:true if the payload’s name is startting with processing prefix.

load

public InputStream load()

Load the payload content from the input stream. NOTE: This method returns a new instance of input stream.

Throws:
  • IOException – Throws if the payload file does not exist.
Returns:

the content input stream.

loadChannel

public ReadableByteChannel loadChannel()

Load the payload content from the input stream channel.

Throws:
  • IOException – Throws if the payload file does not exist.
Returns:

the content input channel.

moveRoot

public boolean moveRoot(String newPath, boolean force)

Move the root to the specified path.

Parameters:
  • newPath – The absolute new path
  • force – force to move the file to specified path if there is a file with same name already exist in that path.
Returns:

true if the moving operation successfully.

moveToRepository

public boolean moveToRepository(PayloadsRepository newOwner)

Move the root to another payloads repository. The owner of this payloads will changes to newOwner after invocation of this method.

Parameters:
  • newOwner – The new owner of the payload repository.
Returns:

true if the moving operation successfully, false if the newOwner is null or moving operation fail.

moveToRepositoryForce

public boolean moveToRepositoryForce(PayloadsRepository newOwner)

Move the root to another payloads repository force. The owner of this payloads will changes to newOwner after invocation of this method.

Parameters:
  • newOwner – The new owner of the payload repository.
Returns:

true if the moving operation successfully, false if the newOwner is null or moving operation fail.

renameRoot

public boolean renameRoot(String newName)

Rename the root to the specified name. (The file path has not been changed after each invocation.

Parameters:
  • newName – The name of the root.
Throws:
  • IOException – if any kinds of I/O Exception.
Returns:

true if the operation run successfully.

save

public void save(InputStream content, boolean append)

Save the content from the input stream to this payloads. If the content stream is null, it save the file with empty content.

Parameters:
  • content – The input content stream.
  • append – true if the new content is added to the existing content, false if the new content overwrite the existing.

setToPending

public boolean setToPending()

Set the status of payload to pending.

Returns:true if the operation run sucessfully.

setToProcessed

public boolean setToProcessed()

Set the status of payload to processed.

Returns:true if the operation run sucessfully.

setToProcessing

public boolean setToProcessing()

Set the status of payload to processing.

Returns:true if the operation run sucessfully.

setToUploading

public boolean setToUploading()

Set the status of payload to uploading.

Returns:true if the operation run sucessfully.

toString

public String toString()

toString method