Java tutorial
/*$Id: PasientBibValidator.java 12993 2009-02-12 11:41:10Z jens $*/ /* **************************************************************************** * * * (c) Copyright 2005 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.service; import java.text.NumberFormat; import java.util.HashSet; import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.validation.Errors; /** * PasientBibValidator. * * @author: Henning Kulander, hennikul@linpro.no * @author $Author: jens $ * @version $Rev: 12993 $ * @date $Date: 2009-02-12 12:41:10 +0100 (Thu, 12 Feb 2009) $ * @copyright ABM-Utvikling */ public class PasientBibValidator extends SchemaReportValidator { private static final Log logger = (Log) LogFactory.getLog(PasientBibValidator.class); private int pageNumber; public boolean supports(Class clazz) { if (logger.isDebugEnabled()) { logger.debug("Checking if validator supports " + clazz.getName()); } return (clazz.equals(FolkeBibScreen.class) || super.supports(clazz)); } public void validate(Object obj, Errors errors) { NumberFormat fieldNameFormater = NumberFormat.getNumberInstance(); fieldNameFormater.setMinimumIntegerDigits(3); Set fieldKeys = new HashSet(); int i; setSchemaName("pasientBibSchema"); switch (pageNumber) { case 1: break; case 2: for (i = 13; i <= 14; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 16; i <= 17; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 19; i <= 20; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 22; i <= 23; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 31; i <= 32; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 34; i <= 35; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 37; i <= 38; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 40; i <= 41; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 46; i <= 47; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 49; i <= 50; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 58; i <= 59; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 385; i <= 386; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } break; case 3: for (i = 67; i <= 77; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 81; i <= 82; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 82)); for (i = 84; i <= 87; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 90)); for (i = 97; i <= 101; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 389; i <= 390; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 431; i <= 452; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } break; case 4: for (i = 102; i <= 107; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 117; i <= 119; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 147)); for (i = 151; i <= 160; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 162)); for (i = 205; i <= 210; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 223; i <= 224; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 401; i <= 402; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } break; case 5: fieldKeys.add(fieldNameFormater.format((long) 243)); fieldKeys.add(fieldNameFormater.format((long) 246)); fieldKeys.add(fieldNameFormater.format((long) 249)); fieldKeys.add(fieldNameFormater.format((long) 252)); for (i = 259; i <= 264; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 266)); fieldKeys.add(fieldNameFormater.format((long) 372)); for (i = 381; i <= 382; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } break; default: break; } logger.debug("Keys to validate: " + fieldKeys); setValidateFieldKeys(fieldKeys); super.validate(obj, errors); } public int getPageNumber() { return pageNumber; } public void setPageNumber(int pageNumber) { this.pageNumber = pageNumber; } }