关闭

fix协议封装挑战

4687人阅读 评论(0) 收藏 举报
分类:

最近在做金融项目,用到了fix协议,是么是fix协议我就不多说了,由我一个人去封装这个庞然大物,当然很多没用到的我们暂时没封装进去。

下面是我的思路。

msg由个基类BaseMsg

component由个基类BaseGrp

Tag类用来封装一个字段,信息包括字段id,数据类型,字段值,是否必须

下面是Logon msg的一个例子:

package cs.mina.codec.msg;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import cs.mina.exception.InValidDataException;

/*
 *@author(huangxiaoping)
 *@date 2013-10-24
 */
public abstract class BaseMsg {
	public static final String SOH = "\u0001";
	protected String head;
	protected String body;
	protected String tailer;
	protected Head headEntity=new Head();
	protected Body bodyEntity=new Body();
	protected Tailer tailerEntity=new Tailer();
	
	public abstract void validate();
	
	public String encode(){
		String result="";
		List<Tag> headTagList=this.headEntity.getHeadTagList();
		for(int i=0;i<headTagList.size();i++){
			Tag headTag=headTagList.get(i);
			result+=headTag.encode();
		}
		List<Tag> bodyTagList=this.bodyEntity.getBodyTagList();
		for(int i=0;i<bodyTagList.size();i++){
			Tag bodyTag=bodyTagList.get(i);
			result+=bodyTag.encode();
		}
		List<Tag> tailerTagList=this.tailerEntity.getTailerTagList();
		for(int i=0;i<tailerTagList.size();i++){
			Tag tailerTag=tailerTagList.get(i);
			result+=tailerTag.encode();
		}
		return result;
	}
	
	public void decode(){
		decodeHead();
		decodeBody();
		decodeTailer();
	}
	
	public abstract void decodeBody();
	
	public void decodeHead(){
		Set<String> already=new HashSet<String>();
		String[] headItems=this.head.split(SOH);
		for(int i=0;i<headItems.length;i++){
			String headItem=headItems[i];
			String[] headTagItems=headItem.split("=");
			if(headTagItems.length!=2){
				throw new InValidDataException("消息格式错误");
			}
			if(already.contains(headTagItems[0])){
				throw new InValidDataException("消息格式错误");
			}
			already.add(headTagItems[0]);
			if(headTagItems[0].equals("627")){
				int skip=decodeGroup627();
				i=i+skip-1;
			}else{
				List<Tag> headTags=this.headEntity.getHeadTagList();
				for(int j=0;j<headTags.size();j++){
					Tag headTag=headTags.get(j);
					if(headTag.getTagId().equals(headTagItems[0])){
						headTag.setTagValue(headTagItems[1]);
					}
				}
			}
		}
	}
	
	private int decodeGroup627(){
		int index=head.indexOf("627=");
		String rest=head.substring(index);
		String[]tagItems=rest.split(BaseMsg.SOH);
		String[] numTagItems=tagItems[0].split("=");
		if(numTagItems.length!=2){
			throw new InValidDataException("消息格式错误");
		}
		if(!"627".equals(numTagItems[0])){
			throw new InValidDataException("消息格式错误");
		}
		int num=Integer.parseInt(numTagItems[1]);
		int count=1;
		int whileCount=0;
		((HopGrpTag)this.headEntity.getHopGrpTag()).setTagValue(num+"");
		boolean end=false;
		for(int i=0;i<num;i++){
			if(end){
				if(i!=num){
					throw new InValidDataException("消息格式错误");
				}else{
					break;
				}
			}
			HopGrp hopGrp=new HopGrp();
			((HopGrpTag)this.getHeadEntity().getHopGrpTag()).getChildren().add(hopGrp);
			while(true){
				if(whileCount>=3){
					whileCount=0;
					break;
				}
				if(tagItems.length==count){
					break;
				}
				String[] tagIt=tagItems[count].split("=");
				if(tagIt.length!=2){
					throw new InValidDataException("消息格式错误");
				}
				if(whileCount==0){
					if(!HopGrpTag.first.equals(tagIt[0])){
						throw new InValidDataException("消息格式错误");
					}
				}
				
				if(HopGrp.tagIdsSet.contains(tagIt[0])){
					List<Tag> tagList=hopGrp.getTagList();
					for(int j=0;j<tagList.size();j++){
						Tag groupTag=tagList.get(j);
						if(groupTag.getTagId().equals(tagIt[0])){
							groupTag.setTagValue(tagIt[1]);
							break;
						} 
					}
					if(tagItems.length>count+1){
						String[] nextTagIt=tagItems[count+1].split("=");
						if(nextTagIt.length!=2){
							throw new InValidDataException("消息格式错误");
						}
						if(HopGrpTag.first.equals(nextTagIt[0])){
							whileCount=0;
							count++;
							break;
						}
					}
					
					count++;
					whileCount++;
					
				}else{
					end=true;
					break;
				}
				
			}
			
		}
		
		return count;
	}
	
	public void decodeTailer(){
		Set<String> already=new HashSet<String>();
		String[] tailerItems=this.tailer.split(SOH);
		for(int i=0;i<tailerItems.length;i++){
			String tailerItem=tailerItems[i];
			String[] tailerTagItems=tailerItem.split("=");
			if(tailerTagItems.length!=2){
				throw new InValidDataException("消息格式错误");
			}
			if(already.contains(tailerTagItems[0])){
				throw new InValidDataException("消息格式错误");
			}
			already.add(tailerTagItems[0]);
			List<Tag> tailerTags=this.tailerEntity.getTailerTagList();
			for(int j=0;j<tailerTags.size();j++){
				Tag tailerTag=tailerTags.get(j);
				if(tailerTag.getTagId().equals(tailerTagItems[0])){
					tailerTag.setTagValue(tailerTagItems[1]);
				}
			}
			
		}
	}
	
	public String getHead() {
		return head;
	}

	public void setHead(String head) {
		this.head = head;
	}

	public String getBody() {
		return body;
	}

	public void setBody(String body) {
		this.body = body;
	}

	public String getTailer() {
		return tailer;
	}

	public void setTailer(String tailer) {
		this.tailer = tailer;
	}

	public Head getHeadEntity() {
		return headEntity;
	}

	public void setHeadEntity(Head headEntity) {
		this.headEntity = headEntity;
	}

	public Body getBodyEntity() {
		return bodyEntity;
	}

	public void setBodyEntity(Body bodyEntity) {
		this.bodyEntity = bodyEntity;
	}

	public Tailer getTailerEntity() {
		return tailerEntity;
	}

	public void setTailerEntity(Tailer tailerEntity) {
		this.tailerEntity = tailerEntity;
	}

	

}

package cs.mina.codec.msg;

import java.util.ArrayList;
import java.util.List;

/*
 *@author(huangxiaoping)
 *@date 2013-10-25
 */
public abstract class BaseGrp {
	public abstract void validate();
	public  String encode(){
		String result="";
		for(int i=0;i<tagList.size();i++){
			Tag tag=tagList.get(i);
			result+=tag.encode();
		}
		return result;
	}
	
	
	public boolean isTagIdInThisObject(String tagId) {
		for(int i=0;i<tagList.size();i++){
			if(tagList.get(i).isTagIdInThisObject(tagId)){
				return true;
			}
		}
		return false;
	}

	public String decode(String input){
		return null;
	}
	
	protected List<Tag> tagList = new ArrayList<Tag>();

	public List<Tag> getTagList() {
		return tagList;
	}

	public void setTagList(List<Tag> tagList) {
		this.tagList = tagList;
	}

}

package cs.mina.codec.msg;

import java.util.ArrayList;
import java.util.List;

/*
 *@author(huangxiaoping)
 *@date 2013-10-24
 */
public class Body {
	private List<Tag> bodyTagList=new ArrayList<Tag>();

	public List<Tag> getBodyTagList() {
		return bodyTagList;
	}

	public void setBodyTagList(List<Tag> bodyTagList) {
		this.bodyTagList = bodyTagList;
	}
	
	
}

package cs.mina.codec.msg;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import cs.mina.SeqenceNum;
import cs.util.SysInfo;

/*
 *@author(huangxiaoping)
 *@date 2013-10-24
 */
public class Head {
	private Tag beginString = new Tag("8", "String", true);
	private Tag bodyLength = new Tag("9", "Length", true);
	private Tag msgType = new Tag("35", "String", true);
	private Tag applVerID = new Tag("1128", "String", false);
	private Tag cstmApplVerID = new Tag("1129", "String", false);
	private Tag senderCompID = new Tag("49", "String", true);
	private Tag TargetCompID = new Tag("56", "String", true);
	private Tag onBehalfOfCompID = new Tag("115", "String", false);
	private Tag deliverToCompID=new Tag("128","String",false);
	private Tag secureDataLen=new Tag("90","Length",false);
	private Tag secureData=new Tag("91","data",false);
	private Tag msgSeqNum=new Tag("34","SeqNum",true);
	private Tag senderSubID=new Tag("50","String",false);
	private Tag senderLocationID=new Tag("142","String",false);
	private Tag targetSubID=new Tag("57","String",false);
	private Tag targetLocationID=new Tag("143","String",false);
	private Tag onBehalfOfSubID=new Tag("116","String",false);
	private Tag onBehalfOfLocationID=new Tag("144","String",false);
	private Tag deliverToSubID=new Tag("129","String",false);
	private Tag deliverToLocationID=new Tag("145","String",false);
	private Tag possDupFlag=new Tag("43","Boolean",false);
	private Tag possResend=new Tag("97","Boolean",false);
	private Tag sendingTime=new Tag("52","UTCTimestamp",true);
	private Tag origSendingTime=new Tag("122","UTCTimestamp",false);
	private Tag xmlDataLen=new Tag("212","Length",false);
	private Tag xmlData=new Tag("213","data",false);
	private Tag messageEncoding=new Tag("347","String",false);
	private Tag lastMsgSeqNumProcessed=new Tag("369","String",false);
	private Tag hopGrpTag=new HopGrpTag();
	
	private List<Tag> headTagList = new ArrayList<Tag>();

