Java 类org.openide.util.Lookup.Item 实例源码

项目:incubator-netbeans    文件:ProvidedExtensionsTest.java   
private ProvidedExtensionsImpl lookupImpl(boolean providesCanWrite) {
    Result<BaseAnnotationProvider> result = Lookup.getDefault().
                   lookup(new Lookup.Template(BaseAnnotationProvider.class));
    for (Item<BaseAnnotationProvider> item : result.allItems()) {
        if (!item.getId().contains(ProvidedExtensionsTest.class.getSimpleName())) {
            continue;
        }
        BaseAnnotationProvider ap = item.getInstance();
        InterceptionListener iil = ap.getInterceptionListener();
        if (iil instanceof ProvidedExtensionsImpl) {
            ProvidedExtensionsImpl extension = (ProvidedExtensionsImpl) iil;
            if (ProvidedExtensionsAccessor.IMPL.providesCanWrite(extension) == providesCanWrite) {
                return (ProvidedExtensionsImpl) iil;
            }
        }
    }
    return null;
}
项目:incubator-netbeans    文件:FilterNode.java   
@Override
public <T> Item<T> lookupItem(Template<T> template) {
    boolean nodeQ = isNodeQuery(template.getType());
    Item<T> i = checkNode().lookupItem(template);

    if (
        nodeQ && 
        i == null && 
        template.getType().isInstance(node) &&
        (template.getInstance() == null || template.getInstance() == node)
    ) {
        i = checkNode().lookupItem(wackohacko(template.getId(), template.getInstance()));
    }

    return nodeQ && i != null ? new FilterItem<T>(i, template.getType()) : i;
}
项目:incubator-netbeans    文件:QuickSearchProvider.java   
@Override
   public void evaluate(SearchRequest request, SearchResponse response) {
readKeywordsFromNewAnnotation();
       for (Lookup.Item<OptionsCategory> entry : getODCategories()) {
           for (Map.Entry<String, Set<String>> kw : getKeywords(entry).entrySet()) {
               for (String keywords : kw.getValue()) {
        for (String keyword : Arrays.asList(keywords.split(","))) {
        if (keyword.toLowerCase().indexOf(request.getText().toLowerCase()) > -1) {
            String path = entry.getId().substring(entry.getId().indexOf("/") + 1);  // NOI18N
            if (kw.getKey().contains("/")) {
            path = path + kw.getKey().substring(kw.getKey().indexOf("/")); //NOI18N
            }
            if (!response.addResult(new OpenOption(path), keyword)) {
            return;
            }
        }
        }
               }
           }
       }
   }
项目:incubator-netbeans    文件:Lookup.java   
private int getPosition(Item<T> li) {
    int position = Integer.MAX_VALUE;
    try {
        Field foField = li.getClass().getDeclaredField("fo");
        foField.setAccessible(true);
        FileObject fo = (FileObject) foField.get(li);
        if (fo != null) {
            Object positionObj = fo.getAttribute("position");
            if (positionObj instanceof Integer) {
                position = (Integer) positionObj;
            }
        }
    } catch (Exception ex) {
        logger.log(Level.INFO, "Not able to retieve position from item "+li, ex);
    }
    return position;
}
项目:incubator-netbeans    文件:PathLookup.java   
@Override
public Collection<? extends T> allInstances() {
    //return new PathLookupCollection(orig.allInstances(), n);
    Collection<? extends Item<T>> items = getItems();
    if (items == ORIG_ITEMS) {
        return orig.allInstances();
    }
    ArrayList<T> list = new ArrayList<T>(items.size());
    for (Item<T> item : items) {
        T obj = item.getInstance();

        if (clazz.isInstance(obj)) {
            list.add(obj);
        }
    }

    return Collections.unmodifiableList(list);
}
项目:incubator-netbeans    文件:PathLookup.java   
@Override
public Set<Class<? extends T>> allClasses() {
    //return new PathLookupSet(orig.allClasses(), n);
    Collection<? extends Item<T>> items = getItems();
    if (items == ORIG_ITEMS) {
        return orig.allClasses();
    }
    Set<Class<? extends T>> s = new HashSet<Class<? extends T>>();
    for (Item<T> item : items) {
        Class<? extends T> clazz = item.getType();

        if (clazz != null) {
            s.add(clazz);
        }
    }
    s = Collections.unmodifiableSet(s);
    return s;
}
项目:incubator-netbeans    文件:MavenQueryProvider.java   
public MavenQueryProvider() {
    grammars = new ArrayList<GrammarFactory>();
    Result<GrammarFactory> result = Lookup.getDefault().lookupResult(GrammarFactory.class);
    Collection<? extends Item<GrammarFactory>> items = result.allItems();
    for (Item<GrammarFactory> item : items) {
        grammars.add(item.getInstance());
    }

}
项目:incubator-netbeans    文件:FilterNode.java   
/** Updates the state of the lookup.
 * @return true if the lookup really changed
 */
