This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 129772
Collapse All | Expand All

(-)a/core.startup/src/META-INF/services/java.net.URLStreamHandlerFactory (-1 / +1 lines)
Lines 1-2 Link Here
1
org.netbeans.core.startup.NbURLStreamHandlerFactory
1
org.netbeans.core.startup.layers.NbinstURLStreamHandlerFactory
2
org.netbeans.core.startup.layers.NbinstURLStreamHandlerFactory
2
(-)a/core.startup/src/org/netbeans/core/startup/Main.java (-13 / +2 lines)
Lines 46-55 Link Here
46
import java.io.IOException;
46
import java.io.IOException;
47
import java.lang.reflect.Method;
47
import java.lang.reflect.Method;
48
import java.net.URL;
48
import java.net.URL;
49
import java.util.Iterator;
50
import javax.swing.SwingUtilities;
49
import javax.swing.SwingUtilities;
51
import javax.swing.UIManager;
50
import javax.swing.UIManager;
52
import org.netbeans.JarClassLoader;
51
import org.netbeans.ProxyURLStreamHandlerFactory;
53
import org.netbeans.Stamps;
52
import org.netbeans.Stamps;
54
import org.netbeans.Util;
53
import org.netbeans.Util;
55
import org.openide.filesystems.FileObject;
54
import org.openide.filesystems.FileObject;
Lines 61-67 Link Here
61
import org.openide.util.Exceptions;
60
import org.openide.util.Exceptions;
62
import org.openide.util.Lookup;
61
import org.openide.util.Lookup;
63
import org.openide.util.NbBundle;
62
import org.openide.util.NbBundle;
64
import org.openide.util.RequestProcessor;
65
import org.openide.util.Utilities;
63
import org.openide.util.Utilities;
66
64
67
/**
65
/**
Lines 93-110 Link Here
93
  }
91
  }
94
92
95
93
96
  private static boolean nbFactoryInitialized;
97
  /** Initializes default stream factory */
94
  /** Initializes default stream factory */
98
  public static void initializeURLFactory () {
95
  public static void initializeURLFactory () {
99
    if (!nbFactoryInitialized) {
96
      ProxyURLStreamHandlerFactory.register();
100
        NbURLStreamHandlerFactory fact = new NbURLStreamHandlerFactory();
101
        try {
102
            java.net.URL.setURLStreamHandlerFactory(fact);
103
        } catch (Error e) {
104
            fact.registerUsingReflection(e);
105
        }
106
        nbFactoryInitialized = true;
107
    }
108
  }
97
  }
109
  
98
  
110
  /**
99
  /**
(-)a/core.startup/src/org/netbeans/core/startup/NbURLStreamHandlerFactory.java (-78 / +3 lines)
Lines 44-62 Link Here
44
import java.io.IOException;
44
import java.io.IOException;
45
import java.io.InputStream;
45
import java.io.InputStream;
46
import java.io.OutputStream;
46
import java.io.OutputStream;
47
import java.lang.reflect.Field;
48
import java.net.URL;
47
import java.net.URL;
49
import java.net.URLConnection;
48
import java.net.URLConnection;
50
import java.net.URLStreamHandler;
49
import java.net.URLStreamHandler;
51
import java.net.URLStreamHandlerFactory;
50
import java.net.URLStreamHandlerFactory;
52
import java.util.Collection;
53
import java.util.Iterator;
51
import java.util.Iterator;
54
import java.util.logging.Level;
55
import java.util.logging.Logger;
56
import org.openide.filesystems.FileUtil;
52
import org.openide.filesystems.FileUtil;
57
import org.openide.util.Lookup;
53
import org.openide.util.Lookup;
58
import org.openide.util.LookupEvent;
59
import org.openide.util.LookupListener;
60
import org.openide.util.NbBundle;
54
import org.openide.util.NbBundle;
61
55
62
/**
56
/**
Lines 65-90 Link Here
65
 * in which case registering them via Lookup would be deprecated.
59
 * in which case registering them via Lookup would be deprecated.
66
 * @author Jesse Glick
60
 * @author Jesse Glick
67
 */
61
 */
