1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package com.ontotext.ordi.rdbms;
19
20 import java.io.File;
21 import java.util.Map;
22
23 import com.ontotext.ordi.exception.ORDIRuntimeException;
24 import com.ontotext.ordi.exception.ORDIWarning;
25 import com.ontotext.ordi.mapper.model.MapperDescriptor;
26 import com.ontotext.ordi.mapper.processor.N3MapperDescriptorImpl;
27 import com.ontotext.ordi.mapper.processor.Processor;
28 import com.ontotext.ordi.tripleset.TConnection;
29 import com.ontotext.ordi.tripleset.TFactory;
30 import com.ontotext.ordi.tripleset.impl.TFactoryImpl;
31 import com.ontotext.ordi.tripleset.impl.TSourceImpl;
32
33 public class RDBMSAdapter extends TSourceImpl {
34
35 public static final String MAPPER_DESCRIPTOR = "mapper-descriptor";
36
37 private TFactory factory;
38 private Processor processor;
39
40 public RDBMSAdapter(Map<Object, Object> props) {
41 super(props);
42 if (props.containsKey(MAPPER_DESCRIPTOR) == false) {
43 throw new ORDIRuntimeException(
44 "Specify the mapper descriptor parameter!");
45 }
46 Object descriptor = props.get(MAPPER_DESCRIPTOR);
47 if (descriptor instanceof File) {
48 File file = (File) descriptor;
49 if (file.exists() == false) {
50 throw new ORDIRuntimeException(String.format(
51 "Invalid file location %!", file.getAbsolutePath()));
52 }
53 processor = new Processor(new N3MapperDescriptorImpl(file));
54 } else if (descriptor instanceof String) {
55 File file = new File((String) descriptor);
56 if (file.exists() == false) {
57 throw new ORDIRuntimeException(String.format(
58 "Invalid file location %!", file.getAbsolutePath()));
59 }
60 processor = new Processor(new N3MapperDescriptorImpl(file));
61 } else if (descriptor instanceof MapperDescriptor) {
62 processor = new Processor((MapperDescriptor) descriptor);
63 }
64
65 else {
66 throw new ORDIRuntimeException(
67 "The mapper descriptor parameter has invalid type!");
68 }
69 }
70
71 public TConnection getConnection() {
72 return new RDBMSConnection(this, processor);
73 }
74
75 public TConnection getConnection(String user, String pass) {
76 return getConnection();
77 }
78
79 public void shutdown() {
80 ORDIWarning newWarning = new ORDIWarning(
81 "The adapter does not support shutdown!");
82 newWarning.setNextWarning(this.warning);
83 this.warning = newWarning;
84 }
85
86 public boolean isShutdown() {
87 return true;
88 }
89
90 public synchronized TFactory getTriplesetFactory() {
91 if (factory == null) {
92 factory = new TFactoryImpl();
93 }
94 return factory;
95 }
96
97 public Processor getProcessor() {
98 return processor;
99 }
100 }