org.dynalang.dynalink.support.AutoDiscovery Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dynalink Show documentation
Show all versions of dynalink Show documentation
Dynalink is an invokedynamic-based high-level linking and metaobject protocol library. It enables creation of languages on the JVM that can easily interoperate with plain Java objects and each other.
/*
Copyright 2009-2011 Attila Szegedi
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.dynalang.dynalink.support;
import java.util.LinkedList;
import java.util.List;
import java.util.ServiceLoader;
import org.dynalang.dynalink.DynamicLinkerFactory;
import org.dynalang.dynalink.linker.GuardingDynamicLinker;
/**
* Provides methods for automatic discovery of all guarding dynamic linkers
* listed in the
* /META-INF/services/org.dynalang.dynalink.linker.GuardingDynamicLinker
* resources of all JAR files for a particular class loader. Ordinarily, you
* will not use this class directly, but you will use a
* {@link DynamicLinkerFactory} instead.
*/
public class AutoDiscovery {
/**
* Discovers all guarding dynamic linkers listed in JAR files of the context
* class loader of the current thread.
*
* @return a list of available linkers. Can be zero-length list but not
* null.
*/
public static List loadLinkers() {
return getLinkers(ServiceLoader.load(GuardingDynamicLinker.class));
}
/**
* Discovers all guarding dynamic linkers listed in JAR files of the
* specified class loader.
*
* @param cl the class loader to use
* @return a list of guarding dynamic linkers available through the specified class loader. Can
* be zero-length list but not null.
*/
public static List loadLinkers(ClassLoader cl) {
return getLinkers(ServiceLoader.load(GuardingDynamicLinker.class, cl));
}
/**
* I can't believe there's no Collections API for making a List given an
* Iterator...
*/
private static List getLinkers(ServiceLoader loader) {
final List list = new LinkedList();
for(final T linker: loader) {
list.add(linker);
}
return list;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy