/*** 根据物理实体文件在开发工程中创建实体文件*/@Overridepublic void getEntityFilesByErFile(IFile erfile, IFolder entityFolder) {if (null == erfile || null == entityFolder) {ERDiagramActivator.showErrorDialog("ER图表为空!");return;}// 通过file反编译获取diagram,再创建实体,通过流写入文件,到folder路径下File tradeFile = erfile.getLocation().toFile(); // ifile转换成filebyte[] fileByteArray = this.File2ByteArray(tradeFile);// 文件转成二进制数据if (null == fileByteArray) {return;}// 将二进制数组转换成对象ERDiagram resultDiagram = null;try {resultDiagram = (ERDiagram) this.restore(fileByteArray);} catch (ClassNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}// 设置er图中所有表格转换成实体对象for (final ERTable table : resultDiagram.getDiagramContents().getContents().getTableSet().getList()) {final String className = table.getPhysicalName();Document document = DocumentHelper.createDocument();Element root = document.addElement("entity");createElement(root, "schema", "");createElement(root, "name", className);createElement(root, "objName", className);createElement(root, "strategy", "");createColumns(root, table);System.out.println(XmlUtils.formatXML(document.asXML(), true));InputStream in = EntityUtils.parseEntity(document.asXML());String fileName = className + "." + Constants.FILE_EXT_EIX;IFile ifile = entityFolder.getFile(fileName);// 設置實體對象字段值try {if (!ifile.exists()) {ifile.create(null, true, null);}ifile.setContents(in, IFile.FORCE, null);// entityFolder.copy((IPath) new Path(fileName), IFile.FORCE,// null);} catch (CoreException e) {e.printStackTrace();}}}// 将文件转换成byte数组public byte[] File2ByteArray(File tradeFile) {byte[] buffer = null;try {FileInputStream fis = new FileInputStream(tradeFile);// 文件读取成流ByteArrayOutputStream bos = new ByteArrayOutputStream();byte[] b = new byte[(int) tradeFile.length()];// 文件大小长度的数组if(b.length == 0){ERDiagramActivator.showErrorDialog("ER文件为空!");throw new IOException("ER文件为空!");}int n;// 文件没有读取完,一直读取文件,并且写入到数组while ((n = fis.read(b)) != -1) {bos.write(b, 0, n);}fis.close();bos.close();buffer = bos.toByteArray();} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}return buffer;}// 把二进制数组的数据转回对象public Object restore(byte[] b) throws ClassNotFoundException, IOException {if(null == b)return null;ByteArrayInputStream bis = null;ObjectInputStream ois = null;try {// 读取二进制数据并转换成对象bis = new ByteArrayInputStream(b);ois = new ObjectInputStream(bis);return ois.readObject();} finally {if (ois != null) {ois.close();}if (bis != null) {bis.close();}}}// 創建元素節點private Element createElement(Element element, String tag, String value) {Element e = element.addElement(tag);e.addText(value);return e;}// 得到当前sql类型数据的规范名称private String getFullClassName(final SqlType type) {if (type == null) {return "";}final Class clazz = type.getJavaClass();final String name = clazz.getCanonicalName();return name;}// 创建表格中列数据private void createColumns(Element root, ERTable table) {Element columns = createElement(root, "columns", "");List<NormalColumn> columnsList = table.getExpandedColumns();String length = "";String type = "";for (NormalColumn column : columnsList) {Element columnEle = createElement(columns, "column", "");createElement(columnEle, "primaryKey", BooleanUtils.toStringTrueFalse(column.isPrimaryKey()).toLowerCase());createElement(columnEle, "physicalName", column.getPhysicalName());createElement(columnEle, "logicName", column.getLogicalName());type = ObjectUtils.toString(column.getType());if (column.getWord() != null&& column.getWord().getTypeData() != null&& column.getWord().getTypeData().getLength() != null) {length = Integer.toString(column.getWord().getTypeData().getLength());}type = type.replace("(n)", "(" + length + ")");createElement(columnEle, "type", type);createElement(columnEle, "length", length);createElement(columnEle, "notNull",BooleanUtils.toStringTrueFalse(column.isNotNull()).toLowerCase());createElement(columnEle, "mapType",getFullClassName(column.getType()));createElement(columnEle, "comment", column.getDescription());}}

转载于:https://www.cnblogs.com/Soy-technology/p/11429850.html

IFile、File与实体转换相关推荐

  1. java 实体属性个数_?Java中比较实用实体转换工具介绍

    ​Java中比较实用实体转换工具介绍 文中源码地址 大家一般编码过程中,经常会遇到DO对象转化为DTO对象,对象和对象之间转换一般需要用到转换工具,毕竟使用getter/setter太过麻烦 DO:D ...

  2. 多边形网格到B-Rep实体转换:算法详细信息和C ++代码示例

    Using a triangulation algorithm (known as tessellation) on a model's boundary representation is rela ...

  3. html实体转换成xa0,关于javascript:反应道具:在JSX动态内容中使用HTML实体?

    我有一个React组件,我想为其道具分配一个包含JavaScript变量和HTML实体的字符串. 我尝试过的一些方法导致HTML实体被转义.例如,从字面上呈现为" "而不是&quo ...

  4. java gson 工具类_GSON 实体 转换工具类

    /** * Gson转换工具类 */ public class GsonUtils { /** * @param jsonString *            json字符串 * @param cl ...

  5. php将html实体转换成字符串

    定义和用法 htmlspecialchars_decode() 函数把一些预定义的 HTML 实体转换为字符. 会被解码的 HTML 实体是: & 成为 & (和号) " 成 ...

  6. html实体转换,字符串html实体转换

    原字符串:http://www.qdta.cn/xxw/xxInfo.asp?xxlx=旅游热讯&id=12939 想要转换成:http://www.qdta.cn/xxw/xxInfo.as ...

  7. fastjson实体转换异常问题

    com.alibaba.fastjson转实体遇到的一个大坑 问题描述 问题原因 解决方案 问题描述 项目中使用fastjson将json字符串转换为对应的实体,某天因为业务需要,实体需要增加两个属性 ...

  8. 将一个实体转换成 Url 参数的形式 ?a=ab=b

    function toQueryString(obj) { var ret = []; for (var key in obj) { key = encodeURIComponent(key); va ...

  9. 【objectMapper实体转换异常】 com.fasterxml.jackson.databind.exc.MismatchedInputException

    大家好,我是烤鸭: 采坑实录,想把json数据直接转成对象,其中有个属性是list<T>: 异常 1 com.fasterxml.jackson.databind.exc.Mismatch ...

最新文章

  1. ASP.NET MVC系列:添加控制器
  2. C# 中的 null 包容运算符 “!” —— 概念、由来、用法和注意事项
  3. Confluence 6 访问你的宏正文(body)
  4. ubuntu下使用ppa安装codeblocks集成开发环境
  5. 在rac集群上开启OEM
  6. Python入门(基本概念一)
  7. 《算法》第四版中文——学习资料
  8. 【Ubuntu版】CMake安装教程
  9. 常见的相机输出接口CVBS、VGA、DVI、HDMI、SDI、Camera Link、HS-LINK、CoaXPress
  10. 使用adb安装apk
  11. 你所不知道的VoIP通信技术?
  12. jeecgboot开发经验过程
  13. mysql实习报告总结_MySQL数据库实训报告 实训心得
  14. 实数在计算机上存储,实数如何在内存中存储
  15. Redis使用说明书(Windows)
  16. mysql基础单词总结
  17. dsp的ad标志位是什么_关于STM32 AD转换的ADC_FLAG_EOC标志位问题
  18. 世界顶级人像摄影大师作品欣赏
  19. Latex制作Slide的工作流程
  20. java毕业设计实验室主页系统源码+lw文档+mybatis+系统+mysql数据库+调试

热门文章

  1. SVG.js 文本绘制整理
  2. 二分图最大匹配(匈牙利算法) POJ 3020 Antenna Placement
  3. 三层架构(我了解并详细分析)
  4. [jobdu]调整数组顺序使奇数位于偶数前面
  5. 表单FORM的5个属性name,method,action,enctype,target
  6. 关于python中文处理
  7. android游戏画面抖动,抖音游戏主播是怎么直播手机画面的?
  8. 易语言逐条读access数据_易语言操作数据教程之ACCESS实战视频教程
  9. c语言编写atm取款功能_21行C语言代码编写一个具备加密功能的聊天程序!网友:666...
  10. html圆圈里面问号,html,css实现问号提示信息