	public Head() {
		this.getBeginString().setTagValue("FIXT.1.1");
		this.getBodyLength().setTagValue("1");
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HH:mm:ss.SSS");  
	   	this.getSendingTime().setTagValue(sdf.format(new Date()));
	   	this.getSenderCompID().setTagValue(SysInfo.senderCompID);
	   	this.getTargetCompID().setTagValue(SysInfo.targetCompID);
	   	
		headTagList.add(beginString);
		headTagList.add(bodyLength);
		headTagList.add(msgType);
		headTagList.add(applVerID);
		headTagList.add(cstmApplVerID);
		headTagList.add(senderCompID);
		headTagList.add(TargetCompID);
		headTagList.add(onBehalfOfCompID);
		headTagList.add(deliverToCompID);
		headTagList.add(secureDataLen);
		headTagList.add(secureData);
		headTagList.add(msgSeqNum);
		headTagList.add(senderSubID);
		headTagList.add(senderLocationID);
		headTagList.add(targetSubID);
		headTagList.add(targetLocationID);
		headTagList.add(onBehalfOfSubID);
		headTagList.add(onBehalfOfLocationID);
		headTagList.add(deliverToSubID);
		headTagList.add(deliverToLocationID);
		headTagList.add(possDupFlag);
		headTagList.add(possResend);
		headTagList.add(sendingTime);
		headTagList.add(origSendingTime);
		headTagList.add(xmlDataLen);
		headTagList.add(xmlData);
		headTagList.add(messageEncoding);
		headTagList.add(lastMsgSeqNumProcessed);
		headTagList.add(hopGrpTag);
	}
	
	public void validate() {
		for(int i=0;i<headTagList.size();i++){
			headTagList.get(i).validate();
		}
	}

	public Tag getBeginString() {
		return beginString;
	}

	public void setBeginString(Tag beginString) {
		this.beginString = beginString;
	}

	public Tag getBodyLength() {
		return bodyLength;
	}

	public void setBodyLength(Tag bodyLength) {
		this.bodyLength = bodyLength;
	}

	public Tag getMsgType() {
		return msgType;
	}

	public void setMsgType(Tag msgType) {
		this.msgType = msgType;
	}

	public Tag getApplVerID() {
		return applVerID;
	}

	public void setApplVerID(Tag applVerID) {
		this.applVerID = applVerID;
	}

	public Tag getCstmApplVerID() {
		return cstmApplVerID;
	}

	public void setCstmApplVerID(Tag cstmApplVerID) {
		this.cstmApplVerID = cstmApplVerID;
	}

	public Tag getSenderCompID() {
		return senderCompID;
	}

	public void setSenderCompID(Tag senderCompID) {
		this.senderCompID = senderCompID;
	}

	public Tag getTargetCompID() {
		return TargetCompID;
	}

	public void setTargetCompID(Tag targetCompID) {
		TargetCompID = targetCompID;
	}

	public Tag getOnBehalfOfCompID() {
		return onBehalfOfCompID;
	}

	public void setOnBehalfOfCompID(Tag onBehalfOfCompID) {
		this.onBehalfOfCompID = onBehalfOfCompID;
	}

	public List<Tag> getHeadTagList() {
		return headTagList;
	}

	public void setHeadTagList(List<Tag> headTagList) {
		this.headTagList = headTagList;
	}

	public Tag getDeliverToCompID() {
		return deliverToCompID;
	}

	public void setDeliverToCompID(Tag deliverToCompID) {
		this.deliverToCompID = deliverToCompID;
	}

	public Tag getSecureDataLen() {
		return secureDataLen;
	}

	public void setSecureDataLen(Tag secureDataLen) {
		this.secureDataLen = secureDataLen;
	}

	public Tag getSecureData() {
		return secureData;
	}

	public void setSecureData(Tag secureData) {
		this.secureData = secureData;
	}

	public Tag getMsgSeqNum() {
		return msgSeqNum;
	}

	public void setMsgSeqNum(Tag msgSeqNum) {
		this.msgSeqNum = msgSeqNum;
	}

	public Tag getSenderSubID() {
		return senderSubID;
	}

	public void setSenderSubID(Tag senderSubID) {
		this.senderSubID = senderSubID;
	}

	public Tag getSenderLocationID() {
		return senderLocationID;
	}

	public void setSenderLocationID(Tag senderLocationID) {
		this.senderLocationID = senderLocationID;
	}

	public Tag getTargetSubID() {
		return targetSubID;
	}

	public void setTargetSubID(Tag targetSubID) {
		this.targetSubID = targetSubID;
	}

	public Tag getTargetLocationID() {
		return targetLocationID;
	}

	public void setTargetLocationID(Tag targetLocationID) {
		this.targetLocationID = targetLocationID;
	}

	public Tag getOnBehalfOfSubID() {
		return onBehalfOfSubID;
	}

	public void setOnBehalfOfSubID(Tag onBehalfOfSubID) {
		this.onBehalfOfSubID = onBehalfOfSubID;
	}

	public Tag getOnBehalfOfLocationID() {
		return onBehalfOfLocationID;
	}

	public void setOnBehalfOfLocationID(Tag onBehalfOfLocationID) {
		this.onBehalfOfLocationID = onBehalfOfLocationID;
	}

	public Tag getDeliverToSubID() {
		return deliverToSubID;
	}

	public void setDeliverToSubID(Tag deliverToSubID) {
		this.deliverToSubID = deliverToSubID;
	}

	public Tag getDeliverToLocationID() {
		return deliverToLocationID;
	}

	public void setDeliverToLocationID(Tag deliverToLocationID) {
		this.deliverToLocationID = deliverToLocationID;
	}

	public Tag getPossDupFlag() {
		return possDupFlag;
	}

	public void setPossDupFlag(Tag possDupFlag) {
		this.possDupFlag = possDupFlag;
	}

	public Tag getPossResend() {
		return possResend;
	}

	public void setPossResend(Tag possResend) {
		this.possResend = possResend;
	}

	public Tag getSendingTime() {
		return sendingTime;
	}

	public void setSendingTime(Tag sendingTime) {
		this.sendingTime = sendingTime;
	}

	public Tag getOrigSendingTime() {
		return origSendingTime;
	}

	public void setOrigSendingTime(Tag origSendingTime) {
		this.origSendingTime = origSendingTime;
	}

	public Tag getXmlDataLen() {
		return xmlDataLen;
	}

	public void setXmlDataLen(Tag xmlDataLen) {
		this.xmlDataLen = xmlDataLen;
	}

	public Tag getXmlData() {
		return xmlData;
	}

	public void setXmlData(Tag xmlData) {
		this.xmlData = xmlData;
	}

	public Tag getMessageEncoding() {
		return messageEncoding;
	}

	public void setMessageEncoding(Tag messageEncoding) {
		this.messageEncoding = messageEncoding;
	}

	public Tag getLastMsgSeqNumProcessed() {
		return lastMsgSeqNumProcessed;
	}

	public void setLastMsgSeqNumProcessed(Tag lastMsgSeqNumProcessed) {
		this.lastMsgSeqNumProcessed = lastMsgSeqNumProcessed;
	}

	public Tag getHopGrpTag() {
		return hopGrpTag;
	}

	public void setHopGrpTag(Tag hopGrpTag) {
		this.hopGrpTag = hopGrpTag;
	}

}

package cs.mina.codec.msg;

import java.util.ArrayList;
import java.util.List;

/*
 *@author(huangxiaoping)
 *@date 2013-10-24
 */
public class Tailer {
	private Tag signatureLength = new Tag("93", "Length", false);
	private Tag signature = new Tag("89", "data", false);
	private Tag checkSum = new Tag("10", "String", false);
	private List<Tag> tailerTagList = new ArrayList<Tag>();
	
	public Tailer(){
		checkSum.setTagValue("1");
		tailerTagList.add(signatureLength);
		tailerTagList.add(signature);
		tailerTagList.add(checkSum);
	}
	
	public void validate() {
		for(int i=0;i<tailerTagList.size();i++){
			tailerTagList.get(i).validate();
		}
		
	}
	
	public Tag getSignatureLength() {
		return signatureLength;
	}

	public void setSignatureLength(Tag signatureLength) {
		this.signatureLength = signatureLength;
	}

	public Tag getSignature() {
		return signature;
	}

	public void setSignature(Tag signature) {
		this.signature = signature;
	}

	public Tag getCheckSum() {
		return checkSum;
	}

	public void setCheckSum(Tag checkSum) {
		this.checkSum = checkSum;
	}

	public List<Tag> getTailerTagList() {
		return tailerTagList;
	}

	public void setTailerTagList(List<Tag> tailerTagList) {
		this.tailerTagList = tailerTagList;
	}

}

package cs.mina.codec.msg;

import java.util.HashSet;
import java.util.Set;

import cs.mina.exception.InValidDataException;

/*
 *@author(huangxiaoping)
 *@date 2013-10-24
 */
public class Tag {
	private String tagId;
	private String tagValue;
	private String format;
	private boolean must;
	
	public  boolean isTagIdInThisObject(String tagId){
		if(tagId.equals(this.tagId)){
			return true;
		}else {
			return false;
		}
	}
	
	public String encode(){
		if(tagValue==null){
			return "";
		}
		return this.tagId+"="+this.tagValue+BaseMsg.SOH;
	}
	
	public String decode(String input,Set<String> already){
		String myItem=input.substring(0, input.indexOf(BaseMsg.SOH));
		String returnStr=input.substring(input.indexOf(BaseMsg.SOH)+1);
		String [] tagItems=myItem.split("=");
		if(tagItems.length!=2){
			throw new InValidDataException("消息格式错误");
		}
		if(already.contains(tagId)){
			throw new InValidDataException(tagId+"消息已被解析");
		}
		if(this.getTagId().equals(tagItems[0])){
			this.tagValue=tagItems[1];
			already.add(tagItems[0]);
			return returnStr;
		}else{
			throw new InValidDataException("解析错误["+tagId+"-"+tagItems[0]+"]");
		}
	}
	
	public Tag(String tagId,String format,boolean must){
		this.tagId=tagId;
		this.format=format;
		this.must=must;
	}
	
