1 19 package org.netbeans.core; 20 21 import java.net.URL ; 22 import java.net.URLClassLoader ; 23 import java.util.ArrayList ; 24 import java.util.Map ; 25 26 import org.openide.filesystems.MultiFileSystem; 27 import org.openide.filesystems.FileObject; 28 import org.openide.loaders.InstanceDataObject; 29 import org.openide.loaders.DataObject; 30 31 import org.openide.filesystems.multifs.MultiXMLFSTest; 32 import org.openide.filesystems.multifs.MultiXMLFSTest.FileWrapper; 33 import org.openide.filesystems.ReadOnlyFSTest; 34 import org.openide.loaders.Utilities; 35 36 import org.netbeans.ProxyClassLoader; 37 38 import org.netbeans.performance.MapArgBenchmark; 39 import org.netbeans.performance.DataManager; 40 import org.netbeans.performance.DataDescriptor; 41 42 47 public class MultiURLClassLoaderTest extends MapArgBenchmark implements DataManager { 48 49 private static final String CLASS_NO_KEY = "CLASS_NO"; 50 51 private MultiXMLFSTest mfstest; 52 private InstanceDataObject[] instanceObjects; 53 54 57 public MultiURLClassLoaderTest(String name) { 58 super(name); 59 setArgumentArray(createArguments()); 60 init(); 61 } 62 63 64 private Map [] createArguments() { 65 Map [] ret = new Map [] { createDefaultMap(), createDefaultMap() }; 66 ret[1].put(CLASS_NO_KEY, new Integer (1000)); 67 return ret; 68 } 69 70 74 public MultiURLClassLoaderTest(String name, Object [] args) { 75 super(name, args); 76 init(); 77 } 78 79 80 private void init() { 81 mfstest = new MultiXMLFSTest(getName()); 82 } 83 84 86 93 protected void setUp() throws Exception { 94 int size = getIntValue(CLASS_NO_KEY); 95 96 FileObject[] fileObjects = mfstest.setUpFileObjects(size); 97 FileWrapper[] wrappers = mfstest.getFileWrappers(); 98 99 URLClassLoader [] parents = new URLClassLoader [wrappers.length]; 100 for (int i = 0; i < parents.length; i++) { 101 parents[i] = new URLClassLoader (new URL [] { wrappers[i].getMnt().toURL() }); 102 } 103 104 ClassLoader multicloader = new ProxyClassLoader(parents); 106 107 instanceObjects = fileObjects2InstanceDataObjects(fileObjects); 108 setClassLoader(instanceObjects, multicloader); 109 } 110 111 private static InstanceDataObject[] fileObjects2InstanceDataObjects(FileObject[] fos) throws Exception { 112 ArrayList list = new ArrayList (fos.length); 113 for (int i = 0; i < fos.length; i++) { 114 DataObject res = DataObject.find(fos[i]); 115 if (res instanceof InstanceDataObject) { 116 list.add(res); 117 } 118 } 119 120 return (InstanceDataObject[]) list.toArray(new InstanceDataObject[list.size()]); 121 } 122 123 private static void setClassLoader(InstanceDataObject[] idos, ClassLoader cl) throws Exception { 124 for (int i = 0; i < idos.length; i++) { 125 Utilities.setCustomClassLoader(idos[i], cl); 126 } 127 } 128 129 136 protected void tearDown() throws Exception { 137 } 138 139 140 protected Map createDefaultMap() { 141 Map map = super.createDefaultMap(); 142 map.put(CLASS_NO_KEY, new Integer (500)); 143 map.put(MultiXMLFSTest.XMLFS_NO_KEY, new Integer (30)); 144 return map; 145 } 146 147 148 public void tearDownData() throws Exception { 149 mfstest.tearDownData(); 150 } 151 152 153 public DataDescriptor createDataDescriptor() { 154 return new MUCDataDescriptor(getIntValue(CLASS_NO_KEY), getIntValue(MultiXMLFSTest.XMLFS_NO_KEY)); 155 } 156 157 158 public void setUpData(DataDescriptor ddesc) throws Exception { 159 MUCDataDescriptor dd = (MUCDataDescriptor) ddesc; 160 DataDescriptor other = dd.getDD(); 161 162 int fileNo = getIntValue(CLASS_NO_KEY); 163 Map map = (Map ) getArgument(); 164 map.put(ReadOnlyFSTest.FILE_NO_KEY, new Integer (fileNo)); 165 166 mfstest.setParent(this); 167 168 if (other == null) { 169 other = mfstest.createDataDescriptor(); 170 dd.setDD(other); 171 } 172 173 mfstest.setUpData(other); 174 } 175 176 178 public void testInstanceClasses() throws Exception { 179 for (int i = 0; i < instanceObjects.length; i++) { 180 String klass = instanceObjects[i].instanceName(); 181 instanceObjects[i].instanceClass(); 182 } 183 } 184 185 195 } | Popular Tags |