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
41 /***
42 * Constructs a pointer that can be resolved to a set of statements.
43 * @param lineNumber of statement
44 * @param identifier of statment
45 * @param value assigned to statment
46 */
47 public IncludePointer(int lineNumber, String identifier, Value value) {
48 super(INCLUDE, lineNumber, identifier, value);
49 statements = new ArrayList();
50 loadStatus = UNKNOWN;
51 }
52
53 /***
54 * This method attempts to load the referenced statements. If unsuccessful will throw an error.
55 * Once loaded the statements are held in the class so they may be accessed at a later time.
56 * @param includePaths An list of {@link URL} in which to search for the referenced file
57 * @throws ParseException thrown if the file can not be properly loaded
58 * @throws IOException thrown if file can not be accessed
59 */
60 public synchronized void loadReferencedStatements(List includePaths) throws ParseException, IOException {
61 URL labelURL = resolveURL(includePaths);
62 if (!loaded) {
63 loaded = true;
64 LabelParser parser = LabelParserFactory.getInstance().newLabelParser();
65 for (Iterator i = includePaths.iterator(); i.hasNext();)
66 parser.addIncludePath((URL) i.next());
67 String labelContext = context;
68 if (labelContext == null)
69 labelContext = filename;
70 Label label = parser.parsePartial(labelContext, labelURL);
71 loadStatus = label.getStatus();
72 statements = label.getStatements();
73 }
74 }
75
76 /***
77 * Retrieves the list of statements pointed to by this structure pointer
78 * @return external list of statements
79 */
80 public List getStatements() {
81 return statements;
82 }
83
84 /***
85 * Indicates whether or not the statments pointed to have been loaded.
86 * @return flag indicating load status
87 */
88 public boolean isLoaded() {
89 return loaded;
90 }
91
92 public String getLoadStatus() {
93 return loadStatus;
94 }
95
96 }