org.openide.util.Enumerations Java Examples

The following examples show how to use org.openide.util.Enumerations. 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: IdsGrammarQueryManager.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
@Override
public Enumeration enabled(GrammarEnvironment ctx) {
    FileObject f = ctx.getFileObject();
    if (f != null && !f.getMIMEType().equals(IdsDataObject.SETTINGS_MIME_TYPE)) {
        return null;
    }
    Enumeration en = ctx.getDocumentChildren();
    while (en.hasMoreElements()) {
        Node next = (Node) en.nextElement();
        if (next.getNodeType() == Node.ELEMENT_NODE) {
            Element root = (Element) next;
            if ("resources".equals(root.getNodeName())) { // NOI18N
                return Enumerations.singleton(next);
            }
        }
    }
    return null;
}
 
Example #2
Source File: FileObject.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Enumerate all children of this folder. If the children should be enumerated
* recursively, first all direct children are listed; then children of direct subfolders; and so on.
*
* @param rec whether to enumerate recursively
* @return enumeration of type <code>FileObject</code>
*/
public Enumeration<? extends FileObject> getChildren(final boolean rec) {
    class WithChildren implements Enumerations.Processor<FileObject, FileObject> {
        @Override
        public FileObject process(FileObject fo, Collection<FileObject> toAdd) {
            if (rec && fo.isFolder()) {
                for (FileObject child : fo.getChildren()) {
                    try {
                        if (!FileUtil.isRecursiveSymbolicLink(child)) { // #218795
                            toAdd.add(child);
                        }
                    } catch (IOException ex) {
                        ExternalUtil.LOG.log(Level.INFO, null, ex);
                    }
                }
            }

            return fo;
        }
    }

    return Enumerations.queue(Enumerations.array(getChildren()), new WithChildren());
}
 
Example #3
Source File: MultiFileSystem.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Computes a list of FileObjects in the right order
* that can represent this instance.
*
* @param name of resource to find
* @return enumeration of FileObject
*/
Enumeration<FileObject> delegates(final String name) {
    Enumeration<FileSystem> en = Enumerations.array(systems);

    // XXX order (stably) by weight
    class Resources implements Enumerations.Processor<FileSystem, FileObject> {
        public @Override FileObject process(FileSystem fs, Collection<FileSystem> ignore) {
            if (fs == null) {
                return null;
            } else {
                return findResourceOn(fs, name);
            }
        }
    }

    return Enumerations.filter(en, new Resources());
}
 
Example #4
Source File: MenuGrammarQueryManager.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
@Override
public Enumeration enabled(GrammarEnvironment ctx) {
    FileObject f = ctx.getFileObject();
    if (f != null && !f.getMIMEType().equals(MenuDataObject.SETTINGS_MIME_TYPE)) {
        return null;
    }
    Enumeration en = ctx.getDocumentChildren();
    while (en.hasMoreElements()) {
        Node next = (Node) en.nextElement();
        if (next.getNodeType() == Node.ELEMENT_NODE) {
            Element root = (Element) next;
            if ("menu".equals(root.getNodeName())) { // NOI18N
                return Enumerations.singleton(next);
            }
        }
    }
    return null;
}
 
Example #5
Source File: IntegersGrammarQueryManager.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
@Override
public Enumeration enabled(GrammarEnvironment ctx) {
    FileObject f = ctx.getFileObject();
    if (f != null && !f.getMIMEType().equals(IntegersDataObject.SETTINGS_MIME_TYPE)) {
        return null;
    }
    Enumeration en = ctx.getDocumentChildren();
    while (en.hasMoreElements()) {
        Node next = (Node) en.nextElement();
        if (next.getNodeType() == Node.ELEMENT_NODE) {
            Element root = (Element) next;
            if ("resources".equals(root.getNodeName())) { // NOI18N
                return Enumerations.singleton(next);
            }
        }
    }
    return null;
}
 
Example #6
Source File: BoolsGrammarQueryManager.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
@Override
public Enumeration enabled(GrammarEnvironment ctx) {
    FileObject f = ctx.getFileObject();
    if (f != null && !f.getMIMEType().equals(BoolsDataObject.SETTINGS_MIME_TYPE)) {
        return null;
    }
    Enumeration en = ctx.getDocumentChildren();
    while (en.hasMoreElements()) {
        Node next = (Node) en.nextElement();
        if (next.getNodeType() == Node.ELEMENT_NODE) {
            Element root = (Element) next;
            if ("resources".equals(root.getNodeName())) { // NOI18N
                return Enumerations.singleton(next);
            }
        }
    }
    return null;
}
 
