001/* Copyright (C) 2013 TU Dortmund
002 * This file is part of LearnLib, http://www.learnlib.de/.
003 * 
004 * LearnLib is free software; you can redistribute it and/or
005 * modify it under the terms of the GNU Lesser General Public
006 * License version 3.0 as published by the Free Software Foundation.
007 * 
008 * LearnLib is distributed in the hope that it will be useful,
009 * but WITHOUT ANY WARRANTY; without even the implied warranty of
010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
011 * Lesser General Public License for more details.
012 * 
013 * You should have received a copy of the GNU Lesser General Public
014 * License along with LearnLib; if not, see
015 * <http://www.gnu.de/documents/lgpl.en.html>.
016 */
017
018package de.learnlib.oracles;
019
020import java.util.Collection;
021
022import de.learnlib.api.MembershipOracle;
023import de.learnlib.api.Query;
024
025/**
026 *
027 * @author Maik Merten <maikmerten@googlemail.com>
028 */
029public class SafeOracle<I,O> implements MembershipOracle<I,O> {
030    
031    private MembershipOracle<I,O> nextOracle;
032    
033    public SafeOracle(MembershipOracle<I,O> nextOracle) {
034        this.nextOracle = nextOracle;
035    }
036    
037
038    @Override
039    public void processQueries(Collection<? extends Query<I, O>> queries) {
040        // let the next oracle in chain process the queries
041        nextOracle.processQueries(queries);
042        
043        // now, let's see if everything is okay
044        for(Query<I,O> query : queries)
045            checkQuery(query);
046    }
047    
048    protected void checkQuery(Query<I,O> query) {
049        
050        // somebody punched holes into our query batch
051        if(query == null)
052            throw new RuntimeException("Query batch is incomplete, contains null query.");
053        
054        // is there actual output?
055        // FIXME: Removed this because of Query interface change, but since we do not require outputs
056        //        to be alphabet symbols, I believe prohibiting null outputs is not a valid requirement?
057        //        -mi
058        //if(query.getOutput() == null)
059        //    throw new RuntimeException("Query batch is not answered, contains null answer for Query (" + query.getPrefix() + ", " + query.getSuffix() + ")");
060    }
061    
062}