View Javadoc

1   // Copyright 2006-2007, by the California Institute of Technology.
2   // ALL RIGHTS RESERVED. United States Government Sponsorship acknowledged.
3   // Any commercial use must be negotiated with the Office of Technology Transfer
4   // at the California Institute of Technology.
5   //
6   // This software is subject to U. S. export control laws and regulations
7   // (22 C.F.R. 120-130 and 15 C.F.R. 730-774). To the extent that the software
8   // is subject to U.S. export control laws and regulations, the recipient has
9   // the responsibility to obtain export licenses or other export authority as
10  // may be required before exporting such information to foreign countries or
11  // providing access to foreign nationals.
12  //
13  // $Id: LabelParserFactory.java 2904 2007-09-27 13:06:54Z pramirez $ 
14  //
15  
16  package gov.nasa.pds.tools.label.parser;
17  
18  import gov.nasa.pds.tools.label.validate.FileCharacteristicValidator;
19  import gov.nasa.pds.tools.label.validate.DuplicateIdentifierValidator;
20  
21  /***
22   * This class will be used to generate label parsers.
23   * @author pramirez
24   * @version $Revision: 2904 $
25   * 
26   */
27  public class LabelParserFactory {
28      private static LabelParserFactory factory = null;
29      
30      /***
31       * Constructs a parser factory following the Singleton pattern
32       */
33      private LabelParserFactory() {
34      }
35      
36      /***
37       * Retrieve a factory which will create
38       * @return parser factory that will generate parsers
39       */
40      public synchronized static LabelParserFactory getInstance() {
41          if (factory == null) 
42              factory = new LabelParserFactory();
43          
44          return factory;
45      }
46      
47      /***
48       * Retrieves a parser that will read in PDS label files.
49       * @return The parser
50       */
51      public LabelParser newLabelParser() {
52          // TODO: Change to dynamic class loading based upon configuration
53          LabelParser parser = new DefaultLabelParser();
54          parser.addValidator(new FileCharacteristicValidator());
55          parser.addValidator(new DuplicateIdentifierValidator());
56          return parser;
57      }
58  
59  }