001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.core.lookup;
043:
044: import java.io.Serializable;
045: import java.net.URL;
046: import java.util.ArrayList;
047: import java.util.Collection;
048: import java.util.List;
049:
050: //import org.openide.debugger.Debugger;
051: import org.openide.execution.Executor;
052: import org.openide.filesystems.FileObject;
053: import org.openide.filesystems.FileSystem;
054: import org.openide.filesystems.MultiFileSystem;
055: import org.openide.filesystems.XMLFileSystem;
056: import org.openide.loaders.DataFolder;
057: import org.openide.loaders.DataObject;
058: import org.openide.loaders.DataObjectNotFoundException;
059: import org.openide.loaders.FolderLookup;
060: import org.openide.ServiceType;
061: import org.openide.util.Lookup;
062: import org.openide.util.lookup.AbstractLookup;
063:
064: import org.netbeans.core.NbTopManager;
065: import org.netbeans.core.xml.FileEntityResolver;
066: import org.netbeans.performance.Benchmark;
067:
068: import org.xml.sax.SAXException;
069:
070: import junit.framework.TestSuite;
071: import junit.textui.TestRunner;
072:
073: public class FolderLookupBenchmark extends Benchmark {
074:
075: private static final String[] layerResources = new String[] {
076: "/org/netbeans/core/resources/ant.xml", // NOI18N
077: "/org/netbeans/core/resources/applet.xml", // NOI18N
078: "/org/netbeans/core/resources/autoupdate.xml", // NOI18N
079: "/org/netbeans/core/resources/beans.xml", // NOI18N
080: "/org/netbeans/core/resources/core.xml", // NOI18N
081: "/org/netbeans/core/resources/debuggercore.xml", // NOI18N
082: "/org/netbeans/core/resources/debuggerjpda.xml", // NOI18N
083: "/org/netbeans/core/resources/debuggertools.xml", // NOI18N
084: "/org/netbeans/core/resources/editor.xml", // NOI18N
085: "/org/netbeans/core/resources/extbrowser.xml", // NOI18N
086: "/org/netbeans/core/resources/form.xml", // NOI18N
087: "/org/netbeans/core/resources/html.xml", // NOI18N
088: "/org/netbeans/core/resources/httpserver.xml", // NOI18N
089: "/org/netbeans/core/resources/i18n.xml", // NOI18N
090: "/org/netbeans/core/resources/icebrowser.xml", // NOI18N
091: "/org/netbeans/core/resources/image.xml", // NOI18N
092: "/org/netbeans/core/resources/j2ee.xml", // NOI18N
093: "/org/netbeans/core/resources/jarpackager.xml", // NOI18N
094: "/org/netbeans/core/resources/javacvs.xml", // NOI18N
095: "/org/netbeans/core/resources/javadoc.xml", // NOI18N
096: "/org/netbeans/core/resources/java.xml", // NOI18N
097: "/org/netbeans/core/resources/jndi.xml", // NOI18N
098: "/org/netbeans/core/resources/objectbrowser.xml", // NOI18N
099: "/org/netbeans/core/resources/projects.xml", // NOI18N
100: "/org/netbeans/core/resources/properties.xml", // NOI18N
101: "/org/netbeans/core/resources/rmi.xml", // NOI18N
102: "/org/netbeans/core/resources/scripting.xml", // NOI18N
103: "/org/netbeans/core/resources/text.xml", // NOI18N
104: "/org/netbeans/core/resources/usersguide.xml", // NOI18N
105: "/org/netbeans/core/resources/utilities.xml", // NOI18N
106: "/org/netbeans/core/resources/vcscore.xml", // NOI18N
107: "/org/netbeans/core/resources/vcsgeneric.xml", // NOI18N
108: "/org/netbeans/core/resources/web-core.xml", // NOI18N
109: "/org/netbeans/core/resources/web-templates.xml", // NOI18N
110: "/org/netbeans/core/resources/web-tomcat.xml" // NOI18N
111: };
112:
113: /** Instance of folder lookup */
114: private FolderLookup fl;
115:
116: /** Data folder on which to provide lookup. */
117: private DataFolder df;
118:
119: /** Number of found instances. */
120: // private int result = -1;
121:
122: public FolderLookupBenchmark(java.lang.String testName) {
123: super (testName);
124:
125: System.err.println("TopManager=" + NbTopManager.get()); // TEMP
126: System.err.println("Lookup=" + Lookup.getDefault()); // TEMP
127: }
128:
129: /** Runs the test suite. */
130: public static void main(String[] args) {
131: TestRunner.run(new TestSuite(FolderLookupBenchmark.class));
132: }
133:
134: /** Creates XML file system (from core mf-layer.xml) on which to provide lookup. */
135: protected void setUp() throws java.net.MalformedURLException,
136: SAXException, DataObjectNotFoundException {
137:
138: List systems = new ArrayList(layerResources.length);
139:
140: for (int i = 0; i < layerResources.length; i++) {
141: // XXX
142: // URL url = TopManager.getDefault().currentClassLoader().getResource(layerResources[i]);
143: ClassLoader cl = (ClassLoader) Lookup.getDefault().lookup(
144: ClassLoader.class);
145: URL url = cl.getResource(layerResources[i]);
146:
147: systems.add(new XMLFileSystem(url));
148: }
149:
150: FileObject services = new MultiFileSystem(
151: (FileSystem[]) systems.toArray(new FileSystem[0]))
152: .getRoot().getFileObject("Services");
153:
154: df = (DataFolder) DataObject.find(services);
155: }
156:
157: /** Clears the lookup. */
158: protected void tearDown() {
159: fl = null;
160: df = null;
161: // result = -1;
162: }
163:
164: /* private void findTemplate(Class clazz) {
165: fl = new FolderLookup(df);
166:
167: result = fl.getLookup().lookup(new Lookup.Template(clazz)).allInstances().size();
168: }
169: */
170:
171: /** Test to find the first registered object. */
172: public void testCreateFolderLookup() {
173: fl = new FolderLookup(df);
174:
175: fl.getLookup();
176: fl.instanceFinished();
177: }
178:
179: /* public void testFindSerializable() {
180: findTemplate(Serializable.class);
181: }
182:
183: public void testFindService() {
184: findTemplate(ServiceType.class);
185: }
186:
187: public void testFindCompiler() {
188: findTemplate(Compiler.class);
189: }
190:
191: public void testFindExecutor() {
192: findTemplate(Executor.class);
193: }
194:
195: public void testFindDebugger() {
196: findTemplate(Debugger.class);
197: }
198: */
199:
200: }
|