View Javadoc

1   // Copyright 2006-2007, by the California Institute of Technology.
2   // ALL RIGHTS RESERVED. United States Government Sponsorship acknowledged.
3   // Any commercial use must be negotiated with the Office of Technology Transfer
4   // at the California Institute of Technology.
5   //
6   // This software is subject to U. S. export control laws and regulations
7   // (22 C.F.R. 120-130 and 15 C.F.R. 730-774). To the extent that the software
8   // is subject to U.S. export control laws and regulations, the recipient has
9   // the responsibility to obtain export licenses or other export authority as
10  // may be required before exporting such information to foreign countries or
11  // providing access to foreign nationals.
12  //
13  // $Id$ 
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          //Essentially the pointer will be an internal or external pointer
31          //The two classes of external pointers we need to differentiate between are structure pointers which
32          //should allow us to load statments and just external references where we only care of the existence
33          //of the file which is pointed too
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  }