You create a data source by extending the
DataSource
abstract class and other supporting classes.
A
DataSource
requires an
@CasDataSource
annotation. The annotation has several
important attributes you can configure:
displayName
. Optional. The name of a data source as it displays in CAS Console and as it is returned from thelistModules
task of the CAS Server Command-line Utility. If not specified,displayName
defaults to thename
value.description
. Optional. The description of a what the data source can access. The description displays in CAS Console and it is returned from thelistModules
task of the CAS Server Command-line Utility.id
. Optional. If unspecified, the extension defaults to using the fully qualified class name as itsid
.
The
listModules
task of the CAS Server Command-line
Utility and the
listModules()
call of the CAS Server API both return
the attribute values you specify in the
@CasDataSource
annotations.
To create a data source extension:
Create a Java project in your development environment of your choice.
If you are creating several extensions in one plug-in, you can use the same Java project for each extension.
Add the CAS Extension API libraries to your compile classpath. These include all the libraries available in
<install path>\CAS\
.version
\lib\cas-extension-apiCreate a subclass of
DataSource
and specify thePipelineComponentConfiguration
subclass that the extension uses. TheDataSource
requires a zero-argument constructor.For example:
public class CsvDataSource extends DataSource<CsvDataSourceRuntime,CsvDataSourceConfig>{ }
Add a
@CasDataSource
annotation to theDataSource
class.For example:
@CasDataSource(displayName="CSV File", description="Reads comma separated files") public class CsvDataSource extends DataSource<CsvDataSourceRuntime,CsvDataSourceConfig>{ }
Implement the
getConfigurationClass()
method to return the appropriatePipelineComponentConfiguration
subclass.For example:
public Class<CsvDataSourceConfig> getConfigurationClass() { return CsvDataSourceConfig.class; }
Implement the
createDataSourceRuntime()
method to create an implementation of theDataSourceRuntime
class.For example:
public CsvDataSourceRuntime createDataSourceRuntime( CsvDataSourceConfig config, PipelineComponentRuntimeContext context) { return new CsvDataSourceRuntime(context, config); }
Implement the
getRuntimeClass()
method to return the runtime class the data source creates.For example:
public Class<CsvDataSourceRuntime> getRuntimeClass() { return CsvDataSourceRuntime.class; }
Optionally, override the
deleteInstance()
method. CAS Server callsdeleteInstance()
when it removes an extension. In this method, you can perform any clean up that is necessary when CAS Server callsdeleteInstance()
to remove the extension from an acquisition. The default implementation ofdeleteInstance()
is empty.
Example 1. Example of a data source extension
To see many of the steps above, refer to the sample data source
extension in
<install
path>\CAS\
.
version
\sample\cas-extensions\src\main\com\endeca\cas\extension\sample\
datasource\csv\CsvDataSource.java