Java tutorial
/*$Id: HighSchoolLibraryValidator.java 8700 2008-02-24 21:37:58Z jens $*/ /* **************************************************************************** * * * (c) Copyright 2008 ABM-utvikling * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * * Public License for more details. http://www.gnu.org/licenses/gpl.html * * * **************************************************************************** */ package no.abmu.abmstatistikk.annualstatistic.webflow; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.validation.Errors; import org.springframework.util.StopWatch; import no.abmu.abmstatistikk.annualstatistic.service.FolkeBibScreen; import no.abmu.abmstatistikk.annualstatistic.service.VideregaaendeSkoleBibValidator; import no.abmu.abmstatistikk.annualstatistic.service.SchemaReport; /** * <code>HighSchoolLibraryValidator</code> validator that validates and * save when validated OK, high school library schema (folkebiblSchema). * * We only validate fields on current page. * * @author Jens Vindvad, Jens.Vindvad@abm-utvikling.no * @author $Author: jens $ * @version $Rev: 8700 $ * @date $Date: 2008-02-24 22:37:58 +0100 (Sun, 24 Feb 2008) $ * @since 2008-01-25 * copyright ABM-Utvikling */ public class HighSchoolLibraryValidator extends VideregaaendeSkoleBibValidator implements WebFlowValidator { private static final Log logger = (Log) LogFactory.getLog(PrimarySchoolLibraryValidator.class); private WebFlowService webFlowService; public WebFlowService getWebFlowService() { return webFlowService; } public void setWebFlowService(WebFlowService webFlowService) { this.webFlowService = webFlowService; } public void validate(Object obj, Errors errors) { if (logger.isDebugEnabled()) { logger.debug("Executing validate"); } validateAndSave(obj, errors); } public void validateAndSave(Object obj, Errors errors) { if (logger.isDebugEnabled()) { logger.debug("Executing validateAndSave"); } StopWatch stopWatch = new StopWatch(); stopWatch.start("validateAndSave"); SchemaReport schemaReport = webFlowService.webSchemaValuesToDataBaseSchema(this, (WebSchemaDefinition) obj); FolkeBibScreen folkeBibScreen = new FolkeBibScreen(schemaReport.getReport()); super.validate(folkeBibScreen, errors); // Has to be super or else endless loop. webFlowService.saveDataBaseSchemaIfNoError(folkeBibScreen, errors); stopWatch.stop(); logger.info("[validateAndSave] tok [" + stopWatch.getTotalTimeMillis() + "] ms"); } }