* @inheritDoc
*/
@Override
public DataSource create(final Map<String, Object> theMap) throws DataSourceException {
if (!canCreate(theMap)) {
throw new DataSourceException("Invalid configuration map: " + theMap);
}
Object aName = theMap.get(ConfigKeys.NAME);
Object aURL = theMap.get(URL);
Object aRepo = theMap.get(REPO);
Object aFiles = theMap.get(FILES);
Object aDir = theMap.get(DIR);
Object aPhysRepo = theMap.get(REPO_HANDLE);
Repository aRepository;
try {
if (aPhysRepo != null) {
aRepository = (Repository) aPhysRepo;
}
else if (aURL != null && aRepo != null) {
aRepository = new HTTPRepository(aURL.toString(), aRepo.toString());
aRepository.initialize();
}
else if (aFiles != null) {
aRepository = new SailRepository(new MemoryStore());
try {
aRepository.initialize();
RepositoryConnection aConn = null;
try {
aConn = aRepository.getConnection();
aConn.begin();
for (String aFile : Splitter.on(',').omitEmptyStrings().trimResults().split(aFiles.toString())) {
RDFParser aParser = Rio.createParser(Rio.getParserFormatForFileName(aFile));
aParser.setRDFHandler(new RDFInserter(aConn));
if (NetUtils.isURL(aFile)) {
aParser.parse(new java.net.URL(aFile).openStream(), "");
}
else {
aParser.parse(new FileInputStream(aFile), "");
}
}
aConn.commit();
}
finally {
if (aConn != null) {
aConn.close();
}
}
}
catch (Exception e) {
throw new DataSourceException(e);
}
}
else if (aDir != null) {
aRepository = new SailRepository(new MemoryStore(new File(aDir.toString())));
aRepository.initialize();
}
else {
aRepository = new SailRepository(new MemoryStore());
aRepository.initialize();
}
return new RepositoryDataSource(aRepository, theMap.containsKey(QUERY_LANG) && theMap.get(QUERY_LANG).toString().equalsIgnoreCase(LANG_SERQL));
}
catch (RepositoryException e) {
throw new DataSourceException(e);
}
}