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: CatalogPointer.java 3836 2009-01-14 18:50:02Z pramirez $ 
14  //
15  
16  package gov.nasa.pds.tools.label;
17  
18  import gov.nasa.pds.tools.label.parser.LabelParser;
19  import gov.nasa.pds.tools.label.parser.LabelParserFactory;
20  import gov.nasa.pds.tools.label.parser.ParseException;
21  
22  import java.io.IOException;
23  import java.net.URL;
24  import java.util.Iterator;
25  import java.util.List;
26  
27  /***
28   * This class represents a pointer to a catalog file. This is different than normal
29   * pointers in that it can reference several files.
30   * 
31   * @author pramirez
32   * @version $Revision: 3836 $
33   * 
34   */
35  public class CatalogPointer extends IncludePointer {
36  
37  	public CatalogPointer(int lineNumber, String identifier, Value value) {
38  		super(lineNumber, identifier, value);
39  	}
40  
41  	/***
42       * This method attempts to load the referenced statements. If unsuccessful will throw an error.
43       * Once loaded the statements are held in the class so they may be accessed at a later time.
44       * @param includePaths An list of {@link URL} in which to search for the referenced file
45       * @throws ParseException thrown if the file can not be properly loaded
46       * @throws IOException thrown if file can not be accessed
47       */
48      public synchronized void loadReferencedStatements(List includePaths) throws ParseException, IOException {
49          if (!loaded) {
50          	for (Iterator n = getExternalFileReferences().iterator(); n.hasNext();) {
51          		String filename = (String) n.next();
52  	            URL labelURL = URLResolver.resolveURL(includePaths, this, filename);
53  	            loaded = true;
54  	            LabelParser parser = LabelParserFactory.getInstance().newLabelParser();
55  	            for (Iterator i = includePaths.iterator(); i.hasNext();)
56  	                parser.addIncludePath((URL) i.next());
57  	            String labelContext = context;
58  	            if (labelContext == null)
59  	                labelContext = filename;
60  	            Label label = parser.parsePartial(labelContext, labelURL);
61  	            loadStatus = label.getStatus();
62  	            statements = label.getStatements();
63  	            numErrors = label.getNumErrors();
64  	            numWarnings = label.getNumWarnings();
65          	}
66          }
67      }
68  }