public class WorkflowBundleIO extends Object
WorkflowBundle
s.
This class depends on implemented WorkflowBundleReader
and
WorkflowBundleWriter
instances, which are discovered from the
classpath using ServiceLoader
or set using setReaders(List)
and setWriters(List)
. An OSGi service descriptors is provided for
instantiating this class as bean workflowBundleIO
, while non-OSGi
uses can just instantiate this class where needed.
The methods readBundle(File, String)
,
readBundle(InputStream, String)
, readBundle(URL, String)
and writeBundle(WorkflowBundle, File, String)
/
writeBundle(WorkflowBundle, OutputStream, String)
take an argument
to indicate the media type of the format. The reader methods from file and
URL allow the parameter to be null
in order to guess the format,
but the writer method requires the format to be specified explicitly.
Known supported formats (as of 2013-04-23):
Modifier and Type | Field and Description |
---|---|
protected ServiceLoader<WorkflowBundleReader> |
readersLoader |
protected ServiceLoader<WorkflowBundleWriter> |
writersLoader |
Constructor and Description |
---|
WorkflowBundleIO() |
Modifier and Type | Method and Description |
---|---|
WorkflowBundle |
createBundle()
Create a new WorkflowBundle with a default workflow and profile.
|
protected List<WorkflowBundleReader> |
discoverReaders() |
protected List<WorkflowBundleWriter> |
discoverWriters() |
WorkflowBundleReader |
getReaderForMediaType(String mediaType)
Returns a
WorkflowBundleReader for the specified media type. |
List<WorkflowBundleReader> |
getReaders()
Returns all the available
WorkflowBundleReader s. |
WorkflowBundleWriter |
getWriterForMediaType(String mediaType)
Returns a
WorkflowBundleWriter for the specified media type. |
List<WorkflowBundleWriter> |
getWriters()
Returns all the available
WorkflowBundleWriter s. |
String |
guessMediaTypeForSignature(byte[] firstBytes)
Attempt to guess the media type for a stream or file that starts with
these bytes.
|
WorkflowBundle |
readBundle(File bundleFile,
String mediaType)
Reads a file containing a workflow bundle in the specified media type and returns a
WorkflowBundle . |
WorkflowBundle |
readBundle(InputStream inputStream,
String mediaType)
Reads a stream containing a workflow bundle in the specified media type and returns a
WorkflowBundle . |
WorkflowBundle |
readBundle(URL url,
String mediaType)
Reads a URL containing a workflow bundle in the specified media type and returns a
WorkflowBundle . |
void |
setReaders(List<WorkflowBundleReader> readers)
Sets the
WorkflowBundleReader s. |
void |
setWriters(List<WorkflowBundleWriter> writers)
Sets the
WorkflowBundleWriter s. |
void |
writeBundle(WorkflowBundle wfBundle,
File destination,
String mediaType)
Write a
WorkflowBundle to a file with specified media type. |
void |
writeBundle(WorkflowBundle wfBundle,
OutputStream output,
String mediaType)
Write a
WorkflowBundle to a stream with specified media type. |
protected ServiceLoader<WorkflowBundleWriter> writersLoader
protected ServiceLoader<WorkflowBundleReader> readersLoader
protected List<WorkflowBundleReader> discoverReaders()
protected List<WorkflowBundleWriter> discoverWriters()
public WorkflowBundleReader getReaderForMediaType(String mediaType)
WorkflowBundleReader
for the specified media type.
If there is more than one WorkflowBundleReader
for the specified media type the
first reader discovered is returned. Subsequent calls to this method may return a different
reader.
If there is no WorkflowBundleReader
for the specified media type
null
is returned.mediaType
- the media type of the WorkflowBundleReader
WorkflowBundleReader
for the specified media typepublic List<WorkflowBundleReader> getReaders()
WorkflowBundleReader
s.WorkflowBundleReader
spublic WorkflowBundleWriter getWriterForMediaType(String mediaType)
WorkflowBundleWriter
for the specified media type.
If there is more than one WorkflowBundleWriter
for the specified media type the
first writer discovered is returned. Subsequent calls to this method may return a different
writer.
If there is no WorkflowBundleWriter
for the specified media type
null
is returned.mediaType
- the media type of the WorkflowBundleWriter
WorkflowBundleWriter
for the specified media typepublic List<WorkflowBundleWriter> getWriters()
WorkflowBundleWriter
s.WorkflowBundleWriter
spublic String guessMediaTypeForSignature(byte[] firstBytes)
All registered getReaders()
are consulted.
Return null
if ambiguous (more than one possibility) or
unknown.
firstBytes
- The initial bytes, at least 512 bytes long unless the resource
is smaller.null
if the bytes were
ambiguous or unknown.public WorkflowBundle readBundle(File bundleFile, String mediaType) throws ReaderException, IOException
WorkflowBundle
.bundleFile
- the file containing the workflow bundlemediaType
- the media type of the workflow bundle. A WorkflowBundleReader
must
exist for this media type.
If null
, the media type will be guessed as with guessMediaTypeForSignature(byte[])
.WorkflowBundle
read from the fileReaderException
- if there is an error parsing the workflow bundleIOException
- if there is an error reading the fileIllegalArgumentException
- if a WorkflowBundleReader
cannot be found for the media typepublic WorkflowBundle readBundle(InputStream inputStream, String mediaType) throws ReaderException, IOException
WorkflowBundle
.inputStream
- the stream containing the workflow bundlemediaType
- the media type of the workflow bundle. A WorkflowBundleReader
must
exist for this media type.
If null
, the media type will be guessed as with guessMediaTypeForSignature(byte[])
.WorkflowBundle
read from the streamReaderException
- if there is an error parsing the workflow bundleIOException
- if there is an error reading from the streamIllegalArgumentException
- if a WorkflowBundleReader
cannot be found for the media typepublic WorkflowBundle readBundle(URL url, String mediaType) throws ReaderException, IOException
WorkflowBundle
.url
- the URL containing the workflow bundlemediaType
- the media type of the workflow bundle. A WorkflowBundleReader
must
exist for this media type
If null
, the media type will
be guessed as with guessMediaTypeForSignature(byte[])
.WorkflowBundle
read from the URLReaderException
- if there is an error parsing the workflow bundleIOException
- if there is an error reading from the streamIllegalArgumentException
- if a WorkflowBundleReader
cannot be found for the media typepublic void setReaders(List<WorkflowBundleReader> readers)
WorkflowBundleReader
s.
This method will normally be called by Spring when wiring beans.
readers
- the WorkflowBundleReader
spublic void setWriters(List<WorkflowBundleWriter> writers)
WorkflowBundleWriter
s.
This method will normally be called by Spring when wiring beans.
readers
- the WorkflowBundleWriter
spublic void writeBundle(WorkflowBundle wfBundle, File destination, String mediaType) throws WriterException, IOException
WorkflowBundle
to a file with specified media type.
Scufl2Tools.setParents(WorkflowBundle)
will be called on the bundle to
ensure everything contained by the bundle has it as an ancestor.
wfBundle
- the workflow bundle to writedestination
- the file to write the workflow bundle tomediaType
- the media type to write workflow bundle in. A WorkflowBundleWriter
must exist for this media typeWriterException
- if there is an error writing the workflow bundleIOException
- if there is an error writing the fileIllegalArgumentException
- if a WorkflowBundleWriter
cannot be found for the media typepublic void writeBundle(WorkflowBundle wfBundle, OutputStream output, String mediaType) throws WriterException, IOException
WorkflowBundle
to a stream with specified media type.
Scufl2Tools.setParents(WorkflowBundle)
will be called on the bundle to
ensure everything contained by the bundle has it as an ancestor.
wfBundle
- the workflow bundle to writeoutput
- the stream to write the workflow bundle tomediaType
- the media type to write workflow bundle in. A WorkflowBundleWriter
must exist for this media typeWriterException
- if there is an error writing the workflow bundleIOException
- if there is an error writing to the streamIllegalArgumentException
- if a WorkflowBundleWriter
cannot be found for the media typepublic WorkflowBundle createBundle()
Unlike the WorkflowBundle
constructor, this method will also make
a WorkflowBundle.getMainWorkflow()
and
WorkflowBundle.getMainProfile()
, simplifying construction of
workflow bundles from scratch.
Each of the bundle, workflow and profile will also have a revision set
using Revisioned.newRevision()
and their names set to
short default values.
WorkflowBundle
which has a main workflow and main profileCopyright © 2014 myGrid. All rights reserved.