码迷,mamicode.com
首页 > 编程语言 > 详细

去哪网实习总结:递归构建“流程执行顺序”的XML文件(JavaWeb)

时间:2015-08-18 11:52:29      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:xml   java   流程执行文件生成   

本来是以做数据挖掘的目的进去哪网的,结构却成了系统开发。。。

不过还是比较认真的做了三个月,老师很认同我的工作态度和成果。。。

实习马上就要结束了,总结一下几点之前没有注意过的变成习惯和问题,分享给大家。


同时打个广告:去哪网内审部招JavaWeb开发实习生,时间非常自由,每周一天、周六周日甚至都可以,时间充裕的小伙伴给我留言啊,挣个零花钱,还能长点经验。。。。(保研的、想工作的大四狗最合适不过了。。。)



map的结构为(thisProcessID, thisProcessType;nextProcessID1,nextProcessType1;...;nextProcessIDk,nextProcessTypek;),如果processType部位start、end、split、join,则type和id相同。。。。


跑一下代码就知道是怎么回事了,直接上代码:

<span style="white-space:pre">	</span>public String XMLhead = "";	
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public void formXMLfile(Map nodeMap){
		/*穿行没问题
		nodeMap.put("1", "start;2,2");
		nodeMap.put("2", "2;3,3");
		nodeMap.put("3", "3;4,end");
		nodeMap.put("4", "end");
		*/
		/* 简单并行没问题,但需要去重处理
		nodeMap.put("1", "start;2,split");
		nodeMap.put("2", "split;3,3;4,4");
		nodeMap.put("3", "3;5,join");
		nodeMap.put("4", "4;5,join");
		nodeMap.put("5", "join;6,end");
		nodeMap.put("6", "end");
		*/
		
		nodeMap.put("1", "start;2,split");
		nodeMap.put("2", "split;3,3;4,split;5,5");
		nodeMap.put("3", "3;6,6");
		nodeMap.put("4", "split;7,7;8,8");
		nodeMap.put("5", "5;9,join");
		nodeMap.put("6", "6;9,join");
		nodeMap.put("7", "7;10,join");
		nodeMap.put("8", "8;10,join");
		nodeMap.put("9", "join;11,end");
		nodeMap.put("10", "join;9,join");
		nodeMap.put("11", "end");
		/*简单并行没问题,但需要去重处理
		nodeMap.put("1", "start;2,split");
		nodeMap.put("2", "split;3,3;4,4");
		nodeMap.put("3", "3;5,join");
		nodeMap.put("4", "4;5,join");
		nodeMap.put("5", "join;6,split");
		nodeMap.put("6", "split;7,7;8,8");
		nodeMap.put("7", "7;9,join");
		nodeMap.put("8", "8;9,join");
		nodeMap.put("9", "join;10,end");
		nodeMap.put("10", "end");
		*/
		XMLhead = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+"\n";
		XMLhead += "<definitions xmlns=\"http://www.omg.org/spec/BPMN/20100524/MODEL\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:activiti=\"http://activiti.org/bpmn\" xmlns:bpmndi=\"http://www.omg.org/spec/BPMN/20100524/DI\" xmlns:omgdc=\"http://www.omg.org/spec/DD/20100524/DC\" xmlns:omgdi=\"http://www.omg.org/spec/DD/20100524/DI\" typeLanguage=\"http://www.w3.org/2001/XMLSchema\" expressionLanguage=\"http://www.w3.org/1999/XPath\" targetNamespace=\"http://www.activiti.org/test\">"+"\n";
		String XMLtail = "</definitions>";
		XMLhead += "<process id=\"processID\" name=\"processNAME\" isExecutable=\"true\">"+"\n";
		XMLtail = "</process>\n"+XMLtail;
		
		String this_id = "1";//start
		String this_type = "start";
		RECUformXMLfile(nodeMap, this_id, this_type);
		String XMLfile = XMLhead + XMLtail;
		
		//去重
		String[] temp = XMLfile.split("\n");
		List<String> list = new LinkedList<String>();  
        for(int i = 0; i < temp.length; i++) {  
            if(!list.contains(temp[i])) {
                list.add(temp[i]);//改为写文件
                System.out.println(temp[i]);
            }
        }
	}
	
	@SuppressWarnings("rawtypes")
	public void RECUformXMLfile(Map nodeMap, String this_id, String this_type){
		if(this_type.equals("start")){//start
			String[] toNodes = nodeMap.get(this_id).toString().split(";");
			String next_id = toNodes[1].split(",")[0];
			String next_type = toNodes[1].split(",")[1];
			if(next_type.equals("split")){
				XMLhead += "<startEvent id=\"startevent1\" name=\"Start\"></startEvent>"+"\n";
				XMLhead += "<sequenceFlow id=\"flow_"+this_id+"\" sourceRef=\"startevent1\" targetRef=\"gateway_"+next_id+"\"></sequenceFlow>"+"\n";
				RECUformXMLfile(nodeMap, next_id, next_type);
			} else if(next_type.equals("end_start_join")){//不可能
				
			} else{//task
				XMLhead += "<startEvent id=\"startevent1\" name=\"Start\"></startEvent>"+"\n";
				XMLhead += "<sequenceFlow id=\"flow_"+this_id+"\" sourceRef=\"startevent1\" targetRef=\"task_"+next_id+"\"></sequenceFlow>"+"\n";
				RECUformXMLfile(nodeMap, next_id, next_type);
			}
		} else if(this_type.equals("split")){//split
			XMLhead += "<parallelGateway id=\"gateway_"+this_id+"\" name=\"Parallel Gateway\"></parallelGateway>"+"\n";
			String[] toNodes = nodeMap.get(this_id).toString().split(";");
			for(int i=1;i<toNodes.length;i++){
				String next_id = toNodes[i].split(",")[0];
				String next_type = toNodes[i].split(",")[1];
				if(next_type.equals("split")){
					XMLhead += "<sequenceFlow id=\"flow_"+this_id+"\" sourceRef=\"gateway_"+this_id+"\" targetRef=\"gateway_"+next_id+"\"></sequenceFlow>"+"\n";
					RECUformXMLfile(nodeMap, next_id, next_type);
				} else if(next_type.equals("end_start_join")){//不可能
					
				} else{//task
					XMLhead += "<sequenceFlow id=\"flow_"+this_id+"\" sourceRef=\"gateway_"+this_id+"\" targetRef=\"task_"+next_id+"\"></sequenceFlow>"+"\n";
					RECUformXMLfile(nodeMap, next_id, next_type);
				}
			}
		} else if(this_type.equals("end")){//不会出现,接下来的两个判断分支可能的next_type==end时,都已经处理
			
		} else if(this_type.equals("join")){//join,join和task,两者处理逻辑一样,除了一个用gateWay,一个用task
			String[] toNodes = nodeMap.get(this_id).toString().split(";");
			String next_id = toNodes[1].split(",")[0];
			String next_type = toNodes[1].split(",")[1];
			if(next_type.equals("end")){
				XMLhead += "<parallelGateway id=\"gateway_"+this_id+"\" name=\"Parallel Gateway\"></parallelGateway>"+"\n";
				XMLhead += "<sequenceFlow id=\"flow_"+this_id+"\" sourceRef=\"gateway_"+this_id+"\" targetRef=\"endevent1\"></sequenceFlow>"+"\n";
				XMLhead += "<endEvent id=\"endevent1\" name=\"End\"></endEvent>"+"\n";
				return ;
			} else if(next_type.equals("start")){//不可能
				
			} else if(next_type.equals("split")){
				XMLhead += "<parallelGateway id=\"gateway_"+this_id+"\" name=\"Parallel Gateway\"></parallelGateway>"+"\n";
				XMLhead += "<sequenceFlow id=\"flow_"+this_id+"\" sourceRef=\"gateway_"+this_id+"\" targetRef=\"gateway_"+next_id+"\"></sequenceFlow>"+"\n";
				RECUformXMLfile(nodeMap, next_id, next_type);
			} else if(next_type.equals("join")){
				XMLhead += "<parallelGateway id=\"gateway_"+this_id+"\" name=\"Parallel Gateway\"></parallelGateway>"+"\n";
				XMLhead += "<sequenceFlow id=\"flow_"+this_id+"\" sourceRef=\"gateway_"+this_id+"\" targetRef=\"gateway_"+next_id+"\"></sequenceFlow>"+"\n";
				return ;
			} else{//task
				XMLhead += "<parallelGateway id=\"gateway_"+this_id+"\" name=\"Parallel Gateway\"></parallelGateway>"+"\n";
				XMLhead += "<sequenceFlow id=\"flow_"+this_id+"\" sourceRef=\"gateway_"+this_id+"\" targetRef=\"task_"+next_id+"\"></sequenceFlow>"+"\n";
				RECUformXMLfile(nodeMap, next_id, next_type);
			}
		} else{//task,task和join,两者处理逻辑一样,除了一个用gateWay,一个用task
			String[] toNodes = nodeMap.get(this_id).toString().split(";");
			String next_id = toNodes[1].split(",")[0];
			String next_type = toNodes[1].split(",")[1];
			if(next_type.equals("end")){
				XMLhead += "<userTask id=\"task_"+this_id+"\" name=\""+this_id+"\"></userTask>"+"\n";
				XMLhead += "<sequenceFlow id=\"flow_"+this_id+"\" sourceRef=\"task_"+this_id+"\" targetRef=\"endevent1\"></sequenceFlow>"+"\n";
				XMLhead += "<endEvent id=\"endevent1\" name=\"End\"></endEvent>"+"\n";
				return ;
			} else if(next_type.equals("start")){//不可能
				
			} else if(next_type.equals("split")){
				XMLhead += "<userTask id=\"task_"+this_id+"\" name=\""+this_id+"\"></userTask>"+"\n";
				XMLhead += "<sequenceFlow id=\"flow_"+this_id+"\" sourceRef=\"task_"+this_id+"\" targetRef=\"gateway_"+next_id+"\"></sequenceFlow>"+"\n";
				RECUformXMLfile(nodeMap, next_id, next_type);
			} else if(next_type.equals("join")){
				XMLhead += "<userTask id=\"task_"+this_id+"\" name=\""+this_id+"\"></userTask>"+"\n";
				XMLhead += "<sequenceFlow id=\"flow_"+this_id+"\" sourceRef=\"task_"+this_id+"\" targetRef=\"gateway_"+next_id+"\"></sequenceFlow>"+"\n";
				//return ;
				RECUformXMLfile(nodeMap, next_id, next_type);
			} else{//task
				XMLhead += "<userTask id=\"task_"+this_id+"\" name=\""+this_id+"\"></userTask>"+"\n";
				XMLhead += "<sequenceFlow id=\"flow_"+this_id+"\" sourceRef=\"task_"+this_id+"\" targetRef=\"task_"+next_id+"\"></sequenceFlow>"+"\n";
				RECUformXMLfile(nodeMap, next_id, next_type);
			}
		}
	}


版权声明:本文为博主原创文章,未经博主允许不得转载。

去哪网实习总结:递归构建“流程执行顺序”的XML文件(JavaWeb)

标签:xml   java   流程执行文件生成   

原文地址:http://blog.csdn.net/mmc2015/article/details/47749645

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!