Java tutorial
/** * PureInfo Quake * @(#)ContractSidGenerator.java 1.0 2005-12-10 * * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. * All rights reserved, see the license file. * * www.pureinfo.com.cn */ package com.pureinfo.srm.contract.model.impl; import java.text.DateFormat; import java.text.DecimalFormat; import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.Date; import org.apache.commons.lang.StringUtils; import com.pureinfo.ark.content.ArkContentHelper; import com.pureinfo.force.exception.PureException; import com.pureinfo.srm.contract.model.IContractSidGenerator; import com.pureinfo.srm.org.model.Organization; import com.pureinfo.srm.outlay.domain.IIDTableMgr; import com.pureinfo.srm.outlay.model.IDTable; import com.pureinfo.srm.project.model.Project; /** * <P> * Created on 2005-12-10 21:42:01 <BR> * Last modified on 2005-12-10 * </P> * * @author wind * @version 1.0, 2005-12-10 * @since Quake 1.0 */ public class ZjuContractSidGeneratorImpl implements IContractSidGenerator { private static final DateFormat DATE_FORMATTER = new SimpleDateFormat("yy"); private static final NumberFormat NUMBER_FORMATTER = new DecimalFormat("000"); public String generateCode(Project _prj) throws PureException { StringBuffer sbuff = new StringBuffer(); IIDTableMgr mgr = (IIDTableMgr) ArkContentHelper.getContentMgrOf(IDTable.class); String sIdName = getCodePrefix(_prj); try { sbuff.append(sIdName); String sFlowid = NUMBER_FORMATTER.format(mgr.getIdValue(sIdName)); sbuff.append(sFlowid); return sbuff.toString(); } finally { sbuff.setLength(0); } } public String getCodePrefix(Project _prj) throws PureException { Organization org = _prj.getDepartment(); String sDeptCode; if (org == null) { sDeptCode = "XXXXX"; } else { sDeptCode = StringUtils.rightPad(org.getCode(), 5, '0'); } return getCodePrefix(sDeptCode); } /** * @param _sCode * @return */ public String getCodePrefix(String _sCode) { String sDateString = DATE_FORMATTER.format(new Date()); StringBuffer sbuff = new StringBuffer(); try { sbuff.append(sDateString); sbuff.append('-'); sbuff.append(_sCode); sbuff.append('-'); return sbuff.toString(); } finally { sbuff.setLength(0); } } }