www.pudn.com > cmppNeu.rar > QueryResp.java


package cmpp.v2_0; 
 
import java.util.Arrays; 
import java.util.Calendar; 
import java.util.Date; 
 
public class QueryResp extends CMPP 
{ 
 
    private  final int commandId 		= CMPP.ID_CMPP_QUERY_RESP; 
    private  final int commandLength 	= 51; 
 
    private	String 	Time		= null; 
    private	int		QueryType	= 0; 
    private	String	QueryCode	= null; 
    private	int		MTTLMsg		= 0; 
    private	int		MTTLUsr		= 0; 
    private	int		MTScs		= 0; 
    private	int		MTWT		= 0; 
    private	int		MTFL		= 0; 
    private	int		MOScs		= 0; 
    private	int		MOWT		= 0; 
    private	int		MOFL		= 0; 
     
    public QueryResp() { 
    	super(CMPP.ID_CMPP_QUERY_RESP); 
    } 
    public QueryResp(CMPP cmpp) { 
        super(cmpp); 
    } 
 
    public int getCommandId() { 
		return commandId; 
	} 
	public int getCommandLength() { 
		return commandLength; 
	} 
     
    // getter 
	public int getMOFL() { 
		return MOFL; 
	} 
	public void setMOFL(int mofl) { 
		MOFL = mofl; 
	} 
	public int getMOScs() { 
		return MOScs; 
	} 
	public void setMOScs(int scs) { 
		MOScs = scs; 
	} 
	public int getMOWT() { 
		return MOWT; 
	} 
	public void setMOWT(int mowt) { 
		MOWT = mowt; 
	} 
	public int getMTFL() { 
		return MTFL; 
	} 
	public void setMTFL(int mtfl) { 
		MTFL = mtfl; 
	} 
	public int getMTScs() { 
		return MTScs; 
	} 
	public void setMTScs(int scs) { 
		MTScs = scs; 
	} 
	public int getMTTLMsg() { 
		return MTTLMsg; 
	} 
	public void setMTTLMsg(int msg) { 
		MTTLMsg = msg; 
	} 
	public int getMTTLUsr() { 
		return MTTLUsr; 
	} 
	public void setMTTLUsr(int usr) { 
		MTTLUsr = usr; 
	} 
	public int getMTWT() { 
		return MTWT; 
	} 
	public void setMTWT(int mtwt) { 
		MTWT = mtwt; 
	} 
	public String getQueryCode() { 
		return QueryCode; 
	} 
	public void setQueryCode(String queryCode) { 
		QueryCode = queryCode; 
	} 
	public int getQueryType() { 
		return QueryType; 
	} 
	public void setQueryType(int queryType) { 
		QueryType = queryType; 
	} 
	public String getTime() { 
		return Time; 
	} 
	public void setTime(String time) { 
		Time = time; 
	} 
 
	/** 
	 *  
	 */ 
	protected int parseBody() { 
		 
    	if( super.bodyLength < commandLength ) {	//length too short. 
    		return -1; 
    	} 
    	 
    	byte[] abyte0 = new byte[21]; 
    	int off = 0; 
 
    	Arrays.fill(abyte0,(byte)0); 
    	CMPP.BytesCopy(super.bodybytes, abyte0, off, off+7, 0); 
    	Time = new String(abyte0, 0, 8); 
    	off += 8; 
    	 
    	Arrays.fill(abyte0,(byte)0); 
    	CMPP.BytesCopy(super.bodybytes, abyte0, off, off, 0); 
    	QueryType = CMPP.ByteToInt(abyte0[0]); 
    	off += 1; 
    	 
    	Arrays.fill(abyte0,(byte)0); 
    	CMPP.BytesCopy(super.bodybytes, abyte0, off, off+9, 0); 
    	QueryCode = new String(abyte0, 0, 10); 
    	off += 10; 
 
    	Arrays.fill(abyte0,(byte)0); 
    	CMPP.BytesCopy(super.bodybytes, abyte0, off, off+3, 0); 
    	MTTLMsg = CMPP.Bytes4ToInt(abyte0); 
    	off += 4; 
    	 
    	Arrays.fill(abyte0,(byte)0); 
    	CMPP.BytesCopy(super.bodybytes, abyte0, off, off+3, 0); 
    	MTTLUsr = CMPP.Bytes4ToInt(abyte0); 
    	off += 4; 
    	 
    	Arrays.fill(abyte0,(byte)0); 
    	CMPP.BytesCopy(super.bodybytes, abyte0, off, off+3, 0); 
    	MTScs = CMPP.Bytes4ToInt(abyte0); 
    	off += 4; 
    	 
    	Arrays.fill(abyte0,(byte)0); 
    	CMPP.BytesCopy(super.bodybytes, abyte0, off, off+3, 0); 
    	MTWT = CMPP.Bytes4ToInt(abyte0); 
    	off += 4; 
    	 
    	Arrays.fill(abyte0,(byte)0); 
    	CMPP.BytesCopy(super.bodybytes, abyte0, off, off+3, 0); 
    	MTFL = CMPP.Bytes4ToInt(abyte0); 
    	off += 4; 
    	 
    	Arrays.fill(abyte0,(byte)0); 
    	CMPP.BytesCopy(super.bodybytes, abyte0, off, off+3, 0); 
    	MOScs = CMPP.Bytes4ToInt(abyte0); 
    	off += 4; 
    	 
    	Arrays.fill(abyte0,(byte)0); 
    	CMPP.BytesCopy(super.bodybytes, abyte0, off, off+3, 0); 
    	MOWT = CMPP.Bytes4ToInt(abyte0); 
    	off += 4; 
    	 
    	Arrays.fill(abyte0,(byte)0); 
    	CMPP.BytesCopy(super.bodybytes, abyte0, off, off+3, 0); 
    	MOFL = CMPP.Bytes4ToInt(abyte0); 
    	off += 4; 
    	 
        return 0; 
    } 
 
