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: ObjectDefinition.java 2601 2007-04-12 18:34:25Z pramirez $
14  //
15  
16  package gov.nasa.pds.tools.dict;
17  
18  import java.util.List;
19  import java.util.ArrayList;
20  
21  /***
22   * This class represents an object definition in the PDS data
23   * dictionary. 
24   * 
25   * @author pramirez
26   * @version $Revision: 2601 $
27   * 
28   */
29  public class ObjectDefinition extends Definition {
30      private List requiredElements;
31      private List optionalElements;
32      private List requiredObjects;
33      private List optionalObjects;
34      private static final String PSDD = "PSDD";
35      
36      public ObjectDefinition(String identifier) {
37          super(identifier);
38          requiredElements = new ArrayList();
39          optionalElements = new ArrayList();
40          requiredObjects = new ArrayList();
41          optionalObjects = new ArrayList();
42      }
43      
44      /***
45       * @return Returns the names optional elements.
46       */
47      public List getOptionalElements() {
48          return optionalElements;
49      }
50      
51      /***
52       * @param optionalElements The names of optional elements.
53       */
54      public void setOptionalElements(List optionalElements) {
55          this.optionalElements = optionalElements;
56      }
57      
58      /***
59       * @return Returns the name of optional objects.
60       */
61      public List getOptionalObjects() {
62          return optionalObjects;
63      }
64      
65      /***
66       * @param optionalObjects The names of optional objects.
67       */
68      public void setOptionalObjects(List optionalObjects) {
69          this.optionalObjects = optionalObjects;
70      }
71      
72      /***
73       * @return Returns the names of required elements.
74       */
75      public List getRequiredElements() {
76          return requiredElements;
77      }
78      
79      /***
80       * @param requiredElements The names of required elements.
81       */
82      public void setRequiredElements(List requiredElements) {
83          this.requiredElements = requiredElements;
84      }
85      
86      /***
87       * @return Returns the names of required objects.
88       */
89      public List getRequiredObjects() {
90          return requiredObjects;
91      }
92      
93      /***
94       * @param requiredObjects The names of required objects.
95       */
96      public void setRequiredObjects(List requiredObjects) {
97          this.requiredObjects = requiredObjects;
98      }
99      
100   
101     /***
102      * 
103      * @param identifier
104      * @return true if element is required otherwise false.
105      */
106     public boolean isElementRequired(String identifier) {
107         return requiredElements.contains(identifier);
108     }
109     
110     /***
111      * 
112      * @param identifier
113      * @return true if element can occur otherwise false.
114      */
115     public boolean isElementPossible(String identifier) {
116         if (requiredElements.contains(identifier))
117             return true;
118         else if (optionalElements.contains(identifier))
119             return true;
120         return optionalElements.contains(PSDD);
121     }
122     
123     /***
124      * 
125      * @param identifier
126      * @return true if element is optional otherwise false.
127      */
128     public boolean isElementOptional(String identifier) {
129         if (optionalElements.contains(identifier))
130             return true;
131         return optionalElements.contains(PSDD);
132     }
133     
134     /***
135      * 
136      * @param identifier
137      * @return true if the object is required otherwise false.
138      */
139     public boolean isObjectRequired(String identifier) {
140         return requiredObjects.contains(identifier);
141     }
142     
143     /***
144      * 
145      * @param identifier
146      * @return true if the object is optional otherwise false.
147      */
148     public boolean isObjectOptional(String identifier) {
149         return optionalObjects.contains(identifier);
150     }
151     
152     /***
153      * 
154      * @param identifier
155      * @return true if the object can occur.
156      */
157     public boolean isObjectPossible(String identifier) {
158         boolean exists = requiredObjects.contains(identifier);
159         if (exists)
160             return true;
161         return optionalObjects.contains(identifier);
162     }
163     
164 }