68
final class NbURLStreamHandlerFactory implements URLStreamHandlerFactory, LookupListener {
62
public final class NbURLStreamHandlerFactory implements URLStreamHandlerFactory {
69
    private static final Logger LOG = Logger.getLogger(NbURLStreamHandlerFactory.class.getName());
70
    
63
    
71
    private final Lookup.Result<URLStreamHandlerFactory> r;
64
    /** public for lookup */
72
    private URLStreamHandlerFactory[] handlers;
65
    public NbURLStreamHandlerFactory() {}
73
    private URLStreamHandlerFactory delegate;
74
    
75
    public NbURLStreamHandlerFactory() {
76
        r = Lookup.getDefault().lookupResult(URLStreamHandlerFactory.class);
77
        r.addLookupListener(this);
78
        resultChanged(null);
79
    }
80
    
66
    
81
    public URLStreamHandler createURLStreamHandler(String protocol) {
67
    public URLStreamHandler createURLStreamHandler(String protocol) {
82
        if (protocol.equals("jar") || protocol.equals("file") || // NOI18N
83
                protocol.equals("http") || protocol.equals("https") || protocol.equals("resource")) { // NOI18N
84
            // Well-known handlers in JRE. Do not try to initialize lookup, etc.
85
            return null;
86
        }
87
        
88
        if (protocol.equals("nbfs")) { // NOI18N
68
        if (protocol.equals("nbfs")) { // NOI18N
89
             return FileUtil.nbfsURLStreamHandler();
69
             return FileUtil.nbfsURLStreamHandler();
90
        }
70
        }
Lines 94-155 Link Here
94
           return new NbResourceStreamHandler();
74
           return new NbResourceStreamHandler();
95
        }
75
        }
96
        
76
        
97
        URLStreamHandlerFactory d = delegate;
98
        if (d != null) {
99
            URLStreamHandler h = d.createURLStreamHandler(protocol);
100
            if (h != null) {
101
                return h;
102
            }
103
        }
104
        
105
        URLStreamHandlerFactory[] _handlers;
106
        synchronized (this) {
107
            _handlers = handlers;
108
        }
109
        if (_handlers == null) {
110
            // Too early during startup (#75422)
111
            return null;
112
        }
113
        for (int i = 0; i < _handlers.length; i++) {
114
            URLStreamHandler h = _handlers[i].createURLStreamHandler(protocol);
115
            if (h != null) {
116
                return h;
117
            }
118
        }
119
        return null;
77
        return null;
120
    }
121
    
122
    public void resultChanged(LookupEvent ev) {
123
        Collection<? extends URLStreamHandlerFactory> c = r.allInstances();
124
        synchronized (this) {
125
            handlers = c.toArray(new URLStreamHandlerFactory[0]);
126
        }
127
    }
128
129
    void registerUsingReflection(Error e) {
130
        LOG.log(Level.CONFIG, "Problems registering URLStreamHandlerFactory, trying reflection", e); // NOI18N
131
        try {
132
            URLStreamHandlerFactory prev = null;
133
            for (Field f : URL.class.getDeclaredFields()) {
134
                LOG.log(Level.FINEST, "Found field {0}", f);
135
                if (f.getType() == URLStreamHandlerFactory.class) {
136
                    LOG.log(Level.FINEST, "Clearing field {0}");
137
                    f.setAccessible(true);
138
                    prev = (URLStreamHandlerFactory)f.get(null);
139
                    LOG.log(Level.CONFIG, "Previous value was {0}", prev);
140
                    f.set(null, null);
141
                    LOG.config("Field is supposed to be empty");
142
                    break;
143
                }
144
            }
145
            URL.setURLStreamHandlerFactory(this);
146
            delegate = prev;
147
        } catch (Throwable t) {
148
            LOG.log(Level.SEVERE, 
149
                "No way to register URLStreamHandlerFactory; NetBeans is unlikely to work", 
150
                t
151
            ); // NOI18N
152
        }
153
    }
78
    }
154
    
79
    
