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 2939 2007-09-27 20:21:20Z 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: 2939 $
27   * 
28   */
29  public class ObjectDefinition extends Definition implements DictionaryTokens {
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          objectType = OBJECT_TYPE_GENERIC;
43      }
44      
45      /***
46       * @return Returns the names optional elements.
47       */
48      public List getOptionalElements() {
49          return optionalElements;
50      }
51      
52      /***
53       * @param optionalElements The names of optional elements.
54       */
55      public void setOptionalElements(List optionalElements) {
56          this.optionalElements = optionalElements;
57      }
58      
59      /***
60       * @return Returns the name of optional objects.
61       */
62      public List getOptionalObjects() {
63          return optionalObjects;
64      }
65      
66      /***
67       * @param optionalObjects The names of optional objects.
68       */
69      public void setOptionalObjects(List optionalObjects) {
70          this.optionalObjects = optionalObjects;
71      }
72      
73      /***
74       * @return Returns the names of required elements.
75       */
76      public List getRequiredElements() {
77          return requiredElements;
78      }
79      
80      /***
81       * @param requiredElements The names of required elements.
82       */
83      public void setRequiredElements(List requiredElements) {
84          this.requiredElements = requiredElements;
85      }
86      
87      /***
88       * @return Returns the names of required objects.
89       */
90      public List getRequiredObjects() {
91          return requiredObjects;
92      }
93      
94      /***
95       * @param requiredObjects The names of required objects.
96       */
97      public void setRequiredObjects(List requiredObjects) {
98          this.requiredObjects = requiredObjects;
99      }
100     
101   
102     /***
103      * 
104      * @param identifier
105      * @return true if element is required otherwise false.
106      */
107     public boolean isElementRequired(String identifier) {
108         return requiredElements.contains(identifier);
109     }
110     
111     /***
112      * 
113      * @param identifier
114      * @return true if element can occur otherwise false.
115      */
116     public boolean isElementPossible(String identifier) {
117         if (requiredElements.contains(identifier))
118             return true;
119         else if (optionalElements.contains(identifier))
120             return true;
121         return optionalElements.contains(PSDD);
122     }
123     
124     /***
125      * 
126      * @param identifier
127      * @return true if element is optional otherwise false.
128      */
129     public boolean isElementOptional(String identifier) {
130         if (optionalElements.contains(identifier))
131             return true;
132         return optionalElements.contains(PSDD);
133     }
134     
135     /***
136      * 
137      * @param identifier
138      * @return true if the object is required otherwise false.
139      */
140     public boolean isObjectRequired(String identifier) {
141         return requiredObjects.contains(identifier);
142     }
143     
144     /***
145      * 
146      * @param identifier
147      * @return true if the object is optional otherwise false.
148      */
149     public boolean isObjectOptional(String identifier) {
150         return optionalObjects.contains(identifier);
151     }
152     
153     /***
154      * 
155      * @param identifier
156      * @return true if the object can occur.
157      */
158     public boolean isObjectPossible(String identifier) {
159         boolean exists = requiredObjects.contains(identifier);
160         if (exists)
161             return true;
162         return optionalObjects.contains(identifier);
163     }
164     
165 }