	public void validate(){
		if(must){
			if(tagValue==null){
				throw new InValidDataException(tagId+"的值不可以为空");
			}else{
				if(format==null){
					throw new InValidDataException("format的不可以为空");
				}else{
					if(format.equals("int")){
						try{
							Integer.parseInt(tagValue);
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值不是int类型");
						}
						
					}else if(format.equals("Length")){
						try{
							int value=Integer.parseInt(tagValue);
							if(value<=0){
								throw new InValidDataException(tagId+"-"+tagValue+":值(Length)不是正的int类型");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(Length)不是int类型");
						}
					}else if(format.equals("TagNum")){
						try{
							if(tagValue.startsWith("0")){
								throw new InValidDataException(tagId+"-"+tagValue+":TagNum类型不能以0开头");
							}
							int value=Integer.parseInt(tagValue);
							if(value<=0){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TagNum)不是正的int类型");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(TagNum)不是int类型");
						}
					}else if(format.equals("SeqNum")){
						try{
							int value=Integer.parseInt(tagValue);
							if(value<0){
								throw new InValidDataException(tagId+"-"+tagValue+":值(SeqNum)小于0");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(SeqNum)不是int类型");
						}
					}else if(format.equals("NumInGroup")){
						try{
							int value=Integer.parseInt(tagValue);
							if(value<=0){
								throw new InValidDataException(tagId+"-"+tagValue+":值(NumInGroup)不是正的int类型");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(NumInGroup)不是int类型");
						}
					}else if(format.equals("DayOfMonth")){
						try{
							int value=Integer.parseInt(tagValue);
							if(!(value<=31&&value>=1)){
								throw new InValidDataException(tagId+"-"+tagValue+":值(DayOfMonth)不在1和31之间");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(DayOfMonth)不是int类型");
						}
					}else if(format.equals("float")){
						try{
							Float.parseFloat(tagValue);
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(float)不是float类型");
						}
						
					}else if(format.equals("Qty")){
						try{
							Float.parseFloat(tagValue);
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(Qty)不是float类型");
						}
					}else if(format.equals("Price")){
						try{
							Float.parseFloat(tagValue);
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(Price)不是float类型");
						}
					}else if(format.equals("PriceOffset")){
						try{
							Float.parseFloat(tagValue);
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(PriceOffset)不是float类型");
						}
					}else if(format.equals("Amt")){
						try{
							Float.parseFloat(tagValue);
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(Amt)不是float类型");
						}
					}else if(format.equals("Percentage")){
						try{
							Float.parseFloat(tagValue);
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(Percentage)不是float类型");
						}
					}else if(format.equals("char")){
						if(tagValue.length()>1||tagValue.length()==0){
							throw new InValidDataException(tagId+"-"+tagValue+":值(char)长度大于1或等于0");
						}
						if(tagValue.equals(BaseMsg.SOH)){
							throw new InValidDataException(tagId+"-"+tagValue+":值(char)不能是分隔符");
						}
						
					}else if(format.equals("Boolean")){
						if(tagValue.length()>1||tagValue.length()==0){
							throw new InValidDataException(tagId+"-"+tagValue+":值(Boolean)长度大于1或等于0");
						}
						if(!(tagValue.equals("N")||tagValue.equals("Y"))){
							throw new InValidDataException(tagId+"-"+tagValue+":值(Boolean)不是N或Y");
						}
					}else if(format.equals("String")){
						int index=tagValue.indexOf(BaseMsg.SOH);
						if(index!=-1){
							throw new InValidDataException(tagId+"-"+tagValue+":值(String)不能包含分隔符");
						}
					}else if(format.equals("MultipleCharValue")){
						int index=tagValue.indexOf(BaseMsg.SOH);
						if(index!=-1){
							throw new InValidDataException(tagId+"-"+tagValue+":值(String)不能包含分隔符");
						}
						String[] valueArray=tagValue.split(" ");
						for(int i=0;i<valueArray.length;i++){
							String value=valueArray[i];
							if(value.length()>1){
								throw new InValidDataException(tagId+"-"+tagValue+":值(MultipleCharValue)包含String小单元了");
							}
						}
					}else if(format.equals("MultipleStringValue")){
						int index=tagValue.indexOf(BaseMsg.SOH);
						if(index!=-1){
							throw new InValidDataException(tagId+"-"+tagValue+":值(String)不能包含分隔符");
						}
					}else if(format.equals("Country")){
						if(tagValue.length()!=2){
							throw new InValidDataException(tagId+"-"+tagValue+":值(Country)长度错误");
						}
						//TODO country比较
					}else if(format.equals("Currency")){
						if(tagValue.length()!=3){
							throw new InValidDataException(tagId+"-"+tagValue+":值(Currency)长度错误");
						}
						//TODO Currency比较
					}else if(format.equals("Exchange")){		
						//TODO Exchange
					}else if(format.equals("MonthYear")){		
						 if(!(tagValue.length()==6||tagValue.length()==8)){
							 throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)长度错误");
						 }
						 String year=tagValue.substring(0, 4);
						 String month=tagValue.substring(4, 6);
						 if(tagValue.length()==8){
							 String weekOrDay=tagValue.substring(6, 8);
							 try{
								int y= Integer.parseInt(year);
								if(y<0){
									throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)年份错误");
								}
							 }catch(Exception e){
								 throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)年份错误");
							 }
							 try{
								 int mon= Integer.parseInt(month);
								 if(!(mon>=1&&mon<=12)){
									 throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)月份错误");
								 }
							 }catch(Exception e){
								 throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)月份错误");
							 }
							 if(weekOrDay.startsWith("w")){
								 try{
									int week= Integer.parseInt(weekOrDay.substring(1));
									if(!(week>=1&&week<=5)){
										throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)星期错误");
									}
								 }catch(Exception e){
									 throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)星期错误");
								 }
							 }else{
								 try{
									 int day=Integer.parseInt(weekOrDay);
									 if(!(day>=1&&day<=31)){
										 throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)day错误");
									 }
								 }catch(Exception e){
									 throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)day错误");
								 }
							 }
							 
						 }else{
							 try{
								 int y= Integer.parseInt(year);
									if(y<0){
										throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)年份错误");
									}
							 }catch(Exception e){
								 throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)年份错误");
							 }
							 try{
								 int mon= Integer.parseInt(month);
								 if(!(mon>=1&&mon<=12)){
									 throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)月份错误");
								 }
							 }catch(Exception e){
								 throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)月份错误");
							 }
							
						 }
					}else if(format.equals("UTCTimestamp")){
						if(tagValue.length()==17){
							String yearStr=tagValue.substring(0, 4);
							String monthStr=tagValue.substring(4, 6);
							String dayStr=tagValue.substring(6, 8);
							String seperator1=tagValue.substring(8, 9);
							String hourStr=tagValue.substring(9, 11);
							String seperaotr2=tagValue.substring(11, 12);
							String minuteStr=tagValue.substring(12, 14);
							String seperator3=tagValue.substring(14, 15);
							String secondStr=tagValue.substring(15, 17);
							if(!seperator1.equals("-")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)日期错误");
							}
							if(!seperaotr2.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)日期错误");
							}
							if(!seperator3.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)日期错误");
							}
							try{
								int year=Integer.parseInt(yearStr);
								if(year<0){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)年份错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)年份错误");
							}
							try{
								int month=Integer.parseInt(monthStr);
								if(!(month>=1&&month<=12)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)月份错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)月份错误");
							}
							try{
								int day=Integer.parseInt(dayStr);
								if(!(day>=1&&day<=31)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)日期错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)日期错误");
							}
							try{
								int hour=Integer.parseInt(hourStr);
								if(!(hour>=0&&hour<=23)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)小时错误");
							}
							try{
								int minute=Integer.parseInt(minuteStr);
								if(!(minute>=0&&minute<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)分钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)分钟错误");
							}
							try{
								int second=Integer.parseInt(secondStr);
								if(!(second>=0&&second<=60)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)秒钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)秒钟错误");
							}
							
						}else if(tagValue.length()==21){
							String yearStr=tagValue.substring(0, 4);
							String monthStr=tagValue.substring(4, 6);
							String dayStr=tagValue.substring(6, 8);
							String seperator1=tagValue.substring(8, 9);
							String hourStr=tagValue.substring(9, 11);
							String seperaotr2=tagValue.substring(11, 12);
							String minuteStr=tagValue.substring(12, 14);
							String seperator3=tagValue.substring(14, 15);
							String secondStr=tagValue.substring(15, 17);
							String seperater4=tagValue.substring(17, 18);
							String miliSecondStr=tagValue.substring(18, 21);
							if(!seperator1.equals("-")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)日期错误");
							}
							if(!seperaotr2.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)日期错误");
							}
							if(!seperator3.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)日期错误");
							}
							if(!seperater4.equals(".")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)日期错误");
							}
							try{
								int year=Integer.parseInt(yearStr);
								if(year<0){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)年份错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)年份错误");
							}
							try{
								int month=Integer.parseInt(monthStr);
								if(!(month>=1&&month<=12)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)月份错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)月份错误");
							}
							try{
								int day=Integer.parseInt(dayStr);
								if(!(day>=1&&day<=31)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)日期错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)日期错误");
							}
							try{
								int hour=Integer.parseInt(hourStr);
								if(!(hour>=0&&hour<=23)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)小时错误");
							}
							try{
								int minute=Integer.parseInt(minuteStr);
								if(!(minute>=0&&minute<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)分钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)分钟错误");
							}
							try{
								int second=Integer.parseInt(secondStr);
								if(!(second>=0&&second<=60)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)秒钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)秒钟错误");
							}
							try{
								int miliSecond=Integer.parseInt(miliSecondStr);
								if(miliSecond<0){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)毫秒错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)毫秒错误");
							}
							
						}else{
							throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)长度错误");
						}
					}else if(format.equals("UTCTimeOnly")){
						if(tagValue.length()==8){
							String hourStr=tagValue.substring(0, 2);
							String seperator1=tagValue.substring(2, 3);
							String minuteStr=tagValue.substring(3, 5);
							String seperator2=tagValue.substring(5, 6);
							String secondStr=tagValue.substring(6, 8);
							if(!seperator1.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)时间错误");
							}
							if(!seperator2.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)时间错误");
							}
							try{
								int hour=Integer.parseInt(hourStr);
								if(!(hour>=0&&hour<=23)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)小时错误");
							}
							try{
								int minute=Integer.parseInt(minuteStr);
								if(!(minute>=0&&minute<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)分钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)分钟错误");
							}
							try{
								int second=Integer.parseInt(secondStr);
								if(!(second>=0&&second<=60)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)秒钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)秒钟错误");
							}
						}else if(tagValue.length()==12){
							String hourStr=tagValue.substring(0, 2);
							String seperator1=tagValue.substring(2, 3);
							String minuteStr=tagValue.substring(3, 5);
							String seperator2=tagValue.substring(5, 6);
							String secondStr=tagValue.substring(6, 8);
							String seperator3=tagValue.substring(8,9);
							String milliSecondStr=tagValue.substring(9, 12);
							if(!seperator1.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)时间错误");
							}
							if(!seperator2.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)时间错误");
							}
							if(!seperator3.equals(".")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)时间错误");
							}
							try{
								int hour=Integer.parseInt(hourStr);
								if(!(hour>=0&&hour<=23)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)小时错误");
							}
							try{
								int minute=Integer.parseInt(minuteStr);
								if(!(minute>=0&&minute<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)分钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)分钟错误");
							}
							try{
								int second=Integer.parseInt(secondStr);
								if(!(second>=0&&second<=60)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)秒钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)秒钟错误");
							}
							try{
								int milliSecond=Integer.parseInt(milliSecondStr);
								if(milliSecond<0){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)毫秒错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)毫秒错误");
							}
						}else{
							throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)长度错误");
						}
					}else if(format.equals("UTCDateOnly")){
						if(tagValue.length()!=8){
							throw new InValidDataException(tagId+"-"+tagValue+":值(UTCDateOnly)长度错误");
						}
						String yearStr=tagValue.substring(0, 4);
						String monthStr=tagValue.substring(4, 6);
						String dayStr=tagValue.substring(6, 8);
						try{
							int year=Integer.parseInt(yearStr);
							if(year<0){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCDateOnly)年份错误");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(UTCDateOnly)年份错误");
						}
						try{
							int month=Integer.parseInt(monthStr);
							if(!(month>=1&&month<=12)){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCDateOnly)月份错误");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(UTCDateOnly)月份错误");
						}
						try{
							int day=Integer.parseInt(dayStr);
							if(!(day>=1&&day<=31)){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCDateOnly)日期错误");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(UTCDateOnly)日期错误");
						}
					}else if(format.equals("LocalMktDate")){
						if(tagValue.length()!=8){
							throw new InValidDataException(tagId+"-"+tagValue+":值(LocalMktDate)长度错误");
						}
						String yearStr=tagValue.substring(0, 4);
						String monthStr=tagValue.substring(4, 6);
						String dayStr=tagValue.substring(6, 8);
						try{
							int year=Integer.parseInt(yearStr);
							if(year<0){
								throw new InValidDataException(tagId+"-"+tagValue+":值(LocalMktDate)年份错误");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(LocalMktDate)年份错误");
						}
						try{
							int month=Integer.parseInt(monthStr);
							if(!(month>=1&&month<=12)){
								throw new InValidDataException(tagId+"-"+tagValue+":值(LocalMktDate)月份错误");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(LocalMktDate)月份错误");
						}
						try{
							int day=Integer.parseInt(dayStr);
							if(!(day>=1&&day<=31)){
								throw new InValidDataException(tagId+"-"+tagValue+":值(LocalMktDate)日期错误");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(LocalMktDate)日期错误");
						}
					}else if(format.equals("TZTimeOnly")){
						if(tagValue.length()==6){
							String hourStr=tagValue.substring(0, 2);
							String seperate1=tagValue.substring(2, 3);
							String minuteStr=tagValue.substring(3, 5);
							String Z=tagValue.substring(5, 6);
							if(!seperate1.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
							}
							if(!Z.equals("Z")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)Z错误");
							}
							try{
								int hour=Integer.parseInt(hourStr);
								if(!(hour>=0&&hour<=23)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)小时错误");
							}
							try{
								int minute=Integer.parseInt(minuteStr);
								if(!(minute>=0&&minute<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)分钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)分钟错误");
							}
							
						}else if(tagValue.length()==9){
							String hourStr=tagValue.substring(0, 2);
							String seperate1=tagValue.substring(2, 3);
							String minuteStr=tagValue.substring(3, 5);
							String seperate2=tagValue.substring(5,6);
							String secondStr=tagValue.substring(6, 8);
							String Z=tagValue.substring(8, 9);
							if(!seperate1.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
							}
							if(!Z.equals("Z")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)Z错误");
							}
							if(!seperate2.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
							}
							try{
								int hour=Integer.parseInt(hourStr);
								if(!(hour>=0&&hour<=23)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)小时错误");
							}
							try{
								int minute=Integer.parseInt(minuteStr);
								if(!(minute>=0&&minute<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)分钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)分钟错误");
							}
							try{
								int second=Integer.parseInt(secondStr);
								if(!(second>=0&&second<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)秒钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)秒钟错误");
							}
						}else if(tagValue.length()==8){
							String hourStr=tagValue.substring(0, 2);
							String seperate1=tagValue.substring(2, 3);
							String minuteStr=tagValue.substring(3, 5);
							String seperate2=tagValue.substring(5,6);
							String offsetHourStr=tagValue.substring(6, 8);
							
							if(!seperate1.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
							}
							
							if(!(seperate2.equals("-")||seperate2.equals("+"))){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
							}
							try{
								int hour=Integer.parseInt(hourStr);
								if(!(hour>=0&&hour<=23)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)小时错误");
							}
							try{
								int minute=Integer.parseInt(minuteStr);
								if(!(minute>=0&&minute<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)分钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)分钟错误");
							}
							try{
								int offsetHour=Integer.parseInt(offsetHourStr);
								if(!(offsetHour>=1&&offsetHour<=12)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
							}
						}else if(tagValue.length()==11){
							String seperator1=tagValue.substring(5, 6);
							String hourStr=tagValue.substring(0,2);
							String seperator2=tagValue.substring(2, 3);
							String minuteStr=tagValue.substring(3, 5);
							if(!seperator2.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
							}
							try{
								int hour=Integer.parseInt(hourStr);
								if(!(hour>=0&&hour<=23)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)小时错误");
							}
							try{
								int minute=Integer.parseInt(minuteStr);
								if(!(minute>=0&&minute<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)分钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)分钟错误");
							}
							if(seperator1.equals(":")){
								String secondStr=tagValue.substring(6, 8);
								String seperator3=tagValue.substring(8,9);
								String offsetHourStr=tagValue.substring(9, 11);
								if(!(seperator3.equals("-")||seperator3.equals("+"))){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
								}
								try{
									int second=Integer.parseInt(secondStr);
									if(!(second>=0&&second<=59)){
										throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)秒钟错误");
									}
								}catch(Exception e){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)秒钟错误");
								}
								try{
									int offsetHour=Integer.parseInt(offsetHourStr);
									if(!(offsetHour>=1&&offsetHour<=12)){
										throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
									}
								}catch(Exception e){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
								}
							}else if(seperator1.equals("-")||seperator1.equals("+")){
								String offsetHourStr=tagValue.substring(6,8);
								String seperator3=tagValue.substring(8, 9);
								String offsetMinuteStr=tagValue.substring(9, 11);
								if(!seperator3.equals(":")){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
								}
								try{
									int offsetHour=Integer.parseInt(offsetHourStr);
									if(!(offsetHour>=1&&offsetHour<=12)){
										throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
									}
								}catch(Exception e){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
								}
								try{
									int offsetMinute=Integer.parseInt(offsetMinuteStr);
									if(!(offsetMinute>=0&&offsetMinute<=59)){
										throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移分钟错误");
									}
								}catch(Exception e){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移分钟错误");
								}
							}else{
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
							}
						}else if(tagValue.length()==14){
							String hourStr=tagValue.substring(0,2);
							String seperator1=tagValue.substring(2, 3);
							String minuteStr=tagValue.substring(3, 5);
							String seperator2=tagValue.substring(5, 6);
							String secondStr=tagValue.substring(6, 8);
							String seperator3=tagValue.substring(8,9);
							String offsetHourStr=tagValue.substring(9, 11);
							String seperator4=tagValue.substring(11, 12);
							String offsetMinuteStr=tagValue.substring(12, 14);
							if(!seperator1.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
							}
							if(!seperator2.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
							}
							if(!(seperator3.equals("+")||seperator3.equals("-"))){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
							}
							if(!seperator4.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
							}
							try{
								int hour=Integer.parseInt(hourStr);
								if(!(hour>=0&&hour<=23)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)小时错误");
							}
							try{
								int minute=Integer.parseInt(minuteStr);
								if(!(minute>=0&&minute<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)分钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)分钟错误");
							}
							try{
								int second=Integer.parseInt(secondStr);
								if(!(second>=0&&second<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)秒钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)秒钟错误");
							}
							try{
								int offsetHour=Integer.parseInt(offsetHourStr);
								if(!(offsetHour>=1&&offsetHour<=12)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
							}
							try{
								int offsetMinute=Integer.parseInt(offsetMinuteStr);
								if(!(offsetMinute>=0&&offsetMinute<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移分钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移分钟错误");
							}
						}else {
							throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)长度错误");
						}
					}else if(format.equals("TZTimestamp")){
						if(tagValue.length()<15){
							throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)长度错误");
						}
						String yearStr=tagValue.substring(0, 4);
						String monthStr=tagValue.substring(4, 6);
						String dayStr=tagValue.substring(6, 8);
						String seperator1=tagValue.substring(8, 9);
						String hourStr=tagValue.substring(9, 11);
						String seperator2=tagValue.substring(11, 12);
						String minuteStr=tagValue.substring(12, 14);
						if(!seperator1.equals("-")){
							throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)日期错误");
						}
						if(!seperator2.equals(":")){
							throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)日期错误");
						}
						try{
							int year=Integer.parseInt(yearStr);
							if(year<0){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)年份错误");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)年份错误");
						}
						try{
							int month=Integer.parseInt(monthStr);
							if(!(month>=1&&month<=12)){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)月份错误");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)月份错误");
						}
						try{
							int day=Integer.parseInt(dayStr);
							if(!(day>=1&&day<=31)){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)日期错误");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)日期错误");
						}
						try{
							int hour=Integer.parseInt(hourStr);
							if(!(hour>=0&&hour<=23)){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)小时错误");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)小时错误");
						}
						try{
							int minute=Integer.parseInt(minuteStr);
							if(!(minute>=0&&minute<=59)){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)分钟错误");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)分钟错误");
						}
						
						if(tagValue.length()==15){
							String Z=tagValue.substring(14, 15);
							if(!Z.equals("Z")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)Z错误");
							}
						}else if(tagValue.length()==17){
							String seperator3=tagValue.substring(14, 15);
							String offsetHourStr=tagValue.substring(15, 17);
							if(!(seperator3.equals("-")||seperator3.equals("+"))){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)日期错误");
							}
							try{
								int offsetHour=Integer.parseInt(offsetHourStr);
								if(!(offsetHour>=1&&offsetHour<=12)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
							}
						}else if(tagValue.length()==20){
							String seperator3=tagValue.substring(14, 15);
							String offsetHourStr=tagValue.substring(15, 17);
							String seperator4=tagValue.substring(17, 18);
							String offsetMinuteStr=tagValue.substring(18, 20);
							if(!(seperator3.equals("-")||seperator3.equals("+"))){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)日期错误");
							}
							if(!(seperator4.equals("-")||seperator3.equals(":"))){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)日期错误");
							}
							try{
								int offsetHour=Integer.parseInt(offsetHourStr);
								if(!(offsetHour>=1&&offsetHour<=12)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
							}
							try{
								int offsetMinute=Integer.parseInt(offsetMinuteStr);
								if(!(offsetMinute>=0&&offsetMinute<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移分钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移分钟错误");
							}
						}else {
							throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)长度错误");
						}
					}else if(format.equals("data")){
						//TODO
					}else if(format.equals("Pattern")){
						
					}else if(format.equals("Tenor")){
						
					}else if(format.equals("Reserved100Plus")){
						
					}else if(format.equals("Reserved1000Plus")){
						
					}else if(format.equals("Reserved4000Plus")){
						
					}else if(format.equals("XMLData")){
						
					}else if(format.equals("Language")){
						
					}else{
						throw new InValidDataException(tagId+"-"+tagValue+"-"+format+":format类型错误");
					}
				}
			}
		}else{
			if(tagValue!=null){
				if(format==null){
					throw new InValidDataException("format的不可以为空");
				}else{
					if(format.equals("int")){
						try{
							Integer.parseInt(tagValue);
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值不是int类型");
						}
						
					}else if(format.equals("Length")){
						try{
							int value=Integer.parseInt(tagValue);
							if(value<=0){
								throw new InValidDataException(tagId+"-"+tagValue+":值(Length)不是正的int类型");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(Length)不是int类型");
						}
					}else if(format.equals("TagNum")){
						try{
							if(tagValue.startsWith("0")){
								throw new InValidDataException(tagId+"-"+tagValue+":TagNum类型不能以0开头");
							}
							int value=Integer.parseInt(tagValue);
							if(value<=0){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TagNum)不是正的int类型");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(TagNum)不是int类型");
						}
					}else if(format.equals("SeqNum")){
						try{
							int value=Integer.parseInt(tagValue);
							if(value<0){
								throw new InValidDataException(tagId+"-"+tagValue+":值(SeqNum)小于0");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(SeqNum)不是int类型");
						}
					}else if(format.equals("NumInGroup")){
						try{
							int value=Integer.parseInt(tagValue);
							if(value<=0){
								throw new InValidDataException(tagId+"-"+tagValue+":值(NumInGroup)不是正的int类型");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(NumInGroup)不是int类型");
						}
					}else if(format.equals("DayOfMonth")){
						try{
							int value=Integer.parseInt(tagValue);
							if(!(value<=31&&value>=1)){
								throw new InValidDataException(tagId+"-"+tagValue+":值(DayOfMonth)不在1和31之间");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(DayOfMonth)不是int类型");
						}
					}else if(format.equals("float")){
						try{
							Float.parseFloat(tagValue);
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(float)不是float类型");
						}
						
					}else if(format.equals("Qty")){
						try{
							Float.parseFloat(tagValue);
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(Qty)不是float类型");
						}
					}else if(format.equals("Price")){
						try{
							Float.parseFloat(tagValue);
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(Price)不是float类型");
						}
					}else if(format.equals("PriceOffset")){
						try{
							Float.parseFloat(tagValue);
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(PriceOffset)不是float类型");
						}
					}else if(format.equals("Amt")){
						try{
							Float.parseFloat(tagValue);
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(Amt)不是float类型");
						}
					}else if(format.equals("Percentage")){
						try{
							Float.parseFloat(tagValue);
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(Percentage)不是float类型");
						}
					}else if(format.equals("char")){
						if(tagValue.length()>1||tagValue.length()==0){
							throw new InValidDataException(tagId+"-"+tagValue+":值(char)长度大于1或等于0");
						}
						if(tagValue.equals(BaseMsg.SOH)){
							throw new InValidDataException(tagId+"-"+tagValue+":值(char)不能是分隔符");
						}
						
					}else if(format.equals("Boolean")){
						if(tagValue.length()>1||tagValue.length()==0){
							throw new InValidDataException(tagId+"-"+tagValue+":值(Boolean)长度大于1或等于0");
						}
						if(!(tagValue.equals("N")||tagValue.equals("Y"))){
							throw new InValidDataException(tagId+"-"+tagValue+":值(Boolean)不是N或Y");
						}
					}else if(format.equals("String")){
						int index=tagValue.indexOf(BaseMsg.SOH);
						if(index!=-1){
							throw new InValidDataException(tagId+"-"+tagValue+":值(String)不能包含分隔符");
						}
					}else if(format.equals("MultipleCharValue")){
						int index=tagValue.indexOf(BaseMsg.SOH);
						if(index!=-1){
							throw new InValidDataException(tagId+"-"+tagValue+":值(String)不能包含分隔符");
						}
						String[] valueArray=tagValue.split(" ");
						for(int i=0;i<valueArray.length;i++){
							String value=valueArray[i];
							if(value.length()>1){
								throw new InValidDataException(tagId+"-"+tagValue+":值(MultipleCharValue)包含String小单元了");
							}
						}
					}else if(format.equals("MultipleStringValue")){
						int index=tagValue.indexOf(BaseMsg.SOH);
						if(index!=-1){
							throw new InValidDataException(tagId+"-"+tagValue+":值(String)不能包含分隔符");
						}
					}else if(format.equals("Country")){
						if(tagValue.length()!=2){
							throw new InValidDataException(tagId+"-"+tagValue+":值(Country)长度错误");
						}
						//TODO country比较
					}else if(format.equals("Currency")){
						if(tagValue.length()!=3){
							throw new InValidDataException(tagId+"-"+tagValue+":值(Currency)长度错误");
						}
						//TODO Currency比较
					}else if(format.equals("Exchange")){		
						//TODO Exchange
					}else if(format.equals("MonthYear")){		
						 if(!(tagValue.length()==6||tagValue.length()==8)){
							 throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)长度错误");
						 }
						 String year=tagValue.substring(0, 4);
						 String month=tagValue.substring(4, 6);
						 if(tagValue.length()==8){
							 String weekOrDay=tagValue.substring(6, 8);
							 try{
								int y= Integer.parseInt(year);
								if(y<0){
									throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)年份错误");
								}
							 }catch(Exception e){
								 throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)年份错误");
							 }
							 try{
								 int mon= Integer.parseInt(month);
								 if(!(mon>=1&&mon<=12)){
									 throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)月份错误");
								 }
							 }catch(Exception e){
								 throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)月份错误");
							 }
							 if(weekOrDay.startsWith("w")){
								 try{
									int week= Integer.parseInt(weekOrDay.substring(1));
									if(!(week>=1&&week<=5)){
										throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)星期错误");
									}
								 }catch(Exception e){
									 throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)星期错误");
								 }
							 }else{
								 try{
									 int day=Integer.parseInt(weekOrDay);
									 if(!(day>=1&&day<=31)){
										 throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)day错误");
									 }
								 }catch(Exception e){
									 throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)day错误");
								 }
							 }
							 
						 }else{
							 try{
								 int y= Integer.parseInt(year);
									if(y<0){
										throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)年份错误");
									}
							 }catch(Exception e){
								 throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)年份错误");
							 }
							 try{
								 int mon= Integer.parseInt(month);
								 if(!(mon>=1&&mon<=12)){
									 throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)月份错误");
								 }
							 }catch(Exception e){
								 throw new InValidDataException(tagId+"-"+tagValue+":值(MonthYear)月份错误");
							 }
							
						 }
					}else if(format.equals("UTCTimestamp")){
						if(tagValue.length()==17){
							String yearStr=tagValue.substring(0, 4);
							String monthStr=tagValue.substring(4, 6);
							String dayStr=tagValue.substring(6, 8);
							String seperator1=tagValue.substring(8, 9);
							String hourStr=tagValue.substring(9, 11);
							String seperaotr2=tagValue.substring(11, 12);
							String minuteStr=tagValue.substring(12, 14);
							String seperator3=tagValue.substring(14, 15);
							String secondStr=tagValue.substring(15, 17);
							if(!seperator1.equals("-")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)日期错误");
							}
							if(!seperaotr2.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)日期错误");
							}
							if(!seperator3.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)日期错误");
							}
							try{
								int year=Integer.parseInt(yearStr);
								if(year<0){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)年份错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)年份错误");
							}
							try{
								int month=Integer.parseInt(monthStr);
								if(!(month>=1&&month<=12)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)月份错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)月份错误");
							}
							try{
								int day=Integer.parseInt(dayStr);
								if(!(day>=1&&day<=31)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)日期错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)日期错误");
							}
							try{
								int hour=Integer.parseInt(hourStr);
								if(!(hour>=0&&hour<=23)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)小时错误");
							}
							try{
								int minute=Integer.parseInt(minuteStr);
								if(!(minute>=0&&minute<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)分钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)分钟错误");
							}
							try{
								int second=Integer.parseInt(secondStr);
								if(!(second>=0&&second<=60)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)秒钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)秒钟错误");
							}
							
						}else if(tagValue.length()==21){
							String yearStr=tagValue.substring(0, 4);
							String monthStr=tagValue.substring(4, 6);
							String dayStr=tagValue.substring(6, 8);
							String seperator1=tagValue.substring(8, 9);
							String hourStr=tagValue.substring(9, 11);
							String seperaotr2=tagValue.substring(11, 12);
							String minuteStr=tagValue.substring(12, 14);
							String seperator3=tagValue.substring(14, 15);
							String secondStr=tagValue.substring(15, 17);
							String seperater4=tagValue.substring(17, 18);
							String miliSecondStr=tagValue.substring(18, 21);
							if(!seperator1.equals("-")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)日期错误");
							}
							if(!seperaotr2.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)日期错误");
							}
							if(!seperator3.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)日期错误");
							}
							if(!seperater4.equals(".")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)日期错误");
							}
							try{
								int year=Integer.parseInt(yearStr);
								if(year<0){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)年份错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)年份错误");
							}
							try{
								int month=Integer.parseInt(monthStr);
								if(!(month>=1&&month<=12)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)月份错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)月份错误");
							}
							try{
								int day=Integer.parseInt(dayStr);
								if(!(day>=1&&day<=31)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)日期错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)日期错误");
							}
							try{
								int hour=Integer.parseInt(hourStr);
								if(!(hour>=0&&hour<=23)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)小时错误");
							}
							try{
								int minute=Integer.parseInt(minuteStr);
								if(!(minute>=0&&minute<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)分钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)分钟错误");
							}
							try{
								int second=Integer.parseInt(secondStr);
								if(!(second>=0&&second<=60)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)秒钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)秒钟错误");
							}
							try{
								int miliSecond=Integer.parseInt(miliSecondStr);
								if(miliSecond<0){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)毫秒错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)毫秒错误");
							}
							
						}else{
							throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimestamp)长度错误");
						}
					}else if(format.equals("UTCTimeOnly")){
						if(tagValue.length()==8){
							String hourStr=tagValue.substring(0, 2);
							String seperator1=tagValue.substring(2, 3);
							String minuteStr=tagValue.substring(3, 5);
							String seperator2=tagValue.substring(5, 6);
							String secondStr=tagValue.substring(6, 8);
							if(!seperator1.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)时间错误");
							}
							if(!seperator2.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)时间错误");
							}
							try{
								int hour=Integer.parseInt(hourStr);
								if(!(hour>=0&&hour<=23)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)小时错误");
							}
							try{
								int minute=Integer.parseInt(minuteStr);
								if(!(minute>=0&&minute<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)分钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)分钟错误");
							}
							try{
								int second=Integer.parseInt(secondStr);
								if(!(second>=0&&second<=60)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)秒钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)秒钟错误");
							}
						}else if(tagValue.length()==12){
							String hourStr=tagValue.substring(0, 2);
							String seperator1=tagValue.substring(2, 3);
							String minuteStr=tagValue.substring(3, 5);
							String seperator2=tagValue.substring(5, 6);
							String secondStr=tagValue.substring(6, 8);
							String seperator3=tagValue.substring(8,9);
							String milliSecondStr=tagValue.substring(9, 12);
							if(!seperator1.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)时间错误");
							}
							if(!seperator2.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)时间错误");
							}
							if(!seperator3.equals(".")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)时间错误");
							}
							try{
								int hour=Integer.parseInt(hourStr);
								if(!(hour>=0&&hour<=23)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)小时错误");
							}
							try{
								int minute=Integer.parseInt(minuteStr);
								if(!(minute>=0&&minute<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)分钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)分钟错误");
							}
							try{
								int second=Integer.parseInt(secondStr);
								if(!(second>=0&&second<=60)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)秒钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)秒钟错误");
							}
							try{
								int milliSecond=Integer.parseInt(milliSecondStr);
								if(milliSecond<0){
									throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)毫秒错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)毫秒错误");
							}
						}else{
							throw new InValidDataException(tagId+"-"+tagValue+":值(UTCTimeOnly)长度错误");
						}
					}else if(format.equals("UTCDateOnly")){
						if(tagValue.length()!=8){
							throw new InValidDataException(tagId+"-"+tagValue+":值(UTCDateOnly)长度错误");
						}
						String yearStr=tagValue.substring(0, 4);
						String monthStr=tagValue.substring(4, 6);
						String dayStr=tagValue.substring(6, 8);
						try{
							int year=Integer.parseInt(yearStr);
							if(year<0){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCDateOnly)年份错误");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(UTCDateOnly)年份错误");
						}
						try{
							int month=Integer.parseInt(monthStr);
							if(!(month>=1&&month<=12)){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCDateOnly)月份错误");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(UTCDateOnly)月份错误");
						}
						try{
							int day=Integer.parseInt(dayStr);
							if(!(day>=1&&day<=31)){
								throw new InValidDataException(tagId+"-"+tagValue+":值(UTCDateOnly)日期错误");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(UTCDateOnly)日期错误");
						}
					}else if(format.equals("LocalMktDate")){
						if(tagValue.length()!=8){
							throw new InValidDataException(tagId+"-"+tagValue+":值(LocalMktDate)长度错误");
						}
						String yearStr=tagValue.substring(0, 4);
						String monthStr=tagValue.substring(4, 6);
						String dayStr=tagValue.substring(6, 8);
						try{
							int year=Integer.parseInt(yearStr);
							if(year<0){
								throw new InValidDataException(tagId+"-"+tagValue+":值(LocalMktDate)年份错误");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(LocalMktDate)年份错误");
						}
						try{
							int month=Integer.parseInt(monthStr);
							if(!(month>=1&&month<=12)){
								throw new InValidDataException(tagId+"-"+tagValue+":值(LocalMktDate)月份错误");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(LocalMktDate)月份错误");
						}
						try{
							int day=Integer.parseInt(dayStr);
							if(!(day>=1&&day<=31)){
								throw new InValidDataException(tagId+"-"+tagValue+":值(LocalMktDate)日期错误");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(LocalMktDate)日期错误");
						}
					}else if(format.equals("TZTimeOnly")){
						if(tagValue.length()==6){
							String hourStr=tagValue.substring(0, 2);
							String seperate1=tagValue.substring(2, 3);
							String minuteStr=tagValue.substring(3, 5);
							String Z=tagValue.substring(5, 6);
							if(!seperate1.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
							}
							if(!Z.equals("Z")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)Z错误");
							}
							try{
								int hour=Integer.parseInt(hourStr);
								if(!(hour>=0&&hour<=23)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)小时错误");
							}
							try{
								int minute=Integer.parseInt(minuteStr);
								if(!(minute>=0&&minute<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)分钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)分钟错误");
							}
							
						}else if(tagValue.length()==9){
							String hourStr=tagValue.substring(0, 2);
							String seperate1=tagValue.substring(2, 3);
							String minuteStr=tagValue.substring(3, 5);
							String seperate2=tagValue.substring(5,6);
							String secondStr=tagValue.substring(6, 8);
							String Z=tagValue.substring(8, 9);
							if(!seperate1.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
							}
							if(!Z.equals("Z")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)Z错误");
							}
							if(!seperate2.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
							}
							try{
								int hour=Integer.parseInt(hourStr);
								if(!(hour>=0&&hour<=23)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)小时错误");
							}
							try{
								int minute=Integer.parseInt(minuteStr);
								if(!(minute>=0&&minute<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)分钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)分钟错误");
							}
							try{
								int second=Integer.parseInt(secondStr);
								if(!(second>=0&&second<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)秒钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)秒钟错误");
							}
						}else if(tagValue.length()==8){
							String hourStr=tagValue.substring(0, 2);
							String seperate1=tagValue.substring(2, 3);
							String minuteStr=tagValue.substring(3, 5);
							String seperate2=tagValue.substring(5,6);
							String offsetHourStr=tagValue.substring(6, 8);
							
							if(!seperate1.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
							}
							
							if(!(seperate2.equals("-")||seperate2.equals("+"))){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
							}
							try{
								int hour=Integer.parseInt(hourStr);
								if(!(hour>=0&&hour<=23)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)小时错误");
							}
							try{
								int minute=Integer.parseInt(minuteStr);
								if(!(minute>=0&&minute<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)分钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)分钟错误");
							}
							try{
								int offsetHour=Integer.parseInt(offsetHourStr);
								if(!(offsetHour>=1&&offsetHour<=12)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
							}
						}else if(tagValue.length()==11){
							String seperator1=tagValue.substring(5, 6);
							String hourStr=tagValue.substring(0,2);
							String seperator2=tagValue.substring(2, 3);
							String minuteStr=tagValue.substring(3, 5);
							if(!seperator2.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
							}
							try{
								int hour=Integer.parseInt(hourStr);
								if(!(hour>=0&&hour<=23)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)小时错误");
							}
							try{
								int minute=Integer.parseInt(minuteStr);
								if(!(minute>=0&&minute<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)分钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)分钟错误");
							}
							if(seperator1.equals(":")){
								String secondStr=tagValue.substring(6, 8);
								String seperator3=tagValue.substring(8,9);
								String offsetHourStr=tagValue.substring(9, 11);
								if(!(seperator3.equals("-")||seperator3.equals("+"))){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
								}
								try{
									int second=Integer.parseInt(secondStr);
									if(!(second>=0&&second<=59)){
										throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)秒钟错误");
									}
								}catch(Exception e){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)秒钟错误");
								}
								try{
									int offsetHour=Integer.parseInt(offsetHourStr);
									if(!(offsetHour>=1&&offsetHour<=12)){
										throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
									}
								}catch(Exception e){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
								}
							}else if(seperator1.equals("-")||seperator1.equals("+")){
								String offsetHourStr=tagValue.substring(6,8);
								String seperator3=tagValue.substring(8, 9);
								String offsetMinuteStr=tagValue.substring(9, 11);
								if(!seperator3.equals(":")){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
								}
								try{
									int offsetHour=Integer.parseInt(offsetHourStr);
									if(!(offsetHour>=1&&offsetHour<=12)){
										throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
									}
								}catch(Exception e){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
								}
								try{
									int offsetMinute=Integer.parseInt(offsetMinuteStr);
									if(!(offsetMinute>=0&&offsetMinute<=59)){
										throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移分钟错误");
									}
								}catch(Exception e){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移分钟错误");
								}
							}else{
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
							}
						}else if(tagValue.length()==14){
							String hourStr=tagValue.substring(0,2);
							String seperator1=tagValue.substring(2, 3);
							String minuteStr=tagValue.substring(3, 5);
							String seperator2=tagValue.substring(5, 6);
							String secondStr=tagValue.substring(6, 8);
							String seperator3=tagValue.substring(8,9);
							String offsetHourStr=tagValue.substring(9, 11);
							String seperator4=tagValue.substring(11, 12);
							String offsetMinuteStr=tagValue.substring(12, 14);
							if(!seperator1.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
							}
							if(!seperator2.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
							}
							if(!(seperator3.equals("+")||seperator3.equals("-"))){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
							}
							if(!seperator4.equals(":")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)时间错误");
							}
							try{
								int hour=Integer.parseInt(hourStr);
								if(!(hour>=0&&hour<=23)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)小时错误");
							}
							try{
								int minute=Integer.parseInt(minuteStr);
								if(!(minute>=0&&minute<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)分钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)分钟错误");
							}
							try{
								int second=Integer.parseInt(secondStr);
								if(!(second>=0&&second<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)秒钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)秒钟错误");
							}
							try{
								int offsetHour=Integer.parseInt(offsetHourStr);
								if(!(offsetHour>=1&&offsetHour<=12)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
							}
							try{
								int offsetMinute=Integer.parseInt(offsetMinuteStr);
								if(!(offsetMinute>=0&&offsetMinute<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移分钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移分钟错误");
							}
						}else {
							throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)长度错误");
						}
					}else if(format.equals("TZTimestamp")){
						if(tagValue.length()<15){
							throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)长度错误");
						}
						String yearStr=tagValue.substring(0, 4);
						String monthStr=tagValue.substring(4, 6);
						String dayStr=tagValue.substring(6, 8);
						String seperator1=tagValue.substring(8, 9);
						String hourStr=tagValue.substring(9, 11);
						String seperator2=tagValue.substring(11, 12);
						String minuteStr=tagValue.substring(12, 14);
						if(!seperator1.equals("-")){
							throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)日期错误");
						}
						if(!seperator2.equals(":")){
							throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)日期错误");
						}
						try{
							int year=Integer.parseInt(yearStr);
							if(year<0){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)年份错误");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)年份错误");
						}
						try{
							int month=Integer.parseInt(monthStr);
							if(!(month>=1&&month<=12)){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)月份错误");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)月份错误");
						}
						try{
							int day=Integer.parseInt(dayStr);
							if(!(day>=1&&day<=31)){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)日期错误");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)日期错误");
						}
						try{
							int hour=Integer.parseInt(hourStr);
							if(!(hour>=0&&hour<=23)){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)小时错误");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)小时错误");
						}
						try{
							int minute=Integer.parseInt(minuteStr);
							if(!(minute>=0&&minute<=59)){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)分钟错误");
							}
						}catch(Exception e){
							throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)分钟错误");
						}
						
						if(tagValue.length()==15){
							String Z=tagValue.substring(14, 15);
							if(!Z.equals("Z")){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)Z错误");
							}
						}else if(tagValue.length()==17){
							String seperator3=tagValue.substring(14, 15);
							String offsetHourStr=tagValue.substring(15, 17);
							if(!(seperator3.equals("-")||seperator3.equals("+"))){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)日期错误");
							}
							try{
								int offsetHour=Integer.parseInt(offsetHourStr);
								if(!(offsetHour>=1&&offsetHour<=12)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
							}
						}else if(tagValue.length()==20){
							String seperator3=tagValue.substring(14, 15);
							String offsetHourStr=tagValue.substring(15, 17);
							String seperator4=tagValue.substring(17, 18);
							String offsetMinuteStr=tagValue.substring(18, 20);
							if(!(seperator3.equals("-")||seperator3.equals("+"))){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)日期错误");
							}
							if(!(seperator4.equals("-")||seperator3.equals(":"))){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)日期错误");
							}
							try{
								int offsetHour=Integer.parseInt(offsetHourStr);
								if(!(offsetHour>=1&&offsetHour<=12)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移小时错误");
							}
							try{
								int offsetMinute=Integer.parseInt(offsetMinuteStr);
								if(!(offsetMinute>=0&&offsetMinute<=59)){
									throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移分钟错误");
								}
							}catch(Exception e){
								throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimeOnly)偏移分钟错误");
							}
						}else {
							throw new InValidDataException(tagId+"-"+tagValue+":值(TZTimestamp)长度错误");
						}
					}else if(format.equals("data")){
						//TODO
					}else if(format.equals("Pattern")){
						
					}else if(format.equals("Tenor")){
						
					}else if(format.equals("Reserved100Plus")){
						
					}else if(format.equals("Reserved1000Plus")){
						
					}else if(format.equals("Reserved4000Plus")){
						
					}else if(format.equals("XMLData")){
						
					}else if(format.equals("Language")){
						
					}else{
						throw new InValidDataException(tagId+"-"+tagValue+"-"+format+":format类型错误");
					}
				}
			}
			
		}
	}
	
	public String getTagId() {
		return tagId;
	}

	public void setTagId(String tagId) {
		this.tagId = tagId;
	}

	public String getTagValue() {
		return tagValue;
	}

	public void setTagValue(String tagValue) {
		this.tagValue = tagValue;
	}

	public String getFormat() {
		return format;
	}

	public void setFormat(String format) {
		this.format = format;
	}

	public boolean isMust() {
		return must;
	}

	public void setMust(boolean must) {
		this.must = must;
	}

}
package cs.mina.codec.msg;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import cs.mina.exception.InValidDataException;

