package com.anji.xwl.pojo;

import java.io.File;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONArray;
import org.json.JSONObject;

import com.wb.common.Var;
import com.wb.util.DbUtil;
import com.wb.util.JsonUtil;


public class XwlMain {
	public  static void  getJson( HttpServletRequest request, HttpServletResponse response)
	{
	  String path=	request.getServletContext().getRealPath("");
	  System.out.println("path===="+path);
	   File file = new File(path);
		String filePath = file.getParent();
		
		System.out.println("-------------开始加载配置信息------------");
		
		//Conf conf = XmlUtil.getConf(path+"/conf/conf.xml");
		Conf conf = new Conf();
		String str=request.getParameter("TABLE_NAME");
		String table, jndi=request.getParameter("jndi");;
		if (str.indexOf(".")>0) {
			table=str.split("\\.")[1];
		}else
		{
			 table=str;

		}
		if (jndi==null)
		jndi="default";
		conf.setTableName(table);
		JSONObject jo=null;
		try {
			jo = JsonUtil.readObject(Var.file);
		} catch (IOException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}
		
	
		jo = (JSONObject) jo.get("sys");
		jo = (JSONObject) jo.get("ide");
		JSONArray js=(JSONArray)jo.get("syncPath");
		
	
		
		conf.setModelpath(path+"//model//");
		String proPath = request.getSession().getServletContext().getRealPath("/");
		conf.setTopath(js.get(0)+"//wb//modules");
		MackMainPage m = new MackMainPage();
	//	String jndi=(String) request.getAttribute("sys.jndi");
		try {
			
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

    
		try {

			m.initDB(DbUtil.getConnection(jndi.toLowerCase()));
			conf.setJndi(jndi.toLowerCase());
			m.getModel(conf);
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("-------------代码生成结束------------");	
	}
	
	

	public static void main(String[] args)
	{
		//new XwlMain().init();
	}
}