Example #7
Source File: WritableXMLFileSystem.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Enumeration<String> attributes(String name) {
    TreeElement el = findElement(name);
    if (el == null) {
        return Enumerations.empty();
    }
    java.util.List<String> l = new ArrayList<String>(10);
    Iterator<TreeElement> it = el.getChildNodes(TreeElement.class).iterator();
    while (it.hasNext()) {
        TreeElement sub = it.next();
        if (sub.getLocalName().equals("attr")) { // NOI18N
            TreeAttribute nameAttr = sub.getAttribute("name"); // NOI18N
            if (nameAttr == null) {
                // Malformed.
                continue;
            }
            l.add(nameAttr.getValue());
        }
    }
    return Collections.enumeration(l);
}
 
Example #8
Source File: NbCollections.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Create a typesafe filter of an unchecked enumeration.
 * @param rawEnum an unchecked enumeration
 * @param type the desired enumeration type
 * @param strict if false, elements which are not null but not assignable to the requested type are omitted;
 *               if true, {@link ClassCastException} may be thrown from an enumeration operation
 * @return an enumeration guaranteed to contain only objects of the requested type (or null)
 */
public static <E> Enumeration<E> checkedEnumerationByFilter(Enumeration<?> rawEnum, final Class<E> type, final boolean strict) {
    @SuppressWarnings("unchecked")
    Enumeration<?> _rawEnum = rawEnum;
    return Enumerations.<Object,E>filter(_rawEnum, new Enumerations.Processor<Object,E>() {
        public E process(Object o, Collection<Object> ignore) {
            if (o == null) {
                return null;
            } else {
                try {
                    return type.cast(o);
                } catch (ClassCastException x) {
                    if (strict) {
                        throw x;
                    } else {
                        return null;
                    }
                }
            }
        }
    });
}
 
Example #9
Source File: FlatSearchIterator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 */
public FlatSearchIterator(FileObject root,
        SearchScopeOptions options,
        List<SearchFilterDefinition> filters,
        SearchListener listener,
        AtomicBoolean terminated) {
    this.rootFile = root;
    if (rootFile.isFolder()) {
        this.childrenEnum = SimpleSearchIterator.sortEnum(
                rootFile.getChildren(false));
    } else {
        this.childrenEnum = Enumerations.singleton(rootFile);
    }
    this.listener = listener;
    this.fileNameMatcher = FileNameMatcher.create(options);
    this.filterHelper = new FilterHelper(filters, options);
    this.terminated = terminated;
}
 
Example #10
Source File: SimpleSearchIterator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 */
public SimpleSearchIterator(FileObject root,
        SearchScopeOptions options,
        List<SearchFilterDefinition> filters,
        SearchListener listener,
        AtomicBoolean terminated) {
    this.rootFile = root;
    if (rootFile.isFolder()) {
        this.childrenEnum = sortEnum(rootFile.getChildren(false));
    } else {
        this.childrenEnum = Enumerations.singleton(rootFile);
    }
    this.listener = listener;
    this.fileNameMatcher = FileNameMatcher.create(options);
    this.searchInArchives = options.isSearchInArchives();
    this.filterHelper = new FilterHelper(filters, options);
    this.terminated = terminated;
}
 
Example #11
Source File: ModuleManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
synchronized Enumeration<URL> getResourcesImpl(String name) throws IOException {
    if (JRE_PROVIDED_FACTORIES.contains(name)) {
        // #146082: prefer JRE versions of JAXP factories when available.
        // #147082: use empty file rather than null (~ delegation to ClassLoader.systemClassLoader) to work around JAXP #6723276
        return parents.systemCL().getResources(name);
    } else {
        Enumeration<URL> first = super.getResourcesImpl(name);
        ClassLoader l = netigso.findFallbackLoader();
        if (l != null && l != this) {
            return Enumerations.removeDuplicates(
                Enumerations.concat(first, l.getResources(name))
            );
        } else {
            return first;
        }
    }
}
 
Example #12
Source File: Module.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Locates resource in this module. May search only the main JAR
 * of the module (which is what it does in case of OSGi bundles). 
 * Should be as lightweight as possible - e.g. if it is OK to not
 * initialize something in the module while performing this method,
 * the something should not be initialized (e.g. OSGi bundles are
 * not resolved).
 * 
 * @param resources path to the resources we are looking for
 * @since 2.49
 */
