From 0bd011e9dda3aabf6bbe3b9fad3f855a1ff2fae6 Mon Sep 17 00:00:00 2001 From: ?? ? <ulysseskao@ximple.com.tw> Date: Mon, 26 May 2008 14:06:48 +0800 Subject: [PATCH] update for EOFM-106 --- xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java | 138 ++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 134 insertions(+), 4 deletions(-) diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java index 2e91dda..bc01df6 100644 --- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java +++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java @@ -110,6 +110,7 @@ jobContext.setShapeData(_dataPath); jobContext.setConvertDB(_convertDB); jobContext.setConvertFile(_convertFile); + jobContext.setConvertElementIn(_convertElementIn); jobContext.setElementLogging(checkElementLogging()); jobContext.setExecutionContext(context); @@ -132,6 +133,12 @@ convertIndexDesignFile(context); logger.info("-- step:convertOtherDesignFile --"); convertOtherDesignFile(context); + } + + if (checkConvertElementIn()) + { + logger.info("-- step:convertFeatureDesignFile --"); + convertFeatureDesignFile(context); } } catch (SQLException e) { @@ -462,6 +469,7 @@ * �����ഫ�����ɪ��u�@ * * @param context �u�@�������� + * @throws org.quartz.JobExecutionException exception */ private void convertIndexDesignFile(JobExecutionContext context) throws JobExecutionException { @@ -589,20 +597,21 @@ /** * �����ഫ��L�]�p���ɪ��u�@ * - * @param context + * @param context jobContext + * @throws org.quartz.JobExecutionException exception */ private void convertOtherDesignFile(JobExecutionContext context) throws JobExecutionException { File otherDir = new File(getDataPath(), "other"); if (!otherDir.exists()) { - logger.info("index dir=" + otherDir + " not exist."); + logger.info("other dir=" + otherDir + " not exist."); return; } if (!otherDir.isDirectory()) { - logger.info("index dir=" + otherDir + " is not a directory."); + logger.info("other dir=" + otherDir + " is not a directory."); } File[] dgnFiles = otherDir.listFiles(new FilenameFilter() @@ -705,7 +714,8 @@ logger.debug("ElementRecord Count=" + count); } - private void processOtherElement(Element element, GeneralDgnConvertJobContext convertContext) throws IllegalAttributeException, SchemaException + private void processOtherElement(Element element, GeneralDgnConvertJobContext convertContext) + throws IllegalAttributeException, SchemaException { convertContext.putFeatureCollection(element); } @@ -762,4 +772,124 @@ } } } + + private void convertFeatureDesignFile(JobExecutionContext context) throws JobExecutionException + { + File elminDir = new File(getDataPath(), "elmin"); + if (!elminDir.exists()) + { + logger.info("elmin dir=" + elminDir + " not exist."); + return; + } + + if (!elminDir.isDirectory()) + { + logger.info("elmin dir=" + elminDir + " is not a directory."); + } + + File[] dgnFiles = elminDir.listFiles(new FilenameFilter() + { + public boolean accept(File dir, String name) + { + return name.toLowerCase().endsWith(".dgn"); + } + }); + + for (File dgnFile : dgnFiles) + { + FeatureDgnConvertJobContext convertContext = new FeatureDgnConvertJobContext(getDataPath(), _filterPath); + logger.info("--- start dgnfile-" + dgnFile.toString() + " ---"); + try + { + convertContext.setExecutionContext(context); + String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.separator); + convertContext.setFilename(dgnPaths[dgnPaths.length - 1]); + + FileInputStream fs = new FileInputStream(dgnFile); + FileChannel fc = fs.getChannel(); + Dgn7fileReader reader = new Dgn7fileReader(fc, new Lock()); + convertContext.setReader(reader); + + scanFeatureDgnElement(convertContext); + + convertContext.commitTransaction(); + convertContext.closeFeatureWriter(); + System.gc(); + } catch (FileNotFoundException e) + { + convertContext.rollbackTransaction(); + logger.warn(e.getMessage(), e); + throw new JobExecutionException(e.getMessage(), e); + } catch (Dgn7fileException e) + { + convertContext.rollbackTransaction(); + logger.warn(e.getMessage(), e); + throw new JobExecutionException(e.getMessage(), e); + } catch (IOException e) + { + convertContext.rollbackTransaction(); + logger.warn(e.getMessage(), e); + throw new JobExecutionException(e.getMessage(), e); + } catch (IllegalAttributeException e) + { + convertContext.rollbackTransaction(); + logger.warn(e.getMessage(), e); + throw new JobExecutionException(e.getMessage(), e); + } catch (SchemaException e) + { + convertContext.rollbackTransaction(); + logger.warn(e.getMessage(), e); + throw new JobExecutionException(e.getMessage(), e); + } + } + } + + public void scanFeatureDgnElement(FeatureDgnConvertJobContext convertContext) + throws Dgn7fileException, IOException, IllegalAttributeException, SchemaException + { + Dgn7fileReader reader = convertContext.getReader(); + int count = 0; + Element lastComplex = null; + while (reader.hasNext()) + { + Dgn7fileReader.Record record = reader.nextElement(); + if (record.element() != null) + { + Element element = (Element) record.element(); + ElementType type = element.getElementType(); + + if ((!type.isComplexElement()) && (!element.isComponentElement())) + { + lastComplex = null; + + processFeatureElement(element, convertContext); + } else if (element.isComponentElement()) + { + if (lastComplex != null) + { + ((ComplexElement) lastComplex).add(element); + } + } else if (type.isComplexElement()) + { + if (lastComplex == null) + { + lastComplex = element; + } else + { + processFeatureElement(element, convertContext); + lastComplex = element; + } + } + } + count++; + } + + logger.debug("ElementRecord Count=" + count); + } + + private void processFeatureElement(Element element, FeatureDgnConvertJobContext convertContext) + throws IllegalAttributeException, SchemaException + { + convertContext.putFeatureCollection(element); + } } -- Gitblit v0.0.0-SNAPSHOT