File tree Expand file tree Collapse file tree 4 files changed +152
-0
lines changed
src/org/linkeddatafragments/datasource Expand file tree Collapse file tree 4 files changed +152
-0
lines changed Original file line number Diff line number Diff line change
1
+ package org .linkeddatafragments .datasource ;
2
+
3
+ import java .util .HashMap ;
4
+ import java .util .Map ;
5
+
6
+ /**
7
+ * A registry of {@link IDataSourceType}s.
8
+ *
9
+ * @author <a href="http://olafhartig.de">Olaf Hartig</a>
10
+ */
11
+ public class DataSourceTypesRegistry
12
+ {
13
+ private static Map <String , IDataSourceType > registry =
14
+ new HashMap <String , IDataSourceType >();
15
+
16
+ public static synchronized IDataSourceType getType ( final String typeName )
17
+ {
18
+ return registry .get ( typeName );
19
+ }
20
+
21
+ public static synchronized boolean isRegistered ( final String typeName )
22
+ {
23
+ return registry .containsKey ( typeName );
24
+ }
25
+
26
+ public static synchronized void register ( final String typeName ,
27
+ final IDataSourceType type )
28
+ {
29
+ if ( registry .containsKey (typeName ) ) {
30
+ throw new IllegalArgumentException ( "The registry already " +
31
+ "contains a type with the name '" + typeName + "'." );
32
+ }
33
+ registry .put ( typeName , type );
34
+ }
35
+
36
+ }
Original file line number Diff line number Diff line change
1
+ package org .linkeddatafragments .datasource ;
2
+
3
+ import java .io .File ;
4
+ import java .io .IOException ;
5
+
6
+ import org .linkeddatafragments .exceptions .DataSourceException ;
7
+
8
+ import com .google .gson .JsonObject ;
9
+
10
+ /**
11
+ * The type of HDT-backed Triple Pattern Fragment data sources.
12
+ *
13
+ * @author <a href="http://olafhartig.de">Olaf Hartig</a>
14
+ */
15
+ public class HdtDataSourceType implements IDataSourceType
16
+ {
17
+ public static final String TYPE_NAME = "HdtDatasource" ;
18
+
19
+ public static void register () {
20
+ if ( ! DataSourceTypesRegistry .isRegistered (TYPE_NAME ) ) {
21
+ DataSourceTypesRegistry .register ( TYPE_NAME ,
22
+ new HdtDataSourceType () );
23
+ }
24
+ }
25
+
26
+ @ Override
27
+ public IDataSource createDataSource ( final String title ,
28
+ final String description ,
29
+ final JsonObject settings )
30
+ throws DataSourceException
31
+ {
32
+ final String fname = settings .getAsJsonPrimitive ("file" ).getAsString ();
33
+ final File file = new File ( fname );
34
+
35
+ try {
36
+ return new HdtDataSource (title , description , file .getAbsolutePath ());
37
+ } catch (IOException ex ) {
38
+ throw new DataSourceException (ex );
39
+ }
40
+ }
41
+
42
+ }
Original file line number Diff line number Diff line change
1
+ package org .linkeddatafragments .datasource ;
2
+
3
+ import org .linkeddatafragments .exceptions .DataSourceException ;
4
+
5
+ import com .google .gson .JsonObject ;
6
+
7
+ /**
8
+ * Represents types of {@link IDataSource}s that can be used to provide some
9
+ * Linked Data Fragments interface.
10
+ *
11
+ * @author <a href="http://olafhartig.de">Olaf Hartig</a>
12
+ */
13
+ public interface IDataSourceType
14
+ {
15
+ /**
16
+ * Creates a data source of this type.
17
+ *
18
+ * @param title
19
+ * The title of the data source (as given in the config file).
20
+ *
21
+ * @param description
22
+ * The description of the data source (as given in the config file).
23
+ *
24
+ * @param settings
25
+ * The properties of the data source to be created; usually, these
26
+ * properties are given in the config file of the LDF server.
27
+ */
28
+ IDataSource createDataSource ( final String title ,
29
+ final String description ,
30
+ final JsonObject settings )
31
+ throws DataSourceException ;
32
+ }
Original file line number Diff line number Diff line change
1
+ package org .linkeddatafragments .datasource ;
2
+
3
+ import java .io .File ;
4
+
5
+ import org .linkeddatafragments .exceptions .DataSourceException ;
6
+
7
+ import com .google .gson .JsonObject ;
8
+
9
+ /**
10
+ * The type of Triple Pattern Fragment data sources that are backed by
11
+ * a Jena TDB instance.
12
+ *
13
+ * @author <a href="http://olafhartig.de">Olaf Hartig</a>
14
+ */
15
+ public class JenaTDBDataSourceType implements IDataSourceType
16
+ {
17
+ public static final String TYPE_NAME = "JenaTDBDatasource" ;
18
+
19
+ public static void register () {
20
+ if ( ! DataSourceTypesRegistry .isRegistered (TYPE_NAME ) ) {
21
+ DataSourceTypesRegistry .register ( TYPE_NAME ,
22
+ new JenaTDBDataSourceType () );
23
+ }
24
+ }
25
+
26
+ @ Override
27
+ public IDataSource createDataSource ( final String title ,
28
+ final String description ,
29
+ final JsonObject settings )
30
+ throws DataSourceException
31
+ {
32
+ final String dname = settings .getAsJsonPrimitive ("directory" ).getAsString ();
33
+ final File dir = new File ( dname );
34
+
35
+ try {
36
+ return new JenaTDBDataSource (title , description , dir );
37
+ } catch (Exception ex ) {
38
+ throw new DataSourceException (ex );
39
+ }
40
+ }
41
+
42
+ }
You can’t perform that action at this time.
0 commit comments