155
    /** Stream handler for internal resource-based URLs.
80
    /** Stream handler for internal resource-based URLs.
(-)a/o.n.bootstrap/src/org/netbeans/JarClassLoader.java (-151 / +30 lines)
Lines 49-60 Link Here
49
import java.io.IOException;
49
import java.io.IOException;
50
import java.io.InputStream;
50
import java.io.InputStream;
51
import java.io.OutputStream;
51
import java.io.OutputStream;
52
import java.lang.reflect.Field;
52
import java.lang.reflect.Method;
53
import java.net.JarURLConnection;
53
import java.net.MalformedURLException;
54
import java.net.MalformedURLException;
54
import java.net.URL;
55
import java.net.URL;
55
import java.net.URLConnection;
56
import java.net.URLStreamHandler;
56
import java.net.URLStreamHandler;
57
import java.net.URLStreamHandlerFactory;
58
import java.security.CodeSource;
57
import java.security.CodeSource;
59
import java.security.PermissionCollection;
58
import java.security.PermissionCollection;
60
import java.security.Policy;
59
import java.security.Policy;
Lines 111-134 Link Here
111
    }
110
    }
112
    
111
    
113
    static {
112
    static {
114
        ResURLStreamHandlerFactory fact = new ResURLStreamHandlerFactory();
113
        ProxyURLStreamHandlerFactory.register();
115
        try {
116
            java.net.URL.setURLStreamHandlerFactory(fact);
117
        } catch (Error e) {
118
            try {
119
                for (Field f : URL.class.getDeclaredFields()) {
120
                    if (f.getType() == URLStreamHandlerFactory.class) {
121
                        f.setAccessible(true);
122
                        fact.del = (URLStreamHandlerFactory)f.get(null);
123
                        f.set(null, null);
124
                        break;
125
                    }
126
                }
127
                URL.setURLStreamHandlerFactory(fact);
128
            } catch (Throwable t) {
129
                throw new InternalError(); // can't really continue
130
            }
131
        }
132
    }
114
    }
133
    
115
    
134
    private static final Logger LOGGER = Logger.getLogger(JarClassLoader.class.getName());
116
    private static final Logger LOGGER = Logger.getLogger(JarClassLoader.class.getName());
Lines 343-348 Link Here
343
            sources.put(f.toURI().toString(), src);
325
            sources.put(f.toURI().toString(), src);
344
            return src;
326
            return src;
345
        }
327
        }
328
329
        @Override
330
        public String toString() {
331
            return url.toString();
332
        }
333
346
    }
334
    }
347
335
348
    static class JarSource extends Source {
336
    static class JarSource extends Source {
Lines 356-362 Link Here
356
        
344
        
357
        JarSource(File file) throws IOException {
345
        JarSource(File file) throws IOException {
358
            super(file.toURL());
346
            super(file.toURL());
359
            resPrefix = ResURLStreamHandler.RES_PROTO +":" + file.toURI() + "!/"; // NOI18N;
347
            resPrefix = "jar:" + file.toURI() + "!/"; // NOI18N;
360
            this.file = file;
348
            this.file = file;
361
        }
349
        }
362
350
Lines 665-692 Link Here
665
        return known;
653
        return known;
666
    }
654
    }
667
    
655
    
668
    private static class ResURLStreamHandlerFactory implements URLStreamHandlerFactory {
669
        URLStreamHandlerFactory del;
670
        /**
671
         * Creates URLStreamHandler for nbinst protocol
672
         * @param protocol
673
         * @return NbinstURLStreamHandler if the protocol is nbinst otherwise null
674
         */
675
        public URLStreamHandler createURLStreamHandler(String protocol) {
676
            if (ResURLStreamHandler.RES_PROTO.equals(protocol)) {
677
                return new ResURLStreamHandler ();
678
            }
679
            return del != null ? del.createURLStreamHandler(protocol): null;
680
        }
681
    }
682
    
683
    /**
656
    /**
684
     * URLStreamHandler for res protocol
657
     * URLStreamHandler for res protocol
685
     */
658
     */