public Enumeration<URL> findResources(String resources) {
    try { // #149136
        // Cannot use getResources because we do not wish to delegate to parents.
        // In fact both URLClassLoader and ProxyClassLoader override this method to be public.
        if (findResources == null) {
            findResources = ClassLoader.class.getDeclaredMethod("findResources", String.class); // NOI18N
            findResources.setAccessible(true);
        }
        ClassLoader cl = getClassLoader();
        @SuppressWarnings("unchecked")
        Enumeration<URL> en = (Enumeration<URL>) findResources.invoke(cl, resources); // NOI18N
        return en;
    } catch (Exception x) {
        Exceptions.printStackTrace(x);
        return Enumerations.empty();
    }
}
 
Example #13
Source File: ColorsGrammarQueryManager.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
@Override
public Enumeration enabled(GrammarEnvironment ctx) {
    FileObject f = ctx.getFileObject();
    if (f != null && !f.getMIMEType().equals(ColorsDataObject.SETTINGS_MIME_TYPE)) {
        return null;
    }
    Enumeration en = ctx.getDocumentChildren();
    while (en.hasMoreElements()) {
        Node next = (Node) en.nextElement();
        if (next.getNodeType() == Node.ELEMENT_NODE) {
            Element root = (Element) next;
            if ("resources".equals(root.getNodeName())) { // NOI18N
                return Enumerations.singleton(next);
            }
        }
    }
    return null;
}
 