/*
 *@author(huangxiaoping)
 *@date 2013-10-25
 */
public class LogonMsg extends BaseMsg {
	private Tag encryptMethod=new Tag("98","int",true);
	private Tag heartBtInt=new Tag("108","int",true);
	private Tag rawDataLength=new Tag("95","Length",false);
	private Tag rawData=new Tag("96","data",false);
	private Tag resetSeqNumFlag=new Tag("141","Boolean",false);
	private Tag nextExpectedMsgSeqNum=new Tag("789","SeqNum",true);
	private Tag maxMessageSize=new Tag("383","Length",false);
	private Tag msgTypeGrpTag=new MsgTypeGrpTag();
	private Tag testMessageIndicator=new Tag("464","Boolean",false);
	private Tag username=new Tag("553","String",false);
	private Tag password=new Tag("554","String",false);
	private Tag defaultApplVerID=new Tag("1137","String",true);
	private Tag text=new Tag("58","String",false);
	private Tag newPassword=new Tag("529","String",false);
	private Tag encryptedPasswordMethod=new Tag("1400","int",false);
	private Tag encryptedPasswordLen=new Tag("1401","Length",false);
	private Tag encryptedPassword=new Tag("1402","data",false);
	private Tag encryptedNewPasswordLen=new Tag("1403","Length",false);
	private Tag encryptedNewPassword=new Tag("1404","data",false);
	private Tag SessionStatus=new Tag("1409","int",false);
	private Tag defaultApplExtID=new Tag("1407","int",false);
	private Tag defaultCstmApplVerID=new Tag("1408","String",false);
	private Tag encodedTextLen=new Tag("354","Length",false);
	private Tag encodedText=new Tag("355","data",false);
	
