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 java.io.IOException;
19 import java.net.URL;
20 import java.util.ArrayList;
21 import java.util.Iterator;
22 import java.util.List;
23
24 import gov.nasa.pds.tools.label.parser.LabelParser;
25 import gov.nasa.pds.tools.label.parser.LabelParserFactory;
26 import gov.nasa.pds.tools.label.parser.ParseException;
27 import gov.nasa.pds.tools.label.validate.Status;
28
29 /***
30 * This class represents a pointer that is a set of external statements that can and should
31 * be included in label containing this statement when performing validation.
32 * @author pramirez
33 * @version $Revision$
34 *
35 */
36 public class IncludePointer extends ExternalPointer implements PointerType, Status {
37 private List statements;
38 private boolean loaded = false;
39 private String loadStatus = null;
40 private int numErrors;
41 private int numWarnings;
42
43 /***
44 * Constructs a pointer that can be resolved to a set of statements.
45 * @param lineNumber of statement
46 * @param identifier of statment
47 * @param value assigned to statment
48 */
49 public IncludePointer(int lineNumber, String identifier, Value value) {
50 super(INCLUDE, lineNumber, identifier, value);
51 statements = new ArrayList();
52 numWarnings = 0;
53 numErrors = 0;
54 loadStatus = UNKNOWN;
55 }
56
57 /***
58 * This method attempts to load the referenced statements. If unsuccessful will throw an error.
59 * Once loaded the statements are held in the class so they may be accessed at a later time.
60 * @param includePaths An list of {@link URL} in which to search for the referenced file
61 * @throws ParseException thrown if the file can not be properly loaded
62 * @throws IOException thrown if file can not be accessed
63 */
64 public synchronized void loadReferencedStatements(List includePaths) throws ParseException, IOException {
65 URL labelURL = resolveURL(includePaths);
66 if (!loaded) {
67 loaded = true;
68 LabelParser parser = LabelParserFactory.getInstance().newLabelParser();
69 for (Iterator i = includePaths.iterator(); i.hasNext();)
70 parser.addIncludePath((URL) i.next());
71 String labelContext = context;
72 if (labelContext == null)
73 labelContext = filename;
74 Label label = parser.parsePartial(labelContext, labelURL);
75 loadStatus = label.getStatus();
76 statements = label.getStatements();
77 numErrors = label.getNumErrors();
78 numWarnings = label.getNumWarnings();
79 }
80 }
81
82 /***
83 * Retrieves the list of statements pointed to by this structure pointer
84 * @return external list of statements
85 */
86 public List getStatements() {
87 return statements;
88 }
89
90 /***
91 * Indicates whether or not the statments pointed to have been loaded.
92 * @return flag indicating load status
93 */
94 public boolean isLoaded() {
95 return loaded;
96 }
97
98 public String getLoadStatus() {
99 return loadStatus;
100 }
101
102 public int getNumErrors() {return numErrors;}
103 public int getNumWarnings() {return numWarnings;}
104
105 }