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 3836 2009-01-14 18:50:02Z pramirez $ 
14  //
15  
16  package gov.nasa.pds.tools.label.parser;
17  
18  import gov.nasa.pds.tools.label.validate.CatalogNameValidator;
19  import gov.nasa.pds.tools.label.validate.FileCharacteristicValidator;
20  import gov.nasa.pds.tools.label.validate.DuplicateIdentifierValidator;
21  
22  /***
23   * This class will be used to generate label parsers.
24   * @author pramirez
25   * @version $Revision: 3836 $
26   * 
27   */
28  public class LabelParserFactory {
29      private static LabelParserFactory factory = null;
30      
31      /***
32       * Constructs a parser factory following the Singleton pattern
33       */
34      private LabelParserFactory() {
35      }
36      
37      /***
38       * Retrieve a factory which will create
39       * @return parser factory that will generate parsers
40       */
41      public synchronized static LabelParserFactory getInstance() {
42          if (factory == null) 
43              factory = new LabelParserFactory();
44          
45          return factory;
46      }
47      
48      /***
49       * Retrieves a parser that will read in PDS label files.
50       * @return The parser
51       */
52      public LabelParser newLabelParser() {
53          // TODO: Change to dynamic class loading based upon configuration
54          LabelParser parser = new DefaultLabelParser();
55          parser.addLabelValidator(new FileCharacteristicValidator());
56          parser.addLabelValidator(new DuplicateIdentifierValidator());
57          parser.addLabelValidator(new CatalogNameValidator());
58          parser.addFragmentValidator(new DuplicateIdentifierValidator());
59          return parser;
60      }
61  
62  }