public class DataTypeIDService extends Object
DataElement
types, ElementReader
s,
and ElementWriter
s, and facilitates links
between SlideSet
table columns and command
input and output parameters. It also maintains an
index of human-readable MIME type names which can
be used by the user interface. A single instance of
DataTypeIDService
is created when Slide Set
is run and is shared by all the Slide Set components.
DataElement
classes and their metadata. Along with the MIME
type index, it allows DataTypeIDService to create
human-readable labels for column data types. The
complement of DataElement
types is currently
fixed, though extension may be possible in future
releases. The available types are: BooleanElement
("Logical"; Boolean
underlying value)
IntegerElement
("Integer"; Integer
underlying value)
DoubleElement
("Numeric"; Double
underlying value)
StringElement
("Text"; String
underlying value)
FileLinkElement
("~ File"*; String
underlying value)
ElementReader
classes used to link DataElement
"underlying"
data to the "processed" data needed for command inputs
and available ElementWriter
classes used to create
DataElement
"underlying" data from "processed"
data in command results. They are populated when
DataTypeIDService
is instantiated. Readers and
writers in Slide Set core include: java.lang
wrapper classes
and String
)
DataElement
classes (byte
, short
, long
,
and float
), casts to and from int
or
double
DataTypeIDService
will identify table columns
and ElementReader
s appropriate for a command
input by searching the index for readers which produce a
"processed" data type cast-compatible with the input type,
and the table for columns with DataElement classes and
MIME types that are appropriate for the selected reader.
A convenience class binding an instance of the reader to
the appropriate column (ColumnBoundReader
) is returned
so that once the match has been made, the component requesting
the match has no need to interact directly with the
SlideSet
table or manage "underlying" data
conversion to produce "processed" data for the command input.
ColumnBoundReader
s can also wrap constant data,
as if they were table columns with identical values in each row.
Similarly for command results, DataTypeIDService
will identify ElementWriter
s that can be used to
convert "processed" data from the command to "underlying"
data in a DataElement
. An empty SlideSet
can be created with columns appropriate for the DataElement
classes produced by the selected ElementWriter
s,
along with convenience classes binding writer instances
to the appropriate columns (ColumnBoundWriter
s).
Lastly, DataTypeIDService
can search for
ElementReader
— ElementWriter
pairs which can be used to read and write data from
a SlideSet
table column without altering its format.
This type of match facilitates in situ editing of table
"processed" data without creating a separate results table.
For example, the RoiEditor
uses this match to read and write ROI set file data that
are included in a table as path references.
Modifier and Type | Class and Description |
---|---|
private class |
DataTypeIDService.DataElementRecord<T> |
private class |
DataTypeIDService.ReaderRecord<E extends DataElement,P> |
private class |
DataTypeIDService.WriterRecord<E extends DataElement,P> |
Modifier and Type | Field and Description |
---|---|
private ArrayList<DataTypeIDService.DataElementRecord> |
dataElementIndex
Index of available
DataElement types |
private ArrayList<DataTypeIDService.ReaderRecord> |
elementReaderIndex
Index of available
ElementReader s |
private ArrayList<DataTypeIDService.WriterRecord> |
elementWriterIndex
Index of available
ElementWriter s |
private net.imagej.ImageJ |
ij |
private LinkedHashMap<String,String> |
mimeReadableIndex
Index associating MIME types with human-readable names:
<MIME type, readable name>
|
private org.scijava.plugin.PluginService |
ps |
private LinkedHashMap<Class<?>,Class<? extends TypeAlias>> |
typeAliasIndex
Index of aliased types:
<real type, alias type>
|
Constructor and Description |
---|
DataTypeIDService(net.imagej.ImageJ ij) |
Modifier and Type | Method and Description |
---|---|
private void |
buildDataElementIndex()
Set-up the
DataElement index |
private void |
buildElementReaderIndex()
Set-up the
ElementReader index |
private void |
buildElementWriterIndex()
Set-up the
ElementWriter index |
private void |
buildMimeReadableIndex()
Set-up the MIME type index
|
private void |
buildTypeAliasIndex()
Set-up the
TypeAlias index |
void |
getColumnReadWritePairs(Class<?> type,
SlideSet data,
ArrayList<ColumnBoundReader> readers,
ArrayList<ColumnBoundWriter> writers)
Get
ColumnBoundReader —ColumnBoundWriter pairs
that can be used to read and write the specified type to a column
in the provided SlideSet table. |
ArrayList<ColumnBoundReader> |
getCompatableColumnReaders(Class<?> type,
SlideSet data)
Get a list of
ColumnBoundReader s that will read
data from the given table that are assignment-compatible with
the specified class. |
void |
getCompatableReaders(Class<?> type,
ArrayList<Class<? extends ElementReader>> readers,
ArrayList<String> names,
boolean filterHidden)
Get the list of
ElementReader s that will
read to the specified type. |
void |
getCompatableWriters(Class<?> type,
ArrayList<Class<? extends ElementWriter>> writers,
ArrayList<String> names,
ArrayList<String> linkExt)
Get a list of
ElementWriter s compatible with a class. |
ArrayList<Class<? extends DataElement>> |
getElementTypes(boolean includeHidden)
Get a list of
DataElement types in the index. |
String |
getMimeReadableName(String mimeType)
Get the human-readable name of an MIME type, if
it is registered in the index.
|
ArrayList<String> |
getMimeTypes()
Get a list of MIME types from the index
|
private Class<?> |
getPrimitiveWrapper(Class<?> type)
Returns the wrapper class for a primitive type.
|
String |
getReadableElementType(Class<? extends DataElement> type,
String mimeType)
Get a human-readable name for a
DataElement type—
MIME type pair |
Class<? extends DataElement> |
getReaderElementType(Class<? extends ElementReader> reader)
Get the
DataElement type read by an ElementReader type. |
ArrayList<String> |
getReaderMimeTypes(Class<? extends ElementReader> reader)
Get the list of MIME types that can be read by
an
ElementReader type. |
Class<?> |
getReaderUnderlyingType(Class<? extends ElementReader> reader)
Get the underlying type read by an
ElementReader type. |
void |
getTableForWriters(ArrayList<String> columnNames,
ArrayList<Class<? extends ElementWriter>> writerTypes,
SlideSet table,
ArrayList<ColumnBoundWriter> writers)
Create a table with column types matching the specified list
of
ElementWriter classes. |
private Class<?> |
getTypeAlias(Class<?> type)
Replace a
TypeAlias type with it's 'real' type. |
Class<? extends DataElement> |
getWriterElementType(Class<? extends ElementWriter> writer)
Get the
DataElement type written by an ElementWriter type. |
private boolean |
isPrimativeWrapper(Class<?> type)
Is the type a wrapper class for a java primitive?
|
ColumnBoundReader<?,?> |
makeColumnBoundConstantReader(Class<? extends ElementReader> readerType,
Object data,
SlideSet table)
Create a
ColumnBoundReader that will always read from
a constant DataElement . |
private net.imagej.ImageJ ij
private org.scijava.plugin.PluginService ps
private ArrayList<DataTypeIDService.DataElementRecord> dataElementIndex
DataElement
typesprivate ArrayList<DataTypeIDService.ReaderRecord> elementReaderIndex
ElementReader
sprivate ArrayList<DataTypeIDService.WriterRecord> elementWriterIndex
ElementWriter
sprivate LinkedHashMap<String,String> mimeReadableIndex
private LinkedHashMap<Class<?>,Class<? extends TypeAlias>> typeAliasIndex
TypeAlias
public void getCompatableReaders(Class<?> type, ArrayList<Class<? extends ElementReader>> readers, ArrayList<String> names, boolean filterHidden)
ElementReader
s that will
read to the specified type.type
- Selected ElementReader
s will return objects
that are assignment-compatible with this classreaders
- List to receive the compatible ElementReader
classesnames
- List to receive the human-readable names of the
compatible ElementReader
sfilterHidden
- If true, will not select ElementReader
s
that have been marked as hidden
in their
ElementReaderMetadata
annotations.public ArrayList<ColumnBoundReader> getCompatableColumnReaders(Class<?> type, SlideSet data) throws SlideSetException
ColumnBoundReader
s that will read
data from the given table that are assignment-compatible with
the specified class. If not compatible CoulmnBoundReader
s
can be created, returns an empty list.type
- Selected readers will return values assignment-compatible
with this classdata
- Table to which the selected ColumnBoundReader
s
will be boundSlideSetException
public void getCompatableWriters(Class<?> type, ArrayList<Class<? extends ElementWriter>> writers, ArrayList<String> names, ArrayList<String> linkExt)
ElementWriter
s compatible with a class.type
- Selected ElementWriters
will accept this
class as input for their write()
methodswriters
- List to receive the selected ElementWriter
s.
If no appropriate writers are found, the list will be emptied.names
- List to receive human-readable names of the selected
ElementWriter
spublic void getTableForWriters(ArrayList<String> columnNames, ArrayList<Class<? extends ElementWriter>> writerTypes, SlideSet table, ArrayList<ColumnBoundWriter> writers) throws SlideSetException
ElementWriter
classes.
Specifically, for each
ElementWriter
type provided, the table will contain
one column, set with DataElement
class and MIME type
to match the output of the ElementWriter
type.
A ColumnBoundWriter
will be instantiated for each
column in the table, binding an instance of the specified
ElementWriter
to it's corresponding column.
Note that the created SlideSet
will have 0 rows.
Rows must be added to the table before the created
ColumnBoundWriter
s can be used.
columnNames
- List of labels for the table columnswriterTypes
- List of ElementWriter
types that
will be used to define the table column data types.table
- Empty SlideSet
that will receive the new tablewriters
- List to receive the ColumnBoundWriter
s.
This list will be in the same order as the provided
ElementWriter
types.SlideSetException
public void getColumnReadWritePairs(Class<?> type, SlideSet data, ArrayList<ColumnBoundReader> readers, ArrayList<ColumnBoundWriter> writers) throws SlideSetException
ColumnBoundReader
—ColumnBoundWriter
pairs
that can be used to read and write the specified type to a column
in the provided SlideSet
table.
One ColumnBoundReader
and one ColumnBoundWriter
will be instantiated for each case where:
ElementReader
and ElementWriter
both
support the specified processed type;
DataElement
type and MIME type; and
DataElement
type
and MIME type.ColumnBoundReader
—ColumnBoundWriter
pairs
are expected to support reciprocal read—write operations, i.e.
editing processed data stored in a table (ex. ROI data), rather than
the more straightforward situation of editing the table's
underlying values (ex. ROI file references). If no appropriate
reader—writer pairs can be created, returns empty lists.type
- Processed type used to select reader—writer pairsdata
- Table to which the returned readers and writers will be boundreaders
- List to receive the ColumnBoundReader
swriters
- List to receive the ColumnBoundWriter
sSlideSetException
public Class<? extends DataElement> getReaderElementType(Class<? extends ElementReader> reader) throws SlideSetException
DataElement
type read by an ElementReader
type.SlideSetException
public Class<? extends DataElement> getWriterElementType(Class<? extends ElementWriter> writer) throws SlideSetException
DataElement
type written by an ElementWriter
type.SlideSetException
public Class<?> getReaderUnderlyingType(Class<? extends ElementReader> reader) throws SlideSetException
ElementReader
type.SlideSetException
public ArrayList<String> getReaderMimeTypes(Class<? extends ElementReader> reader) throws SlideSetException
ElementReader
type.SlideSetException
public ColumnBoundReader<?,?> makeColumnBoundConstantReader(Class<? extends ElementReader> readerType, Object data, SlideSet table) throws SlideSetException
ColumnBoundReader
that will always read from
a constant DataElement
. This contrasts with the usual
behavior of ColumnBoundReader
s, to bind an
ElementReader
to one column of a SlideSet
table.
The method facilitates the use of constants
for command inputs instead of values from the input table.readerType
- The ElementReader
type that will
be used to read the constant data. Note that the reader
must support underlying data of the same type as the
data
parameter passed to this method.data
- The underlying data that will be wrapped in an
appropriate DataElement
and read by the returned
ColumnBoundReader
table
- Table that will be the 'owner' of the created
DataElement
. This table's working directory will
be used to resolve any relative paths in file links.SlideSetException
- If the requested ElementReader
is not in the index or cannot be instantiated; if an
appropriate DataElement
cannot be found; of if
the ColumnBoundReader
cannot be created.public String getReadableElementType(Class<? extends DataElement> type, String mimeType)
DataElement
type—
MIME type pairpublic ArrayList<Class<? extends DataElement>> getElementTypes(boolean includeHidden)
DataElement
types in the index.includeHidden
- If true
, include types
marked as 'hidden' in their annotations
.public String getMimeReadableName(String mimeType)
private void buildDataElementIndex()
DataElement
indexprivate void buildElementReaderIndex()
ElementReader
indexprivate void buildElementWriterIndex()
ElementWriter
indexprivate void buildMimeReadableIndex()
private void buildTypeAliasIndex()
TypeAlias
indexprivate Class<?> getPrimitiveWrapper(Class<?> type)
private boolean isPrimativeWrapper(Class<?> type)
Copyright © 2023. All rights reserved.