KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > startup > NbRepository


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.core.startup;
21
22 import java.beans.PropertyVetoException JavaDoc;
23 import java.io.File JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.StringTokenizer JavaDoc;
28
29 import org.openide.filesystems.*;
30
31 import org.netbeans.core.startup.layers.SessionManager;
32 import org.openide.util.NbBundle;
33
34 /** Default repository.
35  */

36 public final class NbRepository extends Repository {
37     /** name of system folder to be located in the USER_DIR and HOME_DIR */
38     static final String JavaDoc SYSTEM_FOLDER = "config"; // NOI18N
39

40     /**
41      * Create a repository based on the normal system file system.
42      */

43     public NbRepository () {
44         super (createDefaultFileSystem());
45         // make sure the factory for nbfs and other protocols is on
46
Main.initializeURLFactory ();
47     }
48
49     /** Creates defalt file system.
50     */

51     private static FileSystem createDefaultFileSystem () {
52         String JavaDoc systemDir = System.getProperty("system.dir"); // NOI18N
53

54         if (systemDir != null) {
55             // initiliaze the filesystem for this property
56

57             try {
58                 return SessionManager.getDefault().create(new File JavaDoc (systemDir), null, new File JavaDoc[0]);
59             } catch (IOException JavaDoc ex) {
60                 ex.printStackTrace();
61                 throw new InternalError JavaDoc ();
62             } catch (PropertyVetoException JavaDoc ex) {
63                 ex.printStackTrace();
64                 throw new InternalError JavaDoc ();
65             }
66         }
67         
68         File JavaDoc u = null;
69         File JavaDoc h = null;
70         List JavaDoc<File JavaDoc> extradirs = new ArrayList JavaDoc<File JavaDoc>();
71         String JavaDoc homeDir = CLIOptions.getHomeDir ();
72         if (homeDir != null) {
73             // -----------------------------------------------------------------------------------------------------
74
// 1. Initialization and checking of netbeans.home and netbeans.user directories
75

76             File JavaDoc homeDirFile = new File JavaDoc (CLIOptions.getHomeDir ());
77             if (!homeDirFile.exists ()) {
78                 System.err.println (NbBundle.getMessage(NbRepository.class, "CTL_Netbeanshome_notexists"));
79                 doExit (2);
80             }
81             if (!homeDirFile.isDirectory ()) {
82                 System.err.println (NbBundle.getMessage(NbRepository.class, "CTL_Netbeanshome1"));
83                 doExit (3);
84             }
85
86             h = new File JavaDoc (homeDirFile, SYSTEM_FOLDER);
87             
88             // #27151: may also be additional install dirs
89
String JavaDoc nbdirs = System.getProperty("netbeans.dirs");
90             if (nbdirs != null) {
91                 StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(nbdirs, File.pathSeparator);
92                 while (tok.hasMoreTokens()) {
93                     File JavaDoc f = new File JavaDoc(tok.nextToken(), SYSTEM_FOLDER);
94                     if (f.isDirectory()) {
95                         extradirs.add(f);
96                     }
97                 }
98             }
99         }
100         String JavaDoc ud = CLIOptions.getUserDir ();
101         if (!ud.equals("memory")) { // NOI18N
102
File JavaDoc userDirFile = new File JavaDoc (ud);
103             if (!userDirFile.exists ()) {
104                 System.err.println (NbBundle.getMessage(NbRepository.class, "CTL_Netbeanshome2"));
105                 doExit (4);
106             }
107             if (!userDirFile.isDirectory ()) {
108                 System.err.println (NbBundle.getMessage(NbRepository.class, "CTL_Netbeanshome3"));
109                 doExit (5);
110             }
111             u = new File JavaDoc (userDirFile, SYSTEM_FOLDER);
112         }
113
114         Exception JavaDoc exc;
115         try {
116             return SessionManager.getDefault().create(u, h, extradirs.toArray(new File JavaDoc[extradirs.size()]));
117         } catch (IOException JavaDoc ex) {
118             exc = ex;
119         } catch (PropertyVetoException JavaDoc ex) {
120             exc = ex;
121         } catch (RuntimeException JavaDoc ex) {
122             exc = ex;
123         }
124
125         exc.printStackTrace ();
126         Object JavaDoc[] arg = new Object JavaDoc[] {systemDir};
127         System.err.println (new java.text.MessageFormat JavaDoc(
128             NbBundle.getMessage(NbRepository.class, "CTL_Cannot_mount_systemfs")
129         ).format(arg));
130         doExit (3);
131         return null;
132     }
133
134     
135     //
136
// methods that delegate to TM
137
//
138

139     private static void doExit (int value) {
140         org.netbeans.TopSecurityManager.exit(value);
141     }
142     
143 }
144
Popular Tags