Java Doc for DiscoverClass.java in  » Library » Apache-common-Discovery » org » apache » commons » discovery » tools » 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 » Library » Apache common Discovery » org.apache.commons.discovery.tools 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.commons.discovery.tools.DiscoverClass

DiscoverClass
public class DiscoverClass (Code)

Discover class that implements a given service interface, with discovery and configuration features similar to that employed by standard Java APIs such as JAXP.

In the context of this package, a service interface is defined by a Service Provider Interface (SPI). The SPI is expressed as a Java interface, abstract class, or (base) class that defines an expected programming interface.

DiscoverClass provides the find methods for locating a class that implements a service interface (SPI). Each form of find varies slightly, but they all perform the same basic function. The DiscoverClass.find methods proceed as follows:

  • Get the name of an implementation class. The name is the first non-null value obtained from the following resources:
    • The value of the (scoped) system property whose name is the same as the SPI's fully qualified class name (as given by SPI.class.getName()). The ScopedProperties class provides a way to bind properties by classloader, in a secure hierarchy similar in concept to the way classloader find class and resource files. See ScopedProperties for more details.

      If the ScopedProperties are not set by users, then behaviour is equivalent to System.getProperty().

    • The value of a Properties properties property, if provided as a parameter, whose name is the same as the SPI's fully qualifed class name (as given by SPI.class.getName()).
    • The value obtained using the JDK1.3+ 'Service Provider' specification (http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html) to locate a service named SPI.class.getName(). This is implemented internally, so there is not a dependency on JDK 1.3+.
  • If the name of the implementation class is non-null, load that class. The class loaded is the first class loaded by the following sequence of class loaders:
    • Thread Context Class Loader
    • DiscoverSingleton's Caller's Class Loader
    • SPI's Class Loader
    • DiscoverSingleton's (this class or wrapper) Class Loader
    • System Class Loader
    An exception is thrown if the class cannot be loaded.
  • If the name of the implementation class is null, AND the default implementation class name (defaultImpl) is null, then an exception is thrown.
  • If the name of the implementation class is null, AND the default implementation class (defaultImpl) is non-null, then load the default implementation class. The class loaded is the first class loaded by the following sequence of class loaders:
    • SPI's Class Loader
    • DiscoverSingleton's (this class or wrapper) Class Loader
    • System Class Loader

    This limits the scope in which the default class loader can be found to the SPI, DiscoverSingleton, and System class loaders. The assumption here is that the default implementation is closely associated with the SPI or system, and is not defined in the user's application space.

    An exception is thrown if the class cannot be loaded.

  • Verify that the loaded class implements the SPI: an exception is thrown if the loaded class does not implement the SPI.

IMPLEMENTATION NOTE - This implementation is modelled after the SAXParserFactory and DocumentBuilderFactory implementations (corresponding to the JAXP pluggability APIs) found in Apache Xerces.


author:
   Richard A. Sitze
author:
   Craig R. McClanahan
author:
   Costin Manolache
version:
   $Revision: 480374 $ $Date: 2006-11-28 19:33:25 -0800 (Tue, 28 Nov 2006) $


Field Summary
final public static  DefaultClassHoldernullDefaultImpl
     Readable placeholder for a null value.
final public static  PropertiesHoldernullProperties
     Readable placeholder for a null value.

Constructor Summary
public  DiscoverClass()
     Create a class instance with dynamic environment (thread context class loader is determined on each call).
public  DiscoverClass(ClassLoaders classLoaders)
     Create a class instance with dynamic environment (thread context class loader is determined on each call).

Method Summary
public static  String[]discoverClassNames(SPInterface spi, Properties properties)
    

Discover names of SPI implementation Classes from properties. The names are the non-null values, in order, obtained from the following resources:

  • ManagedProperty.getProperty(SPI.class.getName());
  • properties.getProperty(SPI.class.getName());

Parameters:
  properties - Properties that may define the implementationclass name(s).
public  Classfind(Class spiClass)
     Find class implementing SPI.
Parameters:
  spiClass - Service Provider Interface Class.
public  Classfind(Class spiClass, Properties properties)
     Find class implementing SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  properties - Used to determine name of SPI implementation.
public  Classfind(Class spiClass, String defaultImpl)
     Find class implementing SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  defaultImpl - Default implementation name.
public  Classfind(Class spiClass, Properties properties, String defaultImpl)
     Find class implementing SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  properties - Used to determine name of SPI implementation,.
Parameters:
  defaultImpl - Default implementation class.
public  Classfind(Class spiClass, String propertiesFileName, String defaultImpl)
     Find class implementing SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  propertiesFileName - Used to determine name of SPI implementation,.
