KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.PrintWriter JavaDoc;
25 import java.net.MalformedURLException JavaDoc;
26 import java.net.URL JavaDoc;
27 import java.net.URLClassLoader JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.Collection JavaDoc;
30 import org.netbeans.CLIHandler;
31 import org.netbeans.Module;
32 import org.openide.filesystems.Repository;
33 import org.openide.util.Exceptions;
34 import org.openide.util.Lookup;
35
36 /**
37  * Handler for core.jar options.
38  * @author Jaroslav Tulach
39  */

40 public class CLICoreBridge extends CLIHandler {
41     /**
42      * Create a default handler.
43      */

44     public CLICoreBridge() {
45         super(WHEN_INIT);
46     }
47     
48     protected int cli(Args arguments) {
49         Lookup clis = Lookup.getDefault();
50         Collection JavaDoc handlers = clis.lookupAll(CLIHandler.class);
51         int h = notifyHandlers(arguments, handlers, WHEN_EXTRA, true, true);
52         if (h == 0) {
53             h = CoreBridge.getDefault().cli(
54                 arguments.getArguments(),
55                 arguments.getInputStream(),
56                 arguments.getOutputStream(),
57                 arguments.getErrorStream(),
58                 arguments.getCurrentDirectory()
59             );
60         }
61         return h;
62     }
63
64     protected void usage(PrintWriter JavaDoc w) {
65         if (MainLookup.isStarted()) {
66             Lookup clis = Lookup.getDefault();
67             Collection JavaDoc handlers = clis.lookupAll(CLIHandler.class);
68             showHelp(w, handlers, WHEN_EXTRA);
69             w.flush();
70             return;
71         }
72         
73         ModuleSystem moduleSystem;
74         try {
75             moduleSystem = new ModuleSystem(Repository.getDefault().getDefaultFileSystem());
76         } catch (IOException JavaDoc ioe) {
77             // System will be screwed up.
78
throw (IllegalStateException JavaDoc) new IllegalStateException JavaDoc("Module system cannot be created").initCause(ioe); // NOI18N
79
}
80
81 // moduleSystem.loadBootModules();
82
moduleSystem.readList();
83         
84         
85         ArrayList JavaDoc<URL JavaDoc> urls = new ArrayList JavaDoc<URL JavaDoc>();
86         for (Module m : moduleSystem.getManager().getModules()) {
87             for (File JavaDoc f : m.getAllJars()) {
88                 try {
89                     urls.add(f.toURI().toURL());
90                 }
91                 catch (MalformedURLException JavaDoc ex) {
92                     Exceptions.printStackTrace(ex);
93                 }
94             }
95         }
96         
97         URLClassLoader JavaDoc loader = new URLClassLoader JavaDoc(urls.toArray(new URL JavaDoc[0]), getClass().getClassLoader());
98         MainLookup.systemClassLoaderChanged(loader);
99         Lookup clis = Lookup.getDefault();
100         Collection JavaDoc handlers = clis.lookupAll(CLIHandler.class);
101         showHelp(w, handlers, WHEN_EXTRA);
102         w.flush();
103     }
104 }
105
Popular Tags