001    /*
002     * $RCSfile: RequestTypeHandler.java,v $ 
003     *
004     * Created on Dec 1 2004, 15:16 PM 
005     *
006     * This file is part of the STAR Scheduler.
007     * Copyright (c) 2004-2006 STAR Collaboration - Brookhaven National Laboratory
008     *
009     * STAR Scheduler is free software; you can redistribute it and/or modify
010     * it under the terms of the GNU General Public License as published by
011     * the Free Software Foundation; either version 2 of the License, or
012     * (at your option) any later version.
013     *
014     * STAR Scheduler is distributed in the hope that it will be useful,
015     * but WITHOUT ANY WARRANTY; without even the implied warranty of
016     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017     * GNU General Public License for more details.
018     *
019     * You should have received a copy of the GNU General Public License
020     * along with STAR Scheduler; if not, write to the Free Software
021     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
022     */
023    package gov.bnl.star.offline.scheduler.request;
024    
025    import org.xml.sax.helpers.DefaultHandler;
026    import org.xml.sax.Attributes;
027    
028    /** Reads a STAR scheduler job request
029     * to determine its format and version.
030     *
031     * @author  paulh
032     * @version $Revision: 1.2 $ $Date: 2006/11/21 00:41:31 $
033     */
034    public class RequestTypeHandler extends DefaultHandler {
035       
036        public static final String JDLRootElement = "job";
037        public static final String RDLRootElement = "AbstractRequest";
038    
039        private int requestType;
040    
041        /** Parses an XML file to determine its format and version.
042         *  Looks for JDL 0.4 or RDL 0.5
043         */
044        public RequestTypeHandler() {
045            requestType = RequestType.NONE;
046        }
047        
048        /** Parsing method.
049         * If JDLRootElement is found, type is JDL
050         * If RDLRootElement element is found, type is RDL
051         * After type is set, throw RequestTypeException to stop parse
052         */
053        public void startElement(String namespaceURI, String sName, String qName,
054            Attributes attrs) throws RequestTypeException {
055            if (qName.equals(JDLRootElement)) {
056                setRequestType(RequestType.JDL);
057                throw new RequestTypeException("JDL request");
058            } else if (qName.equals(RDLRootElement)) {
059                setRequestType(RequestType.RDL);
060                throw new RequestTypeException("RDL request");
061            }
062        }
063    
064        /** Set the request type
065         */
066        private void setRequestType(int type) { 
067            requestType = type;
068        }
069                                                                                    
070        /** Get the request type
071         */
072        public int getRequestType() { return requestType; }
073     
074    }