The Service API is in all sun JVMs since 1.3 under sun.misc.Service.<br>The docs can be found under the previous links I've sent.<br><br><div><span class="gmail_quote">On 2/15/07, <b class="gmail_sendername">Boris Unckel
</b> <<a href="mailto:boris.unckel.mlg@gmx.net">boris.unckel.mlg@gmx.net</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br><br>Eric Crahen wrote:<br>> ....<br>> I think that we can resolve the undesirable issues while still<br>> retaining the behavior we have today. Here is my proposal:<br>><br>> Create a single LoggerFactory and placed it into slf4j-api, and
<br>> deleted the LoggerFactory classes everywhere else they exist<br>> (slf4j-simple, logback, etc). This new LoggerFactory leverages Sun's<br>> ServiceProvider API which exists in all JDK's since 1.4 (maybe
1.3).<br>> It looks like this:<br><br>do you have a link to the service provider API? I searched the SUN site<br>but did not find anything but the usage of the Service Provider but<br><a href="http://java.sun.com/j2se/1.4.2/docs/guide/jar/jar.html#Service%20Provider">
http://java.sun.com/j2se/1.4.2/docs/guide/jar/jar.html#Service%20Provider</a><br><br>I am wondering this nice feature is just accesible through sun. packages.<br><br>Regards<br>Boris<br><br><br>public class SampleServiceLoader {
<br><br> public static final String SERVICE_ID =<br> "META-INF/services/org.slf4j.ILoggerFactory";<br><br> /**<br> *<br> */<br> public SampleServiceLoader() {<br> super();<br> }
<br><br> public Object obtainFactory() {<br> ILoggerFactory ret = null;<br> ClassLoader cl = Thread.currentThread().getContextClassLoader();<br> InputStream is = cl.getResourceAsStream(SERVICE_ID);
<br> String factoryname = null;<br> if(is != null) {<br> BufferedReader bufferedReader = null;<br> String errmsg = "Error obtaining service provider with<br>id["+SERVICE_ID+"]";
<br> try {<br> bufferedReader = new BufferedReader(new<br>InputStreamReader(is));<br> factoryname = bufferedReader.readLine();<br> Class factoryClass = cl.loadClass(factoryname);
<br> ret = factoryClass.newInstance();<br> } catch (IOException e) {<br> throw new RuntimeException(errmsg,e);<br> } catch (ClassNotFoundException e) {<br> throw new RuntimeException(errmsg,e);
<br> } catch (InstantiationException e) {<br> throw new RuntimeException(errmsg,e);<br> } catch (IllegalAccessException e) {<br> throw new RuntimeException(errmsg,e);<br>
} finally {<br> try {<br> bufferedReader.close();<br> } catch (IOException e) {<br> // NOP<br> }<br> }<br> } else {
<br> throw new RuntimeException("Service Provider["+SERVICE_ID+"]<br>not found.");<br> }<br> return ret;<br> }<br><br>}<br><br>_______________________________________________
<br>dev mailing list<br><a href="mailto:dev@slf4j.org">dev@slf4j.org</a><br><a href="http://www.slf4j.org/mailman/listinfo/dev">http://www.slf4j.org/mailman/listinfo/dev</a><br></blockquote></div><br><br clear="all"><br>--
<br><br>- Eric