alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.masterfs;

import org.openide.filesystems.*;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;
import org.openide.ErrorManager;

import java.io.File;
import java.io.IOException;
import java.util.MissingResourceException;
import java.util.Set;
import java.util.Iterator;
import java.util.HashSet;
import java.awt.*;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;

public class Utils {

    static String getString(String s) {
        try {
            return NbBundle.getBundle("org.netbeans.modules.masterfs.resources.Bundle", //NOI18N
                    java.util.Locale.getDefault(), MasterFileSystem.class.getClassLoader()).getString(s);
        } catch (MissingResourceException msx) {
            return "";
        }
    }

    static String formatString(String excName, Object[] args) {
        String format = getString(excName);
        if (args == null)
            return format;
        else
            return java.text.MessageFormat.format(format, args);
    }

    static void throwIOException(String format, Object[] args) throws IOException {
        throwIOException(new IOException(formatString(format, args)));
    }

    static void throwIOException(IOException exc2Fire) throws IOException {
        ErrorManager.getDefault().annotate(exc2Fire, ErrorManager.WARNING, null,
                exc2Fire.getLocalizedMessage(), null, null);
        throw exc2Fire;
    }

    static Image getRootIcon(int iconType, Object obj) {
        try {
            BeanInfo bI = Utilities.getBeanInfo(obj.getClass());
            Image img = bI.getIcon(iconType);
            return img;
        } catch (IntrospectionException iex) {
            return null;
        }
    }

    static MasterFileObject transformSet(Set files, Set transformedSet) {
        MasterFileObject hfo = null;
        Iterator it = files.iterator();
        while (it.hasNext()) {

            Object obj = it.next();
            if (obj instanceof MasterFileObject) {
                hfo = ((MasterFileObject) obj);
                FileObject fo = hfo.getDelegate().get();
                if (fo != null) {
                    transformedSet.add(fo);
                }
            }
        }
        return hfo;
    }

    static ResourcePath getResource (File f) {
        String path;
        try {
            path = f.getCanonicalPath();
        } catch (IOException iex) {
            path = f.getAbsolutePath();
        }
        return new ResourcePath (path);
    }

    static Set transformToDelegates(java.util.Set foSet, boolean prefered) {
        Set retVal = new HashSet();
        Iterator it = foSet.iterator();
        while (it.hasNext()) {
            Object obj = it.next();
            if (obj instanceof MasterFileObject) {
                FileObject fo;
                if (prefered) {                  
                    MasterFileObject hfo = (MasterFileObject) obj;
                    fo = hfo.getDelegate().getPrefered();
                } else {
                    MasterFileObject hfo = (MasterFileObject) obj;
                    fo = hfo.getDelegate().get();
                }

                if (fo != null)
                    retVal.add(fo);
            }
        }
        return retVal;
    }

}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.