1 6 7 package com.hp.hpl.jena.rdf.model; 8 9 import com.hp.hpl.jena.shared.*; 10 11 17 public class ModelFactoryBase 18 { 19 public static String guessDBURL() 20 { return gp( "db.url" ); } 21 22 public static String guessDBUser() 23 { return gp( "db.user", "test" ); } 24 25 public static String guessDBPassword() 26 { return gp( "db.password", "" ); } 27 28 public static String guessDBType() 29 { 30 String possible = gp( "db.type", null ); 31 if (possible == null) possible = extractType( guessDBURL() ); 32 if (possible == null) throw new JenaException( "cannot guess database type" ); 33 return possible; 34 } 35 36 public static String guessDBDriver() 37 { return gp( "db.driver", null ); } 38 39 46 public static String extractType( String dbURL ) 47 { 48 int a = dbURL.indexOf( ':' ); 49 int b = dbURL.indexOf( ':', a + 1 ); 50 return dbURL.substring( a + 1, b ); 51 } 52 53 protected static String gp( String name ) 54 { 55 String answer = gp( name, null ); 56 if (answer == null) throw new JenaException( "no binding for " + name ); 57 return answer; 58 } 59 60 protected static String gp( String name, String ifAbsent ) 61 { 62 String answer = System.getProperty( "jena." + name ); 63 return answer == null ? ifAbsent : answer; 64 } 65 66 } 67 68 69 | Popular Tags |