Package org.gjt.sp.jedit
Class ServiceManager
- java.lang.Object
-
- org.gjt.sp.jedit.ServiceManager
-
public class ServiceManager extends java.lang.ObjectA generic way for plugins (and core) to provide various API extensions.Services are loaded from files named
services.xmlinside the plugin JAR. A service definition file has the following form:<?xml version="1.0"?> <!DOCTYPE SERVICES SYSTEM "services.dtd"> <SERVICES> <SERVICE NAME="service name" CLASS="fully qualified class name"> // BeanShell code evaluated when the sevice is first activated </SERVICE> </SERVICES>The following elements are valid:-
SERVICESis the top-level element and refers to the set of services offered by the plugin. -
A
SERVICEcontains the factory method for this service singleton. The ServiceManager manages named singletons created from these factory methods. It has two attributes, both required:NAMEandCLASS. TheCLASSattribute must be the name of a known sevice type; see below. -
A
SERVICEelement should the BeanShell code that returns a new instance of the named class. Note that this code can returnnull.
services.xmlfile. Some core services are listed below:FoldHandlerFoldPainterVFSEncodingEncodingDetectorStatusWidgetFactoryDockingFrameworkProviderJEditTrayIcon
getServiceTypes().
To use a service from a plugin, add a piece of code somewhere that callsgetServiceNames(String)andgetService(String,String). -
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classServiceManager.ServiceFoldHandlerProviderA FoldHandler based on the ServiceManager
-
Constructor Summary
Constructors Constructor Description ServiceManager()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <E> EgetService(java.lang.Class<E> clazz, java.lang.String name)Returns an instance of the given service.static java.lang.ObjectgetService(java.lang.String clazz, java.lang.String name)Returns an instance of the given service.static java.lang.String[]getServiceNames(java.lang.Class clazz)static java.lang.String[]getServiceNames(java.lang.String clazz)Returns the names of all registered services with the given class.static java.lang.String[]getServiceTypes()Returns all known service class types.static voidloadServices(PluginJAR plugin, java.net.URL uri, PluginJAR.PluginCacheEntry cache)Loads aservices.xmlfile.static voidregisterService(java.lang.String clazz, java.lang.String name, java.lang.String code, PluginJAR plugin)Registers a service.static voidunloadServices(PluginJAR plugin)Removes all services belonging to the specified plugin.static voidunregisterService(java.lang.String clazz, java.lang.String name)Unregisters a service.
-
-
-
Method Detail
-
loadServices
public static void loadServices(PluginJAR plugin, java.net.URL uri, PluginJAR.PluginCacheEntry cache)
Loads aservices.xmlfile.- Since:
- jEdit 4.2pre1
-
unloadServices
public static void unloadServices(PluginJAR plugin)
Removes all services belonging to the specified plugin.- Parameters:
plugin- The plugin- Since:
- jEdit 4.2pre1
-
registerService
public static void registerService(java.lang.String clazz, java.lang.String name, java.lang.String code, PluginJAR plugin)Registers a service. Plugins should provide aservices.xmlfile instead of calling this directly.- Parameters:
clazz- The service classname- The service namecode- BeanShell code to create an instance of thisplugin- The plugin JAR, or null if this is a built-in service- Since:
- jEdit 4.2pre1
-
unregisterService
public static void unregisterService(java.lang.String clazz, java.lang.String name)Unregisters a service.- Parameters:
clazz- The service classname- The service name- Since:
- jEdit 4.2pre1
-
getServiceTypes
public static java.lang.String[] getServiceTypes()
Returns all known service class types.- Since:
- jEdit 4.2pre1
-
getServiceNames
public static java.lang.String[] getServiceNames(java.lang.String clazz)
Returns the names of all registered services with the given class. For example, calling this with a parameter of "org.gjt.sp.jedit.io.VFS" returns all known virtual file systems.- Parameters:
clazz- The class name- Since:
- jEdit 4.2pre1
-
getServiceNames
public static java.lang.String[] getServiceNames(java.lang.Class clazz)
-
getService
public static java.lang.Object getService(java.lang.String clazz, java.lang.String name)Returns an instance of the given service. The first time this is called for a given service, the BeanShell code is evaluated. The result is cached for future invocations, so in effect services are singletons.- Parameters:
clazz- The service classname- The service name- Since:
- jEdit 4.2pre1
-
getService
public static <E> E getService(java.lang.Class<E> clazz, java.lang.String name)Returns an instance of the given service. The first time this is called for a given service, the BeanShell code is evaluated. The result is cached for future invocations, so in effect services are singletons.- Parameters:
clazz- The service classname- The service name- Returns:
- the service instance
- Since:
- jEdit 4.4pre1
-
-