001: /*
002: * Created on 13/02/2004
003: *
004: * Swing Components - visit http://sf.net/projects/gfd
005: *
006: * Copyright (C) 2004 Igor Regis da Silva Simões
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or (at your option) any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022:
023: package br.com.gfp.data;
024:
025: import java.sql.SQLException;
026: import java.util.Map;
027:
028: import br.com.gfp.dao.AccountTypeDAO;
029: import br.com.gfp.dao.GFPController;
030: import br.com.gfp.internationalization.ErrosDeDadosMessages;
031: import br.com.gfp.util.SimpleLog;
032: import br.com.gfpshare.db.Column;
033: import br.com.gfpshare.db.Table;
034:
035: /**
036: * Classe que representa uma Account Corrente e tudo que queremos guardar a seu respeito
037: * @author Igor Regis da Silva Simoes
038: */
039: @Table(name="ContaCorrente")
040: public class CheckingAccount extends Account {
041: /**
042: * Numero da agencia desta conta
043: */
044: @Column(nome="NumeroAgencia",isPk=false,writeMethodName="setNumeroAgencia",readMethodName="getNumeroAgencia")
045: private String numeroAgencia = null;
046:
047: /**
048: * Codigo do banco
049: */
050: @Column(nome="Banco",isPk=false,writeMethodName="setBanco",readMethodName="getBanco")
051: private Integer banco = null;
052:
053: /*
054: * Inicializamos campo tipoConta para contaCorrente, indicando o tipo desta conta
055: */
056: {
057: try {
058: tipoConta = ""
059: + new AccountTypeDAO().getBy(
060: new AccountType("contaCorrente")).getId();
061: } catch (SQLException e) {
062: ((SimpleLog) GFPController.getGFPController().getContexto()
063: .get(GFPController.LOG))
064: .log("Erro ao reter tipo da conta, conta corrente!");
065: ((SimpleLog) GFPController.getGFPController().getContexto()
066: .get(GFPController.LOG)).log(e
067: .getLocalizedMessage());
068: ((SimpleLog) GFPController.getGFPController().getContexto()
069: .get(GFPController.LOG)).log(e);
070: }
071: }
072:
073: /** Cria uma nova instância de ContaCorrente */
074: public CheckingAccount() {
075: //Não fazemos nada
076: }
077:
078: /** Cria uma nova instância de ContaCorrente
079: * @param id Id desta nova conta corrente
080: */
081: public CheckingAccount(Integer id) {
082: setId(id);
083: }
084:
085: /** Cria uma nova instância de ContaCorrente
086: * @param dados Map contendo os dados desta nova ContaCorrente
087: */
088: public CheckingAccount(Map<String, Object> dados) {
089: setDados(dados);
090: }
091:
092: /** Cria uma nova instância de ContaCorrente
093: * @param saldoInicial
094: */
095: public CheckingAccount(Double saldoInicial) {
096: setSaldoInicial(saldoInicial);
097: }
098:
099: /**
100: * Getter for property banco.
101: * @return Value of property banco.
102: */
103: public Integer getBanco() {
104: return banco;
105: }
106:
107: /** Setter for property banco.
108: * @param banco New value of property banco.
109: *
110: */
111: public void setBanco(Integer banco) {
112: this .banco = banco;
113: }
114:
115: /**
116: * Getter for property numeroAgencia.
117: * @return Value of property numeroAgencia.
118: */
119: public String getNumeroAgencia() {
120: return numeroAgencia;
121: }
122:
123: /**
124: * Setter for property numeroAgencia.
125: * @param numeroAgencia New value of property numeroAgencia.
126: */
127: public void setNumeroAgencia(java.lang.String numeroAgencia) {
128: this .numeroAgencia = numeroAgencia;
129: }
130:
131: /**
132: * @see br.com.gfp.data.Account#validate()
133: */
134: @Override
135: public void validate() throws SQLException {
136: super .validate();
137: if (this .banco == null || this .banco.intValue() < 0)
138: throw new SQLException(ErrosDeDadosMessages.getMessages()
139: .getString("BancoInvalido"));
140: if (this .numeroAgencia == null)
141: throw new SQLException(ErrosDeDadosMessages.getMessages()
142: .getString("NumeroAgenciaInvalido"));
143: if (this .tipoConta == null)
144: throw new SQLException(ErrosDeDadosMessages.getMessages()
145: .getString("TipoContaInvalido"));
146: }
147:
148: /**
149: * @see br.com.gfpshare.db.PersistentObject#getAsString(int)
150: */
151: public String getAsString(int format) {
152: switch (format) {
153: case AccountSaving.CURTO:
154: return getDescricao();
155: case AccountSaving.MEDIO:
156: return tipoConta + " Account: " + getNumeroConta()
157: + " Agencia: " + getNumeroAgencia()
158: + " Cod. Banco: " + getBanco() + " Descricao: "
159: + getDescricao();
160: case AccountSaving.LONGO:
161: return toString();
162: }
163: return "";
164: }
165: }
|