KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > derby > spi > support > DerbySupport


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.derby.spi.support;
21
22 import java.io.File JavaDoc;
23 import org.netbeans.modules.derby.DerbyOptions;
24 import org.netbeans.modules.derby.RegisterDerby;
25 import org.openide.util.NbBundle;
26
27 /**
28  *
29  * @author Andrei Badea
30  */

31 public final class DerbySupport {
32     
33     private DerbySupport() {
34     }
35     
36     /**
37      * Sets the location of the Derby installation and registers the Derby drivers.
38      * The Derby installation must have a lib subdirectory in which the Derby JAR
39      * files are located.
40      *
41      * @param location the jars locations. This must be an existing directory.
42      */

43     public static void setLocation(String JavaDoc location) {
44         DerbyOptions.getDefault().setLocation(location);
45     }
46     
47     /**
48      * Returns the location of the Derby jars. Never returns null,
49      * instead it returns an empty string if the location is unknown.
50      */

51     public static String JavaDoc getLocation() {
52         return DerbyOptions.getDefault().getLocation();
53     }
54     
55     /**
56      * Sets the Derby system home, that is, the directory
57      * where the Derby databases are located.
58      */

59     public static void setSystemHome(String JavaDoc systemHome) {
60         DerbyOptions.getDefault().setSystemHome(systemHome);
61     }
62     
63     /**
64      * Returns the Derby system home. Never returns null,
65      * instead it returns an empty string if the location is unknown.
66      */

67     public static String JavaDoc getSystemHome() {
68         return DerbyOptions.getDefault().getSystemHome();
69     }
70     
71     /**
72      * Returns the default Derby system home. It is not guaranteed that
73      * the directory returned by this method exists.
74      */

75     public static String JavaDoc getDefaultSystemHome() {
76         // issue 76908
77
String JavaDoc propertySystemHome = System.getProperty(DerbyOptions.NETBEANS_DERBY_SYSTEM_HOME);
78         if (propertySystemHome != null) {
79             return propertySystemHome;
80         }
81
82         String JavaDoc userHome = System.getProperty("user.home"); // NOI18N
83
return new File JavaDoc(userHome, NbBundle.getMessage(DerbySupport.class, "LBL_DerbyDatabaseDirectory")).getAbsolutePath();
84     }
85     
86     /**
87      * Ensures the Derby database is started, that is, starts it if it is
88      * not running and does nothing otherwise.
89      *
90      * @since 1.5
91      */

92     public static void ensureStarted() {
93         RegisterDerby.getDefault().ensureStarted();
94     }
95 }
96
Popular Tags