001/**
002 * The contents of this file are subject to the Mozilla Public License Version 1.1
003 * (the "License"); you may not use this file except in compliance with the License.
004 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
005 * Software distributed under the License is distributed on an "AS IS" basis,
006 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
007 * specific language governing rights and limitations under the License.
008 *
009 * The Original Code is "IStructureDefinition.java"
010 *
011 * The Initial Developer of the Original Code is University Health Network. Copyright (C)
012 * 2001.  All Rights Reserved.
013 *
014 * Contributor(s):
015 *
016 * Alternatively, the contents of this file may be used under the terms of the
017 * GNU General Public License (the  �GPL�), in which case the provisions of the GPL are
018 * applicable instead of those above.  If you wish to allow use of your version of this
019 * file only under the terms of the GPL and not to allow others to use your version
020 * of this file under the MPL, indicate your decision by deleting  the provisions above
021 * and replace  them with the notice and other provisions required by the GPL License.
022 * If you do not delete the provisions above, a recipient may use your version of
023 * this file under either the MPL or the GPL.
024 *
025 */
026
027package ca.uhn.hl7v2.parser;
028
029import java.util.Collections;
030import java.util.List;
031import java.util.Set;
032
033/**
034 * Structure definition which defines a non-standard structure within a parent
035 * structure.
036 * 
037 * This class is used more as a runtime placeholder than as something that would
038 * be produced by the structure parser.
039 */
040public class NonStandardStructureDefinition implements IStructureDefinition {
041
042        private final String myName;
043        private final IStructureDefinition myParent;
044        private final int myPosition;
045        private final IStructureDefinition myPreviousSibling;
046
047        /**
048         * Constructor
049         */
050        public NonStandardStructureDefinition(IStructureDefinition theParent, IStructureDefinition thePreviousSibling, String theName, int thePosition) {
051                if (theName == null || theName.length() == 0) {
052                        throw new IllegalArgumentException("theName is missing");
053                }
054                
055                myParent = theParent;
056                myName = theName;
057                myPreviousSibling = thePreviousSibling;
058                myPosition = thePosition;
059        }
060
061        /**
062         * {@inheritDoc }
063         */
064        @Override
065        public Set<String> getAllChildNames() {
066                return Collections.emptySet();
067        }
068
069        /**
070         * {@inheritDoc }
071         */
072        @Override
073    public Set<String> getAllPossibleFirstChildren() {
074                return Collections.emptySet();
075        }
076
077        /**
078         * {@inheritDoc }
079         */
080        @Override
081        public List<StructureDefinition> getChildren() {
082                return Collections.emptyList();
083        }
084
085        /**
086         * {@inheritDoc }
087         */
088        @Override
089        public IStructureDefinition getFirstChild() {
090                return null;
091        }
092
093        /**
094         * {@inheritDoc }
095         */
096        @Override
097        public IStructureDefinition getFirstSibling() {
098                return null;
099        }
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}