Code example for Stack

Methods: empty, get, peek, push, size

0
            CSSMediaRuleImpl mr = new CSSMediaRuleImpl(
                CSSOMParser.this.getParentStyleSheet(),
                this.getParentRule(),
                ml);
            this.addLocator(mr);
            if (!this._nodeStack.empty()) {
                ((CSSRuleListImpl)this._nodeStack.peek()).add(mr);
            } 
 
            // Create the rule list 
            CSSRuleListImpl rules = new CSSRuleListImpl();
            mr.setRuleList(rules);
            this._nodeStack.push(mr);
            this._nodeStack.push(rules);
        } 
 
        public void endMedia(SACMediaList media) throws CSSException {
 
            // Pop the rule list and media rule nodes 
            this._nodeStack.pop();
            this._root = this._nodeStack.pop();
        } 
 
        public void startPage(String name, String pseudo_page) throws CSSException {
 
            // Create the page rule and add it to the rule list 
            CSSPageRuleImpl pr = new CSSPageRuleImpl(
                CSSOMParser.this.getParentStyleSheet(),
                this.getParentRule(), name, pseudo_page);
            this.addLocator(pr);
            if (!this._nodeStack.empty()) {
                ((CSSRuleListImpl)this._nodeStack.peek()).add(pr);
            } 
 
            // Create the style declaration 
            CSSStyleDeclarationImpl decl = new CSSStyleDeclarationImpl(pr);
            pr.setStyle(decl);
            this._nodeStack.push(pr);
            this._nodeStack.push(decl);
        } 
 
        public void endPage(String name, String pseudo_page) throws CSSException {
 
            // Pop both the style declaration and the page rule nodes 
            this._nodeStack.pop();
            this._root = this._nodeStack.pop();
        } 
 
        public void startFontFace() throws CSSException { 
 
            // Create the font face rule and add it to the rule list 
            CSSFontFaceRuleImpl ffr = new CSSFontFaceRuleImpl(
                CSSOMParser.this.getParentStyleSheet(),
                this.getParentRule());
            this.addLocator(ffr);
            if (!this._nodeStack.empty()) {
                ((CSSRuleListImpl)this._nodeStack.peek()).add(ffr);
            } 
 
            // Create the style declaration 
            CSSStyleDeclarationImpl decl = new CSSStyleDeclarationImpl(ffr);
            ffr.setStyle(decl);
            this._nodeStack.push(ffr);
            this._nodeStack.push(decl);
        } 
 
        public void endFontFace() throws CSSException { 
 
            // Pop both the style declaration and the font face rule nodes 
            this._nodeStack.pop();
            this._root = this._nodeStack.pop();
        } 
 
        public void startSelector(SelectorList selectors) throws CSSException {
 
            // Create the style rule and add it to the rule list 
            CSSStyleRuleImpl sr = new CSSStyleRuleImpl(
                CSSOMParser.this.getParentStyleSheet(),
                this.getParentRule(), selectors);
            this.addLocator(sr);
            if (!this._nodeStack.empty()) {
                Object o = this._nodeStack.peek();
                ((CSSRuleListImpl)/*this._nodeStack.peek()*/o).add(sr);
            } 
             
            // Create the style declaration 
            CSSStyleDeclarationImpl decl = new CSSStyleDeclarationImpl(sr);
            sr.setStyle(decl);
            this._nodeStack.push(sr);
            this._nodeStack.push(decl);
        } 
 
        public void endSelector(SelectorList selectors) throws CSSException {
 
            // Pop both the style declaration and the style rule nodes 
            this._nodeStack.pop();
            this._root = this._nodeStack.pop();
        } 
 
        public void property(String name, LexicalUnit value, boolean important)
                throws CSSException { 
            CSSStyleDeclarationImpl decl =
                (CSSStyleDeclarationImpl) this._nodeStack.peek();
            try 
            { 
                Property property = 
                    new Property(name, new CSSValueImpl(value), important);
                this.addLocator(property);
                decl.addProperty(property);
            } 
            catch (DOMException e)
            { 
                // call ErrorHandler? 
            } 
        } 
         
        private CSSRule getParentRule() 
        { 
            if (!this._nodeStack.empty() && this._nodeStack.size() > 1)
            { 
                Object node = this._nodeStack.get(this._nodeStack.size() - 2);
                if (node instanceof CSSRule)
                { 
                    return (CSSRule) node;
                } 
            }