1 6 7 package com.hp.hpl.jena.rdf.model.impl; 8 9 import com.hp.hpl.jena.db.IDBConnection; 10 import com.hp.hpl.jena.rdf.model.*; 11 import com.hp.hpl.jena.shared.*; 12 import com.hp.hpl.jena.vocabulary.*; 13 14 20 21 public class RDBMakerCreator implements ModelMakerCreator 22 { 23 public ModelMaker create( Model desc, Resource root ) 24 { 25 return ModelFactory.createModelRDBMaker( createConnection( desc, root ) ); 26 } 27 28 public static IDBConnection createConnection( Model description, Resource root ) 29 { 30 Resource connection = description.listStatements( root, JenaModelSpec.hasConnection, (RDFNode) null ).nextStatement().getResource(); 31 String url = getURL( description, connection, JenaModelSpec.dbURL ); 32 String user = getString( description, connection, JenaModelSpec.dbUser ); 33 String password = getString( description, connection , JenaModelSpec.dbPassword ); 34 String className = getClassName( description, connection ); 35 String dbType = getString( description, connection, JenaModelSpec.dbType ); 36 loadDrivers( dbType, className ); 37 return ModelFactory.createSimpleRDBConnection( url, user, password, dbType ); 38 } 39 40 public static String getClassName( Model description, Resource root ) 41 { 42 Statement cnStatement = description.getProperty( root, JenaModelSpec.dbClass ); 43 return cnStatement == null ? null : cnStatement.getString(); 44 } 45 46 public static String getURL( Model description, Resource root, Property p ) 47 { 48 return description.getRequiredProperty( root, p ).getResource().getURI(); 49 } 50 51 public static String getString( Model description, Resource root, Property p ) 52 { 53 return description.getRequiredProperty( root, p ).getString(); 54 } 55 56 public static void loadDrivers( String dbType, String className ) 57 { 58 try 59 { 60 Class.forName( "com.hp.hpl.jena.db.impl.Driver_" + dbType ); 61 if (className != null) Class.forName( className ); 62 } 63 catch (ClassNotFoundException c) 64 { throw new JenaException( c ); } 65 } 66 } 67 68 | Popular Tags |