KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > registry > mergedctx > SetUpUtils


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.api.registry.mergedctx;
20
21 import org.netbeans.api.registry.Context;
22 import org.netbeans.api.registry.ContextException;
23 import org.openide.filesystems.FileObject;
24 import org.openide.filesystems.Repository;
25
26 import java.util.ArrayList JavaDoc;
27
28 public class SetUpUtils {
29     private static Context subctx1;
30     private static Context subctx2;
31     private static Context subctx3;
32
33     static Context getSimpleContext(Context originalCtx) {
34         System.gc();
35         System.gc();
36         System.gc();
37         ArrayList JavaDoc l = new ArrayList JavaDoc ();
38         try {
39             subctx1 = originalCtx.createSubcontext("first");
40             l.add(getSubctx1());
41             subctx2 = originalCtx.createSubcontext("second");
42             l.add (getSubctx2());
43             subctx3 = originalCtx.createSubcontext("third");
44             l.add (getSubctx3());
45
46             Context[] retVal = new Context [l.size()];
47             l.toArray(retVal);
48             Context mretVal = Context.merge(retVal);
49             return mretVal;
50         } catch (ContextException e) {
51             throw new UnknownError JavaDoc();
52         }
53     }
54
55     static FileObject getSimpleRoot () {
56        return Repository.getDefault ().getDefaultFileSystem ().findResource("first");
57     }
58
59     static FileObject findSimpleResource (String JavaDoc resource) {
60         if (resource.startsWith("/"))
61             resource = resource.substring(1);
62         return Repository.getDefault ().getDefaultFileSystem ().findResource("first/"+resource);
63     }
64
65     static Context getSubctx1() {
66         return subctx1;
67     }
68
69     static Context getSubctx2() {
70         return subctx2;
71     }
72
73     static Context getSubctx3() {
74         return subctx3;
75     }
76 }
77
Popular Tags