Java tutorial
/*$Id: FengselBibValidator.java 12990 2009-02-11 23:00:45Z 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; /** * FengselBibValidator. * * @author: Henning Kulander, hennikul@linpro.no * @author $Author: jens $ * @version $Rev: 12990 $ * @date $Date: 2009-02-12 00:00:45 +0100 (Thu, 12 Feb 2009) $ * @copyright ABM-Utvikling * */ public class FengselBibValidator extends SchemaReportValidator { private static final Log logger = (Log) LogFactory.getLog(FengselBibValidator.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("fengselBibSchema"); switch (pageNumber) { case 1: break; case 2: 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 = 34; i <= 35; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 40; i <= 41; 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 <= 387; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } break; case 3: fieldKeys.add(fieldNameFormater.format((long) 82)); for (i = 84; i <= 86; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 90)); fieldKeys.add(fieldNameFormater.format((long) 97)); for (i = 99; i <= 100; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 258)); fieldKeys.add(fieldNameFormater.format((long) 374)); fieldKeys.add(fieldNameFormater.format((long) 389)); for (i = 435; i <= 438; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 441; i <= 442; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 445; i <= 446; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 449; 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)); fieldKeys.add(fieldNameFormater.format((long) 164)); for (i = 205; i <= 210; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 384)); for (i = 223; i <= 224; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 401; i <= 402; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 225)); break; case 5: for (i = 243; i <= 254; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 259; i <= 264; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 266)); for (i = 381; i <= 382; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } break; default: break; } if (logger.isDebugEnabled()) { logger.debug("Keys to validate: " + fieldKeys); } setValidateFieldKeys(fieldKeys); super.validate(obj, errors); } /** * getPageNumber. * * @return Returns the pageNumber. */ public int getPageNumber() { return pageNumber; } /** * setPageNumber. * * @param pageNumber The pageNumber to set. */ public void setPageNumber(int pageNumber) { this.pageNumber = pageNumber; } }