View Javadoc
1   /**
2    * The contents of this file are subject to the Mozilla Public License Version 1.1
3    * (the "License"); you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at http://www.mozilla.org/MPL/
5    * Software distributed under the License is distributed on an "AS IS" basis,
6    * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
7    * specific language governing rights and limitations under the License.
8    *
9    * The Original Code is "IStructureDefinition.java"
10   *
11   * The Initial Developer of the Original Code is University Health Network. Copyright (C)
12   * 2001.  All Rights Reserved.
13   *
14   * Contributor(s):
15   *
16   * Alternatively, the contents of this file may be used under the terms of the
17   * GNU General Public License (the  �GPL�), in which case the provisions of the GPL are
18   * applicable instead of those above.  If you wish to allow use of your version of this
19   * file only under the terms of the GPL and not to allow others to use your version
20   * of this file under the MPL, indicate your decision by deleting  the provisions above
21   * and replace  them with the notice and other provisions required by the GPL License.
22   * If you do not delete the provisions above, a recipient may use your version of
23   * this file under either the MPL or the GPL.
24   *
25   */
26  
27  package ca.uhn.hl7v2.parser;
28  
29  import java.util.Collections;
30  import java.util.List;
31  import java.util.Set;
32  
33  /**
34   * Structure definition which defines a non-standard structure within a parent
35   * structure.
36   * 
37   * This class is used more as a runtime placeholder than as something that would
38   * be produced by the structure parser.
39   */
40  public class NonStandardStructureDefinition implements IStructureDefinition {
41  
42  	private final String myName;
43  	private final IStructureDefinition myParent;
44  	private final int myPosition;
45  	private final IStructureDefinition myPreviousSibling;
46  
47  	/**
48  	 * Constructor
49  	 */
50  	public NonStandardStructureDefinition(IStructureDefinitionuhn/hl7v2/parser/IStructureDefinition.html#IStructureDefinition">IStructureDefinition theParent, IStructureDefinition thePreviousSibling, String theName, int thePosition) {
51  		if (theName == null || theName.length() == 0) {
52  			throw new IllegalArgumentException("theName is missing");
53  		}
54  		
55  		myParent = theParent;
56  		myName = theName;
57  		myPreviousSibling = thePreviousSibling;
58  		myPosition = thePosition;
59  	}
60  
61  	/**
62  	 * {@inheritDoc }
63  	 */
64  	@Override
65  	public Set<String> getAllChildNames() {
66  		return Collections.emptySet();
67  	}
68  
69  	/**
70  	 * {@inheritDoc }
71  	 */
72  	@Override
73      public Set<String> getAllPossibleFirstChildren() {
74  		return Collections.emptySet();
75  	}
76  
77  	/**
78  	 * {@inheritDoc }
79  	 */
80  	@Override
81  	public List<StructureDefinition> getChildren() {
82  		return Collections.emptyList();
83  	}
84  
85  	/**
86  	 * {@inheritDoc }
87  	 */
88  	@Override
89  	public IStructureDefinition getFirstChild() {
90  		return null;
91  	}
92  
93  	/**
94  	 * {@inheritDoc }
95  	 */
96  	@Override
97  	public IStructureDefinition getFirstSibling() {
98  		return null;
99  	}
100 
101 	/**
102 	 * {@inheritDoc }
103 	 */
104 	public String getName() {
105 		return myName;
106 	}
107 
108 	/**
109 	 * {@inheritDoc}
110 	 */
111 	@Override
112 	public String getNameAsItAppearsInParent() {
113 		return getName();
114 	}
115 
116 	/**
117 	 * {@inheritDoc }
118 	 */
119 	@Override
120 	public Set<String> getNamesOfAllPossibleFollowingLeaves() {
121 		return myPreviousSibling.getNamesOfAllPossibleFollowingLeaves();
122 	}
123 
124 	/**
125 	 * {@inheritDoc }
126 	 */
127 	@Override
128 	public IStructureDefinition getNextLeaf() {
129 		return myPreviousSibling.getNextLeaf();
130 	}
131 
132 	/**
133 	 * {@inheritDoc }
134 	 */
135 	@Override
136 	public IStructureDefinition getNextSibling() {
137 		return myPreviousSibling.getNextSibling();
138 	}
139 
140 	/**
141 	 * {@inheritDoc }
142 	 */
143 	@Override
144 	public IStructureDefinition getParent() {
145 		return myParent;
146 	}
147 
148 	/**
149 	 * {@inheritDoc }
150 	 */
151 	@Override
152 	public int getPosition() {
153 		return myPosition;
154 	}
155 
156 	/**
157 	 * {@inheritDoc }
158 	 */
159 	@Override
160 	public boolean hasChildren() {
161 		return false;
162 	}
163 
164 	/**
165 	 * {@inheritDoc }
166 	 */
167 	@Override
168 	public boolean isFinalChildOfParent() {
169 		return myPreviousSibling.isFinalChildOfParent();
170 	}
171 
172 	/**
173 	 * {@inheritDoc }
174 	 */
175 	@Override
176 	public boolean isRepeating() {
177 		return true;
178 	}
179 
180 	/**
181 	 * {@inheritDoc }
182 	 */
183 	@Override
184 	public boolean isRequired() {
185 		return false;
186 	}
187 
188 	/**
189 	 * {@inheritDoc }
190 	 */
191 	@Override
192 	public boolean isSegment() {
193 		return true;
194 	}
195 
196 	/**
197 	 * {@inheritDoc }
198 	 */
199 	@Override
200 	public boolean isChoiceElement() {
201 		return false;
202 	}
203 
204 }