	public LogonMsg(){
		this.getHeadEntity().getMsgType().setTagValue("A");
		tagIdsSet.add("98");
		tagIdsSet.add("108");
		tagIdsSet.add("95");
		tagIdsSet.add("96");
		tagIdsSet.add("141");
		tagIdsSet.add("789");
		tagIdsSet.add("383");
		tagIdsSet.add("464");
		tagIdsSet.add("553");
		tagIdsSet.add("554");
		tagIdsSet.add("1137");
		tagIdsSet.add("372");
		tagIdsSet.add("385");
		tagIdsSet.add("1130");
		tagIdsSet.add("1131");
		tagIdsSet.add("384");
		tagIdsSet.add("58");
		tagIdsSet.add("529");
		tagIdsSet.add("1400");
		tagIdsSet.add("1401");
		tagIdsSet.add("1402");
		tagIdsSet.add("1403");
		tagIdsSet.add("1404");
		tagIdsSet.add("1409");
		tagIdsSet.add("1407");
		tagIdsSet.add("1408");
		tagIdsSet.add("354");
		tagIdsSet.add("355");
		this.bodyEntity.getBodyTagList().add(encryptMethod);
		this.bodyEntity.getBodyTagList().add(heartBtInt);
		this.bodyEntity.getBodyTagList().add(rawDataLength);
		this.bodyEntity.getBodyTagList().add(rawData);
		this.bodyEntity.getBodyTagList().add(resetSeqNumFlag);
		this.bodyEntity.getBodyTagList().add(nextExpectedMsgSeqNum);
		this.bodyEntity.getBodyTagList().add(maxMessageSize);
		this.bodyEntity.getBodyTagList().add(msgTypeGrpTag);
		this.bodyEntity.getBodyTagList().add(testMessageIndicator);
		this.bodyEntity.getBodyTagList().add(username);
		this.bodyEntity.getBodyTagList().add(password);
		this.bodyEntity.getBodyTagList().add(defaultApplVerID);
		this.bodyEntity.getBodyTagList().add(text);
		this.bodyEntity.getBodyTagList().add(newPassword);
		this.bodyEntity.getBodyTagList().add(encryptedPasswordMethod);
		this.bodyEntity.getBodyTagList().add(encryptedPasswordLen);
		this.bodyEntity.getBodyTagList().add(encryptedPassword);
		this.bodyEntity.getBodyTagList().add(encryptedNewPasswordLen);
		this.bodyEntity.getBodyTagList().add(encryptedNewPassword);
		this.bodyEntity.getBodyTagList().add(SessionStatus);
		this.bodyEntity.getBodyTagList().add(defaultApplExtID);
		this.bodyEntity.getBodyTagList().add(defaultCstmApplVerID);
		this.bodyEntity.getBodyTagList().add(encodedTextLen);
		this.bodyEntity.getBodyTagList().add(encodedText);
	}
	
