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.net.MalformedURLException;
19
20 /***
21 * This class hides the construction of pointers. It helps determine the exact type of pointer and
22 * contstructs it. If modifications need to be made to this behavior it will be hidden here.
23 *
24 * @author pramirez
25 * @version $Revision$
26 *
27 */
28 public class PointerStatementFactory implements PointerType {
29 public static PointerStatement newInstance(int line, String identifier, Value value) throws MalformedURLException {
30
31
32
33
34
35 if (value instanceof TextString) {
36 for (int i = 0; i < INCLUDE_NAMES.length; i++) {
37 if (identifier.endsWith(INCLUDE_NAMES[i]))
38 return new IncludePointer(line, identifier, value);
39 }
40 return new ExternalPointer(resolvePointerType(identifier), line, identifier, value);
41 } else if (value instanceof Sequence) {
42 return new ExternalPointer(resolvePointerType(identifier), line, identifier, value);
43 }
44 else
45 return new PointerStatement(resolvePointerType(identifier), line, identifier, value);
46 }
47
48 private static int resolvePointerType(String identifier) {
49 int pointerType = UNDEFINED;
50 for (int i = 0; i < DESCRIPTION_NAMES.length && pointerType == UNDEFINED; i++) {
51 if (identifier.endsWith(DESCRIPTION_NAMES[i]))
52 pointerType = DESCRIPTION;
53 }
54 if (pointerType == UNDEFINED)
55 pointerType = DATA_LOCATION;
56
57 return pointerType;
58 }
59 }