686
    private static class ResURLStreamHandler extends URLStreamHandler {
659
    static class ResURLStreamHandler extends URLStreamHandler {
687
        public static final String RES_PROTO = "nbjcl";
688
660
689
        ResURLStreamHandler() {}
661
        private final URLStreamHandler originalJarHandler;
662
663
        ResURLStreamHandler(URLStreamHandler originalJarHandler) {
664
            this.originalJarHandler = originalJarHandler;
665
        }
690
666
691
        /**
667
        /**
692
         * Creates URLConnection for URL with res protocol.
668
         * Creates URLConnection for URL with res protocol.
Lines 694-825 Link Here
694
         * @return URLConnection
670
         * @return URLConnection
695
         * @throws IOException
671
         * @throws IOException
696
         */
672
         */
697
        protected URLConnection openConnection(URL u) throws IOException {
673
        protected JarURLConnection openConnection(URL u) throws IOException {
698
            String url = u.getFile();//toExternalForm();
674
            String url = u.getFile();//toExternalForm();
699
            int bang = url.indexOf("!/");
675
            int bang = url.indexOf("!/");
700
            String jar = url.substring(0, bang);
676
            String jar = url.substring(0, bang);
701
            String _name = url.substring(bang+2);
677
            String _name = url.substring(bang+2);
702
            Source _src = Source.sources.get(jar);
678
            Source _src = Source.sources.get(jar);
703
            if (_src == null) {
679
            if (_src == null) {
704
                String replace = u.toExternalForm().replaceAll("nbjcl:", "jar:");
680
                try {
705
                
681
                    Method m = URLStreamHandler.class.getDeclaredMethod("openConnection", URL.class);
706
                if (archive.isActive()) {
682
                    m.setAccessible(true);
707
                    LOGGER.log(Level.WARNING, "Cannot find {0} in current sources", jar);
683
                    return (JarURLConnection) m.invoke(originalJarHandler, u);
708
                    if (LOGGER.isLoggable(Level.FINER)) {
684
                } catch (Exception e) {
709
                        LOGGER.log(Level.FINER, dumpSources(Source.sources, jar));
685
                    throw (IOException) new IOException(e.toString()).initCause(e);
710
                    }
711
                    LOGGER.log(Level.WARNING, "Trying {0} instead", replace);
712
                    LOGGER.log(Level.WARNING, "Disabling class cache");
713
                    archive.stopServing();
714
                }
686
                }
715
                return new URL(replace).openConnection();
716
            }
687
            }
717
            return new ResURLConnection (u, _src, _name);
688
            return new ResURLConnection (u, _src, _name);
718
        }
689
        }
719
690
720
        protected @Override void parseURL(URL url, String spec, 
721
                                int start, int limit) {
722
            String file = null;
723
            String ref = null;
724
            // first figure out if there is an anchor
725
            int refPos = spec.indexOf('#', limit);
726
            boolean refOnly = refPos == start;
727
            if (refPos > -1) {
728
                ref = spec.substring(refPos + 1, spec.length());
729
                if (refOnly) {
730
                    file = url.getFile();
731
                }
732
            }
733
            // then figure out if the spec is 
734
            // 1. absolute (res:)
735
            // 2. relative (i.e. url + foo/bar/baz.ext)
736
            // 3. anchor-only (i.e. url + #foo), which we already did (refOnly)
737
            boolean absoluteSpec = false;
738
            if (spec.length() >= RES_PROTO.length()+1) {
739
                absoluteSpec = spec.substring(0, RES_PROTO.length()+1).equalsIgnoreCase(RES_PROTO+":");
740
            }
741
            spec = spec.substring(start, limit);
742
743
            if (absoluteSpec) {
744
                file = parseAbsoluteSpec(spec);
745
            } else if (!refOnly) {
746
                file = parseContextSpec(url, spec);
747
748
                // Canonize the result after the bangslash
749
                int bangSlash = file.lastIndexOf("!/") + 1;
750
                String toBangSlash = file.substring(0, bangSlash);
751
                String afterBangSlash = file.substring(bangSlash);
752
                sun.net.www.ParseUtil canonizer = new sun.net.www.ParseUtil(); // XXX
753
                afterBangSlash = canonizer.canonizeString(afterBangSlash);
754
                file = toBangSlash + afterBangSlash;
755
            }
756
            setURLOK(url, file, ref);	
757
        }
758
759
        private static String dumpSources(Map<String, Source> sources, String jar) {
760
            StringBuilder sb = new StringBuilder();
761
            sb.append("Searching for ").append(jar).append("\nwhile available:\n");
762
            for (Map.Entry<String, Source> entry : sources.entrySet()) {
763
                sb.append(entry.getKey()).append('\n');
764
            }
765
            
766
            return sb.toString();
767
        }
768
        
769
        @SuppressWarnings("deprecation")
770
        private void setURLOK(URL url, String file, String ref) {
771
            super.setURL(url, RES_PROTO, "", -1, file, ref);	
772
        }
773
774
        private String parseAbsoluteSpec(String spec) {
775
            URL url = null;
776
            int index = -1;
777
            // check for !/
778
            if ((index = spec.lastIndexOf("!/") + 1) == -1) {
779
                throw new NullPointerException("no !/ in spec");
780
            }
781
            // test the inner URL
782
            try {
783
                String innerSpec = spec.substring(0, index - 1);
784
                url = new URL(innerSpec);
785
            } catch (MalformedURLException e) {
786
                throw new NullPointerException("invalid url: " + 
787
                                               spec + " (" + e + ")");
788
            }
789
            return spec;
790
        }
791
792
        private String parseContextSpec(URL url, String spec) {
793
            String ctxFile = url.getFile();
794
            // if the spec begins with /, chop up the jar back !/
795
            if (spec.startsWith("/")) {
796
                int bangSlash = ctxFile.lastIndexOf("!/");
797
                if (bangSlash == -1) {
798
                    throw new NullPointerException("malformed " +
799
                                                   "context url:" +
800
                                                   url + 
801
                                                   ": no !/");
802
                }
803
                ctxFile = ctxFile.substring(0, bangSlash+1);
804
            }
805
            if (!ctxFile.endsWith("/") && (!spec.startsWith("/"))){
806
                // chop up the last component
807
                int lastSlash = ctxFile.lastIndexOf('/');
808
                if (lastSlash == -1) {
809
                    throw new NullPointerException("malformed " +
810
                                                   "context url:" +
811
                                                   url);
812
                }
813
                ctxFile = ctxFile.substring(0, lastSlash + 1);
814
            }
815
            return (ctxFile + spec);
816
        }
817
    }
691
    }
