lookup/src/main/java/org/netbeans/modules/openide/util/NamedServicesProvider.java
1.1 --- a/lookup/src/main/java/org/netbeans/modules/openide/util/NamedServicesProvider.java Wed Jan 27 17:46:23 2010 -0500
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,87 +0,0 @@
1.4 -/*
1.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1.6 - *
1.7 - * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
1.8 - *
1.9 - * The contents of this file are subject to the terms of either the GNU
1.10 - * General Public License Version 2 only ("GPL") or the Common
1.11 - * Development and Distribution License("CDDL") (collectively, the
1.12 - * "License"). You may not use this file except in compliance with the
1.13 - * License. You can obtain a copy of the License at
1.14 - * http://www.netbeans.org/cddl-gplv2.html
1.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
1.16 - * specific language governing permissions and limitations under the
1.17 - * License. When distributing the software, include this License Header
1.18 - * Notice in each file and include the License file at
1.19 - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
1.20 - * particular file as subject to the "Classpath" exception as provided
1.21 - * by Sun in the GPL Version 2 section of the License file that
1.22 - * accompanied this code. If applicable, add the following below the
1.23 - * License Header, with the fields enclosed by brackets [] replaced by
1.24 - * your own identifying information:
1.25 - * "Portions Copyrighted [year] [name of copyright owner]"
1.26 - *
1.27 - * Contributor(s):
1.28 - *
1.29 - * The Original Software is NetBeans. The Initial Developer of the Original
1.30 - * Software is Sun Microsystems, Inc.
1.31 - *
1.32 - * Portions Copyrighted 2006 Sun Microsystems, Inc.
1.33 - */
1.34 -
1.35 -package org.netbeans.modules.openide.util;
1.36 -
1.37 -import java.lang.ref.Reference;
1.38 -import java.lang.ref.WeakReference;
1.39 -import java.util.Collections;
1.40 -import java.util.HashMap;
1.41 -import java.util.Map;
1.42 -import org.openide.util.Lookup;
1.43 -import org.openide.util.lookup.Lookups;
1.44 -
1.45 -/** Interface for core/startup and core/settings
1.46 - * to provide lookup over system filesystem.
1.47 - *
1.48 - * @author Jaroslav Tulach
1.49 - */
1.50 -public abstract class NamedServicesProvider {
1.51 -
1.52 - private static final Map<String,Reference<Lookup>> map = Collections.synchronizedMap(new HashMap<String,Reference<Lookup>>());
1.53 -
1.54 - public abstract Lookup create(String path);
1.55 -
1.56 - public static Lookup find(String path) {
1.57 - if (!path.endsWith("/")) {
1.58 - path = path + "/";
1.59 - }
1.60 -
1.61 - Reference<Lookup> ref = map.get(path);
1.62 - Lookup lkp = ref == null ? null : ref.get();
1.63 - if (lkp != null) {
1.64 - return lkp;
1.65 - }
1.66 - NamedServicesProvider prov = Lookup.getDefault().lookup(NamedServicesProvider.class);
1.67 - if (prov != null &&
1.68 - /* avoid stack overflow during initialization */
1.69 - !path.startsWith(
1.70 - "URLStreamHandler/"
1.71 - /*URLStreamHandlerRegistrationProcessor.REGISTRATION_PREFIX*/
1.72 - )
1.73 - ) {
1.74 - lkp = prov.create(path);
1.75 - } else {
1.76 - ClassLoader l = Lookup.getDefault().lookup(ClassLoader.class);
1.77 - if (l == null) {
1.78 - l = Thread.currentThread().getContextClassLoader();
1.79 - if (l == null) {
1.80 - l = NamedServicesProvider.class.getClassLoader();
1.81 - }
1.82 - }
1.83 - lkp = Lookups.metaInfServices(l, "META-INF/namedservices/" + path);
1.84 - }
1.85 -
1.86 - map.put(path, new WeakReference<Lookup>(lkp));
1.87 - return lkp;
1.88 - }
1.89 -
1.90 -}