Java Doc for Service.java in  » 6.0-JDK-Modules » j2me » sun » misc » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » sun.misc 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   sun.misc.Service

Service
final public class Service (Code)
A simple service-provider lookup mechanism. A service is a well-known set of interfaces and (usually abstract) classes. A service provider is a specific implementation of a service. The classes in a provider typically implement the interfaces and subclass the classes defined in the service itself. Service providers may be installed in an implementation of the Java platform in the form of extensions, that is, jar files placed into any of the usual extension directories. Providers may also be made available by adding them to the applet or application class path or by some other platform-specific means.

In this lookup mechanism a service is represented by an interface or an abstract class. (A concrete class may be used, but this is not recommended.) A provider of a given service contains one or more concrete classes that extend this service class with data and code specific to the provider. This provider class will typically not be the entire provider itself but rather a proxy that contains enough information to decide whether the provider is able to satisfy a particular request together with code that can create the actual provider on demand. The details of provider classes tend to be highly service-specific; no single class or interface could possibly unify them, so no such class has been defined. The only requirement enforced here is that provider classes must have a zero-argument constructor so that they may be instantiated during lookup.

A service provider identifies itself by placing a provider-configuration file in the resource directory META-INF/services. The file's name should consist of the fully-qualified name of the abstract service class. The file should contain a list of fully-qualified concrete provider-class names, one per line. Space and tab characters surrounding each name, as well as blank lines, are ignored. The comment character is '#' (0x23); on each line all characters following the first comment character are ignored. The file must be encoded in UTF-8.

If a particular concrete provider class is named in more than one configuration file, or is named in the same configuration file more than once, then the duplicates will be ignored. The configuration file naming a particular provider need not be in the same jar file or other distribution unit as the provider itself. The provider must be accessible from the same class loader that was initially queried to locate the configuration file; note that this is not necessarily the class loader that found the file.

Example: Suppose we have a service class named java.io.spi.CharCodec. It has two abstract methods:

 public abstract CharEncoder getEncoder(String encodingName);
 public abstract CharDecoder getDecoder(String encodingName);
 
Each method returns an appropriate object or null if it cannot translate the given encoding. Typical CharCodec providers will support more than one encoding.

If sun.io.StandardCodec is a provider of the CharCodec service then its jar file would contain the file META-INF/services/java.io.spi.CharCodec. This file would contain the single line:

 sun.io.StandardCodec    # Standard codecs for the platform
 
To locate an encoder for a given encoding name, the internal I/O code would do something like this:
 CharEncoder getEncoder(String encodingName) {
 Iterator ps = Service.providers(CharCodec.class);
 while (ps.hasNext()) {
 CharCodec cc = (CharCodec)ps.next();
 CharEncoder ce = cc.getEncoder(encodingName);
 if (ce != null)
 return ce;
 }
 return null;
 }
 
The provider-lookup mechanism always executes in the security context of the caller. Trusted system code should typically invoke the methods in this class from within a privileged security context.
author:
   Mark Reinhold
version:
   1.10, 02/08/19
since:
   1.3




Method Summary
public static  IteratorinstalledProviders(Class service)
     Locates and incrementally instantiates the available providers of a given service using the extension class loader.
public static  Iteratorproviders(Class service, ClassLoader loader)
     Locates and incrementally instantiates the available providers of a given service using the given class loader.

This method transforms the name of the given service class into a provider-configuration filename as described above and then uses the getResources method of the given class loader to find all available files with that name.

public static  Iteratorproviders(Class service)
     Locates and incrementally instantiates the available providers of a given service using the context class loader.



Method Detail
installedProviders
public static Iterator installedProviders(Class service) throws ServiceConfigurationError(Code)
Locates and incrementally instantiates the available providers of a given service using the extension class loader. This convenience method simply locates the extension class loader, call it extClassLoader, and then does
 return Service.providers(service, extClassLoader);
 
If the extension class loader cannot be found then the system class loader is used; if there is no system class loader then the bootstrap class loader is used.
Parameters:
  service - The service's abstract service class An Iterator that yields provider objects for the givenservice, in some arbitrary order. The iterator will throw aServiceConfigurationError if a provider-configurationfile violates the specified format or if a provider class cannotbe found and instantiated.
throws:
  ServiceConfigurationError - If a provider-configuration file violates the specified formator names a provider class that cannot be found and instantiated
See Also:   Service.providers(java.lang.Class,java.lang.ClassLoader)



providers
public static Iterator providers(Class service, ClassLoader loader) throws ServiceConfigurationError(Code)
Locates and incrementally instantiates the available providers of a given service using the given class loader.

This method transforms the name of the given service class into a provider-configuration filename as described above and then uses the getResources method of the given class loader to find all available files with that name. These files are then read and parsed to produce a list of provider-class names. The iterator that is returned uses the given class loader to lookup and then instantiate each element of the list.

Because it is possible for extensions to be installed into a running Java virtual machine, this method may return different results each time it is invoked.


Parameters:
  service - The service's abstract service class
Parameters:
  loader - The class loader to be used to load provider-configuration filesand instantiate provider classes, or null if the systemclass loader (or, failing that the bootstrap class loader) is tobe used An Iterator that yields provider objects for the givenservice, in some arbitrary order. The iterator will throw aServiceConfigurationError if a provider-configurationfile violates the specified format or if a provider class cannotbe found and instantiated.
throws:
  ServiceConfigurationError - If a provider-configuration file violates the specified formator names a provider class that cannot be found and instantiated
See Also:   Service.providers(java.lang.Class)
See Also:   Service.installedProviders(java.lang.Class)




providers
public static Iterator providers(Class service) throws ServiceConfigurationError(Code)
Locates and incrementally instantiates the available providers of a given service using the context class loader. This convenience method is equivalent to
 ClassLoader cl = Thread.currentThread().getContextClassLoader();
 return Service.providers(service, cl);
 

Parameters:
  service - The service's abstract service class An Iterator that yields provider objects for the givenservice, in some arbitrary order. The iterator will throw aServiceConfigurationError if a provider-configurationfile violates the specified format or if a provider class cannotbe found and instantiated.
throws:
  ServiceConfigurationError - If a provider-configuration file violates the specified formator names a provider class that cannot be found and instantiated
See Also:   Service.providers(java.lang.Class,java.lang.ClassLoader)



Methods inherited from java.lang.Object
public boolean equals(Object obj)(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.