1 5 6 package org.joseki.server.source; 7 8 import org.joseki.vocabulary.JosekiVocab ; 9 10 import com.hp.hpl.jena.rdf.model.* ; 11 import com.hp.hpl.jena.db.* ; 12 13 import org.joseki.server.SourceController; 14 import org.joseki.server.ModelSource; 15 import org.joseki.server.module.Loadable; 16 import org.apache.commons.logging.* ; 17 18 23 24 public class SourceControllerRDB implements SourceController, Loadable 25 { 26 static Log logger = LogFactory.getLog(SourceControllerRDB.class.getName()) ; 27 28 String serverURI ; 29 30 33 public String getInterfaceURI() { return JosekiVocab.SourceController.getURI() ; } 34 public void init(Resource binding, Resource implementation) {} 35 36 39 public ModelSource createSourceModel(Resource description, String _serverURI) 41 { 42 serverURI = _serverURI ; 43 44 Resource dbURI = description.getProperty(JosekiVocab.attachedModel).getResource() ; 45 String user, password, dbType, modelName, driver ; 46 try 47 { 48 user = description.getRequiredProperty(JosekiVocab.user).getString() ; 50 password = description.getRequiredProperty(JosekiVocab.password).getString(); 51 dbType = description.getRequiredProperty(JosekiVocab.dbType).getString(); 52 modelName = description.getRequiredProperty(JosekiVocab.dbModelName).getString(); 53 driver = description.getRequiredProperty(JosekiVocab.dbDriver).getString(); 54 } catch (RDFException rdfEx) 55 { 56 logger.warn("Failed to gather all the database information: "+ rdfEx) ; 57 return null ; 58 } 59 60 try { 61 if ( driver != null ) 62 Class.forName(driver).newInstance(); 63 } catch (Exception ex) 64 { 65 logger.warn("Failed to load the driver: "+ex.getMessage()) ; 66 } 67 68 try { 69 IDBConnection conn = ModelFactory.createSimpleRDBConnection(dbURI.getURI(), user, password, dbType) ; 70 ModelRDB modelRDB = ModelRDB.open(conn, modelName) ; 71 ModelSource mSrc = new ModelSourcePermanent(this, modelRDB, serverURI) ; 72 logger.info("Connected to database: "+dbURI.getURI()) ; 73 return mSrc ; 74 } catch (RDFRDBException ex) 75 { 76 logger.warn("Failed to connect to database: "+ex.getMessage()) ; 77 logger.debug("Exception", ex) ; 78 if ( ex.getCause() != null ) 79 logger.warn("Connect failure cause : "+ex.getCause().getMessage()) ; 80 return null ; 81 } 82 } 83 84 public String getServerURI() { return serverURI ; } 85 86 public void activate() { return ; } 88 89 public void deactivate() { return ; } 91 92 public Model buildSource() 94 { 95 logger.warn("Attempt to build a database source") ; 96 return null ; 97 } 98 99 public void releaseSource() 101 { 102 logger.warn("Attempt to release a database source") ; 103 } 104 } 105 106 132 | Popular Tags |