// 
// FooFactory.java
// 

package com.example.foo.spi;

import java.util.ServiceLoader;

public class FooFactory {

  private static Foo theFoo = null;
  private static ServiceLoader<Foo> fooServiceProviders =
    ServiceLoader.load(Foo.class);

  public static Foo getFoo() {
    if (theFoo == null) {
      for (Foo f : fooServiceProviders) {
        theFoo = f;
      }
    }
    return theFoo;
  }

}
