001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.runtime.tag;
020
021import javax.servlet.jsp.tagext.Tag;
022
023import lucee.runtime.exp.ApplicationException;
024import lucee.runtime.ext.tag.TagSupport;
025import lucee.runtime.op.Caster;
026
027public class ProcResult extends TagSupport {
028        
029        private ProcResultBean result=new ProcResultBean();
030
031        public void release() {
032                result=new ProcResultBean();
033                super.release();
034        }
035        
036        /**
037         * @param maxrows The maxrows to set.
038         */
039        public void setMaxrows(double maxrows) {
040                result.setMaxrows(Caster.toIntValue(maxrows));
041        }
042
043        /**
044         * @param name The name to set.
045         */
046        public void setName(String name) {
047                result.setName(name);
048        }
049
050        /**
051         * @param resultset The resultset to set.
052         * @throws ApplicationException 
053         */
054        public void setResultset(double resultset) throws ApplicationException {
055                if(resultset<1)throw new ApplicationException("value of attribute resultset must be a numeric value greater or equal to 1");
056                result.setResultset((int) resultset);
057        }       
058        public int doStartTag() throws ApplicationException {
059                
060                // provide to parent
061                Tag parent=getParent();
062                while(parent!=null && !(parent instanceof StoredProc)) {
063                        parent=parent.getParent();
064                }
065                
066                if(parent instanceof StoredProc) {
067                        ((StoredProc)parent).addProcResult(result);
068                }
069                else {
070                        throw new ApplicationException("Wrong Context, tag ProcResult must be inside a StoredProc tag");        
071                }
072                return SKIP_BODY;
073        }
074}