	private Set<String> tagIdsSet=new HashSet<String>();
	
	@Override
	public void validate() {
		this.headEntity.validate();
		List<Tag> bodyTagList=this.bodyEntity.getBodyTagList();
		for(int i=0;i<bodyTagList.size();i++){
			bodyTagList.get(i).validate();
		}
		this.tailerEntity.validate();
		int encryptMethodType= Integer.parseInt(encryptMethod.getTagValue());
		if(encryptMethodType<0||encryptMethodType>6){
			throw new InValidDataException("encryptMethod错误");
		}
		if(!MsgUtil.applVerID.contains(defaultApplVerID.getTagValue())){
			throw new InValidDataException("defaultApplVerID错误");
		}
		if(SessionStatus.getTagValue()!=null){
			if(!MsgUtil.sessionStatus.contains(SessionStatus.getTagValue())){
				throw new InValidDataException("sessionStatus错误");
			}
		}
		

	}

	public Tag getEncryptMethod() {
		return encryptMethod;
	}

	public void setEncryptMethod(Tag encryptMethod) {
		this.encryptMethod = encryptMethod;
	}

	public Tag getHeartBtInt() {
		return heartBtInt;
	}

	public void setHeartBtInt(Tag heartBtInt) {
		this.heartBtInt = heartBtInt;
	}

