2323import java .lang .reflect .InvocationTargetException ;
2424import java .net .URL ;
2525import java .util .ArrayList ;
26+ import java .util .Collection ;
2627import java .util .Enumeration ;
2728import java .util .HashSet ;
2829import java .util .Iterator ;
2930import java .util .List ;
3031import java .util .Set ;
3132
3233import com .ocpsoft .common .spi .ServiceEnricher ;
34+ import com .ocpsoft .common .spi .ServiceLocator ;
3335
3436/**
3537 * This class handles looking up service providers on the class path. It implements the <a
@@ -109,34 +111,14 @@ public static <S> ServiceLoader<S> load(final Class<S> service, ClassLoader load
109111 return new ServiceLoader <S >(service , loader );
110112 }
111113
112- /**
113- * Creates a new service loader for the given service type, using the extension class loader.
114- *
115- * This convenience method simply locates the extension class loader, call it extClassLoader, and then returns
116- *
117- * <code>ServiceLoader.load(service, extClassLoader)</code>
118- *
119- * If the extension class loader cannot be found then the system class loader is used; if there is no system class
120- * loader then the bootstrap class loader is used.
121- *
122- * This method is intended for use when only installed providers are desired. The resulting service will only find
123- * and load providers that have been installed into the current Java virtual machine; providers on the application's
124- * class path will be ignored.
125- *
126- * @param service The interface or abstract class representing the service
127- * @return A new service loader
128- */
129- public static <S > ServiceLoader <S > loadInstalled (final Class <S > service )
130- {
131- throw new UnsupportedOperationException ("Not implemented" );
132- }
133-
134114 private final String serviceFile ;
135115 private final Class <S > expectedType ;
136116 private final ClassLoader loader ;
137117
138118 private Set <S > providers ;
139119
120+ private java .util .ServiceLoader <ServiceLocator > locatorLoader ;
121+
140122 private ServiceLoader (final Class <S > service , final ClassLoader loader )
141123 {
142124 this .loader = loader ;
@@ -161,6 +143,22 @@ public void reload()
161143 {
162144 loadServiceFile (serviceFile );
163145 }
146+
147+ if (locatorLoader == null )
148+ locatorLoader = java .util .ServiceLoader
149+ .load (ServiceLocator .class );
150+
151+ for (ServiceLocator locator : locatorLoader )
152+ {
153+ Collection <Class <S >> serviceTypes = locator .locate (expectedType );
154+ if ((serviceTypes != null ) && !serviceTypes .isEmpty ())
155+ {
156+ for (Class <S > type : serviceTypes ) {
157+ loadClass (type ); // TODO lb3 test this now
158+ }
159+ }
160+ }
161+
164162 }
165163
166164 private List <URL > loadServiceFiles ()
@@ -232,6 +230,11 @@ private String trim(String line)
232230 private void loadService (final String serviceClassName )
233231 {
234232 Class <? extends S > serviceClass = loadClass (serviceClassName );
233+ loadClass (serviceClass );
234+ }
235+
236+ private void loadClass (final Class <? extends S > serviceClass )
237+ {
235238 if (serviceClass == null )
236239 {
237240 return ;
0 commit comments