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: AttributeStatement.java 2606 2007-04-18 19:35:09Z pramirez $ 
14  //
15  
16  package gov.nasa.pds.tools.label;
17  
18  /***
19   * This class represents an attribute assignment in a PDS label file.
20   * @author pramirez
21   * @version $Revision: 2606 $
22   * 
23   */
24  public class AttributeStatement extends Statement {
25      private Value value;
26      private String namespace;
27      private String elementIdentifier;
28      private CommentStatement comment;
29      
30      /***
31       * Constructs a new attribute statement with no value
32       * @param lineNumber Line on which the statement starts
33       * @param identifier Uniquely identifies the statement
34       */
35      protected AttributeStatement(int lineNumber, String identifier) {
36          this(lineNumber, identifier, null);
37      }
38      
39      /***
40       * Constructs a new attribute statement with no line number or value
41       * @param identifier Uniquely identifies the statement
42       */
43      public AttributeStatement(String identifier) {
44          this(identifier, null);
45      }
46      
47      /***
48       * Constructs a new attribute statement with no line number
49       * @param identifier Uniquely identifies the statement
50       * @param value {@link Value} of the attribute
51       */
52      public AttributeStatement(String identifier, Value value) {
53          this(-1, identifier, value);
54      }
55      
56      /***
57       * 
58       * @param lineNumber Line on which the statement starts
59       * @param identifier Uniquely identifies the statement
60       * @param value {@link Value} of the attribute
61       */
62      public AttributeStatement(int lineNumber, String identifier, Value value) {
63          super(lineNumber, identifier);
64          
65          namespace = "";
66          if (identifier.indexOf(":") != -1)
67              namespace = identifier.substring(0, identifier.indexOf(":"));
68          
69          if (identifier.indexOf(":") == -1)
70              elementIdentifier = identifier;
71          else
72              elementIdentifier = identifier.substring(identifier.indexOf(":") + 1);
73          
74          this.value = value;
75  
76          comment = null;
77      }
78      
79      /***
80       * Gets the namespace for this attribute
81       * @return The namespace or "" if none is found.
82       */
83      public String getNamespace() {
84          return namespace;
85      }
86      
87      /***
88       * Gets the unqualified identifier for the att
89       * @return Returns the element identifier.
90       */
91      public String getElementIdentifier() {
92          return elementIdentifier;
93      }
94  
95      /***
96       * Retrieves the value of the attribute
97       * @return {@link Value} of the attribute
98       */
99      public Value getValue() {
100         return value;
101     }
102     
103     /***
104      * Sets the value for this attribute
105      * @param value {@link Value} of the attribute
106      */
107     public void setValue(Value value) {
108         this.value = value;
109     }
110 
111     public void attachComment(CommentStatement comment) {
112         this.comment = comment;
113     }
114     
115     public boolean hasNamespace() {
116         if ("".equals(namespace))
117             return true;
118         return false;
119     }
120 
121 }