⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logimportimpl.java

📁 具备多表组合查询组件功能。通过将表字段与表间关系映射到对象关系及属性
💻 JAVA
字号:
package cn.edu.buaa.ieguam.logmanage;

import cn.edu.buaa.ieguam.logmanage.ConfigImportLog;
import cn.edu.buaa.ieguam.logmanage.LogTreeImpl;
import cn.edu.buaa.ieguam.logmanage.MBean;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Stack;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.SAXException;

/**
 * 提供日志导入功能
 * @author tongxiaodong
 * Creation time:Apr 23, 2007 10:32:45 PM
 */

public class LogImportImpl {

	private LogTreeImpl lti = null;
	
	private boolean isStart = false;//是否在logDoc中
	private boolean inItem = false;//是否在Item中
	private boolean inMBean = false;//是否在MBean中
	private boolean isPojoCol = false;//是否为Pojo属性名
	
	private Map valueMap = null;
	private MBean curMBean = null;
	
	public LogImportImpl()
	{
		this.lti = new LogTreeImpl("import");
		this.valueMap = new HashMap();
	}
	
	/**
	 * Getting and setting methods
	 */
	public LogTreeImpl getLogTreeImpl()
	{
		return this.lti;
	}
	public void setLogTreeImpl(LogTreeImpl lti)
	{
		this.lti = lti;
	}
	
	public boolean getIsStart()
	{
		return this.isStart;
	}
	public void setIsStart(boolean isStart)
	{
		this.isStart = isStart;
	}
	public boolean getInItem()
	{
		return this.inItem;
	}
	public void setInItem(boolean inItem)
	{
		this.inItem = inItem;
	}
	
	public boolean getInMBean()
	{
		return this.inMBean;
	}
	public void setInMBean(boolean inMBean)
	{
		this.inMBean = inMBean;
	}
	
	public boolean getIsPojoCol()
	{
		return this.isPojoCol;
	}
	public void setIsPojoCol(boolean isPojoCol)
	{
		this.isPojoCol = isPojoCol;
	}
	
	

	/**
	 * 设置并加载当前分析的MBean节点
	 * @param pojoName
	 */
	public void settingCurMBean(String pojoName)
	{
		this.curMBean = this.getLogTreeImpl().getMBean(pojoName);
	}
	
	/**
	 * 导入元素与元素内容的处理
	 * @param eleName
	 * @param value
	 * @throws Exception 
	 */
	public void importImpl(String eleName,String value) throws Exception
	{
		
		Iterator keyIter = null;
		String key = null;
		String keyValue = null;
		
	/**
	 * 刚提取完一条log备份记录,形成MBeanTree,并进行导入处理
	 */
		if(this.isStart==true && this.inItem==false)
		{
			
			this.getLogTreeImpl().initImportMBean();
			this.getLogTreeImpl().createNewImportTree(this.getLogTreeImpl().createOriginTree());//构造导入节点的树结构
			this.getLogTreeImpl().getLogTree().deepInOrderTraverse();//中序遍历LogTree
		}
	
		if(this.isStart==true && this.inItem==true && this.inMBean==false)
		{
			
			//将valueMap的值赋给MBean
			if(this.curMBean!=null && this.valueMap.isEmpty()==false)
			{
				this.curMBean.setDegree("work");//设置当前MBean的工作状态
				
				keyIter = this.valueMap.keySet().iterator();
				while(keyIter.hasNext())
				{
					key = (String)keyIter.next();
					keyValue = (String)this.valueMap.get(key);
					/******* test *********/
					
				    //System.out.print("test1: ");
					//System.out.println("importImpl");			
					//System.out.println("pojoName: "+this.curMBean.getPojoName()+"; key: "+key+"; value: "+keyValue);	       
			        /************************/
					this.curMBean.getPojo().setColValue(key,keyValue);					
					
				}											
			}
			
			//将MBean映射和valueMap置空,为下一个MBean设置做准备。
			this.curMBean = null;
			this.valueMap.clear();
							
		}
		if(this.isStart==true && this.inItem==true && this.inMBean==true && this.isPojoCol==false)
		{
            //设置属性值,放入valueMap中
			this.valueMap.put(eleName,value);
		}
			
	}
	
	/**
	 * 用于单元测试的函数
	 */
	public void test() 
	{
	  try
	  {
			  
		  //this.getLogTreeImpl().misLog.getPojo().getColValue("id").toString();
		 	  
	  }catch(Exception e)
	  {
		  e.getStackTrace();
		  System.out.println("wrong in test()!!");
	  }
	}
	
	/**
	 * @param args
	 * @throws ParserConfigurationException 
	 * @throws SAXException 
	 * @throws IOException 
	 */
	public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException  
	{
		// TODO Auto-generated method stub
		String filename = null;
		filename="D:/testLog.xml";
	
		SAXParserFactory spf = SAXParserFactory.newInstance();
		spf.setNamespaceAware(false);
		spf.setValidating(false);
	
		SAXParser saxParser=null;
		
        //创建一个解析器SAXParser对象
		saxParser = spf.newSAXParser(); 
		
		saxParser.parse(new File(filename),new ConfigImportLog());
		

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -