1 26 27 package net.sourceforge.groboutils.util.classes.v1; 28 29 import java.io.IOException ; 30 31 import org.apache.log4j.Logger; 32 33 34 35 49 public class SPISingletonStore extends AbstractMultipleStore 50 { 51 private static final Logger LOG = Logger.getLogger( 52 SPISingletonStore.class.getName() ); 53 54 private Class baseClass; 55 56 57 68 public SPISingletonStore( Class instanceOf, AllowMultiplesAction ama ) 69 { 70 super( instanceOf, ama ); 71 72 if (instanceOf == null) 73 { 74 throw new IllegalArgumentException ("no null arguments"); 75 } 76 77 this.baseClass = instanceOf; 78 } 79 80 81 85 protected void addDefaultSingletons() 86 { 87 try 88 { 89 addSPI( null ); 90 } 91 catch (IOException ioe) 92 { 93 LOG.warn( "adding SPI caused IOException", ioe ); 94 throw new IllegalStateException ( ioe.toString() ); 95 } 96 } 97 98 99 102 public void addSPI( ClassLoader cl ) 103 throws IOException 104 { 105 SPILoader spil = new SPILoader( this.baseClass, cl ); 106 107 while (spil.hasNext()) 108 { 109 addSingleton( spil.nextProvier() ); 110 } 111 } 112 } 113 114 | Popular Tags |