枚举的另一种使用

枚举类型一般属性的值为常量,不可动态的变化。
由于系统需要,配置信息是写在数量库中的,在加载系统时,需要读入配置信息去填充枚举类型属性。
故想出这种办法,共享之。

/*************************************************
  Copyright (C), 2008-2009, Sunsoft Team Tech. Co., Ltd.
  File name:           TradeState.java
  Author:   sunbeam    Version:  1.0      Date: 2008-11-5
  Description:         
  Others:         
  Function List:       
    
  History:             
   
 *************************************************/

package com.sztelecom.vbao.enumer;

import com.sztelecom.vbao.exception.ServiceException;
import com.sztelecom.vbao.service.CommonParmeterService;



/**
 * 交易状态
 * @author sunbeam
 * @version 1.0
 * @Date 2008-11-5
 */
public enum TradeState {

	WAIT_PAY("TRADE_STATE_WAIT_PAY"), // 等待付款
	HAS_CREATED("TRADE_STATE_HAS_CREATED"), // 交易已创建
	WAIT_SEND_GOODS("TRADE_STATE_WAIT_SEND_GOODS"), // 等待卖家发货
	WAIT_CFM_GOODS("TRADE_STATE_WAIT_CFM_GOODS"), // 等待买家确认收货
	FINISHED("TRADE_STATE_FINISHED"), // 交易已完成
	CLOSED("TRADE_STATE_CLOSED"), // 交易已关闭
	WAIT_DEAL_REFUND("TRADE_STATE_WAIT_DEAL_REFUND");// 等待处理退款
	
	private String status;
	static String wait_pay;
	static String has_created;
	static String wait_send_goods;
	static String wait_cfm_goods;
	static String finished;
	static String closed;
	static String wait_deal_refund;
	
	private TradeState(String status) {
		this.status = status;
	}
	
	public void init(CommonParmeterService cps) throws ServiceException {

		if (wait_pay == null)
			wait_pay = cps.queryTradeState(WAIT_PAY.getStatus());

		if (has_created == null)
			has_created = cps.queryTradeState(HAS_CREATED.getStatus());

		if (wait_send_goods == null)
			wait_send_goods = cps.queryTradeState(WAIT_SEND_GOODS.getStatus());

		if (wait_cfm_goods == null)
			wait_cfm_goods = cps.queryTradeState(WAIT_CFM_GOODS.getStatus());

		if (finished == null)
			finished = cps.queryTradeState(FINISHED.getStatus());

		if (closed == null)
			closed = cps.queryTradeState(CLOSED.getStatus());

		if (wait_deal_refund == null)
			wait_deal_refund = cps.queryTradeState(WAIT_DEAL_REFUND.getStatus());
	}
	
	public String toString() {
		super.toString();
		switch (this) {
		case WAIT_PAY:
			return wait_pay;
		case HAS_CREATED:
			return has_created;
		case WAIT_SEND_GOODS:
			return wait_send_goods;
		case WAIT_CFM_GOODS:
			return wait_cfm_goods;
		case FINISHED:
			return finished;
		case CLOSED:
			return closed;
		case WAIT_DEAL_REFUND:
			return wait_deal_refund;
		default:
			return "";
		}
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}
}
 

 

你可能感兴趣的:(C++,c,C#)