Coverage Report - org.jtheque.primary.PrimaryUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
PrimaryUtils
0 %
0/30
0 %
0/2
1.143
 
 1  
 package org.jtheque.primary;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.jtheque.core.managers.Managers;
 20  
 import org.jtheque.core.managers.feature.Feature;
 21  
 import org.jtheque.core.managers.feature.IFeatureManager;
 22  
 import org.jtheque.core.managers.feature.Menu;
 23  
 import org.jtheque.core.managers.language.ILanguageManager;
 24  
 import org.jtheque.core.managers.schema.ISchemaManager;
 25  
 import org.jtheque.core.managers.schema.Schema;
 26  
 import org.jtheque.primary.od.able.SimpleData;
 27  
 import org.jtheque.primary.utils.DataTypeManager;
 28  
 
 29  
 import java.util.List;
 30  
 
 31  
 /**
 32  
  * The primary utils. This class give to modules some utilities methods to construct primary module.
 33  
  *
 34  
  * @author Baptiste Wicht
 35  
  */
 36  
 public final class PrimaryUtils {
 37  
         private static final String BASE_NAME = "classpath:/org/jtheque/primary/i18n/utils";
 38  
 
 39  
         private static Schema schema;
 40  
 
 41  
         private static Menu menu;
 42  
 
 43  
         private static String primaryImpl;
 44  
 
 45  
         /**
 46  
          * Construct a new PrimaryUtils.
 47  
          */
 48  
         private PrimaryUtils(){
 49  0
                 super();
 50  0
         }
 51  
 
 52  
         /**
 53  
          * Preplug the elements of the utils.
 54  
          */
 55  
         public static void prePlug(){
 56  0
                 schema = new PrimaryUtilsSchema();
 57  
 
 58  0
                 Managers.getManager(ISchemaManager.class).registerSchema(schema);
 59  
 
 60  0
                 Managers.getManager(ILanguageManager.class).addBaseName(BASE_NAME);
 61  0
         }
 62  
 
 63  
         /**
 64  
          * Plug the elements of the utils.
 65  
          */
 66  
         public static void plug(){
 67  0
                 DataTypeManager.bindDataTypeToKey(PrimaryConstants.BORROWERS, "data.titles.borrower");
 68  0
                 DataTypeManager.bindDataTypeToKey(SimpleData.DataType.COUNTRY.getDataType(), "data.titles.country");
 69  0
                 DataTypeManager.bindDataTypeToKey(SimpleData.DataType.LANGUAGE.getDataType(), "data.titles.language");
 70  0
                 DataTypeManager.bindDataTypeToKey(SimpleData.DataType.TYPE.getDataType(), "data.titles.type");
 71  0
                 DataTypeManager.bindDataTypeToKey(SimpleData.DataType.KIND.getDataType(), "data.titles.kind");
 72  0
                 DataTypeManager.bindDataTypeToKey(SimpleData.DataType.SAGA.getDataType(), "data.titles.saga");
 73  0
         }
 74  
 
 75  
         /**
 76  
          * Unplug the elements of the utils.
 77  
          */
 78  
         public static void unplug(){
 79  0
                 DataTypeManager.unbindDataType(PrimaryConstants.BORROWERS);
 80  0
                 DataTypeManager.unbindDataType(SimpleData.DataType.COUNTRY.getDataType());
 81  0
                 DataTypeManager.unbindDataType(SimpleData.DataType.LANGUAGE.getDataType());
 82  0
                 DataTypeManager.unbindDataType(SimpleData.DataType.TYPE.getDataType());
 83  0
                 DataTypeManager.unbindDataType(SimpleData.DataType.KIND.getDataType());
 84  0
                 DataTypeManager.unbindDataType(SimpleData.DataType.SAGA.getDataType());
 85  
 
 86  0
                 Managers.getManager(ISchemaManager.class).unregisterSchema(schema);
 87  
 
 88  0
                 Managers.getManager(ILanguageManager.class).removeBaseName(BASE_NAME);
 89  
 
 90  0
                 if (menu != null){
 91  0
                         Managers.getManager(IFeatureManager.class).removeMenu(menu);
 92  
                 }
 93  0
         }
 94  
 
 95  
         /**
 96  
          * Return the current primary implementation.
 97  
          *
 98  
          * @return The current primary implementation.
 99  
          */
 100  
         public static String getPrimaryImpl(){
 101  0
                 return primaryImpl;
 102  
         }
 103  
 
 104  
         /**
 105  
          * Set the current primary implementation.
 106  
          *
 107  
          * @param primaryImpl The current primary implementation.
 108  
          */
 109  
         public static void setPrimaryImpl(String primaryImpl){
 110  0
                 PrimaryUtils.primaryImpl = primaryImpl;
 111  0
         }
 112  
 
 113  
         /**
 114  
          * Enable the menu of the primary utils module.
 115  
          *
 116  
          * @param addFeatures The sub features of the add menu.
 117  
          * @param removeFeatures The sub features of the remove menu.
 118  
          * @param editFeatures The sub features of the edit menu.
 119  
          */
 120  
         public static void enableMenu(List<Feature> addFeatures, List<Feature> removeFeatures, List<Feature> editFeatures){
 121  0
                 menu = new PrimaryMenu(addFeatures, removeFeatures, editFeatures);
 122  0
         Managers.getManager(IFeatureManager.class).addMenu(menu);
 123  0
         }
 124  
 }