1 package org.jboss.test.bpel.ws.consumption.partner.spi; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 import java.util.Locale ; 6 7 import org.jboss.test.bpel.ws.consumption.partner.resource.ResourceDictionaryFactory; 8 import org.jboss.test.bpel.ws.consumption.partner.types.TDictionaryNotAvailable; 9 10 14 public abstract class DictionaryFactory { 15 16 private static List instances = new ArrayList (); 17 18 public abstract Dictionary createDictionary(Locale sourceLocale, Locale targetLocale); 19 20 public abstract boolean acceptsLocales(Locale sourceLocale, Locale targetLocale); 21 22 public static DictionaryFactory getInstance(Locale sourceLocale, Locale targetLocale) 23 throws TDictionaryNotAvailable { 24 for (int i = 0, n = instances.size(); i < n; i++) { 25 DictionaryFactory factory = (DictionaryFactory) instances.get(i); 26 if (factory.acceptsLocales(sourceLocale, targetLocale)) { 27 return factory; 28 } 29 } 30 throw new TDictionaryNotAvailable(); 31 } 32 33 public static void registerInstance(DictionaryFactory instance) { 34 instances.add(instance); 35 } 36 37 static { 38 registerInstance(new ResourceDictionaryFactory()); 39 } 40 } | Popular Tags |