001    /*
002     * Copyright (c) 2009-2010 Mozilla Foundation
003     *
004     * Permission is hereby granted, free of charge, to any person obtaining a 
005     * copy of this software and associated documentation files (the "Software"), 
006     * to deal in the Software without restriction, including without limitation 
007     * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
008     * and/or sell copies of the Software, and to permit persons to whom the 
009     * Software is furnished to do so, subject to the following conditions:
010     *
011     * The above copyright notice and this permission notice shall be included in 
012     * all copies or substantial portions of the Software.
013     *
014     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
015     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
016     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
017     * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
018     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
019     * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
020     * DEALINGS IN THE SOFTWARE.
021     */
022    
023    package nu.validator.htmlparser.impl;
024    
025    import nu.validator.htmlparser.annotation.Auto;
026    
027    
028    public class StateSnapshot<T> implements TreeBuilderState<T> {
029    
030        private final @Auto StackNode<T>[] stack;
031    
032        private final @Auto StackNode<T>[] listOfActiveFormattingElements;
033    
034        private final T formPointer;
035    
036        private final T headPointer;
037    
038        private final T deepTreeSurrogateParent;
039    
040        private final int mode;
041    
042        private final int originalMode;
043        
044        private final boolean framesetOk;
045    
046        private final boolean needToDropLF;
047    
048        private final boolean quirks;
049    
050        /**
051         * @param stack
052         * @param listOfActiveFormattingElements
053         * @param formPointer
054         * @param quirks 
055         * @param needToDropLF 
056         * @param foreignFlag 
057         * @param originalMode 
058         * @param mode 
059         */
060        StateSnapshot(StackNode<T>[] stack,
061                StackNode<T>[] listOfActiveFormattingElements, T formPointer, T headPointer, T deepTreeSurrogateParent, int mode, int originalMode, boolean framesetOk, boolean needToDropLF, boolean quirks) {
062            this.stack = stack;
063            this.listOfActiveFormattingElements = listOfActiveFormattingElements;
064            this.formPointer = formPointer;
065            this.headPointer = headPointer;
066            this.deepTreeSurrogateParent = deepTreeSurrogateParent;
067            this.mode = mode;
068            this.originalMode = originalMode;
069            this.framesetOk = framesetOk;
070            this.needToDropLF = needToDropLF;
071            this.quirks = quirks;
072        }
073        
074        /**
075         * @see nu.validator.htmlparser.impl.TreeBuilderState#getStack()
076         */
077        public StackNode<T>[] getStack() {
078            return stack;
079        }
080    
081        /**
082         * @see nu.validator.htmlparser.impl.TreeBuilderState#getListOfActiveFormattingElements()
083         */
084        public StackNode<T>[] getListOfActiveFormattingElements() {
085            return listOfActiveFormattingElements;
086        }
087    
088        /**
089         * @see nu.validator.htmlparser.impl.TreeBuilderState#getFormPointer()
090         */
091        public T getFormPointer() {
092            return formPointer;
093        }
094    
095        /**
096         * Returns the headPointer.
097         * 
098         * @return the headPointer
099         */
100        public T getHeadPointer() {
101            return headPointer;
102        }
103    
104        /**
105         * Returns the deepTreeSurrogateParent.
106         * 
107         * @return the deepTreeSurrogateParent
108         */
109        public T getDeepTreeSurrogateParent() {
110            return deepTreeSurrogateParent;
111        }
112        
113        /**
114         * Returns the mode.
115         * 
116         * @return the mode
117         */
118        public int getMode() {
119            return mode;
120        }
121    
122        /**
123         * Returns the originalMode.
124         * 
125         * @return the originalMode
126         */
127        public int getOriginalMode() {
128            return originalMode;
129        }
130    
131        /**
132         * Returns the framesetOk.
133         * 
134         * @return the framesetOk
135         */
136        public boolean isFramesetOk() {
137            return framesetOk;
138        }
139    
140        /**
141         * Returns the needToDropLF.
142         * 
143         * @return the needToDropLF
144         */
145        public boolean isNeedToDropLF() {
146            return needToDropLF;
147        }
148    
149        /**
150         * Returns the quirks.
151         * 
152         * @return the quirks
153         */
154        public boolean isQuirks() {
155            return quirks;
156        }
157        
158        /**
159         * @see nu.validator.htmlparser.impl.TreeBuilderState#getListOfActiveFormattingElementsLength()
160         */
161        public int getListOfActiveFormattingElementsLength() {
162            return listOfActiveFormattingElements.length;
163        }
164    
165        /**
166         * @see nu.validator.htmlparser.impl.TreeBuilderState#getStackLength()
167         */
168        public int getStackLength() {
169            return stack.length;
170        }
171    
172        @SuppressWarnings("unused") private void destructor() {
173            for (int i = 0; i < stack.length; i++) {
174                stack[i].release();
175            }
176            for (int i = 0; i < listOfActiveFormattingElements.length; i++) {
177                if (listOfActiveFormattingElements[i] != null) {
178                    listOfActiveFormattingElements[i].release();                
179                }
180            }
181        }
182    }