	public Tag getRawDataLength() {
		return rawDataLength;
	}

	public void setRawDataLength(Tag rawDataLength) {
		this.rawDataLength = rawDataLength;
	}

	public Tag getRawData() {
		return rawData;
	}

	public void setRawData(Tag rawData) {
		this.rawData = rawData;
	}

	public Tag getResetSeqNumFlag() {
		return resetSeqNumFlag;
	}

	public void setResetSeqNumFlag(Tag resetSeqNumFlag) {
		this.resetSeqNumFlag = resetSeqNumFlag;
	}

	public Tag getNextExpectedMsgSeqNum() {
		return nextExpectedMsgSeqNum;
	}

	public void setNextExpectedMsgSeqNum(Tag nextExpectedMsgSeqNum) {
		this.nextExpectedMsgSeqNum = nextExpectedMsgSeqNum;
	}

	public Tag getMaxMessageSize() {
		return maxMessageSize;
	}

	public void setMaxMessageSize(Tag maxMessageSize) {
		this.maxMessageSize = maxMessageSize;
	}

	public Tag getMsgTypeGrpTag() {
		return msgTypeGrpTag;
	}

	public void setMsgTypeGrpTag(Tag msgTypeGrpTag) {
		this.msgTypeGrpTag = msgTypeGrpTag;
	}

