1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package gov.nasa.pds.tools.label;
17
18 /***
19 * This class hides the construction of pointers. It helps determine the exact type of pointer and
20 * constructs it. If modifications need to be made to this behavior it will be hidden here.
21 *
22 * @author pramirez
23 * @version $Revision$
24 *
25 */
26 public class PointerStatementFactory implements PointerType {
27
28 public static PointerStatement newInstance(int line, String identifier, Value value) {
29 int pointerType = resolvePointerType(identifier, value);
30 PointerStatement newPointer = null;
31
32 if (pointerType == DATA_LOCATION) {
33 newPointer = new DataLocationPointer(line, identifier, value);
34 } else if (pointerType == INCLUDE) {
35 if (identifier.equals(CATALOG))
36 newPointer = new CatalogPointer(line, identifier, value);
37 else
38 newPointer = new IncludePointer(line, identifier, value);
39 } else if (pointerType == DESCRIPTION) {
40 newPointer = new DescriptionPointer(line, identifier, value);
41 } else
42 newPointer = new PointerStatement(UNDEFINED, line, identifier, value);
43
44 return newPointer;
45 }
46
47 private static int resolvePointerType(String identifier, Value value) {
48 int pointerType = UNDEFINED;
49 for (int i = 0; i < DESCRIPTION_NAMES.length && pointerType == UNDEFINED; i++) {
50 if (identifier.endsWith(DESCRIPTION_NAMES[i]))
51 pointerType = DESCRIPTION;
52 }
53 if (value instanceof TextString) {
54 for (int i = 0; i < INCLUDE_NAMES.length && pointerType == UNDEFINED; i++) {
55 if (identifier.endsWith(INCLUDE_NAMES[i]))
56 pointerType = INCLUDE;
57 }
58 if (identifier.equals(CATALOG))
59 pointerType = INCLUDE;
60 }
61 if (pointerType == UNDEFINED)
62 pointerType = DATA_LOCATION;
63
64 return pointerType;
65 }
66 }