818
692
819
    /** URLConnection for URL with res protocol.
693
    /** URLConnection for URL with res protocol.
820
     *
694
     *
821
     */
695
     */
822
    private static class ResURLConnection extends URLConnection {
696
    private static class ResURLConnection extends JarURLConnection {
823
        private JarSource src;
697
        private JarSource src;
824
        private String name;
698
        private String name;
825
        private byte[] data;
699
        private byte[] data;
Lines 830-836 Link Here
830
         * @param url the parameter for which the connection should be
704
         * @param url the parameter for which the connection should be
831
         * created
705
         * created
832
         */
706
         */
833
        private ResURLConnection(URL url, Source src, String name) {
707
        private ResURLConnection(URL url, Source src, String name) throws MalformedURLException {
834
            super(url);
708
            super(url);
835
            this.src = (JarSource)src;
709
            this.src = (JarSource)src;
836
            this.name = name;
710
            this.name = name;
Lines 870-874 Link Here
870
            if (iStream == null) iStream = new ByteArrayInputStream(data);
744
            if (iStream == null) iStream = new ByteArrayInputStream(data);
871
            return iStream;
745
            return iStream;
872
        }
746
        }
747
748
        @Override
749
        public JarFile getJarFile() throws IOException {
750
            return src.jar;
751
        }
873
    }
752
    }