	public Tag getTestMessageIndicator() {
		return testMessageIndicator;
	}

	public void setTestMessageIndicator(Tag testMessageIndicator) {
		this.testMessageIndicator = testMessageIndicator;
	}

	public Tag getUsername() {
		return username;
	}

	public void setUsername(Tag username) {
		this.username = username;
	}

	public Tag getPassword() {
		return password;
	}

	public void setPassword(Tag password) {
		this.password = password;
	}

	public Tag getDefaultApplVerID() {
		return defaultApplVerID;
	}

	public void setDefaultApplVerID(Tag defaultApplVerID) {
		this.defaultApplVerID = defaultApplVerID;
	}

	@Override
	public void decodeBody() {
		Set<String> already=new HashSet<String>();
		String[] bodyItems=this.body.split(BaseMsg.SOH);
		for(int i=0;i<bodyItems.length;i++){
			String[]tagItems=bodyItems[i].split("=");
			if(tagItems.length!=2){
				throw new InValidDataException("消息格式错误");
			}
			String tagId=tagItems[0];
			if(already.contains(tagId)){
				throw new InValidDataException("消息格式错误");
			}
			already.add(tagId);
			if(this.tagIdsSet.contains(tagId)){
				if(tagId.equals("384")){
					int skip=decodeGroup384(this.body);
					i=i+skip-1;
				}else{
					List<Tag> tagList=this.bodyEntity.getBodyTagList();
					for(int j=0;j<tagList.size();j++){
						Tag tag=tagList.get(j);
						if(tag.getTagId().equals(tagId)){
							tag.setTagValue(tagItems[1]);
							break;
						}
					}
				}
			}else{
				throw new InValidDataException("消息格式错误,"+tagId+"不在消息体内");
			}
		}
		
	}
	
	private int decodeGroup384(String body){
		int index=body.indexOf("384=");
		String rest=body.substring(index);
		String[]tagItems=rest.split(BaseMsg.SOH);
		String[] numTagItems=tagItems[0].split("=");
		if(numTagItems.length!=2){
			throw new InValidDataException("消息格式错误");
		}
		if(!"384".equals(numTagItems[0])){
			throw new InValidDataException("消息格式错误");
		}
		int num=Integer.parseInt(numTagItems[1]);
		int count=1;
		int whileCount=0;
		((MsgTypeGrpTag)this.msgTypeGrpTag).setTagValue(num+"");
		boolean end=false;
		for(int i=0;i<num;i++){
			if(end){
				if(i!=num){
					throw new InValidDataException("消息格式错误");
				}else{
					break;
				}
			}
			MsgTypeGrp msgTypeGrp=new MsgTypeGrp();
			((MsgTypeGrpTag)this.msgTypeGrpTag).getChildren().add(msgTypeGrp);
			while(true){
				if(whileCount>=4){
					whileCount=0;
					break;
				}
				String[] tagIt=tagItems[count].split("=");
				if(tagIt.length!=2){
					throw new InValidDataException("消息格式错误");
				}
				if(whileCount==0){
					if(!MsgTypeGrpTag.first.equals(tagIt[0])){
						throw new InValidDataException("消息格式错误");
					}
				}
				
				if(MsgTypeGrp.tagIdsSet.contains(tagIt[0])){
					List<Tag> tagList=msgTypeGrp.getTagList();
					for(int j=0;j<tagList.size();j++){
						Tag groupTag=tagList.get(j);
						if(groupTag.getTagId().equals(tagIt[0])){
							groupTag.setTagValue(tagIt[1]);
							break;
						} 
					}
					if(tagItems.length>count+1){
						String[] nextTagIt=tagItems[count+1].split("=");
						if(nextTagIt.length!=2){
							throw new InValidDataException("消息格式错误");
						}
						if(MsgTypeGrpTag.first.equals(nextTagIt[0])){
							whileCount=0;
							count++;
							break;
						}
					}
					
					count++;
					whileCount++;
					
				}else{
					end=true;
					break;
				}
				
			}
			
		}
		
		return count;
	}

	public Set<String> getTagIdsSet() {
		return tagIdsSet;
	}

	public void setTagIdsSet(Set<String> tagIdsSet) {
		this.tagIdsSet = tagIdsSet;
	}

	public Tag getText() {
		return text;
	}

	public void setText(Tag text) {
		this.text = text;
	}

	public Tag getNewPassword() {
		return newPassword;
	}

	public void setNewPassword(Tag newPassword) {
		this.newPassword = newPassword;
	}

	public Tag getEncryptedPasswordMethod() {
		return encryptedPasswordMethod;
	}

	public void setEncryptedPasswordMethod(Tag encryptedPasswordMethod) {
		this.encryptedPasswordMethod = encryptedPasswordMethod;
	}

	public Tag getEncryptedPasswordLen() {
		return encryptedPasswordLen;
	}

	public void setEncryptedPasswordLen(Tag encryptedPasswordLen) {
		this.encryptedPasswordLen = encryptedPasswordLen;
	}

	public Tag getEncryptedPassword() {
		return encryptedPassword;
	}

	public void setEncryptedPassword(Tag encryptedPassword) {
		this.encryptedPassword = encryptedPassword;
	}

	public Tag getEncryptedNewPasswordLen() {
		return encryptedNewPasswordLen;
	}

	public void setEncryptedNewPasswordLen(Tag encryptedNewPasswordLen) {
		this.encryptedNewPasswordLen = encryptedNewPasswordLen;
	}

	public Tag getEncryptedNewPassword() {
		return encryptedNewPassword;
	}

	public void setEncryptedNewPassword(Tag encryptedNewPassword) {
		this.encryptedNewPassword = encryptedNewPassword;
	}

	public Tag getSessionStatus() {
		return SessionStatus;
	}

	public void setSessionStatus(Tag sessionStatus) {
		SessionStatus = sessionStatus;
	}

	public Tag getDefaultApplExtID() {
		return defaultApplExtID;
	}

	public void setDefaultApplExtID(Tag defaultApplExtID) {
		this.defaultApplExtID = defaultApplExtID;
	}

	public Tag getDefaultCstmApplVerID() {
		return defaultCstmApplVerID;
	}

	public void setDefaultCstmApplVerID(Tag defaultCstmApplVerID) {
		this.defaultCstmApplVerID = defaultCstmApplVerID;
	}

	public Tag getEncodedTextLen() {
		return encodedTextLen;
	}

	public void setEncodedTextLen(Tag encodedTextLen) {
		this.encodedTextLen = encodedTextLen;
	}

	public Tag getEncodedText() {
		return encodedText;
	}

	public void setEncodedText(Tag encodedText) {
		this.encodedText = encodedText;
	}

}



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:602123次
    • 积分:8661
    • 等级:
    • 排名:第2207名
    • 原创:289篇
    • 转载:334篇
    • 译文:1篇
    • 评论:122条
    博客专栏
    文章分类
    最新评论