GlueGen: src/java/com/jogamp/common/net/GenericURLStreamHandlerFactory.java Source File

GlueGen v2.6.0-rc-20250721 GlueGen, Native Binding Generator for Java™ (public API).

GenericURLStreamHandlerFactory.java
Go to the documentation of this file.
1package com.jogamp.common.net;
2
3import java.net.URL;
4import java.net.URLStreamHandler;
5import java.net.URLStreamHandlerFactory;
6import java.security.PrivilegedAction;
7import java.util.HashMap;
8import java.util.Map;
9
10import com.jogamp.common.util.SecurityUtil;
11
12 public class GenericURLStreamHandlerFactory implements URLStreamHandlerFactory {
13 private static GenericURLStreamHandlerFactory factory = null;
14
15 private final Map<String, URLStreamHandler> protocolHandlers;
16
17 private GenericURLStreamHandlerFactory() {
18 protocolHandlers = new HashMap<String, URLStreamHandler>();
19 }
20
21 /**
22 * Sets the <code>handler</code> for <code>protocol</code>.
23 *
24 * @return the previous set <code>handler</code>, or null if none was set.
25 */
26 public synchronized final URLStreamHandler setHandler(final String protocol, final URLStreamHandler handler) {
27 return protocolHandlers.put(protocol, handler);
28 }
29
30 /**
31 * Returns the <code>protocol</code> handler previously set via {@link #setHandler(String, URLStreamHandler)},
32 * or null if none was set.
33 */
34 public synchronized final URLStreamHandler getHandler(final String protocol) {
35 return protocolHandlers.get(protocol);
36 }
37
38 @Override
39 public synchronized final URLStreamHandler createURLStreamHandler(final String protocol) {
40 return getHandler(protocol);
41 }
42
43 /**
44 * Returns the singleton instance of the registered GenericURLStreamHandlerFactory
45 * or null if registration was not successful.
46 * <p>
47 * Registration is only performed once.
48 * </p>
49 */
50 public synchronized static GenericURLStreamHandlerFactory register() {
51 if(null == factory) {
52 factory = SecurityUtil.doPrivileged(new PrivilegedAction<GenericURLStreamHandlerFactory>() {
53 @Override
54 public GenericURLStreamHandlerFactory run() {
55 boolean ok = false;
56 final GenericURLStreamHandlerFactory f = new GenericURLStreamHandlerFactory();
57 try {
58 URL.setURLStreamHandlerFactory(f);
59 ok = true;
60 } catch (final Throwable e) {
61 System.err.println("GenericURLStreamHandlerFactory: Setting URLStreamHandlerFactory failed: "+e.getMessage());
62 }
63 return ok ? f : null;
64 } } );
65 }
66 return factory;
67 }
68}
com.jogamp.common.net.GenericURLStreamHandlerFactory
Definition: GenericURLStreamHandlerFactory.java:12
com.jogamp.common.net.GenericURLStreamHandlerFactory.getHandler
synchronized final URLStreamHandler getHandler(final String protocol)
Returns the protocol handler previously set via setHandler(String, URLStreamHandler),...
Definition: GenericURLStreamHandlerFactory.java:34
com.jogamp.common.net.GenericURLStreamHandlerFactory.register
static synchronized GenericURLStreamHandlerFactory register()
Returns the singleton instance of the registered GenericURLStreamHandlerFactory or null if registrati...
Definition: GenericURLStreamHandlerFactory.java:50
com.jogamp.common.net.GenericURLStreamHandlerFactory.setHandler
synchronized final URLStreamHandler setHandler(final String protocol, final URLStreamHandler handler)
Sets the handler for protocol.
Definition: GenericURLStreamHandlerFactory.java:26
com.jogamp.common.net.GenericURLStreamHandlerFactory.createURLStreamHandler
synchronized final URLStreamHandler createURLStreamHandler(final String protocol)
Definition: GenericURLStreamHandlerFactory.java:39
com.jogamp.common.util.SecurityUtil
Definition: SecurityUtil.java:39
com.jogamp.common.util.SecurityUtil.doPrivileged
static< T > T doPrivileged(final PrivilegedAction< T > o)
Call wrapper for java.security.AccessController#doPrivileged(PrivilegedAction).
Definition: SecurityUtil.java:78