KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > lookup > FolderLookupBenchmark


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
21 package org.netbeans.core.lookup;
22
23
24 import java.io.Serializable JavaDoc;
25 import java.net.URL JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.util.List JavaDoc;
29
30 //import org.openide.debugger.Debugger;
31
import org.openide.execution.Executor;
32 import org.openide.filesystems.FileObject;
33 import org.openide.filesystems.FileSystem;
34 import org.openide.filesystems.MultiFileSystem;
35 import org.openide.filesystems.XMLFileSystem;
36 import org.openide.loaders.DataFolder;
37 import org.openide.loaders.DataObject;
38 import org.openide.loaders.DataObjectNotFoundException;
39 import org.openide.loaders.FolderLookup;
40 import org.openide.ServiceType;
41 import org.openide.util.Lookup;
42 import org.openide.util.lookup.AbstractLookup;
43
44 import org.netbeans.core.NbTopManager;
45 import org.netbeans.core.xml.FileEntityResolver;
46 import org.netbeans.performance.Benchmark;
47
48 import org.xml.sax.SAXException JavaDoc;
49
50 import junit.framework.TestSuite;
51 import junit.textui.TestRunner;
52
53
54 public class FolderLookupBenchmark extends Benchmark {
55
56     private static final String JavaDoc[] layerResources = new String JavaDoc[] {
57         "/org/netbeans/core/resources/ant.xml", // NOI18N
58
"/org/netbeans/core/resources/applet.xml", // NOI18N
59
"/org/netbeans/core/resources/autoupdate.xml", // NOI18N
60
"/org/netbeans/core/resources/beans.xml", // NOI18N
61
"/org/netbeans/core/resources/core.xml", // NOI18N
62
"/org/netbeans/core/resources/debuggercore.xml", // NOI18N
63
"/org/netbeans/core/resources/debuggerjpda.xml", // NOI18N
64
"/org/netbeans/core/resources/debuggertools.xml", // NOI18N
65
"/org/netbeans/core/resources/editor.xml", // NOI18N
66
"/org/netbeans/core/resources/extbrowser.xml", // NOI18N
67
"/org/netbeans/core/resources/form.xml", // NOI18N
68
"/org/netbeans/core/resources/html.xml", // NOI18N
69
"/org/netbeans/core/resources/httpserver.xml", // NOI18N
70
"/org/netbeans/core/resources/i18n.xml", // NOI18N
71
"/org/netbeans/core/resources/icebrowser.xml", // NOI18N
72
"/org/netbeans/core/resources/image.xml", // NOI18N
73
"/org/netbeans/core/resources/j2ee.xml", // NOI18N
74
"/org/netbeans/core/resources/jarpackager.xml", // NOI18N
75
"/org/netbeans/core/resources/javacvs.xml", // NOI18N
76
"/org/netbeans/core/resources/javadoc.xml", // NOI18N
77
"/org/netbeans/core/resources/java.xml", // NOI18N
78
"/org/netbeans/core/resources/jndi.xml", // NOI18N
79
"/org/netbeans/core/resources/objectbrowser.xml", // NOI18N
80
"/org/netbeans/core/resources/projects.xml", // NOI18N
81
"/org/netbeans/core/resources/properties.xml", // NOI18N
82
"/org/netbeans/core/resources/rmi.xml", // NOI18N
83
"/org/netbeans/core/resources/scripting.xml", // NOI18N
84
"/org/netbeans/core/resources/text.xml", // NOI18N
85
"/org/netbeans/core/resources/usersguide.xml", // NOI18N
86
"/org/netbeans/core/resources/utilities.xml", // NOI18N
87
"/org/netbeans/core/resources/vcscore.xml", // NOI18N
88
"/org/netbeans/core/resources/vcsgeneric.xml", // NOI18N
89
"/org/netbeans/core/resources/web-core.xml", // NOI18N
90
"/org/netbeans/core/resources/web-templates.xml", // NOI18N
91
"/org/netbeans/core/resources/web-tomcat.xml" // NOI18N
92
};
93     
94     /** Instance of folder lookup */
95     private FolderLookup fl;
96
97     /** Data folder on which to provide lookup. */
98     private DataFolder df;
99     
100     /** Number of found instances. */
101 // private int result = -1;
102

103     
104     public FolderLookupBenchmark(java.lang.String JavaDoc testName) {
105         super(testName);
106
107         System.err.println("TopManager="+NbTopManager.get()); // TEMP
108
System.err.println("Lookup="+Lookup.getDefault()); // TEMP
109
}
110     
111     
112     /** Runs the test suite. */
113     public static void main(String JavaDoc[] args) {
114         TestRunner.run(new TestSuite(FolderLookupBenchmark.class));
115     }
116     
117
118     /** Creates XML file system (from core mf-layer.xml) on which to provide lookup. */
119     protected void setUp ()
120     throws java.net.MalformedURLException JavaDoc,
121             SAXException JavaDoc,
122             DataObjectNotFoundException {
123
124         List JavaDoc systems = new ArrayList JavaDoc(layerResources.length);
125         
126         for(int i = 0; i < layerResources.length; i++) {
127             // XXX
128
// URL url = TopManager.getDefault().currentClassLoader().getResource(layerResources[i]);
129
ClassLoader JavaDoc cl = (ClassLoader JavaDoc)Lookup.getDefault().lookup(ClassLoader JavaDoc.class);
130             URL JavaDoc url = cl.getResource(layerResources[i]);
131             
132             systems.add(new XMLFileSystem(url));
133         }
134         
135         FileObject services = new MultiFileSystem((FileSystem[])systems.toArray(new FileSystem[0])).getRoot().getFileObject("Services");
136         
137         df = (DataFolder)DataObject.find(services);
138     }
139     
140     /** Clears the lookup. */
141     protected void tearDown () {
142         fl = null;
143         df = null;
144 // result = -1;
145
}
146
147 /* private void findTemplate(Class clazz) {
148         fl = new FolderLookup(df);
149
150         result = fl.getLookup().lookup(new Lookup.Template(clazz)).allInstances().size();
151     }
152  */

153     
154     /** Test to find the first registered object. */
155     public void testCreateFolderLookup() {
156         fl = new FolderLookup(df);
157
158         fl.getLookup();
159         fl.instanceFinished();
160     }
161     
162 /* public void testFindSerializable() {
163         findTemplate(Serializable.class);
164     }
165
166     public void testFindService() {
167         findTemplate(ServiceType.class);
168     }
169
170     public void testFindCompiler() {
171         findTemplate(Compiler.class);
172     }
173
174     public void testFindExecutor() {
175         findTemplate(Executor.class);
176     }
177
178     public void testFindDebugger() {
179         findTemplate(Debugger.class);
180     }
181  */

182
183 }
184
Popular Tags