Home | History | Annotate | Download | only in test
      1 package org.unicode.cldr.test;
      2 
      3 import java.util.List;
      4 
      5 import org.unicode.cldr.util.CLDRConfig;
      6 import org.unicode.cldr.util.CLDRFile;
      7 import org.unicode.cldr.util.Factory;
      8 import org.unicode.cldr.util.PathHeader;
      9 
     10 /**
     11  * Subclass of CheckCLDR that requires a factory during checking.
     12  *
     13  * @author jchye
     14  */
     15 abstract class FactoryCheckCLDR extends CheckCLDR {
     16     private Factory factory;
     17     private CLDRFile resolvedCldrFileToCheck;
     18     private PathHeader.Factory pathHeaderFactory;
     19 
     20     public synchronized CLDRFile getEnglishFile() {
     21         if (super.getEnglishFile() != null) {
     22             return super.getEnglishFile();
     23         }
     24         try {
     25             return getFactory().make("en", true);
     26         } catch (Exception e) {
     27             return CLDRConfig.getInstance().getEnglish();
     28         }
     29     }
     30 
     31     public synchronized PathHeader.Factory getPathHeaderFactory() {
     32         if (pathHeaderFactory == null) {
     33             pathHeaderFactory = PathHeader.getFactory(getEnglishFile() != null ? getEnglishFile() : getFactory().make("en", true));
     34         }
     35         return pathHeaderFactory;
     36     }
     37 
     38     public FactoryCheckCLDR(Factory factory) {
     39         super();
     40         this.factory = factory;
     41     }
     42 
     43     public CLDRFile getResolvedCldrFileToCheck() {
     44         if (resolvedCldrFileToCheck == null) {
     45             resolvedCldrFileToCheck = factory.make(getCldrFileToCheck().getLocaleID(), true);
     46         }
     47         return resolvedCldrFileToCheck;
     48     }
     49 
     50     @Override
     51     public CheckCLDR setCldrFileToCheck(CLDRFile cldrFileToCheck, Options options,
     52         List<CheckStatus> possibleErrors) {
     53         super.setCldrFileToCheck(cldrFileToCheck, options, possibleErrors);
     54         resolvedCldrFileToCheck = null;
     55         return this;
     56     }
     57 
     58     public Factory getFactory() {
     59         return factory;
     60     }
     61 }