874
}
753
}
(-)a/o.n.bootstrap/src/org/netbeans/ProxyURLStreamHandlerFactory.java (+148 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans;
41
42
import java.lang.reflect.Field;
43
import java.lang.reflect.Method;
44
import java.net.URL;
45
import java.net.URLStreamHandler;
46
import java.net.URLStreamHandlerFactory;
47
import java.util.Collection;
48
import java.util.logging.Level;
49
import java.util.logging.Logger;
50
import org.openide.util.Lookup;
51
import org.openide.util.LookupEvent;
52
import org.openide.util.LookupListener;
53
54
/**
55
 * A stream handler factory that delegates to others in lookup.
56
 */
57
public class ProxyURLStreamHandlerFactory implements URLStreamHandlerFactory, LookupListener {
58
59
    private static final Logger LOG = Logger.getLogger(ProxyURLStreamHandlerFactory.class.getName());
60
    private static boolean proxyFactoryInitialized;
61
62
    public static synchronized void register() {
63
        if (!proxyFactoryInitialized) {
64
            URLStreamHandler originalJarHandler = null;
65
            try {
66
                Method m = URL.class.getDeclaredMethod("getURLStreamHandler", String.class);
67
                m.setAccessible(true);
68
                originalJarHandler = (URLStreamHandler) m.invoke(null, "jar");
69
            } catch (Throwable t) {
70
                LOG.log(Level.SEVERE, "No way to find original stream handler for jar protocol", t); // NOI18N
71
            }
72
            try {
73
                URL.setURLStreamHandlerFactory(new ProxyURLStreamHandlerFactory(null, originalJarHandler));
74
            } catch (Error e) {
75
                LOG.log(Level.CONFIG, "Problems registering URLStreamHandlerFactory, trying reflection", e); // NOI18N
76
                try {
77
                    URLStreamHandlerFactory prev = null;
78
                    for (Field f : URL.class.getDeclaredFields()) {
79
                        LOG.log(Level.FINEST, "Found field {0}", f);
80
                        if (f.getType() == URLStreamHandlerFactory.class) {
81
                            LOG.log(Level.FINEST, "Clearing field {0}");
82
                            f.setAccessible(true);
83
                            prev = (URLStreamHandlerFactory) f.get(null);
84
                            LOG.log(Level.CONFIG, "Previous value was {0}", prev);
85
                            f.set(null, null);
86
                            LOG.config("Field is supposed to be empty");
87
                            break;
88
                        }
89
                    }
90
                    URL.setURLStreamHandlerFactory(new ProxyURLStreamHandlerFactory(prev, originalJarHandler));
91
                } catch (Throwable t) {
92
                    LOG.log(Level.SEVERE, "No way to register URLStreamHandlerFactory; NetBeans is unlikely to work", t); // NOI18N
93
                }
94
            }
95
            proxyFactoryInitialized = true;
96
        }
97
    }
98
99
    private final URLStreamHandlerFactory delegate;
100
    private final URLStreamHandler originalJarHandler;
101
    private Lookup.Result<URLStreamHandlerFactory> r;
102
    private URLStreamHandlerFactory[] handlers;
103
104
    private ProxyURLStreamHandlerFactory(URLStreamHandlerFactory delegate, URLStreamHandler originalJarHandler) {
105
        this.delegate = delegate;
106
        this.originalJarHandler = originalJarHandler;
107
    }
108
109
    public URLStreamHandler createURLStreamHandler(String protocol) {
110
        if (protocol.equals("jar")) {
111
            return new JarClassLoader.ResURLStreamHandler(originalJarHandler);
112
        } else if (protocol.equals("file") || protocol.equals("http") || protocol.equals("https") || protocol.equals("resource")) { // NOI18N
113
            // Well-known handlers in JRE. Do not try to initialize lookup, etc.
114
            return null;
115
        } else {
116
            if (delegate != null) {
117
                URLStreamHandler h = delegate.createURLStreamHandler(protocol);
118
                if (h != null) {
119
                    return h;
120
                }
121
            }
122
            URLStreamHandlerFactory[] _handlers;
123
            synchronized (this) {
124
                if (handlers == null) {
125
                    r = Lookup.getDefault().lookupResult(URLStreamHandlerFactory.class);
126
                    r.addLookupListener(this);
127
                    resultChanged(null);
128
                }
129
                _handlers = handlers;
130
            }
131
            for (URLStreamHandlerFactory f : _handlers) {
132
                URLStreamHandler h = f.createURLStreamHandler(protocol);
133
                if (h != null) {
134
                    return h;
135
                }
136
            }
137
            return null;
138
        }
139
    }
140
141
    public void resultChanged(LookupEvent ev) {
142
        Collection<? extends URLStreamHandlerFactory> c = r.allInstances();
143
        synchronized (this) {
144
            handlers = c.toArray(new URLStreamHandlerFactory[0]);
145
        }
146
    }
147
148
}

Return to bug 129772