中国开发网: 论坛: 程序员情感CBD: 贴子 384356
老玉米
贴一个我写的用于j2ee程序的基础类,欢迎拍砖
public abstract class Record {
private int ID;
private RecordState State;

public Record()
{
ID= -1;
State = RecordState.StateAdd;
}

public Record(int id) throws DataValidationException
{
if (id <0)
throw new DataValidationException("id[" + id +"] of class Member < 0");
ID = id;
State = RecordState.StateBrowse;
}

public RecordState getState() {
return State;
}

public void setState(RecordState newState) throws StateException
{
if (State == newState)
throw new StateException(this,State,newState);

if (State == RecordState.StateBrowse){
//permit transfer from StateBrowse to StateAdd or StateCancel
if (newState != RecordState.StateUpdate)
throw new StateException(this,State,newState);
}
else if (State == RecordState.StateAdd
|| State == RecordState.StateUpdate
|| State == RecordState.StateDelete){
if (newState != RecordState.StateCancel && newState != RecordState.StateBrowse)
throw new StateException(this,State,newState);
}
else if (State == RecordState.StateCancel){
throw new StateException(this,State,newState);
}

State = newState;
}

public final int getID() throws StateException
{
if (State == RecordState.StateAdd)
throw new StateException(this,getState());
return ID;
}

public final void setID(int id) throws DataValidationException
{
if (id <0)
throw new DataValidationException("id[" + id +"] of class Member < 0");
if (ID >= 0)
throw new DataValidationException("Canot reset ID[" + ID + "]");
ID = id;
}

public String toString()
{
int id;
try{
id = getID();
}
catch (StateException e){
id = -1;
}
return getClass().getName() + "["+ id + "]";
}
}
民主不同于专制,不需要强加于人。--- 賴斯

大道之行也,天下为公,选贤与能,讲信修睦。故人不独亲其亲,不独子其子,使老有所终,壮有所用,幼有所长,矜、寡、孤、独、废疾者,皆有所养。男有分,女有归。货恶其弃於地也,不必藏於己;力恶其不出於身也,不必为己。是故,谋闭而不兴,盗窃乱贼而不作,故外户而不闭,是谓大同。--《礼运·大同篇》

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录