1
2
3
4
5
6
7
8
9
10
11
12
13
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 }