Parameters:
  defaultImpl - Default implementation class.
public static  Classfind(ClassLoaders loaders, SPInterface spi, PropertiesHolder properties, DefaultClassHolder defaultImpl)
     Find class implementing SPI.
Parameters:
  spi - Service Provider Interface Class.
Parameters:
  properties - Used to determine name of SPI implementation,.
Parameters:
  defaultImpl - Default implementation class.
public  ClassLoadersgetClassLoaders(Class spiClass)
    
public static  StringgetManagedProperty(String propertyName)
     Load the class whose name is given by the value of a (Managed) System Property.
public  ObjectnewInstance(Class spiClass)
     Create new instance of class implementing SPI.
Parameters:
  spiClass - Service Provider Interface Class.
public  ObjectnewInstance(Class spiClass, Properties properties)
     Create new instance of class implementing SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  properties - Used to determine name of SPI implementation,and passed to implementation.init() method ifimplementation implements Service interface.
public  ObjectnewInstance(Class spiClass, String defaultImpl)
     Create new instance of class implementing SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  defaultImpl - Default implementation.
public  ObjectnewInstance(Class spiClass, Properties properties, String defaultImpl)
     Create new instance of class implementing SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  properties - Used to determine name of SPI implementation,and passed to implementation.init() method ifimplementation implements Service interface.
Parameters:
  defaultImpl - Default implementation.
public  ObjectnewInstance(Class spiClass, String propertiesFileName, String defaultImpl)
     Create new instance of class implementing SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  propertiesFileName - Used to determine name of SPI implementation,and passed to implementation.init() method ifimplementation implements Service interface.
Parameters:
  defaultImpl - Default implementation.
public static  ObjectnewInstance(ClassLoaders loaders, SPInterface spi, PropertiesHolder properties, DefaultClassHolder defaultImpl)
     Create new instance of class implementing SPI.
Parameters:
  spi - Service Provider Interface Class.
Parameters:
  properties - Used to determine name of SPI implementation,and passed to implementation.init() method ifimplementation implements Service interface.
Parameters:
  defaultImpl - Default implementation.

Field Detail
nullDefaultImpl
final public static DefaultClassHolder nullDefaultImpl(Code)
Readable placeholder for a null value.



nullProperties
final public static PropertiesHolder nullProperties(Code)
Readable placeholder for a null value.




Constructor Detail
DiscoverClass
public DiscoverClass()(Code)
Create a class instance with dynamic environment (thread context class loader is determined on each call). Dynamically construct class loaders on each call.



DiscoverClass
public DiscoverClass(ClassLoaders classLoaders)(Code)
Create a class instance with dynamic environment (thread context class loader is determined on each call). Cache static list of class loaders for each call.




Method Detail
discoverClassNames
public static String[] discoverClassNames(SPInterface spi, Properties properties)(Code)

Discover names of SPI implementation Classes from properties. The names are the non-null values, in order, obtained from the following resources:

  • ManagedProperty.getProperty(SPI.class.getName());
  • properties.getProperty(SPI.class.getName());

Parameters:
  properties - Properties that may define the implementationclass name(s). String[] Name of classes implementing the SPI.
exception:
  DiscoveryException - Thrown if the name of a class implementingthe SPI cannot be found.



find
public Class find(Class spiClass) throws DiscoveryException(Code)
Find class implementing SPI.
Parameters:
  spiClass - Service Provider Interface Class. Class implementing the SPI.
exception:
  DiscoveryException - Thrown if the name of a class implementingthe SPI cannot be found, if the class cannot be loaded, or ifthe resulting class does not implement (or extend) the SPI.



find
public Class find(Class spiClass, Properties properties) throws DiscoveryException(Code)
Find class implementing SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  properties - Used to determine name of SPI implementation. Class implementing the SPI.
exception:
  DiscoveryException - Thrown if the name of a class implementingthe SPI cannot be found, if the class cannot be loaded, or ifthe resulting class does not implement (or extend) the SPI.



find
public Class find(Class spiClass, String defaultImpl) throws DiscoveryException(Code)
Find class implementing SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  defaultImpl - Default implementation name. Class implementing the SPI.
exception:
  DiscoveryException - Thrown if the name of a class implementingthe SPI cannot be found, if the class cannot be loaded, or ifthe resulting class does not implement (or extend) the SPI.



find
public Class find(Class spiClass, Properties properties, String defaultImpl) throws DiscoveryException(Code)
Find class implementing SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  properties - Used to determine name of SPI implementation,.
Parameters:
  defaultImpl - Default implementation class. Class implementing the SPI.
