KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > model > ModelFactoryBase


1 /*
2   (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4   $Id: ModelFactoryBase.java,v 1.4 2005/02/21 12:14:09 andy_seaborne Exp $
5 */

6
7 package com.hp.hpl.jena.rdf.model;
8
9 import com.hp.hpl.jena.shared.*;
10
11 /**
12     Helper functions for ModelFactory - in here to keep from obtruding on the
13     end-users.
14     
15     @author kers
16 */

17 public class ModelFactoryBase
18     {
19     public static String JavaDoc guessDBURL()
20         { return gp( "db.url" ); }
21     
22     public static String JavaDoc guessDBUser()
23         { return gp( "db.user", "test" ); }
24     
25     public static String JavaDoc guessDBPassword()
26         { return gp( "db.password", "" ); }
27     
28     public static String JavaDoc guessDBType()
29         {
30         String JavaDoc 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 JavaDoc guessDBDriver()
37         { return gp( "db.driver", null ); }
38     
39     /**
40         Guess the database type as the string between the first and second colons of the
41         URL. This method is public so that it may be invoked from test packages.
42     
43         @param dbURL a string of the form nocolons:somename:somestuff
44         @return somename
45     */

46     public static String JavaDoc extractType( String JavaDoc 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 JavaDoc gp( String JavaDoc name )
54         {
55         String JavaDoc answer = gp( name, null );
56         if (answer == null) throw new JenaException( "no binding for " + name );
57         return answer;
58         }
59     
60     protected static String JavaDoc gp( String JavaDoc name, String JavaDoc ifAbsent )
61         {
62         String JavaDoc answer = System.getProperty( "jena." + name );
63         return answer == null ? ifAbsent : answer;
64         }
65
66     }
67
68
69 /*
70     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
71     All rights reserved.
72
73     Redistribution and use in source and binary forms, with or without
74     modification, are permitted provided that the following conditions
75     are met:
76
77     1. Redistributions of source code must retain the above copyright
78        notice, this list of conditions and the following disclaimer.
79
80     2. Redistributions in binary form must reproduce the above copyright
81        notice, this list of conditions and the following disclaimer in the
82        documentation and/or other materials provided with the distribution.
83
84     3. The name of the author may not be used to endorse or promote products
85        derived from this software without specific prior written permission.
86
87     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
88     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
89     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
90     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
91     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
92     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
93     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
94     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
95     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
96     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
97 */
Popular Tags