KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.core.startup;
20
21 import java.io.File JavaDoc;
22 import java.io.InputStream JavaDoc;
23 import java.io.OutputStream JavaDoc;
24 import java.io.PrintWriter JavaDoc;
25 import org.openide.util.Lookup;
26
27 /** Interface to environment that the Module system needs around itself.
28  *
29  * @author Jaroslav Tulach
30  */

31 public abstract class CoreBridge {
32
33     private static boolean lookupInitialized;
34
35     public static CoreBridge getDefault () {
36         CoreBridge b = Lookup.getDefault().lookup(CoreBridge.class);
37         if (b == null) {
38             assert lookupInitialized; // XXX does it matter?
39
b = new FakeBridge();
40         }
41         return b;
42     }
43     
44     static void lookupInitialized() {
45         lookupInitialized = true;
46     }
47     
48     static void conditionallyLoaderPoolTransaction(boolean begin) {
49         CoreBridge b = Lookup.getDefault().lookup(CoreBridge.class);
50         if (b != null) {
51             b.loaderPoolTransaction(begin);
52         }
53     }
54     static Lookup conditionallyLookupCacheLoad () {
55         CoreBridge b = Lookup.getDefault().lookup(CoreBridge.class);
56         if (b != null) {
57             return b.lookupCacheLoad ();
58         } else {
59             return Lookup.EMPTY;
60         }
61     }
62     
63     static void conditionallyPrintStatus (String JavaDoc txt) {
64         CoreBridge b = Lookup.getDefault().lookup(CoreBridge.class);
65         if (b != null) {
66             b.setStatusText(txt);
67         } else {
68             System.err.println(txt);
69         }
70         
71     }
72     
73     /** Attaches or detaches to current category of actions.
74      * @param category name or null
75      */

76     protected abstract void attachToCategory (Object JavaDoc category);/*
77         ModuleActions.attachTo(category);
78     */

79     
80     protected abstract void loadDefaultSection (
81         ManifestSection ms,
82         org.openide.util.lookup.InstanceContent.Convertor<ManifestSection,Object JavaDoc> convertor,
83         boolean add
84     ); /*
85         if (load) {
86             if (convert) {
87                 NbTopManager.get().register(s, convertor);
88             } else {
89                 NbTopManager.get().register(s);
90             }
91         } else {
92             if (convert) {
93                 NbTopManager.get().unregister(s, convertor);
94             } else {
95                 NbTopManager.get().unregister(s);
96             }
97         }
98     */

99     
100     protected abstract void loadActionSection(ManifestSection.ActionSection s, boolean load) throws Exception JavaDoc;/* {
101         if (load) {
102             ModuleActions.add(s);
103         } else {
104             ModuleActions.remove(s);
105         }
106     }
107     */

108     
109     protected abstract void loadLoaderSection(ManifestSection.LoaderSection s, boolean load) throws Exception JavaDoc;/* {
110         if (load) {
111             LoaderPoolNode.add(s);
112         } else {
113             LoaderPoolNode.remove((DataLoader)s.getInstance());
114         }
115     }
116 */

117     
118     protected abstract void loaderPoolTransaction (boolean begin); /*
119         LoaderPoolNode.beginUpdates();
120         LoaderPoolNode.endUpdates();
121     */

122
123     /** Abstracts away from definition of property editors.
124      * @since 1.7 */

125     public abstract void registerPropertyEditors();
126     /** Abstracts away from loading of IDESettings.
127      * @since 1.7
128      */

129     protected abstract void loadSettings();
130
131     public abstract Lookup lookupCacheLoad ();
132     public abstract void lookupCacheStore (Lookup l) throws java.io.IOException JavaDoc;
133     
134     /** Delegates to status displayer.
135      */

136     public abstract void setStatusText (String JavaDoc status);
137     
138     public abstract void initializePlaf (Class JavaDoc uiClass, int uiFontSize, java.net.URL JavaDoc themeURL);
139
140     public abstract void cliUsage(PrintWriter JavaDoc printWriter);
141
142     public abstract int cli(
143         String JavaDoc[] string,
144         InputStream JavaDoc inputStream,
145         OutputStream JavaDoc outputStream,
146         OutputStream JavaDoc errorStream,
147         File JavaDoc file
148     );
149     
150     
151     /** Default implementation of the bridge, so certain
152      * applications can run without any bridge being present.
153      */

154     private static final class FakeBridge extends CoreBridge {
155         /** Attaches or detaches to current category of actions.
156          * @param category name or null
157          */

158         protected void attachToCategory (Object JavaDoc category) {
159
160         }
161
162         protected void loadDefaultSection (
163             ManifestSection ms,
164             org.openide.util.lookup.InstanceContent.Convertor convertor,
165             boolean add
166         ) {
167         }
168
169         protected void loadActionSection(ManifestSection.ActionSection s, boolean load) throws Exception JavaDoc {
170             s.getInstance();
171         }
172
173         protected void loadLoaderSection(ManifestSection.LoaderSection s, boolean load) throws Exception JavaDoc {
174         }
175
176         protected void loaderPoolTransaction (boolean begin) {
177             // just ignore
178
}
179
180         protected void addToSplashMaxSteps (int cnt) {
181         }
182         protected void incrementSplashProgressBar () {
183         }
184
185         public Lookup lookupCacheLoad () {
186             return Lookup.EMPTY;
187         }
188         public void lookupCacheStore (Lookup l) throws java.io.IOException JavaDoc {
189         }
190
191         public void setStatusText (String JavaDoc status) {
192             System.err.println("STATUS: " + status);
193         }
194
195         public void initializePlaf (Class JavaDoc uiClass, int uiFontSize, java.net.URL JavaDoc themeURL) {
196         }
197
198         public void cliUsage(PrintWriter JavaDoc printWriter) {
199         }
200
201         public void registerPropertyEditors() {
202         }
203
204         protected void loadSettings() {
205         }
206
207         public int cli(String JavaDoc[] string, InputStream JavaDoc inputStream, OutputStream JavaDoc outputStream, OutputStream JavaDoc errorStream, File JavaDoc file) {
208             return 0;
209         }
210     }
211     
212 }
213
Popular Tags