Java tutorial
/* * Copyright 2008 JRimum Project * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by * applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS * OF ANY KIND, either express or implied. See the License for the specific * language governing permissions and limitations under the License. * * Created at: 30/03/2008 - 18:09:58 * * ================================================================================ * * Direitos autorais 2008 JRimum Project * * Licenciado sob a Licena Apache, Verso 2.0 ("LICENA"); voc no pode usar * esse arquivo exceto em conformidade com a esta LICENA. Voc pode obter uma * cpia desta LICENA em http://www.apache.org/licenses/LICENSE-2.0 A menos que * haja exigncia legal ou acordo por escrito, a distribuio de software sob * esta LICENA se dar COMO EST??, SEM GARANTIAS OU CONDIES DE QUALQUER * TIPO, sejam expressas ou tcitas. Veja a LICENA para a redao especfica a * reger permisses e limitaes sob esta LICENA. * * Criado em: 30/03/2008 - 18:09:58 * */ package br.com.nordestefomento.jrimum.bopepo.campolivre; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import br.com.nordestefomento.jrimum.domkee.financeiro.banco.febraban.Titulo; import br.com.nordestefomento.jrimum.utilix.Field; import br.com.nordestefomento.jrimum.utilix.Filler; import br.com.nordestefomento.jrimum.utilix.ObjectUtil; import br.com.nordestefomento.jrimum.utilix.StringUtil; /** * <p> * Esta classe tem como finalidade encapsular toda a lgica de criao de um * campo livre e de fornecer para o pacote * <code>br.com.nordestefomento.jrimum.bopepo.campolivre</code> * um nico ponto de acesso ao mesmo. * </p> * * * @author <a href="http://gilmatryx.googlepages.com/">Gilmar P.S.L</a> * @author Misael Barreto * @author Rmulo Augusto * @author <a href="http://www.nordeste-fomento.com.br">Nordeste Fomento Mercantil</a> * * @since 0.2 * * @version 0.2 */ public final class CampoLivreFactory { /** * */ private static final long serialVersionUID = 8572635342980404937L; private static Logger log = Logger.getLogger(CampoLivreFactory.class); /** * <p> * Devolve um <code>CampoLivre</code> de acordo com o Banco contido na conta do Cedente. * </p> * <p> * Caso exista implementao para o banco o retorno ter uma referncia no nula. * </p> * * @param titulo * * @return Uma referncia para um CampoLivre. * @throws NotSupportedBancoException * @throws NotSupportedCampoLivreException */ public static CampoLivre create(Titulo titulo) throws NotSupportedBancoException, NotSupportedCampoLivreException { return AbstractCampoLivre.create(titulo); } /** * Devolve um CampoLivre de acordo a partir de uma String. * * @param strCampoLivre * * @return Uma referncia para um ICampoLivre. * * @throws NullPointerException * @throws IllegalArgumentException */ public static CampoLivre create(String strCampoLivre) { CampoLivre campoLivre = null; ObjectUtil.checkNotNull(strCampoLivre); StringUtil.checkNotBlank(strCampoLivre, "O Campo Livre no deve ser vazio!"); strCampoLivre = StringUtils.strip(strCampoLivre); if (strCampoLivre.length() == CampoLivre.STRING_LENGTH) { if (StringUtils.remove(strCampoLivre, ' ').length() == CampoLivre.STRING_LENGTH) { if (StringUtils.isNumeric(strCampoLivre)) { campoLivre = new CampoLivre() { private static final long serialVersionUID = -7592488081807235080L; Field<String> campo = new Field<String>(StringUtils.EMPTY, STRING_LENGTH, Filler.ZERO_LEFT); public void read(String str) { campo.read(str); } public String write() { return campo.write(); } }; campoLivre.read(strCampoLivre); } else { IllegalArgumentException e = new IllegalArgumentException( "O Campo Livre [ " + strCampoLivre + " ] deve ser uma String numrica!"); log.error(StringUtils.EMPTY, e); throw e; } } else { IllegalArgumentException e = new IllegalArgumentException( "O Campo Livre [ " + strCampoLivre + " ] no deve conter espaos em branco!"); log.error(StringUtils.EMPTY, e); throw e; } } else { IllegalArgumentException e = new IllegalArgumentException("O tamanho do Campo Livre [ " + strCampoLivre + " ] deve ser igual a 25 e no [" + strCampoLivre.length() + "]!"); log.error(StringUtils.EMPTY, e); throw e; } return campoLivre; } @Override public String toString() { return ObjectUtil.toString(this); } }