public class ServiceLocator
extends java.lang.Object
Markup languages may be dynamically discovered by adding a Java service file in one of the following locations:
MarkupLanguage
,
MarkupLanguageProvider
Modifier and Type | Class and Description |
---|---|
protected static class |
ServiceLocator.ResourceDescriptor |
Modifier and Type | Field and Description |
---|---|
protected java.lang.ClassLoader |
classLoader |
Modifier | Constructor and Description |
---|---|
protected |
ServiceLocator(java.lang.ClassLoader classLoader) |
Modifier and Type | Method and Description |
---|---|
protected java.util.List<ServiceLocator.ResourceDescriptor> |
discoverServiceResources() |
java.util.Set<MarkupLanguage> |
getAllMarkupLanguages()
Get all known markup languages
|
protected java.util.List<java.lang.String> |
getClasspathServiceResourceNames()
Provides the list of service resource names from which Java services should be loaded.
|
static ServiceLocator |
getInstance()
Get an instance of the service locator
|
static ServiceLocator |
getInstance(java.lang.ClassLoader classLoader)
Get an instance of the service locator
|
MarkupLanguage |
getMarkupLanguage(java.lang.String languageName)
get a markup language by name
|
protected java.lang.Class<?> |
loadClass(ServiceLocator.ResourceDescriptor resource,
java.lang.String className)
Loads the specified class.
|
protected java.util.List<java.lang.String> |
readServiceClassNames(java.net.URL url)
Reads the services provided in the file with the given URL.
|
static void |
setImplementation(java.lang.Class<? extends ServiceLocator> implementationClass) |
public static ServiceLocator getInstance(java.lang.ClassLoader classLoader)
classLoader
- the class loader to use when looking up servicesgetInstance()
public static ServiceLocator getInstance()
getInstance(ClassLoader)
public MarkupLanguage getMarkupLanguage(java.lang.String languageName) throws java.lang.IllegalArgumentException
languageName
- the name
of the markup language, or the fully qualified name of the
class that implements the languagejava.lang.IllegalArgumentException
- if the provided language name is null or if no implementation is available for the given languagepublic java.util.Set<MarkupLanguage> getAllMarkupLanguages()
public static void setImplementation(java.lang.Class<? extends ServiceLocator> implementationClass)
protected java.lang.Class<?> loadClass(ServiceLocator.ResourceDescriptor resource, java.lang.String className) throws java.lang.ClassNotFoundException
resourceUrl
- the service resource from which the class name was discoveredclassName
- the class name to loadjava.lang.ClassNotFoundException
- if the class could not be loadedprotected java.util.List<ServiceLocator.ResourceDescriptor> discoverServiceResources()
getClasspathServiceResourceNames()
protected java.util.List<java.lang.String> getClasspathServiceResourceNames()
protected java.util.List<java.lang.String> readServiceClassNames(java.net.URL url)
ServiceLoader
.ServiceLoader
Copyright © 2007, 2013 David Green and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html