001    package com.khubla.pragmatach.framework.i8n;
002    
003    import java.util.HashSet;
004    import java.util.Map;
005    import java.util.Set;
006    
007    import org.slf4j.Logger;
008    import org.slf4j.LoggerFactory;
009    
010    import com.khubla.pragmatach.framework.api.I8NProvider;
011    import com.khubla.pragmatach.framework.plugin.PluginDescriptor;
012    import com.khubla.pragmatach.framework.plugin.PluginDescriptors;
013    
014    /**
015     * @author tome
016     */
017    public class I8NProviders {
018       /**
019        * instance
020        */
021       private static I8NProviders instance = null;
022    
023       /**
024        * singleton
025        */
026       public static I8NProviders getInstance() {
027          if (null == instance) {
028             instance = new I8NProviders();
029          }
030          return instance;
031       }
032    
033       /**
034        * logger
035        */
036       private final Logger logger = LoggerFactory.getLogger(this.getClass());
037       /**
038        * providers
039        */
040       public Set<I8NProvider> providers;
041    
042       /**
043        * ctor
044        */
045       private I8NProviders() {
046          final Map<String, PluginDescriptor> plugins = PluginDescriptors.getPlugins();
047          if (null != plugins) {
048             providers = new HashSet<I8NProvider>();
049             for (final PluginDescriptor pluginDescriptor : plugins.values()) {
050                final I8NProvider i8NProvider = pluginDescriptor.getPlugin().getI8NProvider();
051                if (null != i8NProvider) {
052                   logger.info("Loaded i8N provider: " + i8NProvider.getName());
053                   providers.add(i8NProvider);
054                }
055             }
056          }
057       }
058    }