public boolean updateLookup(Lookup l) {
    Collection<? extends Item<T>> oldPairs = (delegate != null) ? delegate.allItems() : null;

    synchronized (this) {
        if (delegate != null) {
            delegate.removeLookupListener(this);
        }

        delegate = l.lookup(template);

        if (template.getType().isAssignableFrom(node.getClass()) && delegate.allItems().isEmpty()) {
            delegate = l.lookup(wackohacko(template.getId(), template.getInstance()));
        }

        delegate.addLookupListener(this);
    }

    if (oldPairs == null) {
        // nobody knows about a change
        return false;
    }

    Collection<? extends Item<T>> newPairs = delegate.allItems();

    return !oldPairs.equals(newPairs);
}
项目:incubator-netbeans    文件:MIMEResolverProcessorTest.java   
private static MIMEResolver findResolver(String name) {
    final Collection<? extends Item<MIMEResolver>> arr = Lookups.forPath("Services/MIMEResolver").lookupResult(MIMEResolver.class).allItems();
    for (Lookup.Item<MIMEResolver> i : arr) {
        if (i.getDisplayName().equals(name)) {
            return i.getInstance();
        }
    }
    fail("Cannot find resolver name: " + name + " but found " + arr);
    return null;
}
项目:incubator-netbeans    文件:Lookup.java   
private void fillInstances(List<String> l, Result<T> lr, Set<String> s) {
    for (String className : l) {
        if (className.endsWith(HIDDEN)) {
            continue;
        }
        if (s != null && s.contains (className)) {
            continue;
        }
        fillClassInstance(className);
    }
    for (Item<T> li : lr.allItems()) {
        // TODO: We likely do not have the Item.getId() defined correctly.
        // We have to check the ContextAwareService.serviceID()
        String serviceName = getServiceName(li.getId());
        //System.err.println("ID = '"+li.getId()+"' => serviceName = '"+serviceName+"'");
        // We do not recognize method calls correctly
        if (s != null && (s.contains (serviceName) || s.contains (serviceName+"()"))) {
            continue;
        }
        //add(new LazyInstance<T>(service, li));
        fillServiceInstance(li);
    }
    /*
    for (Object lri : lr.allInstances()) {
        if (lri instanceof ContextAwareService) {
            String className = ((ContextAwareService) lri).serviceName();
            if (s != null && s.contains (className)) continue;
            fillClassInstance(className);
        }
    }
     */
}
项目:incubator-netbeans    文件:Lookup.java   
private String getClassName(Item li) {
    String id = li.getId();
    int i = id.lastIndexOf("/");
    if (i >= 0) {
        id = id.substring(i+1);
    }
    return id.replace('-', '.');
}
项目:incubator-netbeans    文件:PathLookup.java   
private static <T> List<Item<T>> itemsJustForPath(Class<T> clazz, Result<T> result, String path) {
    int l = path.length() + 1;
    Collection<? extends Item<T>> allItems = result.allItems();
    List<Item<T>> pathItems = new ArrayList<Item<T>>(allItems.size());
    for (Item<T> it : allItems) {
        String filePath = it.getId();
        assert filePath.startsWith(path) : "File path '"+filePath+"' does not start with searched path '"+path+"'";
        if (filePath.indexOf('/', l) < l) {
            // This item is from current folder
            if (clazz.isInterface()) {
                // Check whether the lookup item is really declared as an instance of the class we search for:
                FileObject fo = FileUtil.getConfigFile(filePath+".instance");
                if (fo != null) {
                    Object io = fo.getAttribute("instanceOf"); // NOI18N
                    if (io != null) {
                        if (((String) io).indexOf(clazz.getName()) < 0) {
                            continue;
                        }
                    }
                }
            }
            pathItems.add(it);
        }
    }
    if (pathItems.size() == allItems.size()) {
        return (List<Item<T>>) ORIG_ITEMS;
    }
    return pathItems;
}
项目:incubator-netbeans    文件:PathLookup.java   
@Override
public Collection<? extends Item<T>> allItems() {
    Collection<? extends Item<T>> items = getItems();
    if (items == ORIG_ITEMS) {
        return orig.allItems();
    } else {
        return items;
    }
}
项目:incubator-netbeans    文件:ContextManager.java   
@Override
public Collection<? extends Item<T>> allItems() {
    Collection<? extends Item<T>> res = delegate.allItems();
    synchronized (this) {
        if (!res.isEmpty()) {
            allItems = res;
        }
        return allItems;
    }
}
项目:incubator-netbeans    文件:ContextManager.java   
@Override
public void resultChanged(LookupEvent ev) {
    if (ev.getSource() == nodes) {
        Collection<? extends Item<Provider>> arr = nodes.allItems();
        if (arr.size() == 1 && arr.iterator().next().getInstance() == null) {
            return;
        }
        initValues();
        return;
    }
    final LookupEvent mev = new LookupEvent(this);
    for (LookupListener ll : listeners) {
        ll.resultChanged(mev);
    }
}
项目:Joeffice    文件:OfficeUIUtils.java   
/**
 * Retrieves an action instance
 * @param category e.g., "Maps"
 * @param id e.g., "com-emxsys-worldwind-ribbon-actions-ToggleLayerAction"
 * @return the Action instance or null
 * @see http://forums.netbeans.org/topic44790.html
 */