	/** 
	 *  
	 */ 
	protected int makeBody() { 
	 
    	// make bodybytes 
    	super.bodyLength = commandLength;  
    	super.bodybytes  = new byte[super.bodyLength]; 
    	Arrays.fill(super.bodybytes,(byte)0); 
 
    	// make parameter 
    	if( Time == null ) { 
    		Calendar calendar = Calendar.getInstance(); 
     		calendar.setTime(new Date()); 
     		int timestamp = calendar.get(Calendar.YEAR) * 10000 
     			+ (calendar.get(Calendar.MONTH) + 1) * 100 
     			+ calendar.get(Calendar.DAY_OF_MONTH); 
     		Time = String.valueOf(timestamp); 
    	} 
    	if( QueryCode == null ) { 
    		QueryCode = ""; 
    	} 
 
    	// make body 
    	int off = 0; 
    	CMPP.BytesCopy(Time.getBytes(), super.bodybytes, 0, 7, off ); 
    	off += 8; 
    	super.bodybytes[off] = CMPP.IntToByte(QueryType); 
    	off += 1; 
    	CMPP.BytesCopy(QueryCode.getBytes(), super.bodybytes, 0, 9, off ); 
    	off += 10; 
    	CMPP.BytesCopy(CMPP.IntToBytes4(MTTLMsg), super.bodybytes, 0, 3, off ); 
    	off += 4; 
    	CMPP.BytesCopy(CMPP.IntToBytes4(MTTLUsr), super.bodybytes, 0, 3, off ); 
    	off += 4; 
    	CMPP.BytesCopy(CMPP.IntToBytes4(MTScs), super.bodybytes, 0, 3, off ); 
    	off += 4; 
    	CMPP.BytesCopy(CMPP.IntToBytes4(MTWT), super.bodybytes, 0, 3, off ); 
    	off += 4; 
    	CMPP.BytesCopy(CMPP.IntToBytes4(MTFL), super.bodybytes, 0, 3, off ); 
    	off += 4; 
    	CMPP.BytesCopy(CMPP.IntToBytes4(MOScs), super.bodybytes, 0, 3, off ); 
    	off += 4; 
    	CMPP.BytesCopy(CMPP.IntToBytes4(MOWT), super.bodybytes, 0, 3, off ); 
    	off += 4; 
    	CMPP.BytesCopy(CMPP.IntToBytes4(MOFL), super.bodybytes, 0, 3, off ); 
    	off += 4; 
 
    	return 0; 
	} 
	 
	public String toString() { 
		StringBuffer sb = new StringBuffer(); 
		 
		sb.append("Time=" + Time + "\n"); 
		sb.append("QueryType=" + QueryType + "\n"); 
		sb.append("QueryCode=" + QueryCode + "\n"); 
		sb.append("MTTLMsg=" + MTTLMsg + "\n"); 
		sb.append("MTTLUsr=" + MTTLUsr + "\n"); 
		sb.append("MTScs=" + MTScs + "\n"); 
		sb.append("MTWT=" + MTWT + "\n"); 
		sb.append("MTFL=" + MTFL + "\n"); 
		sb.append("MOScs=" + MOScs + "\n"); 
		sb.append("MOWT=" + MOWT + "\n"); 
		sb.append("MOFL=" + MOFL + "\n"); 
		 
		return sb.toString(); 
	} 
 
}