KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > bpel > ws > consumption > partner > spi > DictionaryFactory


1 package org.jboss.test.bpel.ws.consumption.partner.spi;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5 import java.util.Locale JavaDoc;
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 /**
11  * @author Alejandro Guizar
12  * @version $Revision: 43322 $ $Date: 2006-04-03 12:19:24 -0400 (Mon, 03 Apr 2006) $
13  */

14 public abstract class DictionaryFactory {
15   
16   private static List JavaDoc instances = new ArrayList JavaDoc();
17   
18   public abstract Dictionary createDictionary(Locale JavaDoc sourceLocale, Locale JavaDoc targetLocale);
19   
20   public abstract boolean acceptsLocales(Locale JavaDoc sourceLocale, Locale JavaDoc targetLocale);
21     
22   public static DictionaryFactory getInstance(Locale JavaDoc sourceLocale, Locale JavaDoc 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