Java Code Examples for org.openide.util.lookup.AbstractLookup#Pair
The following examples show how to use
org.openide.util.lookup.AbstractLookup#Pair .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CookieSet.java From netbeans with Apache License 2.0 | 6 votes |
static void enhancedQueryMode(Lookup lookup, Class<?> clazz) { Object type = QUERY_MODE.get(); if (type != clazz) { return; } Collection<? extends Lookup.Item<?>> items = lookup.lookupResult(clazz).allItems(); if (items.size() == 0) { return; } AbstractLookup.Pair[] arr = new AbstractLookup.Pair[items.size()]; Iterator<? extends Lookup.Item> it = items.iterator(); for (int i = 0; i < arr.length; i++) { arr[i] = new PairWrap(it.next()); } QUERY_MODE.set(arr); }
Example 2
Source File: CookieSet.java From netbeans with Apache License 2.0 | 5 votes |
/** Exits query mode. */ static Collection<AbstractLookup.Pair> exitQueryMode(Object prev) { Object cookie = QUERY_MODE.get(); QUERY_MODE.set(prev); if (cookie instanceof CookieSet.CookieEntry) { return Collections.singleton((AbstractLookup.Pair)new CookieEntryPair((CookieSet.CookieEntry) cookie)); } else if (cookie instanceof AbstractLookup.Pair[]) { return Arrays.asList((AbstractLookup.Pair[])cookie); } else { return null; } }
Example 3
Source File: MIMESupport69049Test.java From netbeans with Apache License 2.0 | 4 votes |
public void testProblemWithRecursionInIssue69049() throws Throwable { Lkp lkp = (Lkp)Lookup.getDefault(); @SuppressWarnings("unchecked") class Pair extends AbstractLookup.Pair implements Runnable { public MIMEResolver[] all; public MIMEResolver[] all2; public Throwable ex; public RequestProcessor.Task wait; protected boolean instanceOf(Class c) { LOG.info("instanceOf: " + c); return c.isAssignableFrom(getType()); } protected boolean creatorOf(Object obj) { LOG.info("creatorOf: " + obj); return false; } public Object getInstance() { LOG.info("getInstance: " + all); if (all == null) { all = MIMESupport.getResolvers(); assertNotNull("Computed", all); } else { all2 = MIMESupport.getResolvers(); assertNotNull("Computed", all2); } LOG.info("after getInstance: " + all + " and " + all2); return null; } public Class getType() { return MIMEResolver.class; } public String getId() { return getType().getName(); } public String getDisplayName() { return getId(); } public void run() { try { LOG.info("running"); if (wait != null) wait.waitFinished(); all = MIMESupport.getResolvers(); LOG.info("finishing"); } catch (Throwable e) { LOG.log(Level.INFO, "ending with exception", e); ex = e; } } public void assertResults() throws Throwable { if (ex != null) { throw ex; } MIMESupportHid.assertNonDeclarativeResolver("c1 is there", Lkp.c1, all); } } lkp.turn(Lkp.c1); Pair p = new Pair(); lkp.ic.addPair(p); Pair run1 = new Pair(); Pair run2 = new Pair(); LOG.info("Starting the tasks"); RequestProcessor.Task t2 = new RequestProcessor("t2").post(run2, 20, Thread.NORM_PRIORITY); run1.wait = t2; RequestProcessor.Task t1 = new RequestProcessor("t1").post(run1); t1.waitFinished(); t2.waitFinished(); LOG.info("Waiting for the tasks to finish"); assertTrue("t1 done", t1.isFinished()); assertTrue("t2 done", t2.isFinished()); run1.assertResults(); run2.assertResults(); assertNotNull("Been in the query", p.all); assertEquals("In query we cannot do better than nothing", 0, p.all.length); }
Example 4
Source File: Lookup.java From netbeans with Apache License 2.0 | 4 votes |
private void fillServiceInstance(Item<T> li) { String className = getClassName(li); Object instance = null; synchronized(instanceCache) { instance = instanceCache.get (className); Object origInstance = origInstanceCache.get(className); Item lastItem = lookupItemsCache.get(className); if (origInstance != null && li instanceof AbstractLookup.Pair && lastItem != null && lastItem.getId().equals(li.getId())) { // Check whether the cached original instance was created by this lookup item. // If yes, we can use it, if not, we should create a new instance. // Verify whether the item is from the same registry file, // since there can be several registrations for one class instance. try { java.lang.reflect.Method creatorOfMethod = AbstractLookup.Pair.class.getDeclaredMethod("creatorOf", Object.class); creatorOfMethod.setAccessible(true); Object isCreator = creatorOfMethod.invoke(li, origInstance); if (logger.isLoggable(Level.FINE)) { logger.fine("fillServiceInstance("+li+" [HASH = "+System.identityHashCode(li)+"]):"); logger.fine(" className = \""+className+"\", orig instance = "+origInstance+", instance = "+instance+", is creator of = "+isCreator); if (lastItem != null) { logger.fine(" last item was "+lastItem+" [HASH = "+System.identityHashCode(lastItem)+"])"); } if (!Boolean.TRUE.equals(isCreator)) { logger.fine("\n!!!\n"+li+" is not a creator of "+origInstance+" !\nCreating a new instance..."); } } if (!Boolean.TRUE.equals(isCreator)) { instance = null; instanceCache.remove(className); origInstanceCache.remove(className); lookupItemsCache.remove(className); } } catch (Exception ex) { Exceptions.printStackTrace(ex); } } } // remember the instance position for merge purpose: li.fo.getAttribute("position") int position = getPosition(li); while (elementPositions.size() < size()) { elementPositions.add(Integer.MAX_VALUE); } elementPositions.add(position); if (instance != null) { try { add(service.cast(instance), className); } catch (ClassCastException cce) { logger.log(Level.WARNING, null, cce); } listenOn(instance.getClass().getClassLoader()); } else { add(new LazyInstance<T>(service, li)); } }