exception:
  DiscoveryException - Thrown if the name of a class implementingthe SPI cannot be found, if the class cannot be loaded, or ifthe resulting class does not implement (or extend) the SPI.



find
public Class find(Class spiClass, String propertiesFileName, String defaultImpl) throws DiscoveryException(Code)
Find class implementing SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  propertiesFileName - Used to determine name of SPI implementation,.
Parameters:
  defaultImpl - Default implementation class. Class implementing the SPI.
exception:
  DiscoveryException - Thrown if the name of a class implementingthe SPI cannot be found, if the class cannot be loaded, or ifthe resulting class does not implement (or extend) the SPI.



find
public static Class find(ClassLoaders loaders, SPInterface spi, PropertiesHolder properties, DefaultClassHolder defaultImpl) throws DiscoveryException(Code)
Find class implementing SPI.
Parameters:
  spi - Service Provider Interface Class.
Parameters:
  properties - Used to determine name of SPI implementation,.
Parameters:
  defaultImpl - Default implementation class. Class implementing the SPI.
exception:
  DiscoveryException - Thrown if the name of a class implementingthe SPI cannot be found, if the class cannot be loaded, or ifthe resulting class does not implement (or extend) the SPI.



getClassLoaders
public ClassLoaders getClassLoaders(Class spiClass)(Code)



getManagedProperty
public static String getManagedProperty(String propertyName)(Code)
Load the class whose name is given by the value of a (Managed) System Property.
See Also:   ManagedProperties
Parameters:
  propertName - the name of the system property whose value isthe name of the class to load.



newInstance
public Object newInstance(Class spiClass) throws DiscoveryException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException(Code)
Create new instance of class implementing SPI.
Parameters:
  spiClass - Service Provider Interface Class. Instance of a class implementing the SPI.
exception:
  DiscoveryException - Thrown if the name of a class implementingthe SPI cannot be found, if the class cannot be loaded andinstantiated, or if the resulting class does not implement(or extend) the SPI.



newInstance
public Object newInstance(Class spiClass, Properties properties) throws DiscoveryException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException(Code)
Create new instance of class implementing SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  properties - Used to determine name of SPI implementation,and passed to implementation.init() method ifimplementation implements Service interface. Instance of a class implementing the SPI.
exception:
  DiscoveryException - Thrown if the name of a class implementingthe SPI cannot be found, if the class cannot be loaded andinstantiated, or if the resulting class does not implement(or extend) the SPI.



newInstance
public Object newInstance(Class spiClass, String defaultImpl) throws DiscoveryException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException(Code)
Create new instance of class implementing SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  defaultImpl - Default implementation. Instance of a class implementing the SPI.
exception:
  DiscoveryException - Thrown if the name of a class implementingthe SPI cannot be found, if the class cannot be loaded andinstantiated, or if the resulting class does not implement(or extend) the SPI.



newInstance
public Object newInstance(Class spiClass, Properties properties, String defaultImpl) throws DiscoveryException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException(Code)
Create new instance of class implementing SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  properties - Used to determine name of SPI implementation,and passed to implementation.init() method ifimplementation implements Service interface.
Parameters:
  defaultImpl - Default implementation. Instance of a class implementing the SPI.
exception:
  DiscoveryException - Thrown if the name of a class implementingthe SPI cannot be found, if the class cannot be loaded andinstantiated, or if the resulting class does not implement(or extend) the SPI.



newInstance
public Object newInstance(Class spiClass, String propertiesFileName, String defaultImpl) throws DiscoveryException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException(Code)
Create new instance of class implementing SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  propertiesFileName - Used to determine name of SPI implementation,and passed to implementation.init() method ifimplementation implements Service interface.
Parameters:
  defaultImpl - Default implementation. Instance of a class implementing the SPI.
exception:
  DiscoveryException - Thrown if the name of a class implementingthe SPI cannot be found, if the class cannot be loaded andinstantiated, or if the resulting class does not implement(or extend) the SPI.



newInstance
public static Object newInstance(ClassLoaders loaders, SPInterface spi, PropertiesHolder properties, DefaultClassHolder defaultImpl) throws DiscoveryException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException(Code)
Create new instance of class implementing SPI.
Parameters:
  spi - Service Provider Interface Class.
Parameters:
  properties - Used to determine name of SPI implementation,and passed to implementation.init() method ifimplementation implements Service interface.
Parameters:
  defaultImpl - Default implementation. Instance of a class implementing the SPI.
exception:
  DiscoveryException - Thrown if the name of a class implementingthe SPI cannot be found, if the class cannot be loaded andinstantiated, or if the resulting class does not implement(or extend) the SPI.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(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.