001: /*
002: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: ModelFactoryBase.java,v 1.10 2008/01/03 15:19:10 chris-dollin Exp $
005: */
006:
007: package com.hp.hpl.jena.rdf.model;
008:
009: import com.hp.hpl.jena.JenaRuntime;
010: import com.hp.hpl.jena.shared.*;
011:
012: /**
013: Helper functions for ModelFactory - in here to keep from obtruding on the
014: end-users.
015:
016: @author kers
017: */
018: public class ModelFactoryBase {
019: public static String guessDBURL() {
020: return gp("db.url");
021: }
022:
023: public static String guessDBUser() {
024: return gp("db.user", "test");
025: }
026:
027: public static String guessDBPassword() {
028: return gp("db.password", "");
029: }
030:
031: public static String guessDBType() {
032: String possible = gp("db.type", null);
033: if (possible == null)
034: possible = extractType(guessDBURL());
035: if (possible == null)
036: throw new JenaException("cannot guess database type");
037: return possible;
038: }
039:
040: public static String guessDBDriver() {
041: return gp("db.driver", null);
042: }
043:
044: /** Return true if the database should support concurrent read during transactions */
045: public static boolean guessDBConcurrent() {
046: return gp("db.concurrent", "true").equalsIgnoreCase("true");
047: }
048:
049: /**
050: Guess the database type as the string between the first and second colons of the
051: URL. This method is public so that it may be invoked from test packages.
052:
053: @param dbURL a string of the form nocolons:somename:somestuff
054: @return somename
055: */
056: public static String extractType(String dbURL) {
057: int a = dbURL.indexOf(':');
058: int b = dbURL.indexOf(':', a + 1);
059: return dbURL.substring(a + 1, b);
060: }
061:
062: protected static String gp(String name) {
063: String answer = gp(name, null);
064: if (answer == null)
065: throw new JenaException("no binding for " + name);
066: return answer;
067: }
068:
069: protected static String gp(String name, String ifAbsent) {
070: String answer = JenaRuntime.getSystemProperty("jena." + name);
071: return answer == null ? ifAbsent : answer;
072: }
073:
074: }
075:
076: /*
077: (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
078: All rights reserved.
079:
080: Redistribution and use in source and binary forms, with or without
081: modification, are permitted provided that the following conditions
082: are met:
083:
084: 1. Redistributions of source code must retain the above copyright
085: notice, this list of conditions and the following disclaimer.
086:
087: 2. Redistributions in binary form must reproduce the above copyright
088: notice, this list of conditions and the following disclaimer in the
089: documentation and/or other materials provided with the distribution.
090:
091: 3. The name of the author may not be used to endorse or promote products
092: derived from this software without specific prior written permission.
093:
094: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
095: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
096: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
097: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
098: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
099: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
100: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
101: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
102: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
103: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
104: */
|