Example #14
Source File: NetigsoLoader.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Enumeration<URL> findResources(String name) {
    //Netigso.start();
    Bundle b = bundle;
    if (b == null) {
        LOG.log(Level.WARNING, "Trying to load resource before initialization finished {0}", name);
        return Enumerations.empty();
    }
    Enumeration<URL> ret = null;
    try {
        if (b.getState() != Bundle.UNINSTALLED) {
            ret = b.getResources(name);
        }
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    return ret == null ? Enumerations.<URL>empty() : NbCollections.checkedEnumerationByFilter(ret, URL.class, true);
}
 
Example #15
Source File: StringsGrammarQueryManager.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
@Override
public Enumeration enabled(GrammarEnvironment ctx) {
    FileObject f = ctx.getFileObject();
    if (f != null && !f.getMIMEType().equals(StringsDataObject.SETTINGS_MIME_TYPE)) {
        return null;
    }
    Enumeration en = ctx.getDocumentChildren();
    while (en.hasMoreElements()) {
        Node next = (Node) en.nextElement();
        if (next.getNodeType() == Node.ELEMENT_NODE) {
            Element root = (Element) next;
            if ("resources".equals(root.getNodeName())) { // NOI18N
                return Enumerations.singleton(next);
            }
        }
    }
    return null;
}
 
Example #16
Source File: UnknownValuesGrammarQueryManager.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
@Override
public Enumeration enabled(GrammarEnvironment ctx) {
    FileObject f = ctx.getFileObject();
    if (f != null && !f.getMIMEType().equals(UnknownValuesDataObject.SETTINGS_MIME_TYPE)) {
        return null;
    }
    Enumeration en = ctx.getDocumentChildren();
    while (en.hasMoreElements()) {
        Node next = (Node) en.nextElement();
        if (next.getNodeType() == Node.ELEMENT_NODE) {
            Element root = (Element) next;
            if ("resources".equals(root.getNodeName())) { // NOI18N
                return Enumerations.singleton(next);
            }
        }
    }
    return null;
}
 
Example #17
Source File: DimensGrammarQueryManager.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
@Override
public Enumeration enabled(GrammarEnvironment ctx) {
    FileObject f = ctx.getFileObject();
    if (f != null && !f.getMIMEType().equals(DimensDataObject.SETTINGS_MIME_TYPE)) {
        return null;
    }
    Enumeration en = ctx.getDocumentChildren();
    while (en.hasMoreElements()) {
        Node next = (Node) en.nextElement();
        if (next.getNodeType() == Node.ELEMENT_NODE) {
            Element root = (Element) next;
            if ("resources".equals(root.getNodeName())) { // NOI18N
                return Enumerations.singleton(next);
            }
        }
    }
    return null;
}
 
Example #18
Source File: SymbolsGrammarQueryManager.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
@Override
public Enumeration enabled(GrammarEnvironment ctx) {
    FileObject f = ctx.getFileObject();
    if (f != null && !f.getMIMEType().equals(SymbolsDataObject.SETTINGS_MIME_TYPE)) {
        return null;
    }
    Enumeration en = ctx.getDocumentChildren();
    while (en.hasMoreElements()) {
        Node next = (Node) en.nextElement();
        if (next.getNodeType() == Node.ELEMENT_NODE) {
            Element root = (Element) next;
            if ("resources".equals(root.getNodeName())) { // NOI18N
                return Enumerations.singleton(next);
            }
        }
    }
    return null;
}
 
Example #19
Source File: MultiFileSystem.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Finds all hidden files on given filesystem. The methods scans all files for
* ones with hidden extension and returns enumeration of names of files
* that are hidden.
*
* @param folder folder to start at
* @param rec proceed recursivelly
* @return enumeration of String with names of hidden files
*/
protected static Enumeration<String> hiddenFiles(FileObject folder, boolean rec) {
    Enumeration<? extends FileObject> allFiles = folder.getChildren(rec);

    class OnlyHidden implements Enumerations.Processor<FileObject, String> {
        public @Override String process(FileObject obj, Collection<FileObject> ignore) {
            String sf = obj.getPath();

            if (sf.endsWith(MASK)) {
                return sf.substring(0, sf.length() - MASK.length());
            } else {
                return null;
            }
        }
    }

    return Enumerations.filter(allFiles, new OnlyHidden());
}
 
Example #20
Source File: ServiceType.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Get all available services that are assignable to the given superclass.
* @param clazz the class that all services should be subclass of
* @return an enumeration of all matching {@link ServiceType}s
*/
public <T extends ServiceType> Enumeration<T> services(final Class<T> clazz) {
    class IsInstance implements Enumerations.Processor<ServiceType,T> {
        public T process(ServiceType obj, Collection ignore) {
            return clazz.isInstance(obj) ? clazz.cast(obj) : null;
        }
    }

    return Enumerations.filter(services(), new IsInstance());
}
 
Example #21
Source File: EnumerationsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected <T,R> Enumeration<R> convert(Enumeration<T> en, final Map<T,R> map) {
    class P implements Enumerations.Processor<T,R> {
        public R process(T obj, Collection<T> nothing) {
            return map.get(obj);
        }
    }
    return Enumerations.convert(en, new P());
}
 
Example #22
Source File: AntBridge.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Enumeration<URL> getResources(String name) throws IOException {
    Enumeration<URL> res =  super.getResources(name);
    if (isFromContextClassLoader(name, false)) {
        final Enumeration<URL> cclRes = contextClassLoader.getResources(name);
        res = Enumerations.concat(res, cclRes);
    }
    return res;
}
 
Example #23
Source File: AngularDoc.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void startLoading() {
    LOG.fine("start loading doc"); //NOI18N
    Directive[] dirs = Directive.values();
    directives = Enumerations.array(dirs);
    progress = ProgressHandleFactory.createHandle(Bundle.doc_building());
    progress.start(dirs.length);

    buildDoc();
}
 
Example #24
Source File: AuxClassLoader.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Enumeration<URL> findResources(String name) throws IOException {
    // XXX probably wrong now... try to fix somehow
    return Enumerations.removeDuplicates (
        Enumerations.concat (
            nbLoader.getResources(name), 
            super.findResources(name)
        )
    );
}
 
Example #25
Source File: BaseFileObj.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Enumeration<FileChangeListener> getListeners() {
    synchronized (EVENT_SUPPORT_LOCK) {
        if (eventSupport == null) {
            return Enumerations.empty();
        }
        return Enumerations.array(eventSupport.getListeners(FileChangeListener.class));
    }
}
 
Example #26
Source File: OperationListenerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected Enumeration loaders () {
    if (extra == null) {
        return Enumerations.empty ();
    } else {
        return Enumerations.singleton (extra);
    }
}
 
Example #27
Source File: EnumerationsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * @param filter the set.contains (...) is called before each object is produced
 * @return Enumeration
 */
protected <T,R> Enumeration<R> queue(Collection<T> initContent, final QueueProcess<T,R> process) {
    class C implements Enumerations.Processor<T,R> {
        public R process(T object, Collection<T> toAdd) {
            return process.process(object, toAdd);
        }
    }
    return Enumerations.queue(
            Collections.enumeration(initContent),
            new C()
            );
}
 
Example #28
Source File: BinaryFS.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Get all file attribute names for this file. */
public Enumeration<String> getAttributes() {
    initialize();
    if (attrs == null) {
        return Enumerations.empty();
    }
    return Collections.enumeration(attrs.keySet());
}
 
Example #29
Source File: PUDataObjectTestBase.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public Enumeration loaders() {
    return Enumerations.singleton(new PUDataLoader());
}
 
Example #30
Source File: CanYouQueryFromRenameTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public Enumeration<? extends DataLoader> loaders() {
    return Enumerations.<DataLoader>singleton(DataLoader.getLoader(MyLoader.class));
}