1 22 package org.netbeans.modules.editor; 23 24 25 import java.beans.PropertyVetoException ; 26 import java.io.IOException ; 27 import java.net.URL ; 28 import junit.framework.Assert; 29 import org.openide.filesystems.Repository; 30 import org.openide.filesystems.XMLFileSystem; 31 import org.openide.util.Lookup; 32 import org.openide.util.lookup.Lookups; 33 import org.openide.util.lookup.ProxyLookup; 34 35 36 41 public class EditorTestLookup extends ProxyLookup { 42 43 public static EditorTestLookup DEFAULT_LOOKUP = null; 44 45 static { 46 EditorTestLookup.class.getClassLoader().setDefaultAssertionStatus(true); 47 System.setProperty("org.openide.util.Lookup", EditorTestLookup.class.getName()); 48 Assert.assertEquals(EditorTestLookup.class, Lookup.getDefault().getClass()); 49 } 50 51 public EditorTestLookup() { 52 Assert.assertNull(DEFAULT_LOOKUP); 53 DEFAULT_LOOKUP = this; 54 } 55 56 59 public static void setLookup(Object [] instances, ClassLoader cl) { 60 DEFAULT_LOOKUP.setLookups(new Lookup[] { 61 Lookups.fixed(instances), 62 Lookups.metaInfServices(cl), 63 Lookups.singleton(cl), 64 }); 65 } 66 67 73 public static void setLookup(URL [] layers, Object [] instances, ClassLoader cl) 74 throws IOException , PropertyVetoException { 75 76 XMLFileSystem system = new XMLFileSystem(); 77 system.setXmlUrls(layers); 78 Repository repository = new Repository(system); 79 80 Object [] lookupContent = new Object [instances.length + 1]; 81 lookupContent[0] = repository; 82 System.arraycopy(instances, 0, lookupContent, 1, instances.length); 83 84 DEFAULT_LOOKUP.setLookup(lookupContent, cl); 85 } 86 87 } 88 | Popular Tags |