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-2000 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.openide.execution;

import java.net.URLStreamHandlerFactory;
import java.net.URLStreamHandler;
import java.util.*;

import org.openide.util.NbBundle;

/** Handle custom URL protocols.
* This class is registered as the
* default stream handler factory for the VM. It comes with several useful
* URL protocols, for accessing IDE-internal resources. You may also add your own.
*
* @author Ales Novak, Petr Hamernik, Jesse Glick
 * @deprecated Instead register URLStreamHandlerFactory instances to Lookup.
*/
public class NbfsStreamHandlerFactory extends Object implements URLStreamHandlerFactory {

    private static NbfsStreamHandlerFactory DEFAULT = null;

    /** Get the default factory instance.
     * @return the default instance
     */
    public static synchronized NbfsStreamHandlerFactory getDefault () {
	if (DEFAULT == null) new NbfsStreamHandlerFactory ();
	return DEFAULT;
    }

    private final Map handlers = new HashMap (); // Map

    /** Create a factory, and preregister several useful protocols.
     * These include:
     * 
*
nbfs *
Locates a particular file on a particular filesystem. * Create such a URL using {@link NbfsURLConnection#encodeFileObject(org.openide.filesystems.FileObject)}. * No longer handled by this factory, but still available. *
nbres *
A resource as loaded by the system (module) classloader. * After the protocol and colon, a resource path beginning with a slash. * No longer handled by this factory, but still available. *
nbrescurr *
As above, but using the current classloader which will also search filesystems. *
nbresloc *
A resource from the system classloader; but will also look for localized variants. * Such variants will have the same package and extension, but the basename may be suffixed * with a locale suffix according to the normal search order and default locale. * No longer handled by this factory, but still available. *
nbrescurrloc *
As above, but using the current classloader. *
nbresboot *
Uses startup classloader (system classpath, no modules). * Deprecated - meaning of "system classpath" is ill-defined. Use nbres instead. *
nbresbootloc *
Startup classloader and localized. * Deprecated - meaning of "system classpath" is ill-defined. Use nbresloc instead. *
* @see NbfsURLConnection * @see NbBundle#getLocalizedFile(String,String,Locale,ClassLoader) */ public NbfsStreamHandlerFactory () { // All deprecated anyway: URLStreamHandler resourceHandler = new NbResourceStreamHandler (); register (NbResourceStreamHandler.PROTOCOL_BOOT_RESOURCE, resourceHandler); register (NbResourceStreamHandler.PROTOCOL_LOCALIZED_BOOT_RESOURCE, resourceHandler); register (NbResourceStreamHandler.PROTOCOL_CURRENT_RESOURCE, resourceHandler); register (NbResourceStreamHandler.PROTOCOL_LOCALIZED_CURRENT_RESOURCE, resourceHandler); // nbfs, nbres, nbresloc now handled by standard core factory synchronized (NbfsURLStreamHandler.class) { if (DEFAULT == null) { DEFAULT = this; } } } /** Register a new stream handler into this factory. * @param protocol the protocol it will recognize * @param handler the handler to register * @throws SecurityException if the protocol is already registered */ public synchronized void register (String protocol, URLStreamHandler handler) throws SecurityException { if (handlers.containsKey (protocol)) throw new SecurityException (NbBundle.getMessage (NbfsStreamHandlerFactory.class, "EXC_protocol_already_registered", protocol)); handlers.put (protocol, handler); } /** Deregister a stream handler. * @param protocol the protocol to deregister * @throws SecurityException if you did not originally register this protocol */ public synchronized void deregister (String protocol) throws SecurityException { // [PENDING] ought to check various conditions and throw secexc if so handlers.remove (protocol); } /** Create a new URL stream handler. * @param protocol the URL protocol. This should have already been registered. * @return a stream handler if a registered protocol was specified, null otherwise */ public synchronized URLStreamHandler createURLStreamHandler(String protocol) { return (URLStreamHandler) handlers.get (protocol); } }
... 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.