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    
027    package ca.uhn.hl7v2.parser;
028    
029    import java.util.Collections;
030    import java.util.List;
031    import 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     */
040    public class NonStandardStructureDefinition implements IStructureDefinition {
041    
042            private String myName;
043            private IStructureDefinition myParent;
044            private int myPosition;
045            private 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            public Set<String> getAllChildNames() {
065                    return Collections.emptySet();
066            }
067    
068            /**
069             * {@inheritDoc }
070             */
071            public Set<String> getAllPossibleFirstChildren() {
072                    return Collections.emptySet();
073            }
074    
075            /**
076             * {@inheritDoc }
077             */
078            public List<StructureDefinition> getChildren() {
079                    return Collections.emptyList();
080            }
081    
082            /**
083             * {@inheritDoc }
084             */
085            public IStructureDefinition getFirstChild() {
086                    return null;
087            }
088    
089            /**
090             * {@inheritDoc }
091             */
092            public IStructureDefinition getFirstSibling() {
093                    return null;
094            }
095    
096            /**
097             * {@inheritDoc }
098             */
099            public String getName() {
100                    return myName;
101            }
102    
103            /**
104             * {@inheritDoc}
105             */
106            public String getNameAsItAppearsInParent() {
107                    return getName();
108            }
109    
110            /**
111             * {@inheritDoc }
112             */
113            public Set<String> getNamesOfAllPossibleFollowingLeaves() {
114                    return myPreviousSibling.getNamesOfAllPossibleFollowingLeaves();
115            }
116    
117            /**
118             * {@inheritDoc }
119             */
120            public IStructureDefinition getNextLeaf() {
121                    return myPreviousSibling.getNextLeaf();
122            }
123    
124            /**
125             * {@inheritDoc }
126             */
127            public IStructureDefinition getNextSibling() {
128                    return myPreviousSibling.getNextSibling();
129            }
130    
131            /**
132             * {@inheritDoc }
133             */
134            public IStructureDefinition getParent() {
135                    return myParent;
136            }
137    
138            /**
139             * {@inheritDoc }
140             */
141            public int getPosition() {
142                    return myPosition;
143            }
144    
145            /**
146             * {@inheritDoc }
147             */
148            public boolean hasChildren() {
149                    return false;
150            }
151    
152            /**
153             * {@inheritDoc }
154             */
155            public boolean isFinalChildOfParent() {
156                    return myPreviousSibling.isFinalChildOfParent();
157            }
158    
159            /**
160             * {@inheritDoc }
161             */
162            public boolean isRepeating() {
163                    return true;
164            }
165    
166            /**
167             * {@inheritDoc }
168             */
169            public boolean isRequired() {
170                    return false;
171            }
172    
173            /**
174             * {@inheritDoc }
175             */
176            public boolean isSegment() {
177                    return true;
178            }
179    
180    }