@Deprecated
public static Action getAction(String category, String id) {
    String folder = "Actions/" + category + "/";
    Lookup pathLookup = Lookups.forPath(folder);

    Template<Action> actionTemplate = new Template<>(Action.class, folder + id, null);
    Item<Action> item = pathLookup.lookupItem(actionTemplate);
    if (item != null) {
        return item.getInstance();
    }
    return null;
}
项目:incubator-netbeans    文件:NetigsoServicesTest.java   
public void testOSGiServicesVisibleInLookup() throws Exception {
    mgr.mutexPrivileged().enterWriteAccess();
    FileObject fo;
    try {
        String mfBar = "Bundle-SymbolicName: org.bar\n" +
            "Bundle-Version: 1.1.0\n" +
            "Bundle-ManifestVersion: 2\n" +
            "Import-Package: org.foo\n" +
            "\n\n";

        File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar);
        Module m2 = mgr.create(j2, null, false, false, false);
        mgr.enable(m2);
    } finally {
        mgr.mutexPrivileged().exitWriteAccess();
    }

    Bundle b = findBundle("org.bar");
    assertNotNull("Bundle really found", b);
    IOException s = new IOException();
    Hashtable dict = new Hashtable();
    dict.put(Constants.SERVICE_DESCRIPTION, "tristatricettri");
    ServiceRegistration sr = b.getBundleContext().registerService(IOException.class.getName(), s, dict);
    assertBundles("Nobody is using the service yet", 0, sr.getReference().getUsingBundles());
    IOException found = Lookup.getDefault().lookup(IOException.class);
    assertNotNull("Result really found", found);
    assertBundles("Someone is using the service now", 1, sr.getReference().getUsingBundles());
    Result<IOException> res = Lookup.getDefault().lookupResult(IOException.class);
    res.addLookupListener(this);
    assertEquals("One instance found", 1, res.allInstances().size());

    Collection<? extends Item<IOException>> items = res.allItems();
    assertEquals("One item found: " + items, 1, items.size());
    Item<IOException> first = items.iterator().next();
    String expectedServiceID = "OSGiService[" + sr.getReference().getProperty(Constants.SERVICE_ID) + "]";
    assertEquals("Proper ID", expectedServiceID, first.getId());
    assertEquals("Right display name", "tristatricettri", first.getDisplayName());

    sr.unregister();
    IOException notFound = Lookup.getDefault().lookup(IOException.class);
    assertNull("Result not found", notFound);
    assertEquals("No instance found", 0, res.allInstances().size());
    assertEquals("One change", 1, cnt);
}
项目:incubator-netbeans    文件:FilterNode.java   
@Override
public Collection<? extends Item<T>> allItems() {
    return checkResult().allItems();
}
项目:incubator-netbeans    文件:FilterNode.java   
FilterItem(Item<T> d, Class<T> clazz) {
    this.delegate = d;
    this.clazz = clazz;
}
项目:incubator-netbeans    文件:QuickSearchProvider.java   
private Iterable<? extends Lookup.Item<OptionsCategory>> getODCategories() {
    Lookup lookup = Lookups.forPath(CategoryModel.OD_LAYER_FOLDER_NAME);
    Lookup.Result<OptionsCategory> result = lookup.lookupResult(OptionsCategory.class);
    return result.allItems();
}
项目:incubator-netbeans    文件:Lookup.java   
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));
    }
}
项目:incubator-netbeans    文件:Lookup.java   
public LazyInstance(Class<T> service, Item<T> lookupItem) {
    this.service = service;
    this.lookupItem = lookupItem;
}
项目:incubator-netbeans    文件:PathLookup.java   
@Override
public <T> T lookup(Class<T> clazz) {
    Item<T> item = lookupItem(new Template<T>(clazz));
    return (item == null) ? null : item.getInstance();
}
项目:incubator-netbeans    文件:PathLookup.java   
private synchronized Collection<Item<T>> getItems() {
    if (items == null) {
        items = itemsJustForPath(clazz, orig, path);
    }
    return items;
}
项目:btrace.nb    文件:AbstractToolbarAction.java   
public <T> Item<T> lookupItem(Template<T> template) {
    return lookup.lookupItem(template);
}
项目:btrace.nb    文件:AbstractToolbarAction.java   
public <T> Item<T> lookupItem(Template<T> template) {
    return lookup.lookupItem(template);
}