1 files modified
151 files added
| | |
| | | * text=auto !eol |
| | | xdgnjobs/pom.xml svneol=native#text/xml |
| | | xdgnjobs/ximple-build/maven/jar-collector/pom.xml svneol=native#text/xml |
| | | xdgnjobs/ximple-build/maven/jar-collector/src/main/java/com/ximple/eofms/maven/JarCollector.java svneol=native#text/plain |
| | | xdgnjobs/ximple-build/maven/pom.xml svneol=native#text/xml |
| | | xdgnjobs/ximple-build/pom.xml svneol=native#text/xml |
| | | xdgnjobs/ximple-dgnio/pom.xml svneol=native#text/xml |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ArcElement.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexChainElement.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexElement.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexShapeElement.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7Exception.java -text |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7OracleReader.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7fileException.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7fileHeader.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7fileReader.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ElementType.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/EllipseElement.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/FrammeAttributeData.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/GeometryConverter.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/IElementHandler.java -text |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/LineElement.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/LineStringElement.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Lock.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/NIOUtilities.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ShapeElement.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/StreamLogging.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TagElement.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TcbElement.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextElement.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextNodeElement.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/UserAttributeData.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/util/DgnUtility.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/main/java/com/ximple/util/PrintfFormat.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7OracleReaderTest.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7TextElementReaderTest.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7fileReaderTest.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/test/java/com/ximple/io/dgn7/OracleTarget.java svneol=native#text/plain |
| | | xdgnjobs/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/Demo.dgn -text |
| | | xdgnjobs/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/HV88491-1.dgn -text |
| | | xdgnjobs/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/HV88491_0888888.dgn -text |
| | | xdgnjobs/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/HV88494_0.dgn -text |
| | | xdgnjobs/ximple-dgnio/src/test/resources/com/ximple/io/dgn7/test-data/testHV.dgn -text |
| | | xdgnjobs/ximple-elmparser/pom.xml svneol=native#text/xml |
| | | xdgnjobs/ximple-elmparser/src/main/java/com/ximple/eofms/XElementFetcher.java svneol=native#text/plain |
| | | xdgnjobs/ximple-elmparser/src/main/java/com/ximple/eofms/XElementParser.java svneol=native#text/plain |
| | | xdgnjobs/ximple-elmparser/src/main/resources/com/ximple/eofms/XElementParser.properties svneol=native#text/plain |
| | | xdgnjobs/ximple-elmparser/src/main/resources/com/ximple/eofms/XElementParser_zh_TW.properties svneol=native#text/plain |
| | | xdgnjobs/ximple-elmparser/src/main/resources/log4j.properties svneol=native#text/plain |
| | | xdgnjobs/ximple-jobcarrier/pom.xml svneol=native#text/xml |
| | | xdgnjobs/ximple-jobcarrier/src/main/java/com/ximple/eofms/XQuartzJobCarrier.java svneol=native#text/plain |
| | | xdgnjobs/ximple-jobcarrier/src/main/java/com/ximple/eofms/XQuartzJobWizard.java svneol=native#text/plain |
| | | xdgnjobs/ximple-jobcarrier/src/main/resources/com/ximple/eofms/XQuartzJobWizard.properties svneol=native#text/plain |
| | | xdgnjobs/ximple-jobcarrier/src/main/resources/com/ximple/eofms/XQuartzJobWizard_zh_TW.properties svneol=native#text/plain |
| | | xdgnjobs/ximple-jobcarrier/src/main/resources/log4j.properties svneol=native#text/plain |
| | | xdgnjobs/ximple-jobcarrier/src/main/resources/quartz.properties svneol=native#text/plain |
| | | xdgnjobs/ximple-jobcarrier/src/main/resources/quartz_jobs.xml svneol=native#text/xml |
| | | xdgnjobs/ximple-jobcarrier/src/main/resources/quartz_jobs_shapefiles.xml svneol=native#text/xml |
| | | xdgnjobs/ximple-jobcarrier/src/test/java/com/ximple/eofms/XQuartzJobCarrierTest.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/pom.xml svneol=native#text/xml |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/collector/FeatureClassification.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/collector/FeatureTypeCollector.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/AbstractDispatchableFilter.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/AbstractFLinkageDispatchableFilter.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateArcLineStringStrategy.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateComplexChainStrategy.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateEllipseShapeStrategy.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateFeatureTypeEventListener.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateFeatureTypeStrategy.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateLineStringStrategy.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateLineTextStrategy.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateMultiSymbolStrategy.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateShapeStrategy.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateSymbolStrategy.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateTextStrategy.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/ElementDispatchableFilter.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/ElementDispatcher.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/ElementLevelCriterion.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/ElementTypeCriterion.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/FeatureTypeEvent.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/TypeCompIdDispatchableFilter.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/TypeCompLevelIdDispatchableFilter.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/TypeIdDispatchableFilter.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/AbstractOracleDatabaseJob.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/DataReposVersionManager.java -text |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/DummyFeatureConvertJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2MySQLJob.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2OraSDOJob.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2PostGISJob.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleElementLogger.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleUpgradeBlob2UDTJob.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/AbstractDgnFileJobContext.java -text |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/AbstractOracleJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/OracleUpgradeJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/AbstractDgnToMySQLJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/AbstractOracleToMySQLJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/DummyFeatureConvertMySQlJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/FeatureDgnConvertMySQLJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/GeneralDgnConvertMySQLJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/IndexDgnConvertMySQLJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/OracleConvertMySQLJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/AbstractDgnToOraSDOJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/AbstractOracleToOraSDOJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/DummyFeatureConvertOraSDOJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/FeatureDgnConvertOraSDOJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/GeneralDgnConvertOraSDOJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/IndexDgnConvertOraSDOJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/OracleConvertOraSDOJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/AbstractDgnToPostGISJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/AbstractOracleToPostGISJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/DummyFeatureConvertPostGISJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/FeatureDgnConvertPostGISJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/GeneralDgnConvertPostGISJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/IndexDgnConvertPostGISJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/OracleConvertPostGISJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/shapefile/AbstractDgnToShapefileJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/shapefile/DummyFeatureConvertShpJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/shapefile/FeatureDgnConvertShpJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/shapefile/GeneralDgnConvertShpJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/shapefile/IndexDgnConvertShpJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/shapefile/OracleConvertShapefilesJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/Base64.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/BinConverter.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/Bits.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/ByteArrayCompressor.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/ColorTableMapping.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/DefaultColorTable.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/FeatureTypeBuilderUtil.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/GeomUtil.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/LangUtil.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/PrintfFormat.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/StringUtils.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/TPCLIDConverter.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/TWD97GeometryConverterDecorator.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/TWDDatumConverter.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/postjts/JTSShape.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/postjts/JtsBinaryParser.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/postjts/JtsBinaryWriter.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/postjts/JtsGeometry.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/postjts/JtsGisWrapper.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/postjts/JtsWrapper.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/resources/com/ximple/eofms/filter/ElementDispatcherRules.xml svneol=native#text/xml |
| | | xdgnjobs/ximple-spatialjob/src/main/resources/com/ximple/eofms/filter/FeatureClassificationRules.xml svneol=native#text/xml |
| | | xdgnjobs/ximple-spatialjob/src/main/resources/conf/ConvertShpFilterForLayer.xml svneol=native#text/xml |
| | | xdgnjobs/ximple-spatialjob/src/main/resources/conf/DefaultConvertShpFilter.xml svneol=native#text/xml |
| | | xdgnjobs/ximple-spatialjob/src/main/resources/conf/DefaultMapGroups.xml svneol=native#text/xml |
| | | xdgnjobs/ximple-spatialjob/src/test/java/com/ximple/eofms/filter/ElementDispatcherTest.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/test/resources/com/ximple/eofms/filter/test-data/testElementFilter.xml svneol=native#text/xml |
| | | xdgnjobs/ximple-spatialjob/src/test/resources/com/ximple/eofms/filter/test-data/testRules.xml svneol=native#text/xml |
New file |
| | |
| | | xdgnjobs/target |
| | | xdgnjobs/ximple-spatialjob/target |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!-- ======================================================================= |
| | | Maven Project Configuration File |
| | | |
| | | The Ximple DgnIO Project |
| | | http://www.ximple.com.tw/ |
| | | |
| | | Version: $Id$ |
| | | ======================================================================= --> |
| | | <project xmlns="http://maven.apache.org/POM/4.0.0" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 |
| | | http://maven.apache.org/maven-v4_0_0.xsd"> |
| | | <modelVersion>4.0.0</modelVersion> |
| | | |
| | | <properties> |
| | | <oracle.jdbc>true</oracle.jdbc> |
| | | <test.maxHeapSize>512M</test.maxHeapSize> |
| | | <src.output>${basedir}/target</src.output> |
| | | <java5>1.5</java5> |
| | | <xdgnio.version>0.9.0</xdgnio.version> |
| | | <gt.version>2.4.4</gt.version> |
| | | <failIfNoTests>false</failIfNoTests> |
| | | </properties> |
| | | |
| | | <profiles> |
| | | <profile> |
| | | <id>java5</id> |
| | | <reporting> |
| | | <plugins> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-javadoc-plugin</artifactId> |
| | | <configuration> |
| | | <source>1.5</source> |
| | | </configuration> |
| | | </plugin> |
| | | </plugins> |
| | | </reporting> |
| | | </profile> |
| | | <profile> |
| | | <id>site.ximple.tw</id> |
| | | <distributionManagement> |
| | | <site> |
| | | <id>artifactorysite-ximple-tw</id> |
| | | <name>Artifactory Web site for Maven reports</name> |
| | | <url>scp://www.ximple.com.tw/home/www/artfactory/libs-releases@repo</url> |
| | | </site> |
| | | </distributionManagement> |
| | | </profile> |
| | | </profiles> |
| | | |
| | | <scm> |
| | | <connection> |
| | | scm:svn:http://www.ximple.com.tw/svn/xeofms/xspatialjob/truck/ |
| | | </connection> |
| | | <url>http://www.ximple.com.tw/svn/xeofms/xspatialjob/truck/</url> |
| | | </scm> |
| | | |
| | | <groupId>com.ximple.eofms</groupId> |
| | | <artifactId>ximple-dgnjobs</artifactId> |
| | | <packaging>pom</packaging> |
| | | <version>0.9.0</version> |
| | | <name>ximple-dgnjobs</name> |
| | | <url>http://www.ximple.com.tw</url> |
| | | |
| | | <description>Ximple Spatial Data Job for Quartz</description> |
| | | |
| | | <organization> |
| | | <name>Ximple</name> |
| | | <url>http://www.ximple.com.tw</url> |
| | | </organization> |
| | | |
| | | <inceptionYear>2008</inceptionYear> |
| | | |
| | | <!-- =========================================================== --> |
| | | <!-- Issue managements and mailing lists. --> |
| | | <!-- =========================================================== --> |
| | | <issueManagement> |
| | | <system>JIRA</system> |
| | | <url>http://www.ximple.com.tw/jira/browse/EOFMS</url> |
| | | </issueManagement> |
| | | |
| | | <!-- =========================================================== --> |
| | | <!-- Continuous Integration --> |
| | | <!-- =========================================================== --> |
| | | <ciManagement> |
| | | <system>continuum</system> |
| | | </ciManagement> |
| | | |
| | | <mailingLists> |
| | | <mailingList> |
| | | </mailingList> |
| | | </mailingLists> |
| | | |
| | | <developers> |
| | | <developer> |
| | | </developer> |
| | | </developers> |
| | | |
| | | <contributors> |
| | | </contributors> |
| | | |
| | | <!-- =========================================================== --> |
| | | <!-- Dependency Management --> |
| | | <!-- If a POM declares one of those dependencies, then it --> |
| | | <!-- will use the version specified here. Otherwise, those --> |
| | | <!-- dependencies are ignored. --> |
| | | <!-- =========================================================== --> |
| | | <dependencyManagement> |
| | | <dependencies> |
| | | <!-- GeoAPI and its dependencies --> |
| | | <dependency> |
| | | <groupId>org.opengis</groupId> |
| | | <artifactId>geoapi-nogenerics</artifactId> |
| | | <version>2.1.1</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>javax.units</groupId> |
| | | <artifactId>jsr108</artifactId> |
| | | <version>0.01</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.vividsolutions</groupId> |
| | | <artifactId>jts</artifactId> |
| | | <version>1.9</version> |
| | | </dependency> |
| | | |
| | | <!-- Apache --> |
| | | <!-- |
| | | <dependency> |
| | | <groupId>commons-beanutils</groupId> |
| | | <artifactId>commons-beanutils</artifactId> |
| | | <version>1.7</version> |
| | | </dependency> |
| | | --> |
| | | <dependency> |
| | | <groupId>commons-collections</groupId> |
| | | <artifactId>commons-collections</artifactId> |
| | | <version>3.2.1</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>commons-digester</groupId> |
| | | <artifactId>commons-digester</artifactId> |
| | | <version>1.8</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>commons-pool</groupId> |
| | | <artifactId>commons-pool</artifactId> |
| | | <version>1.4</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>commons-logging</groupId> |
| | | <artifactId>commons-logging</artifactId> |
| | | <version>1.1.1</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>commons-transaction</groupId> |
| | | <artifactId>commons-transaction</artifactId> |
| | | <version>1.2</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>commons-cli</groupId> |
| | | <artifactId>commons-cli</artifactId> |
| | | <version>1.1</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>log4j</groupId> |
| | | <artifactId>log4j</artifactId> |
| | | <version>1.2.15</version> |
| | | <!-- Same as the dependency in commons-logging --> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.apache.poi</groupId> |
| | | <artifactId>poi</artifactId> |
| | | <version>3.1-FINAL</version> |
| | | </dependency> |
| | | |
| | | <!-- geotools --> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2</artifactId> |
| | | <version>${gt.version}</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-api</artifactId> |
| | | <version>${gt.version}</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-main</artifactId> |
| | | <version>${gt.version}</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-shapefile</artifactId> |
| | | <version>${gt.version}</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-sample-data</artifactId> |
| | | <version>${gt.version}</version> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-data</artifactId> |
| | | <version>${gt.version}</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-jdbc</artifactId> |
| | | <version>${gt.version}</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-oracle-spatial</artifactId> |
| | | <version>${gt.version}</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-postgis</artifactId> |
| | | <version>${gt.version}</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-mysql</artifactId> |
| | | <version>${gt.version}</version> |
| | | </dependency> |
| | | |
| | | <!-- because main and sample-data depend on referencing we need a tie breaker --> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-referencing</artifactId> |
| | | <version>${gt.version}</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>jdom</groupId> |
| | | <artifactId>jdom</artifactId> |
| | | <version>1.0</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.apache.velocity</groupId> |
| | | <artifactId>velocity</artifactId> |
| | | <version>1.5</version> |
| | | </dependency> |
| | | |
| | | <!-- We need this to make the referencing module useful --> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-epsg-hsql</artifactId> |
| | | <version>${gt.version}</version> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | |
| | | <!-- ORACLE --> |
| | | <!-- Download and install into your own repo --> |
| | | <dependency> |
| | | <groupId>com.oracle</groupId> |
| | | <artifactId>ojdbc5</artifactId> |
| | | <version>11.1.0</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.oracle</groupId> |
| | | <artifactId>sdoapi</artifactId> |
| | | <version>11.1.0</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.oracle</groupId> |
| | | <artifactId>sdotype</artifactId> |
| | | <version>11.1.0</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.oracle</groupId> |
| | | <artifactId>sdoutl</artifactId> |
| | | <version>11.1.0</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>postgresql</groupId> |
| | | <artifactId>postgresql</artifactId> |
| | | <version>8.3-603.jdbc3</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.postgis</groupId> |
| | | <artifactId>postgis-driver</artifactId> |
| | | <version>1.3.3</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>mysql</groupId> |
| | | <artifactId>mysql-connector-java</artifactId> |
| | | <version>5.1.6</version> |
| | | </dependency> |
| | | |
| | | <!-- opensymphony --> |
| | | <dependency> |
| | | <groupId>opensymphony</groupId> |
| | | <artifactId>quartz</artifactId> |
| | | <version>1.6.0</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.awl</groupId> |
| | | <artifactId>awl</artifactId> |
| | | <version>1.1.0-rc</version> |
| | | </dependency> |
| | | |
| | | <!-- Tests or legacy --> |
| | | <dependency> |
| | | <groupId>org.testng</groupId> |
| | | <artifactId>testng</artifactId> |
| | | <version>5.8</version> |
| | | <classifier>jdk15</classifier> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | </dependencies> |
| | | </dependencyManagement> |
| | | |
| | | <!-- =========================================================== --> |
| | | <!-- Dependencies to be inherited by all modules. --> |
| | | <!-- =========================================================== --> |
| | | <dependencies> |
| | | <dependency> |
| | | <artifactId>geoapi-nogenerics</artifactId> |
| | | <groupId>org.opengis</groupId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <artifactId>jsr108</artifactId> |
| | | <groupId>javax.units</groupId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.vividsolutions</groupId> |
| | | <artifactId>jts</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- Apache --> |
| | | <dependency> |
| | | <artifactId>commons-collections</artifactId> |
| | | <groupId>commons-collections</groupId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>commons-digester</groupId> |
| | | <artifactId>commons-digester</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>commons-pool</groupId> |
| | | <artifactId>commons-pool</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>commons-logging</groupId> |
| | | <artifactId>commons-logging</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>commons-transaction</groupId> |
| | | <artifactId>commons-transaction</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <artifactId>log4j</artifactId> |
| | | <groupId>log4j</groupId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <artifactId>gt2-api</artifactId> |
| | | <groupId>org.geotools</groupId> |
| | | </dependency> |
| | | <dependency> |
| | | <artifactId>gt2-main</artifactId> |
| | | <groupId>org.geotools</groupId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <artifactId>testng</artifactId> |
| | | <groupId>org.testng</groupId> |
| | | <classifier>jdk15</classifier> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <!-- =========================================================== --> |
| | | <!-- Build Configuration --> |
| | | <!-- =========================================================== --> |
| | | <build> |
| | | <!-- ========================================================= --> |
| | | <!-- Maven plugins dependencies management. --> |
| | | <!-- It should not be needed since Maven select by default --> |
| | | <!-- the latest plugins. Unfortunatly, experience shows that --> |
| | | <!-- new plugin releases sometime introduce new bugs that --> |
| | | <!-- break our build. So it is saferto specify plugin --> |
| | | <!-- versions that are known to work. This list is in --> |
| | | <!-- alphabetical order for easier comparaison with latest --> |
| | | <!-- plugins at --> |
| | | <!-- http://www.ibiblio.org/maven2/org/apache/maven/plugins/ --> |
| | | <!-- ========================================================= --> |
| | | <pluginManagement> |
| | | <plugins> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-assembly-plugin</artifactId> |
| | | <version>2.1</version> |
| | | <configuration> |
| | | <descriptors> |
| | | <descriptor>build/maven/assembly/binaryDist.xml</descriptor> |
| | | <descriptor>build/maven/assembly/sourceDist.xml</descriptor> |
| | | </descriptors> |
| | | </configuration> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-clean-plugin</artifactId> |
| | | <version>2.1.1</version> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-clover-plugin</artifactId> |
| | | <version>2.3</version> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-compiler-plugin</artifactId> |
| | | <version>2.0.2</version> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-install-plugin</artifactId> |
| | | <version>2.1</version> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-jar-plugin</artifactId> |
| | | <version>2.1</version> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-javadoc-plugin</artifactId> |
| | | <version>2.4</version> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-plugin-plugin</artifactId> |
| | | <version>2.3</version> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-pmd-plugin</artifactId> |
| | | <version>2.4</version> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-project-info-reports-plugin</artifactId> |
| | | <version>2.0.1</version> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-resources-plugin</artifactId> |
| | | <version>2.2</version> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-site-plugin</artifactId> |
| | | <version>2.0-beta-5</version> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-surefire-plugin</artifactId> |
| | | <version>2.4.2</version> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-surefire-report-plugin</artifactId> |
| | | <version>2.4.2</version> |
| | | </plugin> |
| | | |
| | | <!-- http://www.ibiblio.org/maven2/org/codehaus/mojo/ --> |
| | | <plugin> |
| | | <groupId>org.codehaus.mojo</groupId> |
| | | <artifactId>changelog-maven-plugin</artifactId> |
| | | <version>2.0-beta-1</version> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.codehaus.mojo</groupId> |
| | | <artifactId>changes-maven-plugin</artifactId> |
| | | <version>2.0-beta-1</version> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.codehaus.mojo</groupId> |
| | | <artifactId>jxr-maven-plugin</artifactId> |
| | | <version>2.0-beta-1</version> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.codehaus.mojo</groupId> |
| | | <artifactId>taglist-maven-plugin</artifactId> |
| | | <version>2.2</version> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.codehaus.mojo</groupId> |
| | | <artifactId>jalopy-maven-plugin</artifactId> |
| | | <version>1.0-SNAPSHOT</version> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-source-plugin</artifactId> |
| | | <configuration> |
| | | <outputDirectory>${src.output}</outputDirectory> |
| | | <attach>false</attach> |
| | | </configuration> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-eclipse-plugin</artifactId> |
| | | <version>2.4</version> |
| | | </plugin> |
| | | </plugins> |
| | | </pluginManagement> |
| | | |
| | | <!-- http://www.ibiblio.org/maven2/org/apache/maven/wagon/ --> |
| | | <!-- |
| | | <extensions> |
| | | <extension> |
| | | <groupId>org.apache.maven.wagon</groupId> |
| | | <artifactId>wagon-webdav</artifactId> |
| | | <version>1.0-beta-2</version> |
| | | </extension> |
| | | </extensions> |
| | | --> |
| | | |
| | | <plugins> |
| | | <!-- ======================================================= --> |
| | | <!-- Source reformat --> |
| | | <!-- (activated only on request, jalopy:format) --> |
| | | <!-- See developer's guide for automated activation --> |
| | | <!-- ======================================================= --> |
| | | <plugin> |
| | | <groupId>org.codehaus.mojo</groupId> |
| | | <artifactId>jalopy-maven-plugin</artifactId> |
| | | <configuration> |
| | | <convention>gt2/jalopygeotools.xml</convention> |
| | | <failOnError>false</failOnError> |
| | | </configuration> |
| | | <dependencies> |
| | | <dependency> |
| | | <groupId>org.geotools.maven</groupId> |
| | | <artifactId>gt2-build-configs</artifactId> |
| | | <version>${gt.version}</version> |
| | | </dependency> |
| | | </dependencies> |
| | | </plugin> |
| | | |
| | | |
| | | <!-- ======================================================= --> |
| | | <!-- Compilation. --> |
| | | <!-- ======================================================= --> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-compiler-plugin</artifactId> |
| | | <configuration> |
| | | <source>1.5</source> |
| | | <!-- The -source argument for the Java compiler. --> |
| | | <target>1.5</target> |
| | | <!-- The -target argument for the Java compiler. --> |
| | | <debug>true</debug> |
| | | <!-- Whether to include debugging information. --> |
| | | <encoding>ISO-8859-1</encoding> |
| | | <!-- The -encoding argument for the Java compiler. --> |
| | | </configuration> |
| | | </plugin> |
| | | |
| | | |
| | | <!-- ======================================================= --> |
| | | <!-- Tests. --> |
| | | <!-- ======================================================= --> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-surefire-plugin</artifactId> |
| | | <configuration> |
| | | <includes> |
| | | <include>**/*Test.java</include> |
| | | </includes> |
| | | <excludes> |
| | | <exclude>${online.skip.pattern}</exclude> |
| | | <exclude>${stress.skip.pattern}</exclude> |
| | | </excludes> |
| | | <argLine>-Xmx${test.maxHeapSize} -Djava.awt.headless=${java.awt.headless} |
| | | </argLine> |
| | | <!-- Ignores test failure only if we are generating a --> |
| | | <!-- report for publication on the web site. See the --> |
| | | <!-- profiles section at the begining of this pom.xml file. --> |
| | | <testFailureIgnore> |
| | | ${allow.test.failure.ignore} |
| | | </testFailureIgnore> |
| | | |
| | | <!-- Option to print summary of test suites or just print the test cases that has errors. --> |
| | | <printSummary>true</printSummary> |
| | | <!-- Redirect the unit test standard output to a file. --> |
| | | <redirectTestOutputToFile>false</redirectTestOutputToFile> |
| | | </configuration> |
| | | </plugin> |
| | | |
| | | |
| | | <!-- ======================================================= --> |
| | | <!-- Code coverage --> |
| | | <!-- ======================================================= --> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-clover-plugin</artifactId> |
| | | <configuration> |
| | | <jdk>1.5</jdk> |
| | | <licenseLocation> |
| | | http://svn.geotools.org/geotools/branches/2.4.x/build/maven/build-configs/src/main/resources/gt2/clover.license |
| | | </licenseLocation> |
| | | <flushPolicy>directed</flushPolicy> |
| | | </configuration> |
| | | <executions> |
| | | <execution> |
| | | <phase>pre-site</phase> |
| | | <goals> |
| | | <goal>instrument</goal> |
| | | <!-- aggregation is disabled due to the bug: --> |
| | | <!-- http://jira.codehaus.org/browse/MCLOVER-34 --> |
| | | </goals> |
| | | </execution> |
| | | </executions> |
| | | <dependencies> |
| | | <dependency> |
| | | <groupId>org.geotools.maven</groupId> |
| | | <artifactId>gt2-build-configs</artifactId> |
| | | <version>${gt.version}</version> |
| | | </dependency> |
| | | </dependencies> |
| | | </plugin> |
| | | |
| | | |
| | | <!-- ======================================================= --> |
| | | <!-- JAR packaging. --> |
| | | <!-- ======================================================= --> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-jar-plugin</artifactId> |
| | | <configuration> |
| | | <archive> |
| | | <manifest> |
| | | <addClasspath>true</addClasspath> |
| | | </manifest> |
| | | </archive> |
| | | </configuration> |
| | | </plugin> |
| | | |
| | | <!-- ======================================================= --> |
| | | <!-- Source packaging. --> |
| | | <!-- ======================================================= --> |
| | | <plugin> |
| | | <inherited>true</inherited> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-source-plugin</artifactId> |
| | | <configuration> |
| | | <attach>true</attach> |
| | | </configuration> |
| | | <executions> |
| | | <execution> |
| | | <id>attach-sources</id> |
| | | <goals> |
| | | <goal>jar</goal> |
| | | </goals> |
| | | </execution> |
| | | </executions> |
| | | </plugin> |
| | | </plugins> |
| | | <resources> |
| | | <!-- |
| | | <resource> |
| | | <targetPath>conf</targetPath> |
| | | <filtering>false</filtering> |
| | | <directory>${basedir}/src/main/resources/conf</directory> |
| | | <includes> |
| | | <include>configuration.xml</include> |
| | | </includes> |
| | | <excludes> |
| | | <exclude>**/*.properties</exclude> |
| | | </excludes> |
| | | </resource> |
| | | --> |
| | | </resources> |
| | | </build> |
| | | |
| | | <distributionManagement> |
| | | <repository> |
| | | <uniqueVersion>false</uniqueVersion> |
| | | <id>ximple</id> |
| | | <name>Ximple - Artifactory lib repo</name> |
| | | <url>dav:http://www.ximple.com.tw/artifactory/libs-releases</url> |
| | | </repository> |
| | | <snapshotRepository> |
| | | <uniqueVersion>false</uniqueVersion> |
| | | <id>ximple-snapshots</id> |
| | | <name>Ximple - Artifactory lib-snapshots repo</name> |
| | | <url>dav:http://www.ximple.com.tw/artifactory/libs-snapshots</url> |
| | | </snapshotRepository> |
| | | </distributionManagement> |
| | | |
| | | <!-- =========================================================== --> |
| | | <!-- Repositories (ibiblio, refractions...). --> |
| | | <!-- This is where Maven looks for dependencies. --> |
| | | <!-- =========================================================== --> |
| | | <repositories> |
| | | <repository> |
| | | <snapshots> |
| | | <enabled>false</enabled> |
| | | </snapshots> |
| | | <id>central</id> |
| | | <name>Ximple Artifactory Maven Repository Switchboard</name> |
| | | <url>http://www.ximple.com.tw/artifactory/repo</url> |
| | | </repository> |
| | | |
| | | <repository> |
| | | <releases> |
| | | <enabled>false</enabled> |
| | | </releases> |
| | | <id>snapshots</id> |
| | | <name>Ximple Artifactory Maven Repository Switchboard</name> |
| | | <url>http://www.ximple.com.tw/artifactory/repo</url> |
| | | </repository> |
| | | </repositories> |
| | | |
| | | |
| | | <!-- =========================================================== --> |
| | | <!-- Plugin repositories. --> |
| | | <!-- This is where Maven looks for plugin dependencies. --> |
| | | <!-- =========================================================== --> |
| | | <pluginRepositories> |
| | | <pluginRepository> |
| | | <id>ximple-snapshots</id> |
| | | <name>ximple-shapshots</name> |
| | | <url>http://www.ximple.com.tw/artifactory/vplugins-snapshots</url> |
| | | <snapshots> |
| | | <enabled>true</enabled> |
| | | </snapshots> |
| | | <releases> |
| | | <enabled>false</enabled> |
| | | </releases> |
| | | </pluginRepository> |
| | | <pluginRepository> |
| | | <id>ximple</id> |
| | | <name>Ximple Maven 2 Repository</name> |
| | | <url>http://www.ximple.com.tw/artifactory/vplugins-releases</url> |
| | | <snapshots> |
| | | <enabled>false</enabled> |
| | | </snapshots> |
| | | <releases> |
| | | <enabled>true</enabled> |
| | | </releases> |
| | | </pluginRepository> |
| | | </pluginRepositories> |
| | | |
| | | <!-- =========================================================== --> |
| | | <!-- Modules for the build in approximate dependency order --> |
| | | <!-- =========================================================== --> |
| | | <modules> |
| | | <module>ximple-build</module> |
| | | <module>ximple-dgnio</module> |
| | | <module>ximple-spatialjob</module> |
| | | <module>ximple-jobcarrier</module> |
| | | <module>ximple-elmparser</module> |
| | | </modules> |
| | | </project> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <project xmlns="http://maven.apache.org/POM/4.0.0" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
| | | <modelVersion>4.0.0</modelVersion> |
| | | |
| | | <parent> |
| | | <groupId>com.ximple.eofms.maven</groupId> |
| | | <artifactId>ximple-maven</artifactId> |
| | | <version>0.9.0</version> |
| | | </parent> |
| | | |
| | | |
| | | <!-- =========================================================== --> |
| | | <!-- Module Description --> |
| | | <!-- =========================================================== --> |
| | | <groupId>com.ximple.eofms.maven</groupId> |
| | | <artifactId>ximple-jar-collector</artifactId> |
| | | <packaging>maven-plugin</packaging> |
| | | <name>JAR files collector</name> |
| | | |
| | | <scm> |
| | | <connection> |
| | | scm:svn:http://www.ximple.com.tw/svn/xeofms/xdgnio/truck/ |
| | | </connection> |
| | | <url>http://www.ximple.com.tw/svn/xeofms/xdgnio/truck/</url> |
| | | </scm> |
| | | |
| | | <description> |
| | | Copy all JAR files (including dependencies) in the target directory |
| | | of the parent project descriptor. |
| | | </description> |
| | | |
| | | <licenses> |
| | | <license> |
| | | <name>Lesser General Public License (LGPL)</name> |
| | | <url>http://www.gnu.org/copyleft/lesser.txt</url> |
| | | <distribution>repo</distribution> |
| | | </license> |
| | | </licenses> |
| | | |
| | | <!-- =========================================================== --> |
| | | <!-- Developers and Contributors --> |
| | | <!-- =========================================================== --> |
| | | |
| | | </project> |
New file |
| | |
| | | package com.ximple.eofms.maven; |
| | | |
| | | import org.apache.maven.artifact.Artifact; |
| | | |
| | | // Maven and Plexus dependencies |
| | | import org.apache.maven.plugin.AbstractMojo; |
| | | import org.apache.maven.plugin.MojoExecutionException; |
| | | import org.apache.maven.project.MavenProject; |
| | | import org.codehaus.plexus.util.FileUtils; |
| | | |
| | | // J2SE dependencies |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.Iterator; |
| | | import java.util.Set; |
| | | |
| | | |
| | | // Note: javadoc in class and fields descriptions must be XHTML. |
| | | /** |
| | | * Copies <code>.jar</code> files in a single directory. Dependencies are copied as well, |
| | | * except if already presents. |
| | | * |
| | | * @goal collect |
| | | * @phase package |
| | | * @source $URL$ |
| | | * @version $Id$ |
| | | * @author Martin Desruisseaux |
| | | */ |
| | | public class JarCollector extends AbstractMojo { |
| | | /** |
| | | * The sub directory to create inside the "target" directory. |
| | | */ |
| | | private static final String SUB_DIRECTORY = "binaries"; |
| | | |
| | | /** |
| | | * The directory where JARs are to be copied. It should |
| | | * be the "target" directory of the parent {@code pom.xml}. |
| | | */ |
| | | private String collectDirectory; |
| | | |
| | | /** |
| | | * Directory containing the generated JAR. |
| | | * |
| | | * @parameter expression="${project.build.directory}" |
| | | * @required |
| | | */ |
| | | private String outputDirectory; |
| | | |
| | | /** |
| | | * Name of the generated JAR. |
| | | * |
| | | * @parameter expression="${project.build.finalName}" |
| | | * @required |
| | | */ |
| | | private String jarName; |
| | | |
| | | /** |
| | | * Project dependencies. |
| | | * |
| | | * @parameter expression="${project.artifacts}" |
| | | * @required |
| | | */ |
| | | private Set /*<Artifact>*/ dependencies; |
| | | |
| | | /** |
| | | * The Maven project running this plugin. |
| | | * |
| | | * @parameter expression="${project}" |
| | | * @required |
| | | */ |
| | | private MavenProject project; |
| | | |
| | | /** |
| | | * Copies the {@code .jar} files to the collect directory. |
| | | * |
| | | * @throws MojoExecutionException if the plugin execution failed. |
| | | */ |
| | | public void execute() throws MojoExecutionException { |
| | | /* |
| | | * Gets the parent "target" directory. |
| | | */ |
| | | MavenProject parent = project; |
| | | |
| | | while (parent.hasParent()) { |
| | | parent = parent.getParent(); |
| | | } |
| | | |
| | | collectDirectory = parent.getBuild().getDirectory(); |
| | | |
| | | /* |
| | | * Now collects the JARs. |
| | | */ |
| | | try { |
| | | collect(); |
| | | } catch (IOException e) { |
| | | throw new MojoExecutionException("Error collecting the JAR file.", e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Implementation of the {@link #execute} method. |
| | | */ |
| | | private void collect() throws MojoExecutionException, IOException { |
| | | /* |
| | | * Make sure that we are collecting the JAR file from a module which produced |
| | | * such file. Some modules use pom packaging, which do not produce any JAR file. |
| | | */ |
| | | final File jarFile = new File(outputDirectory, jarName + ".jar"); |
| | | |
| | | if (!jarFile.isFile()) { |
| | | return; |
| | | } |
| | | |
| | | /* |
| | | * Get the "target" directory of the parent pom.xml and make sure it exists. |
| | | */ |
| | | File collect = new File(collectDirectory); |
| | | |
| | | if (!collect.exists()) { |
| | | if (!collect.mkdir()) { |
| | | throw new MojoExecutionException("Failed to create target directory."); |
| | | } |
| | | } |
| | | |
| | | if (collect.getCanonicalFile().equals(jarFile.getParentFile().getCanonicalFile())) { |
| | | /* |
| | | * The parent's directory is the same one than this module's directory. |
| | | * In other words, this plugin is not executed from the parent POM. Do |
| | | * not copy anything, since this is not the place where we want to |
| | | * collect the JAR files. |
| | | */ |
| | | return; |
| | | } |
| | | |
| | | /* |
| | | * Creates a "binaries" subdirectory inside the "target" directory. |
| | | */ |
| | | collect = new File(collect, SUB_DIRECTORY); |
| | | |
| | | if (!collect.exists()) { |
| | | if (!collect.mkdir()) { |
| | | throw new MojoExecutionException("Failed to create binaries directory."); |
| | | } |
| | | } |
| | | |
| | | int count = 1; |
| | | FileUtils.copyFileToDirectory(jarFile, collect); |
| | | |
| | | if (dependencies != null) { |
| | | for (final Iterator it = dependencies.iterator(); it.hasNext();) { |
| | | final Artifact artifact = (Artifact) it.next(); |
| | | final String scope = artifact.getScope(); |
| | | |
| | | if ((scope != null) // Maven 2.0.6 bug? |
| | | && (scope.equalsIgnoreCase(Artifact.SCOPE_COMPILE) |
| | | || scope.equalsIgnoreCase(Artifact.SCOPE_RUNTIME))) { |
| | | final File file = artifact.getFile(); |
| | | final File copy = new File(collect, file.getName()); |
| | | |
| | | if (!copy.exists()) { |
| | | /* |
| | | * Copies the dependency only if it was not already copied. Note that |
| | | * the module's JAR was copied inconditionnaly above (because it may |
| | | * be the result of a new compilation). If a Geotools JAR from the |
| | | * dependencies list changed, it will be copied inconditionnaly when |
| | | * the module for this JAR will be processed by Maven. |
| | | */ |
| | | FileUtils.copyFileToDirectory(file, collect); |
| | | count++; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | getLog().info("Copied " + count + " JAR to parent directory."); |
| | | } |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <project xmlns="http://maven.apache.org/POM/4.0.0" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
| | | <modelVersion>4.0.0</modelVersion> |
| | | |
| | | <parent> |
| | | <groupId>com.ximple.eofms.maven</groupId> |
| | | <artifactId>ximple-build</artifactId> |
| | | <version>0.9.0</version> |
| | | </parent> |
| | | |
| | | |
| | | <!-- =========================================================== --> |
| | | <!-- Module Description --> |
| | | <!-- =========================================================== --> |
| | | <groupId>com.ximple.eofms.maven</groupId> |
| | | <artifactId>ximple-maven</artifactId> |
| | | <packaging>pom</packaging> |
| | | <name>Maven plugins for Ximple</name> |
| | | |
| | | <scm> |
| | | <connection> |
| | | scm:svn:http://www.ximple.com.tw/svn/xeofms/xdgnio/truck/ |
| | | </connection> |
| | | <url>http://www.ximple.com.tw/svn/xeofms/xdgnio/truck/</url> |
| | | </scm> |
| | | |
| | | <description> |
| | | Maven plugins specific to the the Ximple Dgn IO Library. |
| | | </description> |
| | | |
| | | <licenses> |
| | | <license> |
| | | <name>Lesser General Public License (LGPL)</name> |
| | | <url>http://www.gnu.org/copyleft/lesser.txt</url> |
| | | <distribution>repo</distribution> |
| | | </license> |
| | | </licenses> |
| | | |
| | | |
| | | <!-- =========================================================== --> |
| | | <!-- Dependency Management --> |
| | | <!-- =========================================================== --> |
| | | <dependencies> |
| | | <dependency> |
| | | <groupId>org.apache.maven</groupId> |
| | | <artifactId>maven-plugin-api</artifactId> |
| | | <version>2.0.4</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.apache.maven</groupId> |
| | | <artifactId>maven-project</artifactId> |
| | | <version>2.0.4</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.codehaus.plexus</groupId> |
| | | <artifactId>plexus-utils</artifactId> |
| | | <version>1.2</version> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | |
| | | <!-- =========================================================== --> |
| | | <!-- Modules included in the build --> |
| | | <!-- =========================================================== --> |
| | | <modules> |
| | | <module>jar-collector</module> |
| | | </modules> |
| | | </project> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <project xmlns="http://maven.apache.org/POM/4.0.0" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
| | | <modelVersion>4.0.0</modelVersion> |
| | | |
| | | <parent> |
| | | <groupId>com.ximple.eofms</groupId> |
| | | <artifactId>ximple-dgnjobs</artifactId> |
| | | <version>0.9.0</version> |
| | | </parent> |
| | | |
| | | |
| | | <!-- =========================================================== --> |
| | | <!-- Module Description --> |
| | | <!-- =========================================================== --> |
| | | <groupId>com.ximple.eofms.maven</groupId> |
| | | <artifactId>ximple-build</artifactId> |
| | | <version>0.9.0</version> |
| | | <packaging>pom</packaging> |
| | | <name>Build tools for Ximple DgnJobs</name> |
| | | |
| | | <scm> |
| | | <connection> |
| | | scm:svn:http://www.ximple.com.tw/svn/xeofms/xdgnio/truck/ |
| | | </connection> |
| | | <url>http://www.ximple.com.tw/svn/xeofms/xdgnio/truck/</url> |
| | | </scm> |
| | | |
| | | <description> |
| | | Build tools for the the Ximple Dgn IO Library. |
| | | </description> |
| | | |
| | | <licenses> |
| | | <license> |
| | | <name>Lesser General Public License (LGPL)</name> |
| | | <url>http://www.gnu.org/copyleft/lesser.txt</url> |
| | | <distribution>repo</distribution> |
| | | </license> |
| | | </licenses> |
| | | |
| | | |
| | | <!-- =========================================================== --> |
| | | <!-- Modules included in the build --> |
| | | <!-- =========================================================== --> |
| | | <modules> |
| | | <module>maven</module> |
| | | </modules> |
| | | |
| | | |
| | | </project> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <project xmlns="http://maven.apache.org/POM/4.0.0" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
| | | <modelVersion>4.0.0</modelVersion> |
| | | |
| | | <parent> |
| | | <groupId>com.ximple.eofms</groupId> |
| | | <artifactId>ximple-dgnjobs</artifactId> |
| | | <version>0.9.0</version> |
| | | </parent> |
| | | |
| | | <!-- =========================================================== --> |
| | | <!-- Module Description --> |
| | | <!-- =========================================================== --> |
| | | <groupId>com.ximple.eofms</groupId> |
| | | <artifactId>ximple-dgnio</artifactId> |
| | | <version>0.9.0</version> |
| | | <packaging>jar</packaging> |
| | | <name>ximple-dgnio</name> |
| | | <url>http://www.ximple.com.tw</url> |
| | | |
| | | <scm> |
| | | <connection> |
| | | scm:svn:http://www.ximple.com.tw/svn/xeofms/xdgnio/truck/ |
| | | </connection> |
| | | <url>http://www.ximple.com.tw/svn/xeofms/xdgnio/truck/</url> |
| | | </scm> |
| | | |
| | | <description> |
| | | Ximple Dgn IO Library |
| | | </description> |
| | | |
| | | <organization> |
| | | <name>Ximple</name> |
| | | <url>http://www.ximple.com.tw</url> |
| | | </organization> |
| | | |
| | | <inceptionYear>2008</inceptionYear> |
| | | |
| | | <developers> |
| | | <developer> |
| | | <name>Kuo-Feng Kao</name> |
| | | <id>ulysseskao</id> |
| | | <email>ulysseskao@ximple.com.tw</email> |
| | | <organization>Ximple</organization> |
| | | <roles> |
| | | <role>Java Developer</role> |
| | | </roles> |
| | | </developer> |
| | | </developers> |
| | | |
| | | <contributors> |
| | | </contributors> |
| | | |
| | | |
| | | <!-- =========================================================== --> |
| | | <!-- Dependencies to be inherited by all modules. --> |
| | | <!-- =========================================================== --> |
| | | <dependencies> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-sample-data</artifactId> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.oracle</groupId> |
| | | <artifactId>ojdbc5</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.apache.poi</groupId> |
| | | <artifactId>poi</artifactId> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <!-- =========================================================== --> |
| | | <!-- Build Configuration --> |
| | | <!-- =========================================================== --> |
| | | <build> |
| | | <plugins> |
| | | </plugins> |
| | | </build> |
| | | </project> |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | import java.nio.ByteOrder; |
| | | import java.util.ArrayList; |
| | | |
| | | import org.apache.log4j.Logger; |
| | | |
| | | import com.vividsolutions.jts.geom.Coordinate; |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | import com.ximple.util.DgnUtility; |
| | | |
| | | /** |
| | | * ArcElement |
| | | * |
| | | * @author Ulysses |
| | | * @version 0.1 |
| | | * @since 2006/5/26 ¤U¤È 06:41:45 |
| | | */ |
| | | public class ArcElement extends Element implements GeometryConverter |
| | | { |
| | | private static final Logger logger = Logger.getLogger(ArcElement.class); |
| | | |
| | | public ArcElement(byte[] raw) |
| | | { |
| | | super(raw); |
| | | } |
| | | |
| | | public double getStartAngle() |
| | | { |
| | | int angle = (raw[18] & 0x0000ffff) << 16 | (raw[19] & 0x0000ffff); |
| | | return DgnUtility.converIntToRotation(angle); |
| | | } |
| | | |
| | | public void setStartAngle(double value) |
| | | { |
| | | int angle = DgnUtility.converRotatioToInt(value); |
| | | |
| | | raw[18] = (short) (angle >>> 16 & 0x0000ffff); |
| | | raw[19] = (short) (angle & 0x0000ffff); |
| | | } |
| | | |
| | | public double getSweepAngle() |
| | | { |
| | | int angle = (raw[20] & 0x0000ffff) << 16 | (raw[21] & 0x0000ffff); |
| | | if (angle < 0) |
| | | angle = -1 * (angle & 0x7fffffff); |
| | | |
| | | return DgnUtility.converIntToRotation(angle); |
| | | } |
| | | |
| | | public void setSweepAngle(double value) |
| | | { |
| | | int angle = DgnUtility.converRotatioToInt(value); |
| | | if (angle < 0) |
| | | { |
| | | angle &= 0x7fffffff; |
| | | angle |= 0x80000000; |
| | | } |
| | | |
| | | raw[20] = (short) (angle >> 16 & 0x0000ffff); |
| | | raw[21] = (short) (angle & 0x0000ffff); |
| | | } |
| | | |
| | | public double getPrimary() |
| | | { |
| | | rawBuffer.position(22 * 2); |
| | | ByteOrder bo = rawBuffer.order(); |
| | | rawBuffer.order(ByteOrder.BIG_ENDIAN); |
| | | byte[] primary = new byte[8]; |
| | | rawBuffer.get(primary); |
| | | rawBuffer.order(bo); |
| | | return DgnUtility.convertDGNToIEEEDouble(primary) / 1000.0; |
| | | } |
| | | |
| | | public void setPrimary(double value) |
| | | { |
| | | double temp = value * 1000.0; |
| | | short[] primary = DgnUtility.convertIEEEDoubleToDGN(temp); |
| | | |
| | | System.arraycopy(primary, 0, raw, 22, 4); |
| | | } |
| | | |
| | | public double getSecondary() |
| | | { |
| | | rawBuffer.position(26 * 2); |
| | | ByteOrder bo = rawBuffer.order(); |
| | | rawBuffer.order(ByteOrder.BIG_ENDIAN); |
| | | byte[] secondary = new byte[8]; |
| | | rawBuffer.get(secondary); |
| | | rawBuffer.order(bo); |
| | | return DgnUtility.convertDGNToIEEEDouble(secondary) / 1000.0; |
| | | } |
| | | |
| | | public void setSecondary(double value) |
| | | { |
| | | double temp = value * 1000.0; |
| | | short[] secondary = DgnUtility.convertIEEEDoubleToDGN(temp); |
| | | |
| | | System.arraycopy(secondary, 0, raw, 26, 4); |
| | | } |
| | | |
| | | public double getRotationAngle() |
| | | { |
| | | int rotation = (raw[30] << 16 & 0xffff0000); |
| | | rotation |= raw[31] & 0x0000ffff; |
| | | |
| | | return DgnUtility.converIntToRotation(rotation); |
| | | } |
| | | |
| | | public void setRotationAngle(double value) |
| | | { |
| | | int angle = DgnUtility.converRotatioToInt(value); |
| | | |
| | | raw[30] = (short) (angle >> 16 & 0x0000ffff); |
| | | raw[31] = (short) (angle & 0x0000ffff); |
| | | } |
| | | |
| | | public Coordinate getOrigin() |
| | | { |
| | | rawBuffer.position(32 * 2); |
| | | ByteOrder bo = rawBuffer.order(); |
| | | rawBuffer.order(ByteOrder.BIG_ENDIAN); |
| | | byte[] rawValue = new byte[8]; |
| | | |
| | | rawBuffer.get(rawValue); // x |
| | | double dx = DgnUtility.converUnitToCoord(DgnUtility.convertDGNToIEEEDouble(rawValue)); |
| | | |
| | | rawBuffer.get(rawValue); // y |
| | | double dy = DgnUtility.converUnitToCoord(DgnUtility.convertDGNToIEEEDouble(rawValue)); |
| | | |
| | | rawBuffer.order(bo); |
| | | |
| | | return new Coordinate(dx, dy); |
| | | } |
| | | |
| | | public void setOrigin(Coordinate value) |
| | | { |
| | | double temp = DgnUtility.converCoordToUnit(value.x); |
| | | short[] x = DgnUtility.convertIEEEDoubleToDGN(temp); |
| | | |
| | | System.arraycopy(x, 0, raw, 32, 4); |
| | | temp = DgnUtility.converCoordToUnit(value.y); |
| | | |
| | | short[] y = DgnUtility.convertIEEEDoubleToDGN(temp); |
| | | |
| | | System.arraycopy(y, 0, raw, 36, 4); |
| | | } |
| | | |
| | | public Geometry toGeometry(GeometryFactory factory) |
| | | { |
| | | double sweep = getSweepAngle(); |
| | | double temp = Math.abs(sweep); |
| | | temp /= 4; |
| | | int pts = (temp < 3) ? 3 : (int) temp; |
| | | return factory.createLineString(convertToLineString(pts)); |
| | | } |
| | | |
| | | private Coordinate[] convertToLineString(int pts) |
| | | { |
| | | ArrayList<Coordinate> result = new ArrayList<Coordinate>(); |
| | | double beta = DgnUtility.converRotationToRadian(-getRotationAngle()); |
| | | double startAngle = getStartAngle(); |
| | | double sweepAngle = getSweepAngle(); |
| | | double endAngle = startAngle + sweepAngle; |
| | | double steps = sweepAngle / pts; |
| | | double current; |
| | | if (sweepAngle < 0) |
| | | { |
| | | for (current = startAngle; current > endAngle; current += steps) |
| | | { |
| | | Coordinate pt = computePointOnArcByAngle(beta, current); |
| | | result.add(pt); |
| | | } |
| | | |
| | | } else |
| | | { |
| | | for (current = startAngle; current < endAngle; current += steps) |
| | | { |
| | | Coordinate pt = computePointOnArcByAngle(beta, current); |
| | | result.add(pt); |
| | | } |
| | | } |
| | | |
| | | Coordinate pt = computePointOnArcByAngle(beta, endAngle); |
| | | result.add(pt); |
| | | |
| | | return result.toArray(new Coordinate[result.size()]); |
| | | } |
| | | |
| | | private Coordinate computePointOnArcByAngle(double beta, double current) |
| | | { |
| | | double sinbeta = Math.sin(beta); |
| | | double cosbeta = Math.cos(beta); |
| | | Coordinate pt = new Coordinate(); |
| | | double alpha = DgnUtility.converRotationToRadian(current); |
| | | double sinalpha = Math.sin(alpha); |
| | | double cosalpha = Math.cos(alpha); |
| | | pt.x = getOrigin().x + (getPrimary() * cosalpha * cosbeta - |
| | | getSecondary() * sinalpha * sinbeta); |
| | | pt.y = getOrigin().y + (getPrimary() * cosalpha * sinbeta + |
| | | getSecondary() * sinalpha * cosbeta); |
| | | return pt; |
| | | } |
| | | |
| | | public static class ElementHandler extends Element.ElementHandler |
| | | { |
| | | private static ElementHandler instance = null; |
| | | |
| | | public ElementHandler() |
| | | { |
| | | super(ElementType.ARC); |
| | | } |
| | | |
| | | public static IElementHandler getInstance() |
| | | { |
| | | if (instance == null) |
| | | { |
| | | instance = new ElementHandler(); |
| | | } |
| | | |
| | | return instance; |
| | | } |
| | | |
| | | protected Element createElement(byte[] raw) |
| | | { |
| | | return new ArcElement(raw); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.ListIterator; |
| | | |
| | | import org.apache.log4j.Logger; |
| | | |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | import com.vividsolutions.jts.geom.LineString; |
| | | |
| | | /** |
| | | * ComplexChainElement |
| | | * |
| | | * @author Ulysses |
| | | * @version 0.1 |
| | | * @since 2006/5/18 ¤U¤È 03:44:56 |
| | | */ |
| | | public class ComplexChainElement extends Element implements ComplexElement, GeometryConverter |
| | | { |
| | | private static final Logger logger = Logger.getLogger(ComplexChainElement.class); |
| | | |
| | | protected ArrayList<Element> list = new ArrayList<Element>(); |
| | | |
| | | public ComplexChainElement(byte[] raw) |
| | | { |
| | | super(raw); |
| | | attrOffset = 4; |
| | | } |
| | | |
| | | public int size() |
| | | { |
| | | return list.size(); |
| | | } |
| | | |
| | | public boolean isEmpty() |
| | | { |
| | | return list.isEmpty(); |
| | | } |
| | | |
| | | public boolean contains(Object o) |
| | | { |
| | | return list.contains(o); |
| | | } |
| | | |
| | | public Iterator iterator() |
| | | { |
| | | return list.iterator(); |
| | | } |
| | | |
| | | public Object[] toArray() |
| | | { |
| | | return list.toArray(); |
| | | } |
| | | |
| | | public <T> T[] toArray(T[] ts) |
| | | { |
| | | return list.toArray(ts); |
| | | } |
| | | |
| | | public boolean add(Element element) |
| | | { |
| | | return list.add(element); |
| | | } |
| | | |
| | | public boolean remove(Object o) |
| | | { |
| | | return list.remove(o); |
| | | } |
| | | |
| | | public boolean containsAll(Collection<?> objects) |
| | | { |
| | | return list.containsAll(objects); |
| | | } |
| | | |
| | | public boolean addAll(Collection<? extends Element> elements) |
| | | { |
| | | return list.addAll(elements); |
| | | } |
| | | |
| | | public boolean addAll(int i, Collection<? extends Element> elements) |
| | | { |
| | | return list.addAll(i, elements); |
| | | } |
| | | |
| | | public boolean removeAll(Collection<?> objects) |
| | | { |
| | | return list.removeAll(objects); |
| | | } |
| | | |
| | | public boolean retainAll(Collection<?> objects) |
| | | { |
| | | return list.retainAll(objects); |
| | | } |
| | | |
| | | public void clear() |
| | | { |
| | | list.clear(); |
| | | } |
| | | |
| | | public Element get(int index) |
| | | { |
| | | return list.get(index); |
| | | } |
| | | |
| | | public Element set(int i, Element element) |
| | | { |
| | | return list.set(i, element); |
| | | } |
| | | |
| | | public void add(int i, Element element) |
| | | { |
| | | list.add(i, element); |
| | | } |
| | | |
| | | public Element remove(int index) |
| | | { |
| | | return list.remove(index); |
| | | } |
| | | |
| | | public int indexOf(Object o) |
| | | { |
| | | return list.indexOf(o); |
| | | } |
| | | |
| | | public int lastIndexOf(Object o) |
| | | { |
| | | return list.lastIndexOf(o); |
| | | } |
| | | |
| | | public ListIterator listIterator() |
| | | { |
| | | return list.listIterator(); |
| | | } |
| | | |
| | | public ListIterator listIterator(int index) |
| | | { |
| | | return list.listIterator(index); |
| | | } |
| | | |
| | | public List subList(int fromIndex, int toIndex) |
| | | { |
| | | return list.subList(fromIndex, toIndex); |
| | | } |
| | | |
| | | public Geometry toGeometry(GeometryFactory factory) |
| | | { |
| | | ArrayList<LineString> lineStrings = new ArrayList<LineString>(); |
| | | |
| | | for (ListIterator it = listIterator(); it.hasNext();) |
| | | { |
| | | Element element = (Element) it.next(); |
| | | |
| | | if (element instanceof LineStringElement) |
| | | { |
| | | if (((LineStringElement) element).getVerticeSize() == 0 || ((LineStringElement) element).getVerticeSize() > 1) |
| | | { |
| | | lineStrings.add((LineString) ((LineStringElement) element).toGeometry(factory)); |
| | | } |
| | | |
| | | } else if (element instanceof LineElement) |
| | | { |
| | | |
| | | if (((LineElement) element).getVertices().length == 0 || ((LineElement) element).getVertices().length > 1) |
| | | { |
| | | lineStrings.add((LineString) ((LineElement) element).toGeometry(factory)); |
| | | } |
| | | } else if (element instanceof ArcElement) |
| | | { |
| | | lineStrings.add((LineString) ((ArcElement) element).toGeometry(factory)); |
| | | } else { |
| | | logger.warn("Unknown sub-element in ComplexChain Element-" + element.getElementType()); |
| | | } |
| | | } |
| | | |
| | | LineString[] lines = lineStrings.toArray(new LineString[lineStrings.size()]); |
| | | if ((lines == null) || (lines.length == 0)) |
| | | return null; |
| | | return factory.createMultiLineString(lines); |
| | | } |
| | | |
| | | public double getElementSize() |
| | | { |
| | | return raw[18]; |
| | | } |
| | | |
| | | public boolean isClosed() |
| | | { |
| | | if (isEmpty()) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | public static class ElementHandler extends Element.ElementHandler |
| | | { |
| | | private static ElementHandler instance = null; |
| | | |
| | | public ElementHandler() |
| | | { |
| | | super(ElementType.COMPLEXCHAIN); |
| | | } |
| | | |
| | | public static IElementHandler getInstance() |
| | | { |
| | | if (instance == null) |
| | | { |
| | | instance = new ElementHandler(); |
| | | } |
| | | |
| | | return instance; |
| | | } |
| | | |
| | | protected Element createElement(byte[] raw) |
| | | { |
| | | return new ComplexChainElement(raw); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | //~--- JDK imports ------------------------------------------------------------ |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * ComplexElement |
| | | * |
| | | * @author Ulysses |
| | | * @version 0.1 |
| | | * @since 2006/5/18 ¤U¤È 04:17:37 |
| | | */ |
| | | public interface ComplexElement extends List<Element> |
| | | { |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | //~--- JDK imports ------------------------------------------------------------ |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.ListIterator; |
| | | |
| | | import org.apache.log4j.Logger; |
| | | |
| | | import com.vividsolutions.jts.geom.CoordinateList; |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | /** |
| | | * ComplexShapeElement |
| | | * |
| | | * @author Ulysses |
| | | * @version 0.1 |
| | | * @since 2006/5/18 ¤U¤È 03:45:15 |
| | | */ |
| | | public class ComplexShapeElement extends Element implements ComplexElement, GeometryConverter |
| | | { |
| | | private static final Logger logger = Logger.getLogger(ComplexShapeElement.class); |
| | | |
| | | ArrayList<Element> list = new ArrayList<Element>(); |
| | | |
| | | public ComplexShapeElement(byte[] raw) |
| | | { |
| | | super(raw); |
| | | } |
| | | |
| | | public int size() |
| | | { |
| | | return list.size(); |
| | | } |
| | | |
| | | public boolean isEmpty() |
| | | { |
| | | return list.isEmpty(); |
| | | } |
| | | |
| | | public boolean contains(Object o) |
| | | { |
| | | return list.contains(o); |
| | | } |
| | | |
| | | public Iterator iterator() |
| | | { |
| | | return list.iterator(); |
| | | } |
| | | |
| | | public Object[] toArray() |
| | | { |
| | | return list.toArray(); |
| | | } |
| | | |
| | | public <T> T[] toArray(T[] ts) |
| | | { |
| | | return list.toArray(ts); |
| | | } |
| | | |
| | | public boolean add(Element element) |
| | | { |
| | | return list.add(element); |
| | | } |
| | | |
| | | public boolean remove(Object o) |
| | | { |
| | | return list.remove(o); |
| | | } |
| | | |
| | | public boolean containsAll(Collection<?> objects) |
| | | { |
| | | return list.containsAll(objects); |
| | | } |
| | | |
| | | public boolean addAll(Collection<? extends Element> elements) |
| | | { |
| | | return list.addAll(elements); |
| | | } |
| | | |
| | | public boolean addAll(int i, Collection<? extends Element> elements) |
| | | { |
| | | return list.addAll(i, elements); |
| | | } |
| | | |
| | | public boolean removeAll(Collection<?> objects) |
| | | { |
| | | return list.removeAll(objects); |
| | | } |
| | | |
| | | public boolean retainAll(Collection<?> objects) |
| | | { |
| | | return list.retainAll(objects); |
| | | } |
| | | |
| | | public void clear() |
| | | { |
| | | list.clear(); |
| | | } |
| | | |
| | | public Element get(int index) |
| | | { |
| | | return list.get(index); |
| | | } |
| | | |
| | | public Element set(int i, Element element) |
| | | { |
| | | return list.set(i, element); |
| | | } |
| | | |
| | | public void add(int i, Element element) |
| | | { |
| | | list.add(i, element); |
| | | } |
| | | |
| | | public Element remove(int index) |
| | | { |
| | | return list.remove(index); |
| | | } |
| | | |
| | | public int indexOf(Object o) |
| | | { |
| | | return list.indexOf(o); |
| | | } |
| | | |
| | | public int lastIndexOf(Object o) |
| | | { |
| | | return list.lastIndexOf(o); |
| | | } |
| | | |
| | | public ListIterator listIterator() |
| | | { |
| | | return list.listIterator(); |
| | | } |
| | | |
| | | public ListIterator listIterator(int index) |
| | | { |
| | | return list.listIterator(index); |
| | | } |
| | | |
| | | public List subList(int fromIndex, int toIndex) |
| | | { |
| | | return list.subList(fromIndex, toIndex); |
| | | } |
| | | |
| | | public Geometry toGeometry(GeometryFactory factory) |
| | | { |
| | | ArrayList<Geometry> list = new ArrayList<Geometry>(); |
| | | |
| | | for (ListIterator it = listIterator(); it.hasNext();) |
| | | { |
| | | Element element = (Element) it.next(); |
| | | |
| | | if (element instanceof ShapeElement) |
| | | { |
| | | if (((ShapeElement) element).getVerticeSize() == 0 || ((ShapeElement) element).getVerticeSize() > 1) |
| | | { |
| | | list.add(((ShapeElement) element).toGeometry(factory)); |
| | | } |
| | | } else if (element instanceof LineStringElement) |
| | | { |
| | | if (((LineStringElement) element).getVerticeSize() == 0 || ((LineStringElement) element).getVerticeSize() > 1) |
| | | { |
| | | list.add(((LineStringElement) element).toGeometry(factory)); |
| | | } |
| | | } else if (element instanceof LineElement) |
| | | { |
| | | if (((LineElement) element).getVertices().length == 0 || ((LineElement) element).getVertices().length > 1) |
| | | { |
| | | list.add(((LineElement) element).toGeometry(factory)); |
| | | } |
| | | } else if (element instanceof ArcElement) |
| | | { |
| | | } |
| | | } |
| | | |
| | | |
| | | CoordinateList pts = new CoordinateList(); |
| | | for (Geometry geom : list) |
| | | { |
| | | pts.add(geom.getCoordinates(), true); |
| | | } |
| | | |
| | | return factory.createLinearRing(pts.toCoordinateArray()); |
| | | } |
| | | |
| | | public static class ElementHandler extends Element.ElementHandler |
| | | { |
| | | private static ElementHandler instance = null; |
| | | |
| | | public ElementHandler() |
| | | { |
| | | super(ElementType.COMPLEXSHAPE); |
| | | } |
| | | |
| | | public static IElementHandler getInstance() |
| | | { |
| | | if (instance == null) |
| | | { |
| | | instance = new ElementHandler(); |
| | | } |
| | | |
| | | return instance; |
| | | } |
| | | |
| | | protected Element createElement(byte[] raw) |
| | | { |
| | | return new ComplexShapeElement(raw); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | |
| | | public class Dgn7Exception extends Exception |
| | | { |
| | | public Dgn7Exception() |
| | | { |
| | | } |
| | | |
| | | public Dgn7Exception(String s) |
| | | { |
| | | super(s); |
| | | } |
| | | |
| | | public Dgn7Exception(String s, Throwable throwable) |
| | | { |
| | | super(s, throwable); |
| | | } |
| | | |
| | | public Dgn7Exception(Throwable throwable) |
| | | { |
| | | super(throwable); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.ByteOrder; |
| | | import java.sql.Connection; |
| | | import java.sql.ResultSet; |
| | | import java.sql.SQLException; |
| | | import java.sql.Statement; |
| | | import java.util.Iterator; |
| | | |
| | | import org.apache.log4j.Logger; |
| | | |
| | | import oracle.jdbc.OracleConnection; |
| | | import oracle.sql.BLOB; |
| | | |
| | | /** |
| | | * Dgn7OracleReader |
| | | * User: Ulysses |
| | | * Date: 2007/10/24 |
| | | * Time: ¤U¤È 01:01:08 |
| | | */ |
| | | public class Dgn7OracleReader implements Iterator<Element> |
| | | { |
| | | private final static Logger logger = Logger.getLogger(Dgn7OracleReader.class); |
| | | |
| | | private String _sql; |
| | | private String _fieldName; |
| | | private Connection _connection; |
| | | private ResultSet _resultSet; |
| | | private static final int FETCHSIZE = 20; |
| | | private Element _element; |
| | | |
| | | public Dgn7OracleReader(String sql, String fieldName, OracleConnection connection) |
| | | { |
| | | this._sql = sql; |
| | | this._fieldName = fieldName; |
| | | this._connection = connection; |
| | | } |
| | | |
| | | public String getSql() |
| | | { |
| | | return _sql; |
| | | } |
| | | |
| | | public void setSql(String sql) |
| | | { |
| | | this._sql = sql; |
| | | } |
| | | |
| | | public String getFieldName() |
| | | { |
| | | return _fieldName; |
| | | } |
| | | |
| | | public void setFieldName(String fieldName) |
| | | { |
| | | this._fieldName = fieldName; |
| | | } |
| | | |
| | | public boolean hasNext() |
| | | { |
| | | if (_resultSet == null) |
| | | { |
| | | try |
| | | { |
| | | initializeReader(); |
| | | } catch (SQLException e) |
| | | { |
| | | throw new RuntimeException("initialize oralce error.", e); |
| | | } catch (Dgn7Exception e) |
| | | { |
| | | throw new RuntimeException("initialize oralce error.", e); |
| | | } |
| | | } |
| | | return _element != null; |
| | | } |
| | | |
| | | public Element next() |
| | | { |
| | | Element result = _element; |
| | | |
| | | try |
| | | { |
| | | fetchElement(); |
| | | } catch (SQLException e) |
| | | { |
| | | throw new RuntimeException("Error:" + e.getMessage(), e); |
| | | } catch (Dgn7Exception e) |
| | | { |
| | | throw new RuntimeException("Error:" + e.getMessage(), e); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | public void remove() |
| | | { |
| | | throw new RuntimeException("Not Support this method."); |
| | | } |
| | | |
| | | private boolean initializeReader() throws SQLException, Dgn7Exception |
| | | { |
| | | if (_resultSet != null) return true; |
| | | Statement stmtSrc = _connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
| | | |
| | | stmtSrc.setFetchSize(FETCHSIZE); |
| | | _resultSet = stmtSrc.executeQuery(_sql); |
| | | |
| | | fetchElement(); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | private boolean fetchElement() throws SQLException, Dgn7Exception |
| | | { |
| | | if (_resultSet.next()) |
| | | { |
| | | byte[] raw = null; |
| | | Object value = _resultSet.getObject(this._fieldName); |
| | | |
| | | if (value instanceof BLOB) |
| | | { |
| | | BLOB blob = (BLOB) value; |
| | | |
| | | try |
| | | { |
| | | raw = getBytesFromBLOB(blob); |
| | | } catch (IOException e) |
| | | { |
| | | throw new Dgn7Exception("IOError", e); |
| | | } |
| | | blob.close(); |
| | | } else if (value instanceof byte[]) |
| | | { |
| | | raw = (byte[]) value; |
| | | } |
| | | if (raw == null) |
| | | { |
| | | _element = null; |
| | | return false; |
| | | } |
| | | |
| | | ByteBuffer buffer = ByteBuffer.wrap(raw); |
| | | buffer.order(ByteOrder.LITTLE_ENDIAN); |
| | | short signature = buffer.getShort(); |
| | | |
| | | // byte type = (byte) (buffer.get() & 0x7f); |
| | | byte type = (byte) ((signature >>> 8) & 0x007f); |
| | | |
| | | // silly Bentley say contentLength is in 2-byte words |
| | | // and ByteByffer uses bytes. |
| | | // track the record location |
| | | int elementLength = (buffer.getShort() * 2) + 4; |
| | | ElementType recordType = ElementType.forID(type); |
| | | IElementHandler handler = recordType.getElementHandler(); |
| | | _element = (Element) handler.read(buffer, signature, elementLength); |
| | | if (recordType.isComplexElement() && (elementLength < raw.length)) |
| | | { |
| | | int offset = elementLength; |
| | | while (offset < (raw.length - 4)) |
| | | { |
| | | buffer.position(offset); |
| | | signature = buffer.getShort(); |
| | | type = (byte) ((signature >>> 8) & 0x007f); |
| | | elementLength = (buffer.getShort() * 2) + 4; |
| | | if (raw.length < (offset + elementLength)) |
| | | { |
| | | System.out.println("Length not match:" + offset + ":" + buffer.position() + ":" + buffer.limit()); |
| | | break; |
| | | } |
| | | recordType = ElementType.forID(type); |
| | | handler = recordType.getElementHandler(); |
| | | if (handler != null) |
| | | { |
| | | Element subElement = (Element) handler.read(buffer, signature, elementLength); |
| | | ((ComplexElement) _element).add(subElement); |
| | | offset += elementLength; |
| | | } else |
| | | { |
| | | byte[] remain = new byte[buffer.remaining()]; |
| | | System.arraycopy(raw, offset, remain, 0, buffer.remaining()); |
| | | for (int i = 0; i < remain.length; i++) |
| | | { |
| | | if (remain[i] != 0) |
| | | { |
| | | logger.info("fetch element has some error. index=" + (offset + i) + ":value=" + remain[i]); |
| | | System.out.println("fetch element has some error. index=" + (offset + i) + ":value=" + remain[i]); |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | } else |
| | | { |
| | | _element = null; |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | protected static byte[] getBytesFromBLOB(BLOB blob) throws SQLException, IOException |
| | | { |
| | | byte[] raw; |
| | | |
| | | // BLOB blob = (BLOB) rs.getBlob(1); |
| | | int optimalSize = blob.getChunkSize(); |
| | | byte[] chunk = new byte[optimalSize]; |
| | | InputStream is = blob.getBinaryStream(0); |
| | | ByteBuffer buffer = null; // ByteBuffer.allocate(optimalSize); |
| | | int len; |
| | | |
| | | try |
| | | { |
| | | while ((len = (is.read(chunk))) != -1) |
| | | { |
| | | if (buffer != null) |
| | | { |
| | | buffer.limit(buffer.limit() + len); |
| | | } else |
| | | { |
| | | buffer = ByteBuffer.allocate(len); |
| | | } |
| | | |
| | | buffer.put(chunk); |
| | | } |
| | | |
| | | is.close(); |
| | | assert buffer != null; |
| | | buffer.position(0); |
| | | raw = buffer.array(); |
| | | } catch (IOException e) |
| | | { |
| | | e.printStackTrace(); |
| | | throw e; |
| | | } |
| | | |
| | | return raw; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | public class Dgn7fileException extends Dgn7Exception |
| | | { |
| | | |
| | | public Dgn7fileException() |
| | | { |
| | | } |
| | | |
| | | public Dgn7fileException(String message) |
| | | { |
| | | super(message); |
| | | } |
| | | |
| | | public Dgn7fileException(String message, Throwable cause) |
| | | { |
| | | super(message, cause); |
| | | } |
| | | |
| | | public Dgn7fileException(Throwable cause) |
| | | { |
| | | super(cause); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | //~--- JDK imports ------------------------------------------------------------ |
| | | |
| | | import java.io.IOException; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.ByteOrder; |
| | | |
| | | import com.vividsolutions.jts.util.Assert; |
| | | |
| | | /** |
| | | * Dgn7fileHeader |
| | | * |
| | | * @author Ulysses |
| | | * @version 0.1 |
| | | * @since 2006/5/17 ¤U¤È 01:21:00 |
| | | */ |
| | | public class Dgn7fileHeader |
| | | { |
| | | private short elmtype; |
| | | private byte[] raw; |
| | | |
| | | public Dgn7fileHeader() |
| | | { |
| | | } |
| | | |
| | | public void read(ByteBuffer file, boolean strict) throws IOException |
| | | { |
| | | file.order(ByteOrder.LITTLE_ENDIAN); |
| | | elmtype = file.getShort(); |
| | | |
| | | short wtf = file.getShort(); |
| | | int length = (wtf * 2); |
| | | |
| | | if (file.remaining() != (length)) |
| | | { |
| | | Assert.shouldNeverReachHere(); |
| | | } |
| | | |
| | | raw = new byte[length]; |
| | | file.get(raw, 0, file.remaining()); |
| | | } |
| | | |
| | | public String toString() |
| | | { |
| | | return "Dgn7fileHeader{" + "raw=" + ((raw == null) ? "null" : raw.length) + '}'; |
| | | } |
| | | |
| | | public int size() |
| | | { |
| | | if (raw == null) |
| | | { |
| | | return 0; |
| | | } |
| | | |
| | | return raw.length + 4; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | //~--- JDK imports ------------------------------------------------------------ |
| | | |
| | | import java.io.EOFException; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.ByteOrder; |
| | | import java.nio.MappedByteBuffer; |
| | | import java.nio.channels.FileChannel; |
| | | import java.nio.channels.ReadableByteChannel; |
| | | import javax.swing.JFileChooser; |
| | | import javax.swing.JFrame; |
| | | |
| | | import org.apache.log4j.LogManager; |
| | | import org.apache.log4j.Logger; |
| | | |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | import com.ximple.util.DgnUtility; |
| | | |
| | | |
| | | /** |
| | | * Dgn7fileReader |
| | | * |
| | | * @author Ulysses |
| | | * @version 0.1 |
| | | * @since 2006/5/17 ¤U¤È 01:24:10 |
| | | */ |
| | | public class Dgn7fileReader |
| | | { |
| | | private static final Logger logger = LogManager.getLogger(Dgn7fileReader.class); |
| | | |
| | | private Dgn7fileHeader header; |
| | | private ReadableByteChannel channel; |
| | | ByteBuffer buffer; |
| | | private ElementType fileElementType = ElementType.UNDEFINED; |
| | | private ByteBuffer headerTransfer; |
| | | private final Record record = new Record(); |
| | | private final boolean randomAccessEnabled; |
| | | private Lock lock; |
| | | private boolean useMemoryMappedBuffer; |
| | | private long currentOffset = 0L; |
| | | private StreamLogging streamLogger = new StreamLogging("Shapefile Reader"); |
| | | private int maxElementId = 0; |
| | | |
| | | public Dgn7fileReader(ReadableByteChannel channel, boolean strict, boolean useMemoryMapped, Lock lock) |
| | | throws IOException, Dgn7fileException |
| | | { |
| | | this.channel = channel; |
| | | this.useMemoryMappedBuffer = useMemoryMapped; |
| | | streamLogger.open(); |
| | | randomAccessEnabled = channel instanceof FileChannel; |
| | | this.lock = lock; |
| | | lock.lockRead(); |
| | | init(strict); |
| | | } |
| | | |
| | | public Dgn7fileReader(ReadableByteChannel channel, Lock lock) throws IOException, Dgn7fileException |
| | | { |
| | | this(channel, true, true, lock); |
| | | } |
| | | |
| | | // ensure the capacity of the buffer is of size by doubling the original |
| | | // capacity until it is big enough |
| | | // this may be naiive and result in out of MemoryError as implemented... |
| | | public static ByteBuffer ensureCapacity(ByteBuffer buffer, int size, boolean useMemoryMappedBuffer) |
| | | { |
| | | // This sucks if you accidentally pass is a MemoryMappedBuffer of size |
| | | // 80M |
| | | // like I did while messing around, within moments I had 1 gig of |
| | | // swap... |
| | | if (buffer.isReadOnly() || useMemoryMappedBuffer) |
| | | { |
| | | return buffer; |
| | | } |
| | | |
| | | int limit = buffer.limit(); |
| | | |
| | | while (limit < size) |
| | | { |
| | | limit *= 2; |
| | | } |
| | | |
| | | if (limit != buffer.limit()) |
| | | { |
| | | // if (record.ready) { |
| | | buffer = ByteBuffer.allocateDirect(limit); |
| | | |
| | | // } |
| | | // else { |
| | | // throw new IllegalArgumentException("next before hasNext"); |
| | | // } |
| | | } |
| | | |
| | | return buffer; |
| | | } |
| | | |
| | | // for filling a ReadableByteChannel |
| | | public static int fill(ByteBuffer buffer, ReadableByteChannel channel) throws IOException |
| | | { |
| | | int r = buffer.remaining(); |
| | | |
| | | // channel reads return -1 when EOF or other error |
| | | // because they a non-blocking reads, 0 is a valid return value!! |
| | | while ((buffer.remaining() > 0) && (r != -1)) |
| | | { |
| | | r = channel.read(buffer); |
| | | } |
| | | |
| | | if (r == -1) |
| | | { |
| | | buffer.limit(buffer.position()); |
| | | } |
| | | |
| | | return r; |
| | | } |
| | | |
| | | public static Dgn7fileHeader readHeader(ReadableByteChannel channel, boolean strict) throws IOException |
| | | { |
| | | ByteBuffer buffer = ByteBuffer.allocateDirect(4); |
| | | |
| | | if (fill(buffer, channel) == -1) |
| | | { |
| | | throw new EOFException("Premature end of header"); |
| | | } |
| | | |
| | | buffer.order(ByteOrder.LITTLE_ENDIAN); |
| | | |
| | | int length = buffer.getShort(2) * 2; |
| | | ByteBuffer old = buffer; |
| | | |
| | | old.position(0); |
| | | |
| | | // ensure enough capacity for one more record header |
| | | buffer = ByteBuffer.allocateDirect(length + 4); |
| | | buffer.put(old); |
| | | |
| | | if (fill(buffer, channel) == -1) |
| | | { |
| | | throw new EOFException("Premature end of header"); |
| | | } |
| | | |
| | | buffer.position(0); |
| | | |
| | | Dgn7fileHeader header = new Dgn7fileHeader(); |
| | | |
| | | header.read(buffer, strict); |
| | | |
| | | return header; |
| | | } |
| | | |
| | | public Dgn7fileHeader getHeader() |
| | | { |
| | | return header; |
| | | } |
| | | |
| | | public void close() throws IOException |
| | | { |
| | | lock.unlockRead(); |
| | | |
| | | if (channel.isOpen()) |
| | | { |
| | | channel.close(); |
| | | streamLogger.close(); |
| | | } |
| | | |
| | | if (buffer instanceof MappedByteBuffer) |
| | | { |
| | | NIOUtilities.clean(buffer); |
| | | } |
| | | |
| | | channel = null; |
| | | header = null; |
| | | } |
| | | |
| | | public boolean supportsRandomAccess() |
| | | { |
| | | return randomAccessEnabled; |
| | | } |
| | | |
| | | public Record nextElement() throws IOException, Dgn7fileException |
| | | { |
| | | // need to update position |
| | | buffer.position(this.toBufferOffset(record.end)); |
| | | |
| | | // record header is big endian |
| | | buffer.order(ByteOrder.LITTLE_ENDIAN); |
| | | |
| | | // read shape record header |
| | | int recordNumber = ++maxElementId; |
| | | short signature = buffer.getShort(); |
| | | |
| | | // byte type = (byte) (buffer.get() & 0x7f); |
| | | byte type = (byte) ((signature >>> 8) & 0x007f); |
| | | |
| | | // silly Bentley say contentLength is in 2-byte words |
| | | // and ByteByffer uses bytes. |
| | | // track the record location |
| | | int elementLength = (buffer.getShort() * 2) + 4; |
| | | |
| | | if (!buffer.isReadOnly() && !useMemoryMappedBuffer) |
| | | { |
| | | // capacity is less than required for the record |
| | | // copy the old into the newly allocated |
| | | if (buffer.capacity() < elementLength) |
| | | { |
| | | this.currentOffset += buffer.position(); |
| | | |
| | | ByteBuffer old = buffer; |
| | | |
| | | // ensure enough capacity for one more record header |
| | | buffer = ensureCapacity(buffer, elementLength, useMemoryMappedBuffer); |
| | | buffer.put(old); |
| | | fill(buffer, channel); |
| | | buffer.position(0); |
| | | } else |
| | | |
| | | // remaining is less than record length |
| | | // compact the remaining data and read again, |
| | | // allowing enough room for one more record header |
| | | if (buffer.remaining() < elementLength) |
| | | { |
| | | this.currentOffset += buffer.position(); |
| | | buffer.compact(); |
| | | fill(buffer, channel); |
| | | buffer.position(0); |
| | | } |
| | | } |
| | | |
| | | // shape record is all little endian |
| | | // buffer.order(ByteOrder.LITTLE_ENDIAN); |
| | | // read the type, handlers don't need it |
| | | ElementType recordType = ElementType.forID(type); |
| | | |
| | | logger.debug("nextElement at " + this.toBufferOffset(record.end) + ":type=" + type); |
| | | |
| | | // this usually happens if the handler logic is bunk, |
| | | // but bad files could exist as well... |
| | | |
| | | /* |
| | | * if (recordType != ElementType.NULL && recordType != fileElementType) |
| | | * { |
| | | * throw new IllegalStateException("ShapeType changed illegally from " + fileElementType + " to " + recordType); |
| | | * } |
| | | */ |
| | | |
| | | // peek at bounds, then reset for handler |
| | | // many handler's may ignore bounds reading, but we don't want to |
| | | // second guess them... |
| | | buffer.mark(); |
| | | |
| | | if (recordType.isMultiPoint()) |
| | | { |
| | | int lowCoorX = buffer.getInt(); |
| | | |
| | | lowCoorX = DgnUtility.convertFromDGN(lowCoorX); |
| | | record.minX = DgnUtility.converUnitToCoord(lowCoorX); |
| | | |
| | | int lowCoorY = buffer.getInt(); |
| | | |
| | | lowCoorY = DgnUtility.convertFromDGN(lowCoorY); |
| | | record.minY = DgnUtility.converUnitToCoord(lowCoorY); |
| | | |
| | | int lowCoorZ = buffer.getInt(); |
| | | |
| | | lowCoorZ = DgnUtility.convertFromDGN(lowCoorZ); |
| | | record.minZ = DgnUtility.converUnitToCoord(lowCoorZ); |
| | | |
| | | int highCoorX = buffer.getInt(); |
| | | |
| | | highCoorX = DgnUtility.convertFromDGN(highCoorX); |
| | | record.maxX = DgnUtility.converUnitToCoord(highCoorX); |
| | | |
| | | int highCoorY = buffer.getInt(); |
| | | |
| | | highCoorY = DgnUtility.convertFromDGN(highCoorY); |
| | | record.maxY = DgnUtility.converUnitToCoord(highCoorY); |
| | | |
| | | int highCoorZ = buffer.getInt(); |
| | | |
| | | highCoorZ = DgnUtility.convertFromDGN(highCoorZ); |
| | | record.maxZ = DgnUtility.converUnitToCoord(highCoorZ); |
| | | } |
| | | |
| | | buffer.reset(); |
| | | record.offset = record.end; |
| | | |
| | | // update all the record info. |
| | | record.length = elementLength; |
| | | record.signature = signature; |
| | | record.number = recordNumber; |
| | | |
| | | // remember, we read one int already... |
| | | record.end = this.toFileOffset(buffer.position()) + elementLength - 4; |
| | | // record.end = this.toFileOffset(buffer.position()) + elementLength; |
| | | |
| | | // mark this position for the reader |
| | | record.start = buffer.position(); |
| | | |
| | | // clear any cached record |
| | | record.handler = recordType.getElementHandler(); |
| | | record.element = null; |
| | | |
| | | return record; |
| | | } |
| | | |
| | | public void goTo(int offset) throws IOException, UnsupportedOperationException |
| | | { |
| | | if (randomAccessEnabled) |
| | | { |
| | | if (this.useMemoryMappedBuffer) |
| | | { |
| | | buffer.position(offset); |
| | | } else |
| | | { |
| | | /* |
| | | * Check to see if requested offset is already loaded; ensure |
| | | * that record header is in the buffer |
| | | */ |
| | | if ((this.currentOffset <= offset) && (this.currentOffset + buffer.limit() >= offset + 4)) |
| | | { |
| | | buffer.position(this.toBufferOffset(offset)); |
| | | } else |
| | | { |
| | | FileChannel fc = (FileChannel) this.channel; |
| | | |
| | | fc.position(offset); |
| | | this.currentOffset = offset; |
| | | buffer.position(0); |
| | | fill(buffer, fc); |
| | | buffer.position(0); |
| | | } |
| | | } |
| | | |
| | | int oldRecordOffset = record.end; |
| | | |
| | | record.end = offset; |
| | | |
| | | try |
| | | { |
| | | hasNext(); |
| | | } catch (IOException ioe) |
| | | { |
| | | record.end = oldRecordOffset; |
| | | |
| | | throw ioe; |
| | | } |
| | | } else |
| | | { |
| | | throw new UnsupportedOperationException("Random Access not enabled"); |
| | | } |
| | | } |
| | | |
| | | public Record elementAt(int offset) throws IOException, UnsupportedOperationException, Dgn7fileException |
| | | { |
| | | if (randomAccessEnabled) |
| | | { |
| | | this.goTo(offset); |
| | | |
| | | return nextElement(); |
| | | } |
| | | |
| | | throw new UnsupportedOperationException("Random Access not enabled"); |
| | | } |
| | | |
| | | public boolean hasNext() throws IOException |
| | | { |
| | | // mark current position |
| | | int position = buffer.position(); |
| | | |
| | | // ensure the proper position, regardless of read or handler behavior |
| | | try |
| | | { |
| | | buffer.position(this.toBufferOffset(record.end)); |
| | | } catch (IllegalArgumentException e) |
| | | { |
| | | logger.warn("position=" + this.toBufferOffset(record.end), e); |
| | | |
| | | return false; |
| | | } |
| | | |
| | | // no more data left |
| | | if (buffer.remaining() < 4) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | // looks good |
| | | boolean hasNext = true; |
| | | short type = buffer.getShort(); |
| | | |
| | | if (type == -1) |
| | | { |
| | | hasNext = false; |
| | | } |
| | | |
| | | // reset things to as they were |
| | | buffer.position(position); |
| | | |
| | | return hasNext; |
| | | } |
| | | |
| | | private void init(boolean strict) throws IOException, Dgn7fileException |
| | | { |
| | | header = readHeader(channel, strict); |
| | | |
| | | // fileElementType = header.getElementType(); |
| | | // handler = fileElementType.getElementHandler(); |
| | | |
| | | // recordHeader = ByteBuffer.allocateDirect(4); |
| | | // recordHeader.order(ByteOrder.BIG_ENDIAN); |
| | | // if (handler == null) |
| | | // { |
| | | // throw new IOException("Unsuported shape type:" + fileElementType); |
| | | // } |
| | | if ((channel instanceof FileChannel) && useMemoryMappedBuffer) |
| | | { |
| | | FileChannel fc = (FileChannel) channel; |
| | | |
| | | buffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); |
| | | |
| | | // buffer.position(100); |
| | | buffer.position(header.size()); |
| | | this.currentOffset = 0; |
| | | } else |
| | | { |
| | | // force useMemoryMappedBuffer to false |
| | | this.useMemoryMappedBuffer = false; |
| | | |
| | | // start with 8K buffer |
| | | buffer = ByteBuffer.allocateDirect(8 * 1024); |
| | | fill(buffer, channel); |
| | | buffer.flip(); |
| | | this.currentOffset = header.size(); |
| | | } |
| | | |
| | | headerTransfer = ByteBuffer.allocate(4); |
| | | headerTransfer.order(ByteOrder.LITTLE_ENDIAN); |
| | | |
| | | // make sure the record end is set now... |
| | | record.end = toFileOffset(buffer.position()); |
| | | } |
| | | |
| | | private int toBufferOffset(int offset) |
| | | { |
| | | return (int) (offset - currentOffset); |
| | | } |
| | | |
| | | private int toFileOffset(int offset) |
| | | { |
| | | return (int) (currentOffset + offset); |
| | | } |
| | | |
| | | public int getCount(int count) throws Dgn7fileException |
| | | { |
| | | try |
| | | { |
| | | if (channel == null) |
| | | { |
| | | return -1; |
| | | } |
| | | |
| | | count = 0; |
| | | |
| | | for (int tmp = readElement(); tmp != -1; tmp = readElement()) |
| | | { |
| | | count += tmp; |
| | | } |
| | | } catch (IOException ioe) |
| | | { |
| | | count = -1; |
| | | |
| | | // What now? This seems arbitrarily appropriate ! |
| | | throw new Dgn7fileException("Problem reading dgnfile record", ioe); |
| | | } |
| | | |
| | | return count; |
| | | } |
| | | |
| | | public int getCount() throws Dgn7fileException |
| | | { |
| | | return getCount(0); |
| | | } |
| | | |
| | | private int readElement() throws IOException |
| | | { |
| | | if (!fillBuffer()) |
| | | { |
| | | return -1; |
| | | } |
| | | |
| | | // burn the record number |
| | | buffer.getInt(); |
| | | |
| | | if (!fillBuffer()) |
| | | { |
| | | return -1; |
| | | } |
| | | |
| | | int recordlength = buffer.getInt() * 2; |
| | | |
| | | // Going to read the first 4 bytes of the record so |
| | | // subtract that from the record length |
| | | recordlength -= 4; |
| | | |
| | | if (!fillBuffer()) |
| | | { |
| | | return -1; |
| | | } |
| | | |
| | | // read record type (used to determine if record is a null record) |
| | | int type = buffer.getInt(); |
| | | |
| | | // go to end of record |
| | | while (buffer.limit() < buffer.position() + recordlength) |
| | | { |
| | | recordlength -= buffer.limit() - buffer.position(); |
| | | buffer.clear(); |
| | | |
| | | if (channel.read(buffer) < 1) |
| | | { |
| | | return -1; |
| | | } |
| | | } |
| | | |
| | | buffer.position(buffer.position() + recordlength); |
| | | |
| | | // return 0 if record is null. Null records should be counted. |
| | | if (type == 0) |
| | | { |
| | | // this is a null feature |
| | | return 0; |
| | | } |
| | | |
| | | return 1; |
| | | } |
| | | |
| | | private boolean fillBuffer() throws IOException |
| | | { |
| | | int result = 1; |
| | | |
| | | if (buffer.limit() <= buffer.position() + 4) |
| | | { |
| | | result = fill(buffer, channel); |
| | | } |
| | | |
| | | return result > 0; |
| | | } |
| | | |
| | | public static void main(String[] args) |
| | | { |
| | | JFileChooser jfc = new JFileChooser("D:/TEMP"); |
| | | File f = null; |
| | | int r = jfc.showOpenDialog(new JFrame()); |
| | | |
| | | if (r == JFileChooser.APPROVE_OPTION) |
| | | { |
| | | try |
| | | { |
| | | f = jfc.getSelectedFile(); |
| | | |
| | | FileChannel channel = new FileInputStream(f).getChannel(); |
| | | Dgn7fileReader reader = new Dgn7fileReader(channel, new Lock()); |
| | | |
| | | System.out.println(reader.getHeader().toString()); |
| | | |
| | | GeometryFactory factory = new GeometryFactory(); |
| | | int count, size; |
| | | |
| | | count = 0; |
| | | size = 0; |
| | | |
| | | try |
| | | { |
| | | Element lastComplex = null; |
| | | |
| | | while (reader.hasNext()) |
| | | { |
| | | size++; |
| | | |
| | | Dgn7fileReader.Record record = reader.nextElement(); |
| | | |
| | | if (record.element() != null) |
| | | { |
| | | Element element = (Element) record.element(); |
| | | ElementType type = element.getElementType(); |
| | | |
| | | if ((!type.isComplexElement()) && (!element.isComponentElement())) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | // @todo add process in here |
| | | count++; |
| | | lastComplex = null; |
| | | } |
| | | |
| | | // @todo add process in here |
| | | count++; |
| | | } else if (element.isComponentElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | ((ComplexElement) lastComplex).add(element); |
| | | } |
| | | } else if (type.isComplexElement()) |
| | | { |
| | | if (lastComplex == null) |
| | | { |
| | | lastComplex = element; |
| | | } else |
| | | { |
| | | // @todo add process in here |
| | | count++; |
| | | lastComplex = element; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } catch (IOException e) |
| | | { |
| | | logger.warn("Stop read dgn file", e); |
| | | } catch (Dgn7fileException e) |
| | | { |
| | | e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. |
| | | } finally |
| | | { |
| | | reader.close(); |
| | | } |
| | | |
| | | System.out.println("count=" + count + " size=" + size); |
| | | // reader.close(); |
| | | } catch (IOException ioe) |
| | | { |
| | | System.out.println(ioe); |
| | | ioe.printStackTrace(); |
| | | } catch (Dgn7fileException e) |
| | | { |
| | | e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. |
| | | } |
| | | } |
| | | |
| | | System.exit(0); |
| | | } |
| | | |
| | | public final class Record |
| | | { |
| | | int length; |
| | | int number = 0; |
| | | int offset; // Relative to the whole file |
| | | int start = 0; // Relative to the current loaded buffer |
| | | short signature = 0; |
| | | |
| | | /** |
| | | * The minimum X value. |
| | | */ |
| | | public double minX; |
| | | |
| | | /** |
| | | * The minimum Y value. |
| | | */ |
| | | public double minY; |
| | | |
| | | /** |
| | | * The minimum Z value. |
| | | */ |
| | | public double minZ; |
| | | |
| | | /** |
| | | * The maximum X value. |
| | | */ |
| | | public double maxX; |
| | | |
| | | /** |
| | | * The maximum Y value. |
| | | */ |
| | | public double maxY; |
| | | |
| | | /** |
| | | * The maximum Z value. |
| | | */ |
| | | public double maxZ; |
| | | |
| | | // ElementType type; |
| | | int end = 0; // Relative to the whole file |
| | | Object element = null; |
| | | IElementHandler handler; |
| | | |
| | | public Object element() |
| | | { |
| | | if (element == null) |
| | | { |
| | | buffer.position(start); |
| | | buffer.order(ByteOrder.LITTLE_ENDIAN); |
| | | |
| | | if (handler == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | element = handler.read(buffer, signature, length); |
| | | } |
| | | |
| | | return element; |
| | | } |
| | | |
| | | public int offset() |
| | | { |
| | | return offset; |
| | | } |
| | | |
| | | /** |
| | | * A summary of the record. |
| | | */ |
| | | public String toString() |
| | | { |
| | | return "Record " + number + " length " + length + " bounds " + minX + "," + minY + " " + maxX + "," + maxY; |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | //~--- JDK imports ------------------------------------------------------------ |
| | | |
| | | import java.nio.BufferUnderflowException; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.ByteOrder; |
| | | import java.nio.ShortBuffer; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import com.vividsolutions.jts.geom.Envelope; |
| | | |
| | | import com.ximple.util.DgnUtility; |
| | | |
| | | /** |
| | | * Record |
| | | * |
| | | * @author Ulysses |
| | | * @version 0.1 |
| | | * @since 2006/5/18 ¤W¤È 11:14:50 |
| | | */ |
| | | public class Element |
| | | { |
| | | public static final int CONSTRUCTION_CLASS = 0; |
| | | public static final int CONSTRUCTION_RULE_CLASS = 0; |
| | | public static final int DIMENSION_CLASS = 0; |
| | | public static final int LINEAR_PATTERNED_CLASS = 0; |
| | | public static final int MAX_ELEMENT_SIZE = 0; |
| | | public static final int MAX_VERTICES = 100; |
| | | public static final int PATTERN_AREA = 0; |
| | | public static final int PATTERN_COMPONENT_CLASS = 0; |
| | | public static final int PATTERN_CROSSHATCH = 0; |
| | | public static final int PATTERN_HATCH = 0; |
| | | public static final int PRIMARY_CLASS = 0; |
| | | public static final int PRIMARY_RULE_CLASS = 0; |
| | | |
| | | protected short[] raw; |
| | | protected byte attrOffset = 0; |
| | | protected ByteBuffer rawBuffer; |
| | | |
| | | public Element(byte[] raw) |
| | | { |
| | | // this.raw = raw; |
| | | this.raw = new short[raw.length / 2]; |
| | | rawBuffer = ByteBuffer.wrap(raw); |
| | | rawBuffer.order(ByteOrder.LITTLE_ENDIAN); |
| | | rawBuffer.asShortBuffer().get(this.raw); |
| | | } |
| | | |
| | | public int getLineStyle() |
| | | { |
| | | return (raw[17] & 0x0007); |
| | | } |
| | | |
| | | public Envelope getRange() |
| | | { |
| | | int lowCoorX = ((raw[3] << 16) & 0xffff0000) + (raw[2] & 0x0000ffff); |
| | | lowCoorX = DgnUtility.convertFromDGN(lowCoorX); |
| | | |
| | | int lowCoorY = ((raw[5] << 16) & 0xffff0000) + (raw[4] & 0x0000ffff); |
| | | lowCoorY = DgnUtility.convertFromDGN(lowCoorY); |
| | | |
| | | int highCoorX = ((raw[9] << 16) & 0xffff0000) + (raw[8] & 0x0000ffff); |
| | | highCoorX = DgnUtility.convertFromDGN(highCoorX); |
| | | |
| | | int highCoorY = ((raw[11] << 16) & 0xffff0000) + (raw[10] & 0x0000ffff); |
| | | highCoorY = DgnUtility.convertFromDGN(highCoorY); |
| | | |
| | | return new Envelope(DgnUtility.converUnitToCoord(lowCoorX), DgnUtility.converUnitToCoord(highCoorX), |
| | | DgnUtility.converUnitToCoord(lowCoorY), DgnUtility.converUnitToCoord(highCoorY)); |
| | | } |
| | | |
| | | public void setRange(Envelope bbox) |
| | | { |
| | | int lowCoordX = DgnUtility.converCoordToUnit(bbox.getMinX()); |
| | | int temp = DgnUtility.converToDGN(lowCoordX); |
| | | raw[3] = (short) (temp >> 16 & 0x0000ffff); |
| | | raw[2] = (short) (temp & 0x0000ffff); |
| | | |
| | | int lowCoordY = DgnUtility.converCoordToUnit(bbox.getMinY()); |
| | | temp = DgnUtility.converToDGN(lowCoordY); |
| | | raw[5] = (short) (temp >> 16 & 0x0000ffff); |
| | | raw[4] = (short) (temp & 0x0000ffff); |
| | | |
| | | int highCoorX = DgnUtility.converCoordToUnit(bbox.getMaxX()); |
| | | temp = DgnUtility.converToDGN(highCoorX); |
| | | raw[9] = (short) (temp >> 16 & 0x0000ffff); |
| | | raw[8] = (short) (temp & 0x0000ffff); |
| | | |
| | | int highCoorY = DgnUtility.converCoordToUnit(bbox.getMaxY()); |
| | | temp = DgnUtility.converToDGN(highCoorY); |
| | | raw[11] = (short) (temp >> 16 & 0x0000ffff); |
| | | raw[10] = (short) (temp & 0x0000ffff); |
| | | } |
| | | |
| | | public boolean isComponentElement() |
| | | { |
| | | return (short) ((raw[0] >>> 7) & 0x0001) == 1; |
| | | } |
| | | |
| | | public boolean removeUserAttributeData(int iLinkageId) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | public boolean removeUserAttributeData(int iLinkageId, int iLinkageIndex) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | public boolean isDeleted() |
| | | { |
| | | return (short) ((raw[0] >>> 15) & 0x0001) == 1; |
| | | } |
| | | |
| | | public int getColorIndex() |
| | | { |
| | | return ((raw[17] >>> 8) & 0x00ff); |
| | | } |
| | | |
| | | public int getType() |
| | | { |
| | | return ((raw[0] >>> 8) & 0x007f); |
| | | } |
| | | |
| | | public ElementType getElementType() |
| | | { |
| | | return ElementType.forID(getType()); |
| | | } |
| | | |
| | | public int getLevelIndex() |
| | | { |
| | | return (raw[0] & 0x003f); |
| | | } |
| | | |
| | | public void setLevelIndex(int value) |
| | | { |
| | | raw[0] = (short) ((raw[0] & 0xffc0) | (value & 0x003f)); |
| | | } |
| | | |
| | | public int getWeight() |
| | | { |
| | | return ((raw[17] >>> 3) & 0x001f); |
| | | } |
| | | |
| | | public void setWeight(int value) |
| | | { |
| | | if (value > -1 && value < 31) |
| | | { |
| | | raw[17] = (short) ((raw[17] & 0xff07) | (value << 3 & 0x00f8)); |
| | | } |
| | | else |
| | | { |
| | | throw new RuntimeException("Out of Range!"); |
| | | } |
| | | } |
| | | |
| | | public void addUserAttributeData(byte[] pDataBlock, Class dataClass, int iLinkageId) throws Element.Exception |
| | | { |
| | | } |
| | | |
| | | public void addUserAttributeData(byte[] pDataBlock, int iLinkageId, Object oDataDef) throws Element.Exception |
| | | { |
| | | } |
| | | |
| | | public boolean hasUserAttributeData() |
| | | { |
| | | if (raw[15] <= 0) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | short index = (short) (raw[15] + 16); |
| | | |
| | | if (index == -1) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | public List<UserAttributeData> getUserAttributeData() |
| | | { |
| | | short[] data; |
| | | short length, nextAttribute; |
| | | |
| | | if (raw[15] <= 0) |
| | | { |
| | | return new ArrayList<UserAttributeData>(); |
| | | } |
| | | |
| | | short index = (short) (raw[15] + 16 + attrOffset); |
| | | |
| | | if (index == -1) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | ArrayList<UserAttributeData> aLinkageSet = new ArrayList<UserAttributeData>(); |
| | | |
| | | while (index < raw.length) |
| | | { |
| | | length = (short) (raw[index] & (short) 0x00ff); |
| | | |
| | | if (length == 0) |
| | | { |
| | | break; |
| | | } |
| | | |
| | | nextAttribute = (short) (index + length + 1); |
| | | data = new short[length]; |
| | | System.arraycopy(raw, index + 1, data, 0, length); |
| | | |
| | | if (data[0] == (short) 0x0020) |
| | | { |
| | | aLinkageSet.add(new FrammeAttributeData(data)); |
| | | } else |
| | | { |
| | | aLinkageSet.add(new UserAttributeData(data)); |
| | | } |
| | | |
| | | index = nextAttribute; |
| | | } |
| | | |
| | | return aLinkageSet; |
| | | } |
| | | |
| | | public void getUserAttributeData(byte[] pDataBlock, Class dataClass, int iLinkageId, int iLinkageIndex) |
| | | { |
| | | } |
| | | |
| | | public void getUserAttributeData(byte[] pDataBlock, int iLinkageId, Object oDataDef) |
| | | { |
| | | } |
| | | |
| | | |
| | | public ByteBuffer getRawBuffer() |
| | | { |
| | | return rawBuffer.asReadOnlyBuffer(); |
| | | } |
| | | |
| | | public short[] getRawArray() |
| | | { |
| | | if (raw == null) return null; |
| | | short[] result = new short[raw.length]; |
| | | System.arraycopy(raw, 0, result, 0, raw.length); |
| | | return result; |
| | | } |
| | | |
| | | public static class Exception extends java.lang.Exception |
| | | { |
| | | public Exception() |
| | | { |
| | | } |
| | | |
| | | // Constructs an Record.Exception with no detail message. |
| | | public Exception(String oStrMessage) |
| | | { |
| | | super(oStrMessage); |
| | | } |
| | | } |
| | | |
| | | protected static int getOffsetPosition(int offset) |
| | | { |
| | | return offset * 2; |
| | | } |
| | | |
| | | public void resyncBuffer() |
| | | { |
| | | byte[] tempRaw = new byte[this.raw.length * 2]; |
| | | ByteBuffer tempBuffer = ByteBuffer.wrap(tempRaw); |
| | | tempBuffer.order(ByteOrder.LITTLE_ENDIAN); |
| | | tempBuffer.asShortBuffer().put(this.raw); |
| | | |
| | | int pos = rawBuffer.position(); |
| | | rawBuffer = tempBuffer; |
| | | rawBuffer.position(pos); |
| | | } |
| | | |
| | | public static class ElementHandler implements IElementHandler |
| | | { |
| | | ElementType elementType; |
| | | |
| | | public ElementHandler(ElementType elementType) |
| | | { |
| | | this.elementType = elementType; |
| | | } |
| | | |
| | | public ElementType getElementType() |
| | | { |
| | | return elementType; |
| | | } |
| | | |
| | | public Object read(ByteBuffer buffer, short signature, int length) |
| | | { |
| | | byte[] dst = new byte[length]; |
| | | try |
| | | { |
| | | buffer.get(dst, 4, dst.length - 4); |
| | | } catch (BufferUnderflowException exception) |
| | | { |
| | | throw exception; |
| | | } |
| | | |
| | | ByteBuffer tmpBuffer = ByteBuffer.wrap(dst); |
| | | tmpBuffer.order(ByteOrder.LITTLE_ENDIAN); |
| | | tmpBuffer.position(0); |
| | | tmpBuffer.putShort(signature); |
| | | tmpBuffer.putShort((short) ((length / 2) - 2)); |
| | | |
| | | /* |
| | | ShortBuffer sbuffer = tmpBuffer.asShortBuffer(); |
| | | |
| | | short[] rawMem = new short[(length / 2)]; |
| | | sbuffer.get(rawMem, 2, rawMem.length - 2); |
| | | rawMem[0] = signature; |
| | | rawMem[1] = (short) ((length / 2) - 2); |
| | | */ |
| | | Element elm = createElement(dst); |
| | | |
| | | return elm; |
| | | } |
| | | |
| | | public void write(ByteBuffer buffer, Object element) |
| | | { |
| | | buffer.put(((Element) element).rawBuffer); |
| | | } |
| | | |
| | | public int getLength(Object element) |
| | | { |
| | | return ((Element) element).raw.length; |
| | | } |
| | | |
| | | public int getBufferLength(Object element) |
| | | { |
| | | return ((Element) element).rawBuffer.limit(); |
| | | } |
| | | |
| | | protected Element createElement(byte[] raw) |
| | | { |
| | | return new Element(raw); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | //~--- non-JDK imports -------------------------------------------------------- |
| | | |
| | | /*----------------------------------------------------------------------+ |
| | | | | |
| | | | Type Description | |
| | | | 1 Cell Library Header | |
| | | | 2 Cell (complex) | |
| | | | 3 Line | |
| | | | 4 Line String | |
| | | | 5 Group Data | |
| | | | 6 Shape | |
| | | | 7 Text Node (complex) | |
| | | | 8 Digitizer Setup Data | |
| | | | 9 Design File Header if level 8 | |
| | | | 10 Level Symbology | |
| | | | 11 Curve | |
| | | | 12 Complex String (complex) | |
| | | | 13 Conic | |
| | | | 14 Complex Shape (complex) | |
| | | | 15 Ellipse | |
| | | | 16 Arc | |
| | | | 17 Text | |
| | | | 18 Surface (complex) | |
| | | | 19 Solid (complex) | |
| | | | 20 not used | |
| | | | 21 B-Spline Pole | |
| | | | 22 Point String | |
| | | | 23 Circular Truncated Cone | |
| | | | 24 B-Spline Surface (complex) | |
| | | | 25 B-Spline Surface boundary | |
| | | | 26 B-Spline Knot Record | |
| | | | 27 B-Spline Curve (complex) | |
| | | | 28 B-Spline Weight Factor | |
| | | | 33 Dimension Record | |
| | | | 34 Shared Cell Definition Record | |
| | | | 35 Shared Cell Record | |
| | | | 36 Multiline Record | |
| | | | 37 Attribute Record | |
| | | | 38 DgnStore Component | |
| | | | 39 DgnStore Header | |
| | | | 66 MicroStation Application | |
| | | | 87 Raster Header | |
| | | | 88 Raster Component | |
| | | | 90 Raster Reference Attachment | |
| | | | 91 Raster Reference Component | |
| | | | 92 Raster Hierarchy Record | |
| | | | 93 Raster Hierarchy Component | |
| | | | 94 Raster Frame Record | |
| | | | 95 Table Entry Record | |
| | | | 96 Table Header Record | |
| | | | 97 View Group Record | |
| | | | 98 View Record | |
| | | | 99 Level Mask Record | |
| | | | 100 Reference Attach Record | |
| | | | 101 Matrix Header | |
| | | | 102 Matrix Int Data | |
| | | | 103 Matrix Double Data | |
| | | | 105 Mesh Header | |
| | | | 106 Extended Record (graphic) (complex) | |
| | | | 107 Extended Record (non-graphic) (complex) | |
| | | | 108 Reference Override Record | |
| | | | 110 Named Group Header | |
| | | | 111 Named Group Component | |
| | | | | |
| | | +----------------------------------------------------------------------*/ |
| | | |
| | | /** |
| | | * ElementType |
| | | * |
| | | * @author Ulysses |
| | | * @version 0.1 |
| | | * @since 2006/5/17 ¤U¤È 01:26:49 |
| | | */ |
| | | public final class ElementType |
| | | { |
| | | /** |
| | | * Represents a Null shape (id = 0). |
| | | */ |
| | | public static final ElementType NULL = new ElementType(0, "Null"); |
| | | |
| | | /** |
| | | * Represents a Line shape (id = 3). |
| | | */ |
| | | public static final ElementType LINE = new ElementType(3, "Line"); |
| | | |
| | | /** |
| | | * Represents a LineString shape (id = 4). |
| | | */ |
| | | public static final ElementType LINESTRING = new ElementType(4, "LineString"); |
| | | |
| | | /** |
| | | * Represents a Shape shape (id = 6). |
| | | */ |
| | | public static final ElementType SHAPE = new ElementType(6, "Shape"); |
| | | |
| | | /** |
| | | * Represents an TextNode shape (id = 7). |
| | | */ |
| | | public static final ElementType TEXTNODE = new ElementType(7, "TextNode"); |
| | | |
| | | /** |
| | | * Represents an IGDSDIGITIZER shape (id = 8). |
| | | */ |
| | | public static final ElementType IGDSDIGITIZER = new ElementType(8, "IGDSDigitizer"); |
| | | |
| | | /** |
| | | * Represents an TCB shape (id = 9). |
| | | */ |
| | | public static final ElementType TCB = new ElementType(9, "Tcb"); |
| | | |
| | | /** |
| | | * Represents a LevelSymbology shape (id = 10). |
| | | */ |
| | | public static final ElementType LEVELSYMBOLOGY = new ElementType(10, "LevelSymbology"); |
| | | |
| | | /** |
| | | * Represents a ComplexChain shape (id = 12). |
| | | */ |
| | | public static final ElementType COMPLEXCHAIN = new ElementType(12, "ComplexChain"); |
| | | |
| | | /** |
| | | * Represents a ComplexShape shape (id = 12). |
| | | */ |
| | | public static final ElementType COMPLEXSHAPE = new ElementType(14, "ComplexShape"); |
| | | |
| | | /** |
| | | * Represents a Ellipse shape (id = 15). |
| | | */ |
| | | public static final ElementType ELLIPSE = new ElementType(15, "Ellipse"); |
| | | |
| | | /** |
| | | * Represents a Arc shape (id = 16). |
| | | */ |
| | | public static final ElementType ARC = new ElementType(16, "Arc"); |
| | | |
| | | /** |
| | | * Represents a Text shape (id = 17). |
| | | */ |
| | | public static final ElementType TEXT = new ElementType(17, "Text"); |
| | | |
| | | /** |
| | | * Represents a PointString shape (id = 22). |
| | | */ |
| | | public static final ElementType POINTSTRING = new ElementType(22, "PointString"); |
| | | |
| | | /** |
| | | * Represents a Tag shape (id = 28). |
| | | */ |
| | | public static final ElementType TAG = new ElementType(37, "Tag"); |
| | | |
| | | /** |
| | | * Represents an Undefined shape (id = -1). |
| | | */ |
| | | public static final ElementType UNDEFINED = new ElementType(-1, "Undefined"); |
| | | |
| | | /** |
| | | * The integer id of this ElementType. |
| | | */ |
| | | public final int id; |
| | | |
| | | /** |
| | | * The human-readable name for this ElementType.<br> |
| | | * Could easily use ResourceBundle for internationialization. |
| | | */ |
| | | public final String name; |
| | | |
| | | /** |
| | | * Creates a new instance of ElementType. Hidden on purpose. |
| | | * |
| | | * @param id The id. |
| | | * @param name The name. |
| | | */ |
| | | protected ElementType(int id, String name) |
| | | { |
| | | this.id = id; |
| | | this.name = name; |
| | | } |
| | | |
| | | /** |
| | | * Get the name of this ElementType. |
| | | * |
| | | * @return The name. |
| | | */ |
| | | public String toString() |
| | | { |
| | | return name; |
| | | } |
| | | |
| | | /** |
| | | * Is this a multipoint shape? Hint- all shapes are multipoint except NULL, |
| | | * UNDEFINED, and the POINTs. |
| | | * |
| | | * @return true if multipoint, false otherwise. |
| | | */ |
| | | public boolean isMultiPoint() |
| | | { |
| | | boolean mp = true; |
| | | |
| | | if (this == UNDEFINED) |
| | | { |
| | | mp = false; |
| | | } else if (this == NULL) |
| | | { |
| | | mp = false; |
| | | } else if (this == IGDSDIGITIZER) |
| | | { |
| | | mp = false; |
| | | } else if (this == TCB) |
| | | { |
| | | mp = false; |
| | | } else if (this == LEVELSYMBOLOGY) |
| | | { |
| | | mp = false; |
| | | } |
| | | |
| | | return mp; |
| | | } |
| | | |
| | | public boolean isComplexElement() |
| | | { |
| | | return id == 2 || id == 7 || id == 12 || id == 14 || id == 18 || |
| | | id == 19 || id == 106 || id == 107; |
| | | |
| | | } |
| | | |
| | | public boolean isPointType() |
| | | { |
| | | return id == 7 || id == 17; |
| | | |
| | | } |
| | | |
| | | public boolean isLineType() |
| | | { |
| | | return id == 3 || id == 4 || id == 11 || id == 12 || id == 16; |
| | | |
| | | } |
| | | |
| | | public boolean isPolygonType() |
| | | { |
| | | return id == 6 || id == 14; |
| | | |
| | | } |
| | | |
| | | public boolean isMultiPointType() |
| | | { |
| | | return id == 3 || id == 4 || id == 6 || id == 11 || id == 12 || |
| | | id == 13 || id == 14 || id == 15 || id == 16 || id == 22; |
| | | |
| | | } |
| | | |
| | | public boolean isArcType() |
| | | { |
| | | return id == 15 || (id == 16); |
| | | } |
| | | |
| | | /** |
| | | * Determine the ElementType for the id. |
| | | * |
| | | * @param id The id to search for. |
| | | * @return The ElementType for the id. |
| | | */ |
| | | public static ElementType forID(int id) |
| | | { |
| | | ElementType t; |
| | | |
| | | switch (id) |
| | | { |
| | | case 0: |
| | | t = NULL; |
| | | break; |
| | | |
| | | case 3: |
| | | t = LINE; |
| | | break; |
| | | |
| | | case 4: |
| | | t = LINESTRING; |
| | | break; |
| | | |
| | | case 6: |
| | | t = SHAPE; |
| | | break; |
| | | |
| | | case 7: |
| | | t = TEXTNODE; |
| | | break; |
| | | |
| | | case 8: |
| | | t = IGDSDIGITIZER; |
| | | break; |
| | | |
| | | case 9: |
| | | t = TCB; |
| | | break; |
| | | |
| | | case 10: |
| | | t = LEVELSYMBOLOGY; |
| | | break; |
| | | |
| | | case 12: |
| | | t = COMPLEXCHAIN; |
| | | break; |
| | | |
| | | case 14: |
| | | t = COMPLEXSHAPE; |
| | | break; |
| | | |
| | | case 15: |
| | | t = ELLIPSE; |
| | | break; |
| | | |
| | | case 16: |
| | | t = ARC; |
| | | break; |
| | | |
| | | case 17: |
| | | t = TEXT; |
| | | break; |
| | | |
| | | case 37: |
| | | t = TAG; |
| | | |
| | | default: |
| | | t = UNDEFINED; |
| | | break; |
| | | } |
| | | |
| | | return t; |
| | | } |
| | | |
| | | public IElementHandler getElementHandler() throws Dgn7fileException |
| | | { |
| | | IElementHandler handler; |
| | | |
| | | switch (id) |
| | | { |
| | | case 3: |
| | | handler = LineElement.ElementHandler.getInstance(); |
| | | break; |
| | | |
| | | case 4: |
| | | handler = LineStringElement.ElementHandler.getInstance(); |
| | | break; |
| | | |
| | | case 6: |
| | | handler = ShapeElement.ElementHandler.getInstance(); |
| | | break; |
| | | |
| | | case 7: |
| | | handler = TextNodeElement.ElementHandler.getInstance(); |
| | | break; |
| | | |
| | | case 8: |
| | | handler = new Element.ElementHandler(this); |
| | | break; |
| | | |
| | | case 9: |
| | | handler = new Element.ElementHandler(this); |
| | | break; |
| | | |
| | | case 10: |
| | | handler = new Element.ElementHandler(this); |
| | | break; |
| | | |
| | | case 12: |
| | | handler = ComplexChainElement.ElementHandler.getInstance(); |
| | | break; |
| | | |
| | | case 14: |
| | | handler = ComplexShapeElement.ElementHandler.getInstance(); |
| | | break; |
| | | |
| | | case 15: |
| | | handler = EllipseElement.ElementHandler.getInstance(); |
| | | break; |
| | | |
| | | case 16: |
| | | handler = ArcElement.ElementHandler.getInstance(); |
| | | break; |
| | | |
| | | case 17: |
| | | handler = TextElement.ElementHandler.getInstance(); |
| | | break; |
| | | |
| | | case 37: |
| | | handler = TagElement.ElementHandler.getInstance(); |
| | | break; |
| | | |
| | | default: |
| | | handler = null; |
| | | } |
| | | |
| | | return handler; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | import java.nio.ByteOrder; |
| | | import java.util.ArrayList; |
| | | |
| | | import org.apache.log4j.Logger; |
| | | |
| | | import com.vividsolutions.jts.geom.Coordinate; |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | import com.ximple.util.DgnUtility; |
| | | |
| | | public class EllipseElement extends Element implements GeometryConverter |
| | | { |
| | | private static final Logger logger = Logger.getLogger(EllipseElement.class); |
| | | |
| | | public EllipseElement(byte[] raw) |
| | | { |
| | | super(raw); |
| | | } |
| | | |
| | | public double getStartAngle() |
| | | { |
| | | return 0.0; |
| | | } |
| | | |
| | | public void setStartAngle(double value) |
| | | { |
| | | } |
| | | |
| | | public double getSweepAngle() |
| | | { |
| | | return 360.0; |
| | | } |
| | | |
| | | public void setSweepAngle(double value) |
| | | { |
| | | } |
| | | |
| | | public double getPrimary() |
| | | { |
| | | rawBuffer.position(18 * 2); |
| | | ByteOrder bo = rawBuffer.order(); |
| | | rawBuffer.order(ByteOrder.BIG_ENDIAN); |
| | | byte[] primary = new byte[8]; |
| | | rawBuffer.get(primary); |
| | | rawBuffer.order(bo); |
| | | return DgnUtility.convertDGNToIEEEDouble(primary) / 1000.0; |
| | | } |
| | | |
| | | public void setPrimary(double value) |
| | | { |
| | | double temp = value * 1000.0; |
| | | short[] primary = DgnUtility.convertIEEEDoubleToDGN(temp); |
| | | |
| | | System.arraycopy(primary, 0, raw, 18, 4); |
| | | } |
| | | |
| | | public double getSecondary() |
| | | { |
| | | rawBuffer.position(22 * 2); |
| | | ByteOrder bo = rawBuffer.order(); |
| | | rawBuffer.order(ByteOrder.BIG_ENDIAN); |
| | | byte[] secondary = new byte[8]; |
| | | rawBuffer.get(secondary); |
| | | rawBuffer.order(bo); |
| | | return DgnUtility.convertDGNToIEEEDouble(secondary) / 1000.0; |
| | | } |
| | | |
| | | public void setSecondary(double value) |
| | | { |
| | | double temp = value * 1000.0; |
| | | short[] secondary = DgnUtility.convertIEEEDoubleToDGN(temp); |
| | | |
| | | System.arraycopy(secondary, 0, raw, 22, 4); |
| | | } |
| | | |
| | | public double getRotationAngle() |
| | | { |
| | | int rotation = (raw[26] << 16 & 0xffff0000); |
| | | rotation |= raw[27] & 0x0000ffff; |
| | | |
| | | return DgnUtility.converIntToRotation(rotation); |
| | | } |
| | | |
| | | public void setRotationAngle(double value) |
| | | { |
| | | int angle = DgnUtility.converRotatioToInt(value); |
| | | |
| | | raw[26] = (short) (angle >> 16 & 0x0000ffff); |
| | | raw[27] = (short) (angle & 0x0000ffff); |
| | | } |
| | | |
| | | public Coordinate getOrigin() |
| | | { |
| | | rawBuffer.position(28 * 2); |
| | | ByteOrder bo = rawBuffer.order(); |
| | | rawBuffer.order(ByteOrder.BIG_ENDIAN); |
| | | byte[] rawValue = new byte[8]; |
| | | |
| | | rawBuffer.get(rawValue); // x |
| | | double dx = DgnUtility.converUnitToCoord(DgnUtility.convertDGNToIEEEDouble(rawValue)); |
| | | |
| | | rawBuffer.get(rawValue); // y |
| | | double dy = DgnUtility.converUnitToCoord(DgnUtility.convertDGNToIEEEDouble(rawValue)); |
| | | |
| | | rawBuffer.order(bo); |
| | | |
| | | return new Coordinate(dx, dy); |
| | | } |
| | | |
| | | public void setOrigin(Coordinate value) |
| | | { |
| | | double temp = DgnUtility.converCoordToUnit(value.x); |
| | | short[] x = DgnUtility.convertIEEEDoubleToDGN(temp); |
| | | |
| | | System.arraycopy(x, 0, raw, 28, 4); |
| | | temp = DgnUtility.converCoordToUnit(value.y); |
| | | |
| | | short[] y = DgnUtility.convertIEEEDoubleToDGN(temp); |
| | | |
| | | System.arraycopy(y, 0, raw, 32, 4); |
| | | } |
| | | |
| | | public Geometry toGeometry(GeometryFactory factory) |
| | | { |
| | | double temp = Math.abs(getStartAngle() - getSweepAngle()); |
| | | temp /= 4; |
| | | int pts = (temp < 3) ? 3 : (int) temp; |
| | | return factory.createPolygon(factory.createLinearRing(convertToLineString(pts)), null); |
| | | } |
| | | |
| | | private Coordinate[] convertToLineString(int pts) |
| | | { |
| | | ArrayList<Coordinate> result = new ArrayList<Coordinate>(); |
| | | double beta = DgnUtility.converRotationToRadian(-getRotationAngle()); |
| | | double startAngle = getStartAngle(); |
| | | double sweepAngle = getSweepAngle(); |
| | | double endAngle = startAngle + sweepAngle; |
| | | double steps = sweepAngle / pts; |
| | | double current; |
| | | if (sweepAngle < 0) |
| | | { |
| | | for (current = startAngle; current > endAngle; current += steps) |
| | | { |
| | | Coordinate pt = computePointOnArcByAngle(beta, current); |
| | | result.add(pt); |
| | | } |
| | | |
| | | } else |
| | | { |
| | | for (current = startAngle; current < endAngle; current += steps) |
| | | { |
| | | Coordinate pt = computePointOnArcByAngle(beta, current); |
| | | result.add(pt); |
| | | } |
| | | } |
| | | |
| | | Coordinate pt = computePointOnArcByAngle(beta, endAngle); |
| | | result.add(pt); |
| | | |
| | | if (!result.get(0).equals(result.get(result.size() - 1))) |
| | | { |
| | | result.add(result.get(0)); |
| | | } |
| | | |
| | | return result.toArray(new Coordinate[result.size()]); |
| | | } |
| | | |
| | | |
| | | private Coordinate computePointOnArcByAngle(double beta, double current) |
| | | { |
| | | double sinbeta = Math.sin(beta); |
| | | double cosbeta = Math.cos(beta); |
| | | Coordinate pt = new Coordinate(); |
| | | double alpha = DgnUtility.converRotationToRadian(current); |
| | | double sinalpha = Math.sin(alpha); |
| | | double cosalpha = Math.cos(alpha); |
| | | pt.x = getOrigin().x + (getPrimary() * cosalpha * cosbeta - |
| | | getSecondary() * sinalpha * sinbeta); |
| | | pt.y = getOrigin().y + (getPrimary() * cosalpha * sinbeta + |
| | | getSecondary() * sinalpha * cosbeta); |
| | | return pt; |
| | | } |
| | | |
| | | public static class ElementHandler extends Element.ElementHandler |
| | | { |
| | | private static ElementHandler instance = null; |
| | | |
| | | public ElementHandler() |
| | | { |
| | | super(ElementType.ELLIPSE); |
| | | } |
| | | |
| | | public static IElementHandler getInstance() |
| | | { |
| | | if (instance == null) |
| | | { |
| | | instance = new ElementHandler(); |
| | | } |
| | | |
| | | return instance; |
| | | } |
| | | |
| | | protected Element createElement(byte[] raw) |
| | | { |
| | | return new EllipseElement(raw); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | /** |
| | | * FrammeAttributeData |
| | | * |
| | | * @author Ulysses |
| | | * @version 0.1 |
| | | * @since 2006/5/18 ¤U¤È 06:36:55 |
| | | */ |
| | | public class FrammeAttributeData extends UserAttributeData |
| | | { |
| | | public FrammeAttributeData(short id) |
| | | { |
| | | super(id, 7); |
| | | } |
| | | |
| | | public FrammeAttributeData(short[] src) |
| | | { |
| | | super(src); |
| | | } |
| | | |
| | | public short getFsc() |
| | | { |
| | | int fsc = _src[3] & 0x0000ffff; |
| | | |
| | | return (short) fsc; |
| | | } |
| | | |
| | | public int getUfid() |
| | | { |
| | | int ufid = (int) (_src[2] << 16 & 0xffff0000); |
| | | |
| | | ufid += _src[1] & 0x0000ffff; |
| | | |
| | | return ufid; |
| | | } |
| | | |
| | | public byte getComponentID() |
| | | { |
| | | int cmpid = (int) (_src[5] & 0x000000ff); |
| | | |
| | | return (byte) cmpid; |
| | | } |
| | | |
| | | public byte getRuleNo() |
| | | { |
| | | int no = (int) ((_src[5] >> 8) & 0x000000ff); |
| | | |
| | | return (byte) no; |
| | | } |
| | | |
| | | public short getStatus() |
| | | { |
| | | int status = (int) (_src[4] & 0x0000ffff); |
| | | |
| | | return (short) status; |
| | | } |
| | | |
| | | public short getOccID() |
| | | { |
| | | int occid = (int) (_src[6] & 0x0000ffff); |
| | | |
| | | return (short) occid; |
| | | } |
| | | |
| | | public String toString() |
| | | { |
| | | return "FrammeData{" + getFsc() + "," + getUfid() + "," + getComponentID() + "," + getRuleNo() + "," + getStatus() + "," |
| | | + getOccID() + "}"; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | //~--- non-JDK imports -------------------------------------------------------- |
| | | |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | /** |
| | | * GeometryConverter |
| | | * |
| | | * @author Ulysses |
| | | * @version 0.1 |
| | | * @since 2006/5/18 ¤W¤È 11:38:57 |
| | | */ |
| | | public interface GeometryConverter |
| | | { |
| | | public Geometry toGeometry(GeometryFactory factory); |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | //~--- JDK imports ------------------------------------------------------------ |
| | | |
| | | import java.nio.ByteBuffer; |
| | | |
| | | /** |
| | | * IElementHandler |
| | | * |
| | | * @author Ulysses |
| | | * @version 0.1 |
| | | * @since 2006/5/17 ¤U¤È 01:50:26 |
| | | */ |
| | | public interface IElementHandler |
| | | { |
| | | public ElementType getElementType(); |
| | | |
| | | public Object read(ByteBuffer buffer, short signature, int length); |
| | | |
| | | public void write(ByteBuffer buffer, Object element); |
| | | |
| | | public int getLength(Object element); |
| | | |
| | | public int getBufferLength(Object element); |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | //~--- non-JDK imports -------------------------------------------------------- |
| | | |
| | | import org.apache.log4j.Logger; |
| | | |
| | | import com.vividsolutions.jts.geom.Coordinate; |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | import com.ximple.util.DgnUtility; |
| | | |
| | | /** |
| | | * LineElement |
| | | * |
| | | * @author Ulysses |
| | | * @version 0.1 |
| | | * @since 2006/5/18 ¤W¤È 11:34:59 |
| | | */ |
| | | public class LineElement extends Element implements GeometryConverter |
| | | { |
| | | private static final Logger logger = Logger.getLogger(LineElement.class); |
| | | |
| | | public LineElement(byte[] raw) |
| | | { |
| | | super(raw); |
| | | } |
| | | |
| | | public Coordinate getCentroid(double dTolerance) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | public Coordinate getEndPoint() |
| | | { |
| | | int endX = ((raw[22] << 16) & 0xffff0000) | (raw[23] & 0x0000ffff); |
| | | int endY = ((raw[24] << 16) & 0xffff0000) | (raw[25] & 0x0000ffff); |
| | | |
| | | |
| | | double x = DgnUtility.converUnitToCoord(endX); |
| | | double y = DgnUtility.converUnitToCoord(endY); |
| | | |
| | | return new Coordinate(x, y); |
| | | } |
| | | |
| | | public Coordinate getNormal() |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | public Coordinate getOrigin() |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | public Coordinate getStartPoint() |
| | | { |
| | | int startX = ((raw[18] << 16) & 0xffff0000); |
| | | startX = startX + (raw[19] & 0x0000ffff); |
| | | |
| | | double x = DgnUtility.converUnitToCoord(startX); |
| | | int startY = ((raw[20] << 16) & 0xffff0000); |
| | | |
| | | startY = startY + (raw[21] & 0x0000ffff); |
| | | |
| | | double y = DgnUtility.converUnitToCoord(startY); |
| | | |
| | | return new Coordinate(x, y); |
| | | } |
| | | |
| | | public Coordinate getVertex(int index) |
| | | { |
| | | return (index == 0) |
| | | ? getStartPoint() |
| | | : getEndPoint(); |
| | | } |
| | | |
| | | public double getLength() |
| | | { |
| | | Coordinate p1 = getStartPoint(); |
| | | Coordinate p2 = getEndPoint(); |
| | | |
| | | return DgnUtility.getLength(p1.x, p1.y, p2.x, p2.y); |
| | | } |
| | | |
| | | public Coordinate pointAtDistance(double dDistance, double dTolerance) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | public Coordinate[] getVertices() |
| | | { |
| | | Coordinate[] result = new Coordinate[2]; |
| | | |
| | | result[0] = getStartPoint(); |
| | | result[1] = getEndPoint(); |
| | | |
| | | return result; |
| | | } |
| | | |
| | | public Geometry toGeometry(GeometryFactory factory) |
| | | { |
| | | return factory.createLineString(getVertices()); |
| | | } |
| | | |
| | | public static class ElementHandler extends Element.ElementHandler |
| | | { |
| | | private static ElementHandler instance = null; |
| | | |
| | | public ElementHandler() |
| | | { |
| | | super(ElementType.LINE); |
| | | } |
| | | |
| | | public static IElementHandler getInstance() |
| | | { |
| | | if (instance == null) |
| | | { |
| | | instance = new ElementHandler(); |
| | | } |
| | | |
| | | return instance; |
| | | } |
| | | |
| | | protected Element createElement(byte[] raw) |
| | | { |
| | | return new LineElement(raw); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | //~--- non-JDK imports -------------------------------------------------------- |
| | | |
| | | import org.apache.log4j.Logger; |
| | | |
| | | import com.vividsolutions.jts.geom.Coordinate; |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | import com.ximple.util.DgnUtility; |
| | | |
| | | /** |
| | | * LineStringElement |
| | | * |
| | | * @author Ulysses |
| | | * @version 0.1 |
| | | * @since 2006/5/18 ¤U¤È 02:48:58 |
| | | */ |
| | | public class LineStringElement extends Element implements GeometryConverter |
| | | { |
| | | private static final Logger logger = Logger.getLogger(LineStringElement.class); |
| | | |
| | | public LineStringElement(byte[] raw) |
| | | { |
| | | super(raw); |
| | | } |
| | | |
| | | public Coordinate getCentroid(double dTolerance) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | public Coordinate getEndPoint() |
| | | { |
| | | return new Coordinate(getX(getVerticeSize() - 1), getY(getVerticeSize() - 1)); |
| | | } |
| | | |
| | | public Coordinate getNormal() |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | public Coordinate getOrigin() |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | public Coordinate getStartPoint() |
| | | { |
| | | return new Coordinate(getX(0), getY(0)); |
| | | } |
| | | |
| | | public Coordinate getVertex(int index) |
| | | { |
| | | return (index == 0) |
| | | ? getStartPoint() |
| | | : getEndPoint(); |
| | | } |
| | | |
| | | public int getVerticeSize() |
| | | { |
| | | return raw[18] & 0x0000ffff; |
| | | } |
| | | |
| | | public double getLength() |
| | | { |
| | | double result = 0.0; |
| | | Coordinate[] vset = getVertices(); |
| | | |
| | | for (int i = 1; i < getVerticeSize(); i++) |
| | | { |
| | | Coordinate p1 = vset[i - 1]; |
| | | Coordinate p2 = vset[i]; |
| | | |
| | | result += DgnUtility.getLength(p1.x, p1.y, p2.x, p2.y); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | public Coordinate pointAtDistance(double dDistance, double dTolerance) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | public Coordinate[] getVertices() |
| | | { |
| | | Coordinate[] result = new Coordinate[getVerticeSize()]; |
| | | |
| | | for (int i = 0; i < getVerticeSize(); i++) |
| | | { |
| | | result[i] = new Coordinate(getX(i), getY(i)); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | public Geometry toGeometry(GeometryFactory factory) |
| | | { |
| | | return factory.createLineString(getVertices()); |
| | | } |
| | | |
| | | protected double getX(int index) |
| | | { |
| | | if ((index < 0) || (index > getVerticeSize())) |
| | | { |
| | | return -1; |
| | | } |
| | | |
| | | int x = ((raw[19 + (4 * index)] << 16) & 0xffff0000); |
| | | |
| | | x += (raw[20 + (4 * index)] & 0x0000ffff); |
| | | |
| | | return DgnUtility.converUnitToCoord(x); |
| | | } |
| | | |
| | | protected void setX(int index, double dx) |
| | | { |
| | | int newVal = DgnUtility.converCoordToUnit(dx); |
| | | |
| | | raw[19 + (4 * index)] = (short) (newVal >> 16 & 0x0000ffff); |
| | | raw[20 + (4 * index)] = (short) (newVal & 0x0000ffff); |
| | | } |
| | | |
| | | protected double getY(int index) |
| | | { |
| | | if ((index < 0) || (index > getVerticeSize())) |
| | | { |
| | | return -1; |
| | | } |
| | | |
| | | int y = ((raw[21 + (4 * index)] << 16) & 0xffff0000); |
| | | y = y + (raw[22 + (4 * index)] & 0x0000ffff); |
| | | |
| | | return DgnUtility.converUnitToCoord(y); |
| | | } |
| | | |
| | | protected void setY(int index, double dy) |
| | | { |
| | | int newVal = DgnUtility.converCoordToUnit(dy); |
| | | |
| | | raw[21 + (4 * index)] = (short) ((newVal >> 16) & 0x0000ffff); |
| | | raw[22 + (4 * index)] = (short) (newVal & 0x0000ffff); |
| | | } |
| | | |
| | | public static class ElementHandler extends Element.ElementHandler |
| | | { |
| | | private static ElementHandler instance = null; |
| | | |
| | | public ElementHandler() |
| | | { |
| | | super(ElementType.LINESTRING); |
| | | } |
| | | |
| | | public static IElementHandler getInstance() |
| | | { |
| | | if (instance == null) |
| | | { |
| | | instance = new ElementHandler(); |
| | | } |
| | | |
| | | return instance; |
| | | } |
| | | |
| | | protected Element createElement(byte[] raw) |
| | | { |
| | | return new LineStringElement(raw); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | //~--- JDK imports ------------------------------------------------------------ |
| | | |
| | | import java.io.IOException; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | import org.apache.log4j.LogManager; |
| | | import org.apache.log4j.Logger; |
| | | |
| | | /** |
| | | * Lock |
| | | * |
| | | * @author Ulysses |
| | | * @version 0.1 |
| | | * @since 2006/5/18 ¤W¤È 10:27:24 |
| | | */ |
| | | public class Lock |
| | | { |
| | | Logger logger = LogManager.getLogger("com.ximple.io.dgn7"); |
| | | |
| | | /** |
| | | * indicates a write is occurring |
| | | */ |
| | | int writeLocks = 0; |
| | | |
| | | /** |
| | | * if not null a writer is waiting for the lock or is writing. |
| | | */ |
| | | Thread writer; |
| | | |
| | | /** |
| | | * Thread->Owner map. If empty no read locks exist. |
| | | */ |
| | | Map owners = new HashMap(); |
| | | |
| | | /** |
| | | * If the lock can be read locked the lock will be read and default |
| | | * visibility for tests |
| | | * |
| | | * @return |
| | | * @throws java.io.IOException |
| | | */ |
| | | synchronized boolean canRead() throws IOException |
| | | { |
| | | if ((writer != null) && (writer != Thread.currentThread())) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | if (writer == null) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | if (owners.size() > 1) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * If the lock can be read locked the lock will be read and default |
| | | * visibility for tests |
| | | * |
| | | * @return |
| | | * @throws IOException |
| | | */ |
| | | synchronized boolean canWrite() throws IOException |
| | | { |
| | | if (owners.size() > 1) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | if ((canRead()) && ((writer == Thread.currentThread()) || (writer == null))) |
| | | { |
| | | if (owners.isEmpty()) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | if (owners.containsKey(Thread.currentThread())) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * Called by shapefileReader before a read is started and before an IOStream |
| | | * is openned. |
| | | * |
| | | * @throws IOException |
| | | */ |
| | | public synchronized void lockRead() throws IOException |
| | | { |
| | | if (!canRead()) |
| | | { |
| | | while ((writeLocks > 0) || (writer != null)) |
| | | { |
| | | try |
| | | { |
| | | wait(); |
| | | } catch (InterruptedException e) |
| | | { |
| | | throw (IOException) new IOException().initCause(e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | assertTrue("A write lock exists that is owned by another thread", canRead()); |
| | | |
| | | Thread current = Thread.currentThread(); |
| | | Owner owner = (Owner) owners.get(current); |
| | | |
| | | if (owner != null) |
| | | { |
| | | owner.timesLocked++; |
| | | } else |
| | | { |
| | | owner = new Owner(current); |
| | | owners.put(current, owner); |
| | | } |
| | | |
| | | logger.debug("Start Read Lock:" + owner); |
| | | } |
| | | |
| | | private void assertTrue(String message, boolean b) |
| | | { |
| | | if (!b) |
| | | { |
| | | throw new AssertionError(message); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Called by ShapefileReader after a read is complete and after the IOStream |
| | | * is closed. |
| | | */ |
| | | public synchronized void unlockRead() |
| | | { |
| | | assertTrue("Current thread does not have a readLock", owners.containsKey(Thread.currentThread())); |
| | | |
| | | Owner owner = (Owner) owners.get(Thread.currentThread()); |
| | | |
| | | assertTrue("Current thread has " + owner.timesLocked + "negative number of locks", owner.timesLocked > 0); |
| | | owner.timesLocked--; |
| | | |
| | | if (owner.timesLocked == 0) |
| | | { |
| | | owners.remove(Thread.currentThread()); |
| | | } |
| | | |
| | | notifyAll(); |
| | | logger.debug("unlock Read:" + owner); |
| | | } |
| | | |
| | | /** |
| | | * Called by ShapefileDataStore before a write is started and before an |
| | | * IOStream is openned. |
| | | * |
| | | * @throws IOException |
| | | */ |
| | | public synchronized void lockWrite() throws IOException |
| | | { |
| | | Thread currentThread = Thread.currentThread(); |
| | | |
| | | if (writer == null) |
| | | { |
| | | writer = currentThread; |
| | | } |
| | | |
| | | while (!canWrite()) |
| | | { |
| | | try |
| | | { |
| | | wait(); |
| | | } catch (InterruptedException e) |
| | | { |
| | | throw (IOException) new IOException().initCause(e); |
| | | } |
| | | |
| | | if (writer == null) |
| | | { |
| | | writer = currentThread; |
| | | } |
| | | } |
| | | |
| | | if (writer == null) |
| | | { |
| | | writer = currentThread; |
| | | } |
| | | |
| | | assertTrue("The current thread is not the writer", writer == currentThread); |
| | | assertTrue("There are read locks not belonging to the current thread.", canRead()); |
| | | writeLocks++; |
| | | logger.debug(currentThread.getName() + " is getting write lock:" + writeLocks); |
| | | } |
| | | |
| | | /** |
| | | * default visibility for tests |
| | | */ |
| | | synchronized int getReadLocks(Thread thread) |
| | | { |
| | | Owner owner = (Owner) owners.get(thread); |
| | | |
| | | if (owner == null) |
| | | { |
| | | return -1; |
| | | } |
| | | |
| | | return owner.timesLocked; |
| | | } |
| | | |
| | | public synchronized void unlockWrite() |
| | | { |
| | | if (writeLocks > 0) |
| | | { |
| | | assertTrue("current thread does not own the write lock", writer == Thread.currentThread()); |
| | | assertTrue("writeLock has already been unlocked", writeLocks > 0); |
| | | writeLocks--; |
| | | |
| | | if (writeLocks == 0) |
| | | { |
| | | writer = null; |
| | | } |
| | | } |
| | | |
| | | logger.debug("unlock write:" + Thread.currentThread().getName()); |
| | | notifyAll(); |
| | | } |
| | | |
| | | /** |
| | | * default visibility for tests |
| | | */ |
| | | synchronized boolean ownWriteLock(Thread thread) |
| | | { |
| | | return (writer == thread) && (writeLocks > 0); |
| | | } |
| | | |
| | | private class Owner |
| | | { |
| | | final Thread owner; |
| | | int timesLocked; |
| | | |
| | | Owner(Thread owner) |
| | | { |
| | | this.owner = owner; |
| | | timesLocked = 1; |
| | | } |
| | | |
| | | public String toString() |
| | | { |
| | | return owner.getName() + " has " + timesLocked + " locks"; |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | /* |
| | | * GeoTools - OpenSource mapping toolkit |
| | | * http://geotools.org |
| | | * (C) 2003-2006, Geotools Project Managment Committee (PMC) |
| | | * |
| | | * This library is free software; you can redistribute it and/or |
| | | * modify it under the terms of the GNU Lesser General Public |
| | | * License as published by the Free Software Foundation; either |
| | | * version 2.1 of the License, or (at your option) any later version. |
| | | * |
| | | * This library is distributed in the hope that it will be useful, |
| | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| | | * Lesser General Public License for more details. |
| | | */ |
| | | |
| | | // J2SE dependencies |
| | | |
| | | import java.lang.reflect.Method; |
| | | import java.nio.ByteBuffer; |
| | | import java.security.AccessController; |
| | | import java.security.PrivilegedAction; |
| | | import java.util.logging.Level; |
| | | import java.util.logging.Logger; |
| | | |
| | | |
| | | /** |
| | | * Utility class for managing memory mapped buffers. |
| | | * |
| | | * @author Andres Aimes |
| | | * @version $Id$ |
| | | * @source $URL$ |
| | | * @since 2.0 |
| | | */ |
| | | public class NIOUtilities |
| | | { |
| | | /** |
| | | * {@code true} if a warning has already been logged. |
| | | */ |
| | | private static boolean warned = false; |
| | | |
| | | /** |
| | | * Do not allows instantiation of this class. |
| | | * |
| | | * @todo This constructor will become private when {@code NIOBufferUtils} |
| | | * will have been removed. |
| | | */ |
| | | protected NIOUtilities() |
| | | { |
| | | } |
| | | |
| | | /** |
| | | * Really closes a {@code MappedByteBuffer} without the need to wait for garbage |
| | | * collection. Any problems with closing a buffer on Windows (the problem child in this |
| | | * case) will be logged as {@code SEVERE} to the logger of the package name. To |
| | | * force logging of errors, set the System property "org.geotools.io.debugBuffer" to "true". |
| | | * |
| | | * @param buffer The buffer to close. |
| | | * @return true if the operation was successful, false otherwise. |
| | | * @see java.nio.MappedByteBuffer |
| | | */ |
| | | public static boolean clean(final ByteBuffer buffer) |
| | | { |
| | | if (buffer == null || !buffer.isDirect()) |
| | | { |
| | | return false; |
| | | } |
| | | Boolean b = (Boolean) AccessController.doPrivileged(new PrivilegedAction() |
| | | { |
| | | public Object run() |
| | | { |
| | | Boolean success = Boolean.FALSE; |
| | | try |
| | | { |
| | | Method getCleanerMethod = buffer.getClass().getMethod("cleaner", (Class[]) null); |
| | | getCleanerMethod.setAccessible(true); |
| | | Object cleaner = getCleanerMethod.invoke(buffer, (Object[]) null); |
| | | Method clean = cleaner.getClass().getMethod("clean", (Class[]) null); |
| | | clean.invoke(cleaner, (Object[]) null); |
| | | success = Boolean.TRUE; |
| | | } catch (Exception e) |
| | | { |
| | | // This really is a show stopper on windows |
| | | if (isLoggable()) |
| | | { |
| | | log(e, buffer); |
| | | } |
| | | } |
| | | return success; |
| | | } |
| | | }); |
| | | |
| | | return b.booleanValue(); |
| | | } |
| | | |
| | | /** |
| | | * Check if a warning message should be logged. |
| | | */ |
| | | private static synchronized boolean isLoggable() |
| | | { |
| | | try |
| | | { |
| | | return !warned && ( |
| | | System.getProperty("org.geotools.io.debugBuffer", "false").equalsIgnoreCase("true") || |
| | | System.getProperty("os.name").indexOf("Windows") >= 0); |
| | | } catch (SecurityException exception) |
| | | { |
| | | // The utilities may be running in an Applet, in which case we |
| | | // can't read properties. Assumes we are not in debugging mode. |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Log a warning message. |
| | | */ |
| | | private static synchronized void log(final Exception e, final ByteBuffer buffer) |
| | | { |
| | | warned = true; |
| | | String message = "Error attempting to close a mapped byte buffer : " + buffer.getClass().getName() |
| | | + "\n JVM : " + System.getProperty("java.version") |
| | | + ' ' + System.getProperty("java.vendor"); |
| | | Logger.getLogger("org.geotools.io").log(Level.SEVERE, message, e); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | import org.apache.log4j.Logger; |
| | | |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | import com.vividsolutions.jts.geom.LinearRing; |
| | | import com.vividsolutions.jts.geom.Coordinate; |
| | | |
| | | /** |
| | | * ShapeElement |
| | | * |
| | | * @author Ulysses |
| | | * @version 0.1 |
| | | * @since 2006/5/18 ¤U¤È 03:08:43 |
| | | */ |
| | | public class ShapeElement extends LineStringElement implements GeometryConverter |
| | | { |
| | | private static final Logger logger = Logger.getLogger(ShapeElement.class); |
| | | |
| | | public ShapeElement(byte[] raw) |
| | | { |
| | | super(raw); |
| | | } |
| | | |
| | | public Coordinate[] getVertices() |
| | | { |
| | | Coordinate[] result = super.getVertices(); |
| | | if ((result != null) && (result.length > 2)) |
| | | { |
| | | boolean isClosed = result[0].equals2D(result[result.length - 1]); |
| | | if (!isClosed) |
| | | { |
| | | double distance = result[0].distance(result[result.length - 1]); |
| | | if (distance < 0.00210) |
| | | { |
| | | result[result.length - 1] = new Coordinate(result[0]); |
| | | } else |
| | | { |
| | | logger.info("Shape is not closed. distance=" + distance); |
| | | logger.debug("result[0]=" + result[0].toString()); |
| | | logger.debug("result[length - 1]=" + result[result.length - 1]); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | public Geometry toGeometry(GeometryFactory factory) |
| | | { |
| | | try |
| | | { |
| | | LinearRing ring = factory.createLinearRing(this.getVertices()); |
| | | return factory.createPolygon(ring, null); |
| | | } catch (IllegalArgumentException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | public static class ElementHandler extends Element.ElementHandler |
| | | { |
| | | private static ElementHandler instance = null; |
| | | |
| | | public ElementHandler() |
| | | { |
| | | super(ElementType.SHAPE); |
| | | } |
| | | |
| | | public static IElementHandler getInstance() |
| | | { |
| | | if (instance == null) |
| | | { |
| | | instance = new ElementHandler(); |
| | | } |
| | | |
| | | return instance; |
| | | } |
| | | |
| | | protected Element createElement(byte[] raw) |
| | | { |
| | | return new ShapeElement(raw); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | //~--- non-JDK imports -------------------------------------------------------- |
| | | |
| | | import org.apache.log4j.LogManager; |
| | | import org.apache.log4j.Logger; |
| | | |
| | | /** |
| | | * StreamLogging |
| | | * |
| | | * @author Ulysses |
| | | * @version 0.1 |
| | | * @since 2006/5/18 ¤W¤È 10:31:08 |
| | | */ |
| | | public class StreamLogging |
| | | { |
| | | private static final Logger LOGGER = LogManager.getLogger("com.ximple.io.dgn7"); |
| | | private String name; |
| | | private int open = 0; |
| | | |
| | | /** |
| | | * The name that will appear in the debug message |
| | | * |
| | | * @param name |
| | | */ |
| | | public StreamLogging(String name) |
| | | { |
| | | this.name = name; |
| | | } |
| | | |
| | | /** |
| | | * Call when reader or writer is opened |
| | | */ |
| | | public synchronized void open() |
| | | { |
| | | open++; |
| | | LOGGER.debug(name + " has been opened. Number open: " + open); |
| | | } |
| | | |
| | | public synchronized void close() |
| | | { |
| | | open--; |
| | | LOGGER.debug(name + " has been closed. Number open: " + open); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | import org.apache.log4j.Logger; |
| | | |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | public class TagElement extends Element implements GeometryConverter |
| | | { |
| | | private static final Logger logger = Logger.getLogger(TagElement.class); |
| | | |
| | | public TagElement(byte[] raw) |
| | | { |
| | | super(raw); |
| | | } |
| | | |
| | | public Geometry toGeometry(GeometryFactory factory) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | public static class ElementHandler extends Element.ElementHandler |
| | | { |
| | | private static ElementHandler instance = null; |
| | | |
| | | public ElementHandler() |
| | | { |
| | | super(ElementType.TAG); |
| | | } |
| | | |
| | | public static IElementHandler getInstance() |
| | | { |
| | | if (instance == null) |
| | | { |
| | | instance = new ElementHandler(); |
| | | } |
| | | |
| | | return instance; |
| | | } |
| | | |
| | | protected Element createElement(byte[] raw) |
| | | { |
| | | return new TagElement(raw); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | import org.apache.log4j.Logger; |
| | | |
| | | /** |
| | | * TcbElement |
| | | * |
| | | * @author Ulysses |
| | | * @version 0.1 |
| | | * @since 2006/5/18 ¤U¤È 05:03:46 |
| | | */ |
| | | public class TcbElement extends Element |
| | | { |
| | | private static final Logger logger = Logger.getLogger(TcbElement.class); |
| | | |
| | | public TcbElement(byte[] raw) |
| | | { |
| | | super(raw); |
| | | } |
| | | |
| | | public boolean is2D() |
| | | { |
| | | int dimension = (int) (raw[607] & 0x00000004); |
| | | |
| | | if (dimension == 0) |
| | | { |
| | | return true; |
| | | } else |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | public String getMasterUnitName() |
| | | { |
| | | byte[] master = new byte[1]; |
| | | |
| | | master[0] = (byte) (raw[560] & 0x00ff); |
| | | java.nio.charset.Charset.forName("US-ASCII"); |
| | | |
| | | // ASCIIEncoding encode = new ASCIIEncoding(); |
| | | StringBuilder sb = new StringBuilder(); |
| | | |
| | | sb.append((char) master[0]); |
| | | |
| | | // return encode.GetString(master); |
| | | return sb.toString(); |
| | | } |
| | | |
| | | public String getSubUnitName() |
| | | { |
| | | byte[] sub = new byte[2]; |
| | | |
| | | sub[0] = (byte) (raw[561] & 0x00ff); |
| | | sub[1] = (byte) (raw[561] >> 8 & 0x00ff); |
| | | |
| | | StringBuilder sb = new StringBuilder(); |
| | | |
| | | sb.append((char) sub[0]); |
| | | sb.append((char) sub[0]); |
| | | |
| | | return sb.toString(); |
| | | } |
| | | |
| | | public int getGraphicGroup() |
| | | { |
| | | return (int) (raw[594] & 0x0000ffff); |
| | | } |
| | | |
| | | public static class ElementHandler extends Element.ElementHandler |
| | | { |
| | | private static ElementHandler instance = null; |
| | | |
| | | public ElementHandler() |
| | | { |
| | | super(ElementType.TCB); |
| | | } |
| | | |
| | | public static IElementHandler getInstance() |
| | | { |
| | | if (instance == null) |
| | | { |
| | | instance = new ElementHandler(); |
| | | } |
| | | |
| | | return instance; |
| | | } |
| | | |
| | | protected Element createElement(byte[] raw) |
| | | { |
| | | return new TcbElement(raw); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | import java.awt.geom.AffineTransform; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.CharBuffer; |
| | | import java.nio.charset.CharacterCodingException; |
| | | import java.nio.charset.Charset; |
| | | import java.nio.charset.CharsetDecoder; |
| | | |
| | | import org.apache.log4j.Logger; |
| | | |
| | | import com.vividsolutions.jts.geom.Coordinate; |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | import com.vividsolutions.jts.geom.CoordinateList; |
| | | |
| | | import com.ximple.util.DgnUtility; |
| | | |
| | | /** |
| | | * TextElement |
| | | * |
| | | * @author Ulysses |
| | | * @version 0.1 |
| | | * @since 2006/5/18 ¤W¤È 11:45:29 |
| | | */ |
| | | public class TextElement extends Element implements GeometryConverter |
| | | { |
| | | private static final Logger logger = Logger.getLogger(TextElement.class); |
| | | |
| | | public static final int ED_CENTERJUSTIFICATION = 0; |
| | | |
| | | // Enter data field center justification |
| | | public static final int ED_LEFTJUSTIFICATION = 0; |
| | | |
| | | // Enter data field left justification |
| | | public static final int ED_RIGHTJUSTIFICATION = 0; |
| | | |
| | | public static final int TXTJUST_LT = 0; /* Left Top */ |
| | | public static final int TXTJUST_LC = 1; /* Left Center */ |
| | | public static final int TXTJUST_LB = 2; /* Left Bottom */ |
| | | public static final int TXTJUST_LMT = 3; /* Left Margin Top */ |
| | | public static final int TXTJUST_LMC = 4; /* Left Margin Center */ |
| | | public static final int TXTJUST_LMB = 5; /* Left Margin Bottom */ |
| | | public static final int TXTJUST_CT = 6; /* Center Top */ |
| | | public static final int TXTJUST_CC = 7; /* Center Center */ |
| | | public static final int TXTJUST_CB = 8; /* Center Bottom */ |
| | | public static final int TXTJUST_RMT = 9; /* Right Margin Top */ |
| | | public static final int TXTJUST_RMC = 10; /* Right Margin Center */ |
| | | public static final int TXTJUST_RMB = 11; /* Right Margin Bottom */ |
| | | public static final int TXTJUST_RT = 12; /* Right Top */ |
| | | public static final int TXTJUST_RC = 13; /* Right Center */ |
| | | public static final int TXTJUST_RB = 14; /* Right Bottom */ |
| | | |
| | | public static final int TXTJUST_LU = 15; /* Left Cap */ |
| | | public static final int TXTJUST_LD = 16; /* Left Descender */ |
| | | public static final int TXTJUST_LMU = 17; /* Left Margin Cap */ |
| | | public static final int TXTJUST_LMD = 18; /* Left Margin Descender */ |
| | | public static final int TXTJUST_CU = 19; /* Center Cap */ |
| | | public static final int TXTJUST_CD = 20; /* Center Descender */ |
| | | public static final int TXTJUST_RMU = 21; /* Right Margin Cap */ |
| | | public static final int TXTJUST_RMD = 22; /* Right Margin Descender */ |
| | | public static final int TXTJUST_RU = 23; /* Right Cap */ |
| | | public static final int TXTJUST_RD = 24; /* Right Descender */ |
| | | public static final int TXTJUST_NONE = 127;/* no justfication */ |
| | | |
| | | public TextElement(byte[] raw) |
| | | { |
| | | super(raw); |
| | | } |
| | | |
| | | public Coordinate getOrigin() |
| | | { |
| | | int x = (raw[25] << 16 & 0xffff0000); |
| | | |
| | | x += raw[26] & 0x0000ffff; |
| | | |
| | | double dx = DgnUtility.converUnitToCoord(x); |
| | | int y = (raw[27] << 16 & 0xffff0000); |
| | | |
| | | y += raw[28] & 0x0000ffff; |
| | | |
| | | double dy = DgnUtility.converUnitToCoord(y); |
| | | |
| | | return new Coordinate(dx, dy); |
| | | } |
| | | |
| | | public int getFontIndex() |
| | | { |
| | | return (int) raw[18] & 0x00000000ff; |
| | | } |
| | | |
| | | public boolean hasSlant() |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | public boolean hasUnderline() |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | public boolean isFixedWidthSpacing() |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | public boolean isPlanar() |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | public boolean isVertical() |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | public double getTextHeight() |
| | | { |
| | | int height = ((raw[21] << 16) & 0xffff0000); |
| | | |
| | | height += raw[22] & 0x0000ffff; |
| | | |
| | | return DgnUtility.converIntToDouble(height); |
| | | } |
| | | |
| | | public double getTextWidth() |
| | | { |
| | | int length = (raw[19] << 16 & 0xffff0000); |
| | | |
| | | length += raw[20] & 0x0000ffff; |
| | | |
| | | return DgnUtility.converIntToDouble(length); |
| | | } |
| | | |
| | | public int getJustification() |
| | | { |
| | | return ((raw[18] >>> 8) & 0x00000000ff); |
| | | } |
| | | |
| | | public double getRotationAngle() |
| | | { |
| | | int totation = ((raw[23] & 0x0000ffff) << 16) | (raw[24] & 0x0000ffff); |
| | | return DgnUtility.converIntToRotation(totation); |
| | | } |
| | | |
| | | public boolean isChinese() |
| | | { |
| | | int isChinese = raw[30] & 0x0000ffff; |
| | | |
| | | return (isChinese == 0xfdff); |
| | | } |
| | | |
| | | public int getTextLength() |
| | | { |
| | | int num = raw[29]; |
| | | |
| | | if (isChinese()) |
| | | { |
| | | num = (num / 2) - 1; |
| | | } |
| | | |
| | | return num; |
| | | } |
| | | |
| | | public String getText() |
| | | { |
| | | StringBuilder val = new StringBuilder(); |
| | | char[] temp; |
| | | int num = getTextLength(); |
| | | |
| | | if (!isChinese()) |
| | | { |
| | | temp = new char[num]; |
| | | |
| | | for (int i = 0; i < temp.length; i++) |
| | | { |
| | | if ((i % 2) == 0) |
| | | { |
| | | temp[i] = (char) (raw[30 + (int) (i / 2)] & (short) 0x00ff); |
| | | } else |
| | | { |
| | | temp[i] = (char) ((raw[30 + (int) (i / 2)] >> 8) & (short) 0x00ff); |
| | | } |
| | | |
| | | val.append(temp[i]); |
| | | } |
| | | } else |
| | | { |
| | | byte[] strRaw = new byte[num * 2]; |
| | | for (int i = 0; i < num; i++) |
| | | { |
| | | short charValue = raw[i + 31]; |
| | | byte hi = (byte) (charValue >>> 8); |
| | | byte lo = (byte) charValue; |
| | | strRaw[i * 2] = hi; |
| | | strRaw[i * 2 + 1] = lo; |
| | | } |
| | | |
| | | try |
| | | { |
| | | Charset charsetBig5 = Charset.forName("Big5"); |
| | | CharsetDecoder decoder = charsetBig5.newDecoder(); |
| | | CharBuffer cb = decoder.decode(ByteBuffer.wrap(strRaw)); |
| | | val.append(cb); |
| | | } catch (CharacterCodingException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | return val.toString(); |
| | | } finally |
| | | { |
| | | // rawBuffer.position(pos); |
| | | // rawBuffer.order(order); |
| | | } |
| | | } |
| | | |
| | | return val.toString(); |
| | | } |
| | | |
| | | protected byte[] convertDBCSToUnicode(byte[] buffer) |
| | | { |
| | | byte[] charBuffer = new byte[4]; |
| | | charBuffer[0] = (byte) ((byte) ((buffer[1] & 0xc0) >>> 6) | 0xc0); |
| | | charBuffer[1] = (byte) (buffer[1] & 0x3f | 0x80); |
| | | charBuffer[2] = (byte) ((byte) ((buffer[0] & 0xc0) >>> 6) | 0xc0); |
| | | charBuffer[3] = (byte) (buffer[0] & 0x3f | 0x80); |
| | | return charBuffer; |
| | | } |
| | | |
| | | public Geometry toGeometry(GeometryFactory factory) |
| | | { |
| | | return factory.createPoint(getUserOrigin()); |
| | | } |
| | | |
| | | public Geometry toAnchorGeometry(GeometryFactory factory) |
| | | { |
| | | if (getText() == null) |
| | | { |
| | | return factory.createMultiPoint(new Coordinate[] {}); |
| | | } |
| | | |
| | | return factory.createMultiPoint(toAnchorCoordinates()); |
| | | } |
| | | |
| | | public Coordinate[] toAnchorCoordinates() |
| | | { |
| | | CoordinateList result = new CoordinateList(); |
| | | int len = getText().trim().length(); |
| | | if (len == 0) return result.toCoordinateArray(); |
| | | |
| | | double width = getUserWidth(); |
| | | double height = getUserHeight(); |
| | | double angle = Math.toRadians(getRotationAngle()); |
| | | |
| | | AffineTransform at = new AffineTransform(); |
| | | at.translate(width, height); |
| | | Coordinate p = getOrigin(); |
| | | at.setToRotation(angle, p.x, p.y); |
| | | at.scale(1, 1); |
| | | |
| | | for (int i = 0; i < len; i++) |
| | | { |
| | | double[] srcPt = new double[2]; |
| | | double[] dstPt = new double[2]; |
| | | |
| | | srcPt[0] = p.x + width * i; |
| | | srcPt[1] = p.y; |
| | | |
| | | at.transform(srcPt, 0, dstPt, 0, 1); |
| | | result.add(new Coordinate(dstPt[0], dstPt[1]), false); |
| | | } |
| | | |
| | | return result.toCoordinateArray(); |
| | | } |
| | | |
| | | private double getUserWidth() |
| | | { |
| | | int just = getJustification(); |
| | | // Envelope range = getRange(); // case -1 |
| | | // double width = (range.getWidth()); // case -1 |
| | | // double width = this.getTextWidth() * this.getTextLength() * 1000.0; // case -2 |
| | | double width = (this.getTextWidth() * this.getTextLength()); |
| | | |
| | | switch (just) |
| | | { |
| | | case TXTJUST_LT: |
| | | case TXTJUST_LC: |
| | | case TXTJUST_LB: |
| | | width = 0; |
| | | break; |
| | | |
| | | case TXTJUST_CT: |
| | | case TXTJUST_CC: |
| | | case TXTJUST_CB: |
| | | width = width / 2; |
| | | break; |
| | | |
| | | case TXTJUST_RT: |
| | | case TXTJUST_RC: |
| | | case TXTJUST_RB: |
| | | break; |
| | | } |
| | | |
| | | return width; |
| | | } |
| | | |
| | | private double getUserHeight() |
| | | { |
| | | int just = getJustification(); |
| | | double height = getTextHeight(); |
| | | |
| | | switch (just) |
| | | { |
| | | case TXTJUST_LB: |
| | | case TXTJUST_CB: |
| | | case TXTJUST_RB: // bottom |
| | | height = 0; |
| | | break; |
| | | |
| | | case TXTJUST_LC: |
| | | case TXTJUST_CC: |
| | | case TXTJUST_RC: // center |
| | | height = height / 2; |
| | | break; |
| | | |
| | | case TXTJUST_LT: |
| | | case TXTJUST_CT: |
| | | case TXTJUST_RT: // height |
| | | break; |
| | | } |
| | | |
| | | return height; |
| | | } |
| | | |
| | | public Coordinate getUserOrigin() |
| | | { |
| | | double width = getUserWidth(); |
| | | double height = getUserHeight(); |
| | | double angle = Math.toRadians(getRotationAngle()); |
| | | |
| | | AffineTransform at = new AffineTransform(); |
| | | at.translate(width, height); |
| | | Coordinate p = getOrigin(); |
| | | at.setToRotation(angle, p.x, p.y); |
| | | at.scale(1, 1); |
| | | |
| | | double[] srcPt = new double[2]; |
| | | double[] dstPt = new double[2]; |
| | | |
| | | srcPt[0] = p.x + width; |
| | | srcPt[1] = p.y + height; |
| | | |
| | | at.transform(srcPt, 0, dstPt, 0, 1); |
| | | |
| | | return new Coordinate(dstPt[0], dstPt[1]); |
| | | } |
| | | |
| | | public Object clone() throws CloneNotSupportedException |
| | | { |
| | | int pos = this.rawBuffer.position(); |
| | | this.rawBuffer.position(0); |
| | | byte[] rawBytes = this.rawBuffer.array(); |
| | | byte[] otherRaw = new byte[rawBytes.length]; |
| | | System.arraycopy(rawBytes, 0, otherRaw, 0, rawBytes.length); |
| | | this.rawBuffer.position(pos); |
| | | |
| | | TextElement other = new TextElement(otherRaw); |
| | | return other; |
| | | } |
| | | |
| | | public static class ElementHandler extends Element.ElementHandler |
| | | { |
| | | private static ElementHandler instance = null; |
| | | |
| | | public ElementHandler() |
| | | { |
| | | super(ElementType.TEXT); |
| | | } |
| | | |
| | | public static IElementHandler getInstance() |
| | | { |
| | | if (instance == null) |
| | | { |
| | | instance = new ElementHandler(); |
| | | } |
| | | |
| | | return instance; |
| | | } |
| | | |
| | | protected Element createElement(byte[] raw) |
| | | { |
| | | return new TextElement(raw); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | //~--- JDK imports ------------------------------------------------------------ |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.ListIterator; |
| | | |
| | | import org.apache.log4j.Logger; |
| | | |
| | | import com.vividsolutions.jts.geom.Coordinate; |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | import com.vividsolutions.jts.geom.CoordinateList; |
| | | |
| | | import com.ximple.util.DgnUtility; |
| | | |
| | | /** |
| | | * TextNodeElement |
| | | * |
| | | * @author Ulysses |
| | | * @version 0.1 |
| | | * @since 2006/5/18 ¤U¤È 04:02:58 |
| | | */ |
| | | public class TextNodeElement extends Element implements ComplexElement, GeometryConverter |
| | | { |
| | | private static final Logger logger = Logger.getLogger(TextElement.class); |
| | | |
| | | private ArrayList<Element> list = new ArrayList<Element>(); |
| | | |
| | | public TextNodeElement(byte[] raw) |
| | | { |
| | | super(raw); |
| | | } |
| | | |
| | | public int size() |
| | | { |
| | | return list.size(); |
| | | } |
| | | |
| | | public boolean isEmpty() |
| | | { |
| | | return list.isEmpty(); |
| | | } |
| | | |
| | | public boolean contains(Object o) |
| | | { |
| | | return list.contains(o); |
| | | } |
| | | |
| | | public Iterator<Element> iterator() |
| | | { |
| | | return list.iterator(); |
| | | } |
| | | |
| | | public Object[] toArray() |
| | | { |
| | | return list.toArray(); |
| | | } |
| | | |
| | | public <T> T[] toArray(T[] ts) |
| | | { |
| | | return list.toArray(ts); |
| | | } |
| | | |
| | | public boolean add(Element element) |
| | | { |
| | | return list.add(element); |
| | | } |
| | | |
| | | public boolean remove(Object o) |
| | | { |
| | | return list.remove(o); |
| | | } |
| | | |
| | | public boolean containsAll(Collection<?> objects) |
| | | { |
| | | return list.containsAll(objects); |
| | | } |
| | | |
| | | public boolean addAll(Collection<? extends Element> elements) |
| | | { |
| | | return list.addAll(elements); |
| | | } |
| | | |
| | | public boolean addAll(int i, Collection<? extends Element> elements) |
| | | { |
| | | return list.addAll(i, elements); |
| | | } |
| | | |
| | | public boolean removeAll(Collection<?> objects) |
| | | { |
| | | return list.removeAll(objects); |
| | | } |
| | | |
| | | public boolean retainAll(Collection<?> objects) |
| | | { |
| | | return list.retainAll(objects); |
| | | } |
| | | |
| | | public void clear() |
| | | { |
| | | list.clear(); |
| | | } |
| | | |
| | | public Element get(int index) |
| | | { |
| | | return list.get(index); |
| | | } |
| | | |
| | | public Element set(int index, Element element) |
| | | { |
| | | return list.set(index, element); |
| | | } |
| | | |
| | | public void add(int index, Element element) |
| | | { |
| | | list.add(index, element); |
| | | } |
| | | |
| | | public Element remove(int index) |
| | | { |
| | | return list.remove(index); |
| | | } |
| | | |
| | | public int indexOf(Object o) |
| | | { |
| | | return list.indexOf(o); |
| | | } |
| | | |
| | | public int lastIndexOf(Object o) |
| | | { |
| | | return list.lastIndexOf(o); |
| | | } |
| | | |
| | | public ListIterator<Element> listIterator() |
| | | { |
| | | return list.listIterator(); |
| | | } |
| | | |
| | | public ListIterator<Element> listIterator(int index) |
| | | { |
| | | return list.listIterator(index); |
| | | } |
| | | |
| | | public List<Element> subList(int fromIndex, int toIndex) |
| | | { |
| | | return list.subList(fromIndex, toIndex); |
| | | } |
| | | |
| | | public Element[] toArray(Element[] a) |
| | | { |
| | | return list.toArray(a); |
| | | } |
| | | |
| | | public String[] getTextArray() |
| | | { |
| | | ArrayList<String> list = new ArrayList<String>(); |
| | | |
| | | for (ListIterator it = listIterator(); it.hasNext();) |
| | | { |
| | | Element element = (Element) it.next(); |
| | | |
| | | if (element instanceof TextElement) |
| | | { |
| | | list.add(((TextElement) element).getText()); |
| | | } |
| | | } |
| | | |
| | | return list.toArray(new String[list.size()]); |
| | | } |
| | | |
| | | public Geometry toGeometry(GeometryFactory factory) |
| | | { |
| | | /* |
| | | * CoordinateList coords = new CoordinateList(); |
| | | * for (ListIterator it = listIterator(); it.hasNext(); ) |
| | | * { |
| | | * Element element = (Element) it.next(); |
| | | * if (element instanceof TextElement) |
| | | * { |
| | | * coords.add(((TextElement) element).getUserOrigin()); |
| | | * } |
| | | * } |
| | | */ |
| | | return factory.createPoint(getOrigin()); |
| | | |
| | | // return factory.createMultiPoint(coords.toCoordinateArray()); |
| | | } |
| | | |
| | | public Geometry toAnchorGeometry(GeometryFactory factory) |
| | | { |
| | | CoordinateList coords = new CoordinateList(); |
| | | for (int i = 0; i < size(); i++) |
| | | { |
| | | TextElement txtElm = (TextElement) get(i); |
| | | coords.add(txtElm.toAnchorCoordinates(), false); |
| | | } |
| | | return factory.createMultiPoint(coords.toCoordinateArray()); |
| | | } |
| | | |
| | | public int getTotalWords() |
| | | { |
| | | return (raw[18] & 0x0000ffff); |
| | | } |
| | | |
| | | public void setTotalWords(int value) |
| | | { |
| | | raw[18] = (short) (value & 0x0000ffff); |
| | | } |
| | | |
| | | public int getNumString() |
| | | { |
| | | return (raw[19] & 0x0000ffff); |
| | | } |
| | | |
| | | public void setNumString(int value) |
| | | { |
| | | raw[19] = (short) (value & 0x0000ffff); |
| | | } |
| | | |
| | | public int getNodeNumber() |
| | | { |
| | | return (raw[20] & 0x0000ffff); |
| | | } |
| | | |
| | | public void setNodeNumber(int value) |
| | | { |
| | | raw[20] = (short) (value & 0x0000ffff); |
| | | } |
| | | |
| | | public int getMaxLength() |
| | | { |
| | | return (raw[21] & 0x00ff); |
| | | } |
| | | |
| | | public void setMaxLength(int value) |
| | | { |
| | | raw[21] = (short) ((value & 0x00ff) | (raw[21] & 0xff00)); |
| | | } |
| | | |
| | | public int getMaxUsed() |
| | | { |
| | | return ((raw[21] >> 8) & 0x00ff); |
| | | } |
| | | |
| | | public void setMaxUsed(int value) |
| | | { |
| | | raw[21] = (short) (((value << 8) & 0xff00) | (raw[21] & 0x00ff)); |
| | | } |
| | | |
| | | public int getJustification() |
| | | { |
| | | return ((raw[22] >> 8) & 0x00ff); |
| | | } |
| | | |
| | | public void setJustification(int value) |
| | | { |
| | | raw[22] = (short) (((value << 8) & 0xff00) | (raw[22] & 0x00ff)); |
| | | } |
| | | |
| | | public int getFontIndex() |
| | | { |
| | | return (raw[22] & 0x00ff); |
| | | } |
| | | |
| | | public void setFontIndex(int value) |
| | | { |
| | | raw[22] = (short) ((value & 0x00ff) | (raw[22] & 0xff00)); |
| | | } |
| | | |
| | | public double getLineSpacing() |
| | | { |
| | | int lineSpace; |
| | | lineSpace = ((raw[23] & 0x0000ffff) << 16) | (raw[24] & 0x0000ffff); |
| | | |
| | | return lineSpace; |
| | | } |
| | | |
| | | public void setLineSpacing(double value) |
| | | { |
| | | int temp = (int) (value*1000.0); |
| | | raw[23] = (short) ((temp >> 16) & 0x0000ffff); |
| | | raw[24] = (short) (temp & 0x0000ffff); |
| | | } |
| | | |
| | | public double getTextNodeLength() |
| | | { |
| | | int lengthMult; |
| | | |
| | | lengthMult = ((raw[25] << 16) & 0xffff0000); |
| | | lengthMult += (raw[26] & 0x0000ffff); |
| | | |
| | | return DgnUtility.converIntToDouble(lengthMult); |
| | | } |
| | | |
| | | public void setTextNodeLength(double value) |
| | | { |
| | | int temp = DgnUtility.converDoubleToInt(value); |
| | | raw[25] = (short) ((temp >> 16) & 0x0000ffff); |
| | | raw[26] = (short) (temp & 0x0000ffff); |
| | | } |
| | | |
| | | public double getTextNodeHeight() |
| | | { |
| | | int heightMult; |
| | | |
| | | heightMult = ((raw[27] << 16) & 0xffff0000); |
| | | heightMult += (raw[28] & 0x0000ffff); |
| | | |
| | | return DgnUtility.converIntToDouble(heightMult); |
| | | } |
| | | |
| | | public void setTextNodeHeight(double value) |
| | | { |
| | | int temp = DgnUtility.converDoubleToInt(value); |
| | | raw[27] = (short) ((temp >> 16) & 0x0000ffff); |
| | | raw[28] = (short) (temp & 0x0000ffff); |
| | | } |
| | | |
| | | public double getRotationAngle() |
| | | { |
| | | int rotation = (raw[29] << 16 & 0xffff0000); |
| | | rotation += raw[30]; |
| | | |
| | | return DgnUtility.converIntToRotation(rotation); |
| | | } |
| | | |
| | | public void setRotationAngle(double value) |
| | | { |
| | | int temp = DgnUtility.converRotatioToInt(value); |
| | | raw[29] = (short) (temp >> 16 & 0x0000ffff); |
| | | raw[30] = (short) (temp & 0x0000ffff); |
| | | } |
| | | |
| | | public Coordinate getOrigin() |
| | | { |
| | | int x = ((raw[31] << 16) & 0xffff0000) | (raw[32] & 0x0000ffff); |
| | | double dx = DgnUtility.converUnitToCoord(x); |
| | | // return DgnUtility.convertFromDGN(x); |
| | | |
| | | int y = ((raw[33] << 16) & 0xffff0000) | (raw[34] & 0x0000ffff); |
| | | double dy = DgnUtility.converUnitToCoord(y); |
| | | |
| | | return new Coordinate(dx, dy); |
| | | } |
| | | |
| | | public void setOrigin(Coordinate value) |
| | | { |
| | | int x = DgnUtility.converCoordToUnit(value.x); |
| | | raw[31] = (short) (x >> 16 & 0x0000ffff); |
| | | raw[32] = (short) (x & 0x0000ffff); |
| | | |
| | | int y = DgnUtility.converCoordToUnit(value.y); |
| | | raw[33] = (short) (y >> 16 & 0x0000ffff); |
| | | raw[34] = (short) (y & 0x0000ffff); |
| | | } |
| | | |
| | | public Object clone() throws CloneNotSupportedException |
| | | { |
| | | int pos = this.rawBuffer.position(); |
| | | this.rawBuffer.position(0); |
| | | byte[] rawBytes = this.rawBuffer.array(); |
| | | byte[] otherRaw = new byte[rawBytes.length]; |
| | | System.arraycopy(rawBytes, 0, otherRaw, 0, rawBytes.length); |
| | | this.rawBuffer.position(pos); |
| | | |
| | | TextNodeElement other = new TextNodeElement(otherRaw); |
| | | for (Object o : this) |
| | | { |
| | | TextElement textElm = (TextElement) o; |
| | | other.add((Element) textElm.clone()); |
| | | } |
| | | |
| | | return other; |
| | | } |
| | | |
| | | public static class ElementHandler extends Element.ElementHandler |
| | | { |
| | | private static ElementHandler instance = null; |
| | | |
| | | public ElementHandler() |
| | | { |
| | | super(ElementType.TEXTNODE); |
| | | } |
| | | |
| | | public static IElementHandler getInstance() |
| | | { |
| | | if (instance == null) |
| | | { |
| | | instance = new ElementHandler(); |
| | | } |
| | | |
| | | return instance; |
| | | } |
| | | |
| | | protected Element createElement(byte[] raw) |
| | | { |
| | | return new TextNodeElement(raw); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | /** |
| | | * UserAttributeData |
| | | * |
| | | * @author Ulysses |
| | | * @version 0.1 |
| | | * @since 2006/5/18 ¤U¤È 02:29:29 |
| | | */ |
| | | public class UserAttributeData |
| | | { |
| | | protected short[] _src; |
| | | |
| | | public UserAttributeData(short id, int attributeCount) |
| | | { |
| | | _src = new short[attributeCount]; |
| | | _src[0] = id; |
| | | } |
| | | |
| | | public UserAttributeData(short[] src) |
| | | { |
| | | _src = src; |
| | | } |
| | | |
| | | public short getID() |
| | | { |
| | | return _src[0]; |
| | | } |
| | | |
| | | public void setID(short value) |
| | | { |
| | | _src[0] = value; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.util; |
| | | |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.ByteOrder; |
| | | |
| | | import org.apache.log4j.Logger; |
| | | |
| | | import com.vividsolutions.jts.geom.Envelope; |
| | | |
| | | /** |
| | | * Utility |
| | | * |
| | | * @author Ulysses |
| | | * @version 0.1 |
| | | * @since 2006/5/18 ¤U¤È 01:33:00 |
| | | */ |
| | | public final class DgnUtility |
| | | { |
| | | private static final Logger logger = Logger.getLogger(DgnUtility.class); |
| | | |
| | | public static double converIntToDouble(int src) |
| | | { |
| | | return (double) ((long) ((src * 6) / 1000.0 + 0.5)) / 1000.0; |
| | | } |
| | | |
| | | public static int converDoubleToInt(double src) |
| | | { |
| | | |
| | | return (int) (src / 6 * 1000000.0); |
| | | } |
| | | |
| | | public static int convertFromDGN(int aValue) |
| | | { |
| | | int newVal; |
| | | |
| | | newVal = (((aValue ^ 0x00008000) << 16) & 0xffff0000); |
| | | newVal |= (aValue >>> 16) & 0x0000ffff; |
| | | |
| | | return newVal; |
| | | } |
| | | |
| | | public static int converToDGN(int aValue) |
| | | { |
| | | int newVal; |
| | | |
| | | newVal = (aValue << 16 & 0xffff0000); |
| | | newVal |= (((aValue ^ 0x80000000) >>> 16) & 0x0000ffff); |
| | | |
| | | return newVal; |
| | | } |
| | | |
| | | public static double converIntToRotation(int aValue) |
| | | { |
| | | |
| | | return aValue / 360000.0; |
| | | } |
| | | |
| | | public static int converRotatioToInt(double aValue) |
| | | { |
| | | |
| | | return (int) (aValue * 360000.0); |
| | | } |
| | | |
| | | public static double converRotationToRadian(double aValue) |
| | | { |
| | | |
| | | return aValue * Math.PI / 180; |
| | | } |
| | | |
| | | public static double converUnitToCoord(int aValue) |
| | | { |
| | | double newVal; |
| | | |
| | | newVal = aValue / 1000.0; |
| | | newVal += 2147483.648; // 2147483.648 = 2 ^ 31 |
| | | |
| | | return newVal; |
| | | } |
| | | |
| | | public static double converUnitToCoord(double aValue) |
| | | { |
| | | double newVal; |
| | | |
| | | newVal = aValue / 1000.0; |
| | | newVal += 2147483.648; // 2147483.648 = 2 ^ 31 |
| | | |
| | | return newVal; |
| | | } |
| | | |
| | | public static int converCoordToUnit(double aValue) |
| | | { |
| | | double newVal = aValue; |
| | | |
| | | newVal -= 2147483.648; |
| | | newVal = newVal * 1000.0; |
| | | |
| | | return (int) newVal; |
| | | } |
| | | |
| | | public static Envelope converUnitToCoord(Envelope range) |
| | | { |
| | | if (range == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | return new Envelope(converUnitToCoord((int) range.getMinX()), converUnitToCoord((int) range.getMaxX()), |
| | | converUnitToCoord((int) range.getMinY()), converUnitToCoord((int) range.getMaxY())); |
| | | } |
| | | |
| | | public static Envelope converCoordToUnit(Envelope range) |
| | | { |
| | | if (range == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | return new Envelope(converCoordToUnit(range.getMinX()), converCoordToUnit(range.getMaxX()), |
| | | converCoordToUnit(range.getMinY()), converCoordToUnit(range.getMaxY())); |
| | | } |
| | | |
| | | public static long convertDGNToRAWIEEEDouble(byte[] org) |
| | | { |
| | | ByteBuffer buf = ByteBuffer.allocate(8); |
| | | buf.order(ByteOrder.LITTLE_ENDIAN); |
| | | buf.mark(); |
| | | buf.put(org[2]); |
| | | buf.put(org[3]); |
| | | buf.put(org[0]); |
| | | buf.put(org[1]); |
| | | buf.put(org[6]); |
| | | buf.put(org[7]); |
| | | buf.put(org[4]); |
| | | buf.put(org[5]); |
| | | buf.position(0); |
| | | |
| | | int[] tmp = new int[2]; |
| | | |
| | | tmp[0] = buf.getInt(); |
| | | tmp[1] = buf.getInt(); |
| | | |
| | | int exponent; |
| | | |
| | | int sign = (tmp[0] & 0x80000000); |
| | | exponent = (tmp[0] >>> 23) & 0x000000ff; |
| | | |
| | | if (exponent != 0) |
| | | { |
| | | exponent = exponent - 129 + 1023; |
| | | } |
| | | |
| | | int rndbits = tmp[1] & 0x00000007; |
| | | tmp[1] = tmp[1] >>> 3; |
| | | tmp[1] = (tmp[1] & 0x1fffffff) | (tmp[0] << 29); |
| | | |
| | | if (rndbits != 0) |
| | | { |
| | | tmp[1] = tmp[1] | 0x00000001; |
| | | } |
| | | |
| | | tmp[0] = (tmp[0] >>> 3) & 0x000fffff; |
| | | tmp[0] = tmp[0] | (exponent << 20) | sign; |
| | | |
| | | buf.position(0); |
| | | buf.order(ByteOrder.BIG_ENDIAN); |
| | | buf.putInt(tmp[0]); |
| | | buf.putInt(tmp[1]); |
| | | buf.position(0); |
| | | byte[] tmpRaw = new byte[8]; |
| | | buf.get(tmpRaw); |
| | | buf.position(0); |
| | | buf.order(ByteOrder.LITTLE_ENDIAN); |
| | | for (int i = tmpRaw.length; i > 0; i--) |
| | | { |
| | | buf.put(tmpRaw[i - 1]); |
| | | } |
| | | buf.position(0); |
| | | long result = buf.getLong(); |
| | | return result; |
| | | } |
| | | |
| | | public static double convertDGNToIEEEDouble(byte[] src) |
| | | { |
| | | return Double.longBitsToDouble(convertDGNToRAWIEEEDouble(src)); |
| | | } |
| | | |
| | | public static short[] convertIEEEDoubleToDGN(double src) |
| | | { |
| | | long newVal = Double.doubleToLongBits(src); |
| | | |
| | | // uint[] tmp = new int[ 2 ]; |
| | | // ushort[] des = new short[ 4 ]; |
| | | int[] tmp = new int[2]; |
| | | short[] des = new short[4]; |
| | | int sign; |
| | | int exponent; |
| | | |
| | | tmp[0] = (int) ((newVal >>> 32)); |
| | | tmp[1] = (int) (newVal); |
| | | |
| | | // sign = ( int ) ( ( uint ) tmp[ 0 ] & 0x80000000 ); |
| | | sign = tmp[0] & 0x80000000; |
| | | exponent = (tmp[0] >>> 20) & 0x07ff; |
| | | |
| | | if (exponent != 0) |
| | | { |
| | | exponent = exponent - 1023 + 129; |
| | | } |
| | | |
| | | if (exponent > 255) |
| | | { |
| | | if (sign != 0) |
| | | { |
| | | des[0] = -1; |
| | | } else |
| | | { |
| | | des[0] = 0x7fff; |
| | | } |
| | | |
| | | des[1] = -1; |
| | | des[2] = -1; |
| | | des[3] = -1; |
| | | |
| | | return des; |
| | | } else if ((exponent < 0) || ((exponent == 0) && (sign == 0))) |
| | | { |
| | | des[0] = 0x0; |
| | | des[1] = 0x0; |
| | | des[2] = 0x0; |
| | | des[3] = 0x0; |
| | | |
| | | return des; |
| | | } else |
| | | { |
| | | tmp[0] = (tmp[0] << 3) | (tmp[1] >> 29); |
| | | tmp[0] = tmp[0] & 0x007fffff; |
| | | tmp[0] = tmp[0] | (exponent << 23) | sign; |
| | | |
| | | // changed by phil 07/05/2004 |
| | | // tmp[ 1 ] = tmp[ 1 ] >> 3; |
| | | tmp[1] = tmp[1] << 3; |
| | | } |
| | | |
| | | des[0] = (short) ((tmp[0] >>> 16) & 0x0000ffff); |
| | | des[1] = (short) (tmp[0] & 0x0000ffff); |
| | | des[2] = (short) ((tmp[1] >>> 16) & 0x0000ffff); |
| | | des[3] = (short) (tmp[1] & 0x0000ffff); |
| | | |
| | | return des; |
| | | } |
| | | |
| | | public static double getLength(double x1, double y1, double x2, double y2) |
| | | { |
| | | double dx = x1 - x2; |
| | | double dy = y1 - y2; |
| | | |
| | | return Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | import java.io.IOException; |
| | | import java.sql.SQLException; |
| | | import java.util.List; |
| | | |
| | | import org.testng.annotations.BeforeTest; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import com.vividsolutions.jts.geom.Coordinate; |
| | | |
| | | import oracle.jdbc.OracleConnection; |
| | | |
| | | import com.ximple.util.PrintfFormat; |
| | | |
| | | /** |
| | | * Dgn7OracleReaderTest |
| | | * User: Ulysses |
| | | * Date: 2007/10/24 |
| | | * Time: ¤W¤È 10:49:54 |
| | | */ |
| | | public class Dgn7OracleReaderTest |
| | | { |
| | | @BeforeTest |
| | | public void setUp() |
| | | { |
| | | |
| | | } |
| | | |
| | | @Test |
| | | public void testOracleReader() throws SQLException, IOException |
| | | { |
| | | OracleConnection connection = OracleTarget.getInstance().getOracleConnection(); |
| | | // String fetchSrcStmtFmt = "SELECT IGDSELM FROM \"%s\".\"%s\" ORDER BY ROWID"; |
| | | String fetchSrcStmtFmt = "SELECT IGDSELM FROM \"%s\".\"%s\" WHERE TAG_SFSC=106 ORDER BY ROWID"; |
| | | PrintfFormat spf = new PrintfFormat(fetchSrcStmtFmt); |
| | | String srcschema = "SPATIALDB"; |
| | | String srctable = "IGSET_1"; |
| | | String fetchSrcStmt = spf.sprintf(new Object[]{srcschema, srctable}); |
| | | |
| | | Dgn7OracleReader reader = new Dgn7OracleReader(fetchSrcStmt, "IGDSELM", connection); |
| | | int count = 0; |
| | | while (reader.hasNext()) |
| | | { |
| | | Element element = reader.next(); |
| | | |
| | | if (element instanceof ComplexChainElement) |
| | | { |
| | | ComplexChainElement complexChain = (ComplexChainElement) element; |
| | | FrammeAttributeData frammeLinkage = null; |
| | | |
| | | List<UserAttributeData> attrs = complexChain.getUserAttributeData(); |
| | | for (int k = 0; k < attrs.size(); k++) |
| | | { |
| | | UserAttributeData userAttr = attrs.get(k); |
| | | if (userAttr instanceof FrammeAttributeData) |
| | | { |
| | | frammeLinkage = (FrammeAttributeData) userAttr; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | System.out.print("complexChain:"); |
| | | if (frammeLinkage != null) |
| | | System.out.print(":FSC-" + frammeLinkage.getFsc() + |
| | | ":UFID-" + frammeLinkage.getUfid() + |
| | | ":COMP-" + frammeLinkage.getComponentID()); |
| | | else |
| | | System.out.print("Linkage is null"); |
| | | |
| | | for (int i = 0; i < complexChain.size(); i++) |
| | | { |
| | | Element elm = (Element) complexChain.get(i); |
| | | if (elm instanceof LineStringElement) |
| | | { |
| | | LineStringElement lineStringElement = (LineStringElement) elm; |
| | | int size = lineStringElement.getVerticeSize(); |
| | | System.out.print("size=" + size + ":"); |
| | | Coordinate[] coords = lineStringElement.getVertices(); |
| | | for (int j = 0; j < coords.length; j++) |
| | | System.out.print("[" + j + "]" + coords[j].toString()); |
| | | } |
| | | } |
| | | |
| | | System.out.println(); |
| | | } else if (element instanceof TextNodeElement) |
| | | { |
| | | TextNodeElement textNode = (TextNodeElement) element; |
| | | |
| | | FrammeAttributeData frammeLinkage = null; |
| | | |
| | | List<UserAttributeData> attrs = textNode.getUserAttributeData(); |
| | | for (int k = 0; k < attrs.size(); k++) |
| | | { |
| | | UserAttributeData userAttr = attrs.get(k); |
| | | if (userAttr instanceof FrammeAttributeData) |
| | | { |
| | | frammeLinkage = (FrammeAttributeData) userAttr; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | Coordinate coord = textNode.getOrigin(); |
| | | System.out.print("TextNode:origin=" + coord.toString()); |
| | | if (frammeLinkage != null) |
| | | System.out.print(":FSC-" + frammeLinkage.getFsc() + |
| | | ":UFID-" + frammeLinkage.getUfid() + |
| | | ":COMP-" + frammeLinkage.getComponentID()); |
| | | else |
| | | System.out.print("Linkage is null"); |
| | | for (int i = 0; i < textNode.size(); i++) |
| | | { |
| | | Element elm = (Element) textNode.get(i); |
| | | if (elm instanceof TextElement) |
| | | { |
| | | TextElement textElm = (TextElement) elm; |
| | | System.out.print("---"); |
| | | String text = textElm.getText(); |
| | | System.out.print("'" + text + "'"); |
| | | } |
| | | } |
| | | System.out.println(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileNotFoundException; |
| | | import java.io.IOException; |
| | | import java.nio.channels.FileChannel; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | |
| | | import org.apache.log4j.Logger; |
| | | import org.geotools.TestData; |
| | | import org.testng.annotations.BeforeTest; |
| | | import org.testng.annotations.Test; |
| | | |
| | | /** |
| | | * Dgn7TextElementReaderTest |
| | | * User: Ulysses |
| | | * Date: 2008/1/10 |
| | | * Time: ¤W¤È 12:19:14 |
| | | */ |
| | | public class Dgn7TextElementReaderTest |
| | | { |
| | | private final static Logger logger = Logger.getLogger(Dgn7fileReaderTest.class); |
| | | |
| | | private final static String testFilePathCreated = "demo.dgn"; |
| | | private final static String testFilePathExist = "HV88491-1.dgn"; |
| | | private final static String testFilePathPostComplete = "HV88494_0.dgn"; |
| | | |
| | | private FileInputStream _fs; |
| | | |
| | | @BeforeTest |
| | | public void setUp() throws FileNotFoundException |
| | | { |
| | | } |
| | | |
| | | @Test |
| | | public void testRead() throws Dgn7fileException, IOException |
| | | { |
| | | File dataFile = TestData.file(this, testFilePathCreated); |
| | | if (dataFile.exists()) |
| | | { |
| | | System.out.println("Output--" + testFilePathCreated); |
| | | _fs = new FileInputStream(dataFile); |
| | | FileChannel fc = _fs.getChannel(); |
| | | dumpElements(fc); |
| | | fc.close(); |
| | | _fs.close(); |
| | | } |
| | | |
| | | dataFile = TestData.file(this, testFilePathExist); |
| | | if (dataFile.exists()) |
| | | { |
| | | System.out.println("Output--" + testFilePathExist); |
| | | _fs = new FileInputStream(dataFile); |
| | | FileChannel fc = _fs.getChannel(); |
| | | dumpElements(fc); |
| | | fc.close(); |
| | | _fs.close(); |
| | | } |
| | | |
| | | dataFile = TestData.file(this, testFilePathPostComplete); |
| | | if (dataFile.exists()) |
| | | { |
| | | System.out.println("Output--" + testFilePathPostComplete); |
| | | _fs = new FileInputStream(dataFile); |
| | | FileChannel fc = _fs.getChannel(); |
| | | dumpElements(fc); |
| | | fc.close(); |
| | | _fs.close(); |
| | | } |
| | | } |
| | | |
| | | public void dumpElements(FileChannel fc) throws Dgn7fileException, IOException |
| | | { |
| | | Dgn7fileReader reader = new Dgn7fileReader(fc, new Lock()); |
| | | 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())) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | // @todo add process in here |
| | | lastComplex = null; |
| | | } |
| | | |
| | | // @todo add process in here |
| | | } else if (element.isComponentElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | ((ComplexElement) lastComplex).add(element); |
| | | } |
| | | } else if (type.isComplexElement()) |
| | | { |
| | | if (lastComplex == null) |
| | | { |
| | | lastComplex = element; |
| | | } else |
| | | { |
| | | // @todo add process in here |
| | | lastComplex = element; |
| | | } |
| | | } |
| | | |
| | | if (element.getElementType().isComplexElement()) |
| | | { |
| | | if (element instanceof ComplexChainElement) |
| | | { |
| | | ComplexChainElement complexChain = (ComplexChainElement) element; |
| | | int size = complexChain.size(); |
| | | for (Object aComplexChain : complexChain) |
| | | { |
| | | Element subElement = (Element) aComplexChain; |
| | | subElement.getType(); |
| | | } |
| | | } |
| | | |
| | | if (element instanceof ComplexShapeElement) |
| | | { |
| | | ComplexShapeElement complexShape = (ComplexShapeElement) element; |
| | | } |
| | | |
| | | if (element instanceof TextNodeElement) |
| | | { |
| | | TextNodeElement textNode = (TextNodeElement) element; |
| | | int size = textNode.size(); |
| | | for (int i = 0; i < size; i++) |
| | | { |
| | | Element subElement = (Element) textNode.get(i); |
| | | subElement.getElementType(); |
| | | } |
| | | } |
| | | |
| | | } else |
| | | { |
| | | boolean hasLinkage = false; |
| | | if (element instanceof TextElement) |
| | | { |
| | | TextElement textElm = (TextElement) element; |
| | | List<UserAttributeData> usrData = textElm.getUserAttributeData(); |
| | | Iterator<UserAttributeData> it = usrData.iterator(); |
| | | while (it.hasNext()) |
| | | { |
| | | UserAttributeData attr = it.next(); |
| | | if (attr instanceof FrammeAttributeData) |
| | | { |
| | | hasLinkage = true; |
| | | System.out.println("------------------------------------------"); |
| | | System.out.println("FSC=" + ((FrammeAttributeData) attr).getFsc() + ":" + |
| | | ((FrammeAttributeData) attr).getUfid()); |
| | | } |
| | | } |
| | | |
| | | if (hasLinkage) |
| | | { |
| | | System.out.println("Text.Font=" + textElm.getFontIndex()); |
| | | System.out.println("Text.Just=" + textElm.getJustification()); |
| | | System.out.println("usrData.len=" + usrData.size()); |
| | | System.out.println("text=" + textElm.getText()); |
| | | System.out.println("Origin=" + textElm.getOrigin()); |
| | | System.out.println("UserOrigin=" + textElm.getUserOrigin()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | count++; |
| | | } |
| | | |
| | | logger.info("ElementRecord Count=" + count); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.nio.channels.FileChannel; |
| | | |
| | | import org.apache.log4j.Logger; |
| | | import org.geotools.TestData; |
| | | import org.testng.annotations.BeforeTest; |
| | | import org.testng.annotations.Test; |
| | | |
| | | /** |
| | | * Dgn7fileReaderTest |
| | | * User: Ulysses |
| | | * Date: 2007/10/24 |
| | | * Time: ¤W¤È 01:43:41 |
| | | * To change this template use File | Settings | File Templates. |
| | | */ |
| | | public class Dgn7fileReaderTest |
| | | { |
| | | private final static Logger logger = Logger.getLogger(Dgn7fileReaderTest.class); |
| | | |
| | | // private final static String testFilePath = "test-data\\testHV.dgn"; |
| | | private final static String testFilePath = "testHV.dgn"; |
| | | private FileInputStream _fs; |
| | | |
| | | @BeforeTest |
| | | public void setUp() throws IOException |
| | | { |
| | | File dataFile = TestData.file(this, testFilePath); |
| | | if (!dataFile.exists()) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | _fs = new FileInputStream(dataFile); |
| | | } |
| | | |
| | | @Test |
| | | public void testRead() throws Dgn7fileException, IOException |
| | | { |
| | | if (_fs == null) return; |
| | | FileChannel fc = _fs.getChannel(); |
| | | Dgn7fileReader reader = new Dgn7fileReader(fc, new Lock()); |
| | | 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())) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | // @todo add process in here |
| | | lastComplex = null; |
| | | } |
| | | |
| | | // @todo add process in here |
| | | } else if (element.isComponentElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | ((ComplexElement) lastComplex).add(element); |
| | | } |
| | | } else if (type.isComplexElement()) |
| | | { |
| | | if (lastComplex == null) |
| | | { |
| | | lastComplex = element; |
| | | } else |
| | | { |
| | | // @todo add process in here |
| | | lastComplex = element; |
| | | } |
| | | } |
| | | |
| | | if (element.getElementType().isComplexElement()) |
| | | { |
| | | if (element instanceof ComplexChainElement) |
| | | { |
| | | ComplexChainElement complexChain = (ComplexChainElement) element; |
| | | int size = complexChain.size(); |
| | | for (Object aComplexChain : complexChain) |
| | | { |
| | | Element subElement = (Element) aComplexChain; |
| | | subElement.getType(); |
| | | } |
| | | } |
| | | |
| | | if (element instanceof ComplexShapeElement) |
| | | { |
| | | ComplexShapeElement complexShape = (ComplexShapeElement) element; |
| | | } |
| | | |
| | | if (element instanceof TextNodeElement) |
| | | { |
| | | TextNodeElement textNode = (TextNodeElement) element; |
| | | int size = textNode.size(); |
| | | for (int i = 0; i < size; i++) |
| | | { |
| | | Element subElement = (Element) textNode.get(i); |
| | | subElement.getElementType(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | count++; |
| | | } |
| | | |
| | | logger.info("ElementRecord Count=" + count); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | //~--- JDK imports ------------------------------------------------------------ |
| | | |
| | | import java.sql.DriverManager; |
| | | import java.sql.SQLException; |
| | | import java.util.Properties; |
| | | |
| | | import org.apache.log4j.Logger; |
| | | |
| | | import com.vividsolutions.jts.util.Assert; |
| | | |
| | | import oracle.jdbc.OracleConnection; |
| | | |
| | | /** |
| | | * OracleTarget |
| | | * User: Ulysses |
| | | * Date: 2007/6/15 |
| | | * Time: ?U?? 03:12:43 |
| | | * To change this template use File | Settings | File Templates. |
| | | */ |
| | | public class OracleTarget |
| | | { |
| | | private static final Logger logger = Logger.getLogger(OracleTarget.class); |
| | | private static OracleTarget _instance = null; |
| | | private static final String ORACLE_URL = "jdbc:oracle:thin:@"; |
| | | private static final String _propUsrKey = "user"; |
| | | private static final String _propPassKey = "password"; |
| | | private static String _oracleHost = "192.168.11.200"; |
| | | private static String _oracleInstance = "NNTPC"; |
| | | private static String _oraclePort = "1521"; |
| | | |
| | | static |
| | | { |
| | | try |
| | | { |
| | | DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); |
| | | } catch (SQLException e) |
| | | { |
| | | Assert.shouldNeverReachHere(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | private OracleConnection oracleConnection = null; |
| | | private Properties properties; |
| | | |
| | | private OracleTarget() |
| | | { |
| | | properties = new Properties(); |
| | | properties.put(_propUsrKey, "SPATIALDB"); |
| | | properties.put(_propPassKey, "SPATIALDB000"); |
| | | } |
| | | |
| | | public static String getOracleHost() |
| | | { |
| | | return _oracleHost; |
| | | } |
| | | |
| | | public static void setOracleHost(String oracleHost) |
| | | { |
| | | OracleTarget._oracleHost = oracleHost; |
| | | } |
| | | |
| | | public static String getOracleInstance() |
| | | { |
| | | return _oracleInstance; |
| | | } |
| | | |
| | | public static void setOracleInstance(String oracleInstance) |
| | | { |
| | | OracleTarget._oracleInstance = oracleInstance; |
| | | } |
| | | |
| | | public static String getOraclePort() |
| | | { |
| | | return _oraclePort; |
| | | } |
| | | |
| | | public static void setOraclePort(String oraclePort) |
| | | { |
| | | OracleTarget._oraclePort = oraclePort; |
| | | } |
| | | |
| | | public static String getCurrentURL() |
| | | { |
| | | StringBuilder builder = new StringBuilder(); |
| | | |
| | | builder.append(ORACLE_URL); |
| | | builder.append(_oracleHost); |
| | | builder.append(":"); |
| | | builder.append(_oraclePort); |
| | | builder.append(":"); |
| | | builder.append(_oracleInstance); |
| | | |
| | | return builder.toString(); |
| | | } |
| | | |
| | | public String getLoginPass() |
| | | { |
| | | return (String) properties.get(_propPassKey); |
| | | } |
| | | |
| | | public void setLoginPass(String loginPass) |
| | | { |
| | | properties.put(_propPassKey, loginPass); |
| | | } |
| | | |
| | | public String getLoginUsr() |
| | | { |
| | | return (String) properties.get(_propUsrKey); |
| | | } |
| | | |
| | | public void setLoginUsr(String loginUsr) |
| | | { |
| | | properties.put(_propUsrKey, loginUsr); |
| | | } |
| | | |
| | | public static OracleTarget getInstance() |
| | | { |
| | | if (_instance == null) |
| | | { |
| | | _instance = new OracleTarget(); |
| | | } |
| | | |
| | | return _instance; |
| | | } |
| | | |
| | | public OracleConnection getOracleConnection() |
| | | { |
| | | try |
| | | { |
| | | if (oracleConnection == null) |
| | | { |
| | | oracleConnection = (OracleConnection) DriverManager.getConnection(getCurrentURL(), properties); |
| | | } |
| | | |
| | | return oracleConnection; |
| | | } catch (SQLException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | } |
| | | |
| | | oracleConnection = null; |
| | | |
| | | return null; |
| | | } |
| | | |
| | | public void closeConnection() |
| | | { |
| | | try |
| | | { |
| | | if (oracleConnection != null) |
| | | { |
| | | oracleConnection.close(); |
| | | oracleConnection = null; |
| | | } |
| | | } catch (SQLException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | } |
| | | } |
| | | } |
| | | |
New file |
| | |
| | | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
| | | <modelVersion>4.0.0</modelVersion> |
| | | |
| | | |
| | | <parent> |
| | | <groupId>com.ximple.eofms</groupId> |
| | | <artifactId>ximple-dgnjobs</artifactId> |
| | | <version>0.9.0</version> |
| | | </parent> |
| | | |
| | | |
| | | <groupId>com.ximple.eofms</groupId> |
| | | <artifactId>ximple-elmparser</artifactId> |
| | | <version>0.9.0</version> |
| | | <packaging>jar</packaging> |
| | | <name>ximple-elmparser</name> |
| | | <url>http://maven.apache.org</url> |
| | | |
| | | <properties> |
| | | <xdgnio.version>0.9.0</xdgnio.version> |
| | | </properties> |
| | | |
| | | <scm> |
| | | <connection> |
| | | scm:svn:http://www.ximple.com.tw/svn/xeofms/xspatialjob/truck/ |
| | | </connection> |
| | | <url>http://www.ximple.com.tw/svn/xeofms/xspatialjob/truck/</url> |
| | | </scm> |
| | | |
| | | <description> |
| | | Ximple Element Parser |
| | | </description> |
| | | |
| | | <organization> |
| | | <name>Ximple</name> |
| | | <url>http://www.ximple.com.tw</url> |
| | | </organization> |
| | | |
| | | <inceptionYear>2008</inceptionYear> |
| | | |
| | | <developers> |
| | | <developer> |
| | | <name>Kuo-Feng Kao</name> |
| | | <id>ulysseskao</id> |
| | | <email>ulysseskao@ximple.com.tw</email> |
| | | <organization>Ximple</organization> |
| | | <roles> |
| | | <role>Java Developer</role> |
| | | </roles> |
| | | </developer> |
| | | </developers> |
| | | |
| | | <contributors> |
| | | </contributors> |
| | | |
| | | <!-- =========================================================== --> |
| | | <!-- Dependencies to be inherited by all modules. --> |
| | | <!-- =========================================================== --> |
| | | <dependencies> |
| | | <dependency> |
| | | <artifactId>quartz</artifactId> |
| | | <groupId>opensymphony</groupId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>javax.transaction</groupId> |
| | | <artifactId>jta</artifactId> |
| | | <version>1.0.1B</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-shapefile</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-sample-data</artifactId> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-data</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-jdbc</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-postgis</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-oracle-spatial</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-mysql</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- because main and sample-data depend on referencing we need a tie breaker --> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-referencing</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- We need this to make the referencing module useful --> |
| | | <dependency> |
| | | <artifactId>gt2-epsg-hsql</artifactId> |
| | | <groupId>org.geotools</groupId> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <artifactId>jdom</artifactId> |
| | | <groupId>jdom</groupId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.apache.velocity</groupId> |
| | | <artifactId>velocity</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>commons-cli</groupId> |
| | | <artifactId>commons-cli</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- ORACLE --> |
| | | <dependency> |
| | | <groupId>com.oracle</groupId> |
| | | <artifactId>ojdbc5</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.oracle</groupId> |
| | | <artifactId>ojdbc5</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.oracle</groupId> |
| | | <artifactId>sdoapi</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.oracle</groupId> |
| | | <artifactId>sdotype</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.oracle</groupId> |
| | | <artifactId>sdoutl</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>postgresql</groupId> |
| | | <artifactId>postgresql</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.postgis</groupId> |
| | | <artifactId>postgis-driver</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>mysql</groupId> |
| | | <artifactId>mysql-connector-java</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- AWL --> |
| | | <dependency> |
| | | <groupId>org.awl</groupId> |
| | | <artifactId>awl</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- Ximple Library --> |
| | | <dependency> |
| | | <artifactId>ximple-dgnio</artifactId> |
| | | <groupId>com.ximple.eofms</groupId> |
| | | <version>${xdgnio.version}</version> |
| | | </dependency> |
| | | <dependency> |
| | | <artifactId>ximple-spatialjob</artifactId> |
| | | <groupId>com.ximple.eofms</groupId> |
| | | <version>${xdgnio.version}</version> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
| | | <plugins> |
| | | <!-- ======================================================= --> |
| | | <!-- JAR packaging. --> |
| | | <!-- ======================================================= --> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-jar-plugin</artifactId> |
| | | <configuration> |
| | | <archive> |
| | | <manifest> |
| | | <mainClass>com.ximple.eofms.XElementParser</mainClass> |
| | | <addClasspath>true</addClasspath> |
| | | </manifest> |
| | | </archive> |
| | | </configuration> |
| | | </plugin> |
| | | <!-- ======================================================= --> |
| | | <!-- exec jar. --> |
| | | <!-- ======================================================= --> |
| | | <plugin> |
| | | <!-- |
| | | Use maven from the command line: |
| | | mvn exec:java -Dexec.mainClass="com.ximple.eofms.XElementParser" |
| | | --> |
| | | <artifactId>exec-maven-plugin</artifactId> |
| | | <groupId>org.codehaus.mojo</groupId> |
| | | <!-- |
| | | <executions> |
| | | <execution> |
| | | <phase>package</phase> |
| | | <goals> |
| | | <goal>run</goal> |
| | | </goals> |
| | | </execution> |
| | | </executions> |
| | | --> |
| | | <configuration> |
| | | <mainClass>com.ximple.eofms.XElementParser</mainClass> |
| | | <!-- |
| | | <commandlineArgs>-wizard</commandlineArgs> |
| | | --> |
| | | </configuration> |
| | | <!-- |
| | | <dependencies> |
| | | <dependency> |
| | | <groupId>com.ximple.eofms</groupId> |
| | | <artifactId>ximple-jobcarrier</artifactId> |
| | | <version>0.0.1</version> |
| | | <type>jar</type> |
| | | </dependency> |
| | | </dependencies> |
| | | --> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>com.ximple.eofms.maven</groupId> |
| | | <artifactId>ximple-jar-collector</artifactId> |
| | | <version>${project.version}</version> |
| | | <executions> |
| | | <execution> |
| | | <goals> |
| | | <goal>collect</goal> |
| | | </goals> |
| | | </execution> |
| | | </executions> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.codehaus.mojo</groupId> |
| | | <artifactId>native2ascii-maven-plugin</artifactId> |
| | | <version>1.0-alpha-1</version> |
| | | <configuration> |
| | | <dest>target/classes/com/ximple/eofms</dest> |
| | | <src>src/main/resources/com/ximple/eofms</src> |
| | | </configuration> |
| | | <executions> |
| | | <execution> |
| | | <id>native2ascii-utf8</id> |
| | | <goals> |
| | | <goal>native2ascii</goal> |
| | | </goals> |
| | | <configuration> |
| | | <encoding>UTF8</encoding> |
| | | <includes>XElementParser_zh*.properties</includes> |
| | | </configuration> |
| | | </execution> |
| | | </executions> |
| | | </plugin> |
| | | </plugins> |
| | | <resources> |
| | | <resource> |
| | | <directory>src/main/resources/com/ximple/eofms</directory> |
| | | <excludes> |
| | | <exclude>XElementParser_zh*.properties</exclude> |
| | | </excludes> |
| | | <filtering>true</filtering> |
| | | </resource> |
| | | <resource> |
| | | <directory>src/main/resources</directory> |
| | | <includes> |
| | | <include>log4j.properties</include> |
| | | </includes> |
| | | <filtering>false</filtering> |
| | | </resource> |
| | | </resources> |
| | | </build> |
| | | |
| | | </project> |
New file |
| | |
| | | package com.ximple.eofms; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.math.BigDecimal; |
| | | import java.net.MalformedURLException; |
| | | import java.net.URL; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.ByteOrder; |
| | | import java.sql.Connection; |
| | | import java.sql.ResultSet; |
| | | import java.sql.SQLException; |
| | | import java.sql.Statement; |
| | | import java.sql.Types; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.StringTokenizer; |
| | | import java.util.TreeMap; |
| | | |
| | | import org.apache.commons.collections.OrderedMap; |
| | | import org.apache.commons.collections.OrderedMapIterator; |
| | | import org.apache.commons.collections.map.LinkedMap; |
| | | import org.apache.commons.collections.map.MultiValueMap; |
| | | import org.apache.commons.digester.Digester; |
| | | import org.apache.commons.digester.xmlrules.DigesterLoader; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.geotools.data.Transaction; |
| | | import org.geotools.data.oracle.OracleDataStore; |
| | | import org.geotools.data.oracle.OracleDataStoreFactory; |
| | | import org.xml.sax.SAXException; |
| | | |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | import com.vividsolutions.jts.util.Assert; |
| | | |
| | | import oracle.sql.BLOB; |
| | | |
| | | import com.ximple.eofms.filter.ElementDispatcher; |
| | | import com.ximple.eofms.jobs.OracleElementLogger; |
| | | import com.ximple.eofms.jobs.context.postgis.FeatureDgnConvertPostGISJobContext; |
| | | import com.ximple.io.dgn7.ArcElement; |
| | | import com.ximple.io.dgn7.ComplexChainElement; |
| | | import com.ximple.io.dgn7.ComplexElement; |
| | | import com.ximple.io.dgn7.Dgn7fileException; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.ElementType; |
| | | import com.ximple.io.dgn7.IElementHandler; |
| | | import com.ximple.util.PrintfFormat; |
| | | |
| | | public class XElementFetcher implements Runnable |
| | | { |
| | | /** |
| | | * The Oracle driver class name |
| | | */ |
| | | private static final String JDBC_DRIVER = "oracle.jdbc.driver.OracleDriver"; |
| | | private static final String ORAHOST = "ORAHOST"; |
| | | private static final String ORAINST = "ORAINST"; |
| | | private static final String ORAPORT = "ORAPORT"; |
| | | private static final String ORAUSER = "ORAUSER"; |
| | | private static final String ORAPASS = "ORAPASS"; |
| | | private static final String ORGSCHEMA = "ORGSCHEMA"; |
| | | |
| | | private static final int FETCHSIZE = 30; |
| | | private static final int COMMITSIZE = 100; |
| | | private static final int MAXELM_LOGCOUNT = 6000; |
| | | |
| | | private static final String FETCHLOGGER_PREFIX = "XFE_"; |
| | | |
| | | static Log logger = LogFactory.getLog(XElementFetcher.class); |
| | | static final GeometryFactory geometryFactory = new GeometryFactory(); |
| | | |
| | | static final boolean isCompactMode = true; |
| | | static OracleDataStoreFactory dataStoreFactory = new OracleDataStoreFactory(); |
| | | |
| | | protected static class Pair |
| | | { |
| | | Object first; |
| | | Object second; |
| | | |
| | | public Pair(Object first, Object second) |
| | | { |
| | | this.first = first; |
| | | this.second = second; |
| | | } |
| | | } |
| | | |
| | | private HashMap<String, String> dataConfig; |
| | | private ElementDispatcher elementDispatcher; |
| | | private MultiValueMap featuresContext = new MultiValueMap(); |
| | | private boolean driverFound = true; |
| | | |
| | | public static void main(String[] args) |
| | | { |
| | | XElementFetcher fetcher = new XElementFetcher(); |
| | | fetcher.run(); |
| | | } |
| | | |
| | | public XElementFetcher() |
| | | { |
| | | initializeDataConfig(); |
| | | try |
| | | { |
| | | Class.forName(JDBC_DRIVER); |
| | | } catch (Throwable t) |
| | | { |
| | | // must be running off dummy jar! |
| | | driverFound = false; |
| | | } |
| | | } |
| | | |
| | | private void initializeDataConfig() |
| | | { |
| | | dataConfig = new HashMap<String, String>(); |
| | | dataConfig.put(XElementParser.ROOTDATAPATH, XElementParser.DEFAULT_DATAPATH); |
| | | dataConfig.put(ORAHOST, "192.168.11.200"); |
| | | dataConfig.put(ORAINST, "tctpc"); |
| | | dataConfig.put(ORAPORT, "1521"); |
| | | dataConfig.put(ORAUSER, "spatialdb"); |
| | | dataConfig.put(ORAPASS, "spatialdb000"); |
| | | // dataConfig.put(ORGSCHEMA, "SPATIALDB, CMMS_SPATIALDB"); |
| | | dataConfig.put(ORGSCHEMA, "CMMS_SPATIALDB"); |
| | | |
| | | elementDispatcher = createElementDispatcher(); |
| | | } |
| | | |
| | | private ElementDispatcher createElementDispatcher() |
| | | { |
| | | try |
| | | { |
| | | URL rulesURL = ElementDispatcher.class.getResource("ElementDispatcherRules.xml"); |
| | | assert rulesURL != null; |
| | | Digester digester = DigesterLoader.createDigester(rulesURL); |
| | | URL filterURL; |
| | | |
| | | filterURL = FeatureDgnConvertPostGISJobContext.class.getResource("/conf/DefaultConvertShpFilter.xml"); |
| | | |
| | | assert filterURL != null; |
| | | return (ElementDispatcher) digester.parse(filterURL); |
| | | } catch (UnsupportedEncodingException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } catch (MalformedURLException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } catch (IOException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } catch (SAXException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | public void run() |
| | | { |
| | | try |
| | | { |
| | | OracleDataStore dataStore = createSourceDataStore(); |
| | | ArrayList<String> schemas = getSchemaNames(); |
| | | for (String schema : schemas) |
| | | { |
| | | executeFetchElement(dataStore, schema, getOutputPath()); |
| | | } |
| | | } catch (SQLException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | private String getOutputPath() |
| | | { |
| | | return dataConfig.get(XElementParser.ROOTDATAPATH) + File.separator + XElementParser.DEFAULT_DGNOUTPATH; |
| | | } |
| | | |
| | | protected OracleDataStore createSourceDataStore() |
| | | { |
| | | if (!driverFound) |
| | | { |
| | | throw new RuntimeException("Oracle JDBC Driver not found.-" + JDBC_DRIVER); |
| | | } |
| | | Map<String, String> map = new TreeMap<String, String>(); |
| | | map.put("host", dataConfig.get(ORAHOST)); |
| | | map.put("port", dataConfig.get(ORAPORT)); |
| | | map.put("instance", dataConfig.get(ORAINST)); |
| | | map.put("user", dataConfig.get(ORAUSER)); |
| | | map.put("passwd", dataConfig.get(ORAPASS)); |
| | | map.put("dbtype", "oracle"); |
| | | map.put("alias", dataConfig.get(ORAINST)); |
| | | map.put("namespace", null); |
| | | if (!map.containsKey(OracleDataStoreFactory.MAXCONN.key)) |
| | | { |
| | | map.put(OracleDataStoreFactory.MAXCONN.key, "10"); |
| | | } |
| | | if (!map.containsKey(OracleDataStoreFactory.MINCONN.key)) |
| | | { |
| | | map.put(OracleDataStoreFactory.MINCONN.key, "1"); |
| | | } |
| | | |
| | | if (!dataStoreFactory.canProcess(map)) |
| | | { |
| | | logger.warn("cannot process properties-"); |
| | | throw new RuntimeException("cannot process properties-"); |
| | | } |
| | | try |
| | | { |
| | | return (OracleDataStore) dataStoreFactory.createDataStore(map); |
| | | } catch (IOException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | private ArrayList<String> getSchemaNames() |
| | | { |
| | | ArrayList<String> result = new ArrayList<String>(); |
| | | String strSchema = dataConfig.get(ORGSCHEMA); |
| | | StringTokenizer st = new StringTokenizer(strSchema, ","); |
| | | while (st.hasMoreTokens()) |
| | | { |
| | | String aSchema = st.nextToken().trim(); |
| | | result.add(aSchema); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | protected OrderedMap getBlobStorageList(Connection connection, String schemaSrc, String tableSrc, |
| | | OrderedMap orderedMap) throws SQLException |
| | | { |
| | | if (orderedMap == null) |
| | | orderedMap = new LinkedMap(99); |
| | | String fetchStmtFmt = "SELECT SNID, SPACETABLE FROM \"%s\".\"%s\""; |
| | | PrintfFormat spf = new PrintfFormat(fetchStmtFmt); |
| | | String fetchStmt = spf.sprintf(new Object[]{schemaSrc, tableSrc}); |
| | | Statement stmt = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
| | | ResultSet rs = null; |
| | | |
| | | stmt.setFetchSize(FETCHSIZE); |
| | | try |
| | | { |
| | | rs = stmt.executeQuery(fetchStmt); |
| | | int size = rs.getMetaData().getColumnCount(); |
| | | |
| | | while (rs.next()) |
| | | { |
| | | Object[] values = new Object[size]; |
| | | |
| | | for (int i = 0; i < size; i++) |
| | | { |
| | | values[i] = rs.getObject(i + 1); |
| | | } |
| | | |
| | | Integer key = ((BigDecimal) values[0]).intValue(); |
| | | String name = (String) values[1]; |
| | | |
| | | Pair pair = (Pair) orderedMap.get(key); |
| | | if (pair == null) |
| | | orderedMap.put(key, new Pair(name, null)); |
| | | else |
| | | pair.first = name; |
| | | } |
| | | } catch (SQLException e) |
| | | { |
| | | logger.error(e.toString(), e); |
| | | logger.error("stmt=" + fetchStmt); |
| | | throw e; |
| | | } finally |
| | | { |
| | | if (rs != null) rs.close(); |
| | | if (stmt != null) stmt.close(); |
| | | } |
| | | |
| | | return orderedMap; |
| | | } |
| | | |
| | | public Connection getOracleConnection(OracleDataStore dataStore) |
| | | { |
| | | try |
| | | { |
| | | return dataStore.getConnection(Transaction.AUTO_COMMIT); |
| | | } catch (IOException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | private void executeFetchElement(OracleDataStore dataStore, String schema, String dataPath) throws SQLException |
| | | { |
| | | Connection connection = getOracleConnection(dataStore); |
| | | |
| | | int order = 0; |
| | | OrderedMap map = getBlobStorageList(connection, schema, "SD$SPACENODES", null); |
| | | logger.info("begin fecther job:[" + map.size() + "]"); |
| | | |
| | | int total = map.size(); //spacenodes count |
| | | int step = total / 100; |
| | | int current = 0; |
| | | |
| | | OracleElementLogger elmLogger = createElementLogger(connection, dataPath); |
| | | elmLogger.setLogPrefix(FETCHLOGGER_PREFIX); |
| | | |
| | | for (OrderedMapIterator it = map.orderedMapIterator(); it.hasNext();) |
| | | { |
| | | it.next(); |
| | | |
| | | Pair pair = (Pair) it.getValue(); |
| | | String tableSrc = (String) pair.first; |
| | | |
| | | logger.info("begin convert:[" + order + "]-" + tableSrc); |
| | | queryNFetchIgsetElement(connection, schema, tableSrc, elmLogger); |
| | | |
| | | order++; |
| | | |
| | | if ((order % COMMITSIZE) == 0) |
| | | { |
| | | elmLogger.flashLogging(); |
| | | System.gc(); |
| | | System.runFinalization(); |
| | | } |
| | | |
| | | int now = order % step; |
| | | if (now != current) |
| | | { |
| | | current = now; |
| | | } |
| | | } |
| | | |
| | | elmLogger.flashLogging(); |
| | | } |
| | | |
| | | protected static byte[] getBytesFromBLOB(BLOB blob) throws SQLException |
| | | { |
| | | byte[] raw = null; |
| | | |
| | | // BLOB blob = (BLOB) rs.getBlob(1); |
| | | int optimalSize = blob.getChunkSize(); |
| | | byte[] chunk = new byte[optimalSize]; |
| | | InputStream is = blob.getBinaryStream(0); |
| | | ByteBuffer buffer = null; // ByteBuffer.allocate(optimalSize); |
| | | int len; |
| | | |
| | | try |
| | | { |
| | | while ((len = (is.read(chunk))) != -1) |
| | | { |
| | | if (buffer != null) |
| | | { |
| | | buffer.limit(buffer.limit() + len); |
| | | } else |
| | | { |
| | | buffer = ByteBuffer.allocate(len); |
| | | } |
| | | |
| | | buffer.put(chunk); |
| | | } |
| | | |
| | | is.close(); |
| | | |
| | | assert buffer != null; |
| | | buffer.position(0); |
| | | raw = buffer.array(); |
| | | } catch (IOException e) |
| | | { |
| | | e.printStackTrace(); // To change body of catch statement use File | Settings | File Templates. |
| | | Assert.shouldNeverReachHere(); |
| | | } |
| | | |
| | | return raw; |
| | | } |
| | | |
| | | private Element fetchBinaryElement(byte[] raws) throws Dgn7fileException |
| | | { |
| | | ByteBuffer buffer = ByteBuffer.wrap(raws); |
| | | buffer.order(ByteOrder.LITTLE_ENDIAN); |
| | | short signature = buffer.getShort(); |
| | | |
| | | // byte type = (byte) (buffer.get() & 0x7f); |
| | | byte type = (byte) ((signature >>> 8) & 0x007f); |
| | | |
| | | // silly Bentley say contentLength is in 2-byte words |
| | | // and ByteByffer uses raws. |
| | | // track the record location |
| | | int elementLength = (buffer.getShort() * 2) + 4; |
| | | ElementType recordType = ElementType.forID(type); |
| | | IElementHandler handler; |
| | | |
| | | handler = recordType.getElementHandler(); |
| | | |
| | | Element dgnElement = (Element) handler.read(buffer, signature, elementLength); |
| | | if (recordType.isComplexElement() && (elementLength < raws.length)) |
| | | { |
| | | int offset = elementLength; |
| | | while (offset < (raws.length - 4)) |
| | | { |
| | | buffer.position(offset); |
| | | signature = buffer.getShort(); |
| | | type = (byte) ((signature >>> 8) & 0x007f); |
| | | elementLength = (buffer.getShort() * 2) + 4; |
| | | if (raws.length < (offset + elementLength)) |
| | | { |
| | | System.out.println("Length not match:" + offset + ":" + buffer.position() + ":" + buffer.limit()); |
| | | break; |
| | | } |
| | | recordType = ElementType.forID(type); |
| | | handler = recordType.getElementHandler(); |
| | | if (handler != null) |
| | | { |
| | | Element subElement = (Element) handler.read(buffer, signature, elementLength); |
| | | ((ComplexElement) dgnElement).add(subElement); |
| | | offset += elementLength; |
| | | } else |
| | | { |
| | | byte[] remain = new byte[buffer.remaining()]; |
| | | System.arraycopy(raws, offset, remain, 0, buffer.remaining()); |
| | | for (int i = 0; i < remain.length; i++) |
| | | { |
| | | if (remain[i] != 0) |
| | | { |
| | | logger.info("fetch element has some error. index=" + (offset + i) + ":value=" + remain[i]); |
| | | System.out.println("fetch element has some error. index=" + (offset + i) + ":value=" + remain[i]); |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return dgnElement; |
| | | } |
| | | |
| | | private void queryNFetchIgsetElement(Connection connection, String srcschema, String srctable, OracleElementLogger elmLogger) throws SQLException |
| | | { |
| | | String fetchSrcStmtFmt = "SELECT IGDSELM FROM \"%s\".\"%s\" ORDER BY ROWID"; |
| | | PrintfFormat spf = new PrintfFormat(fetchSrcStmtFmt); |
| | | String fetchSrcStmt = spf.sprintf(new Object[]{srcschema, srctable}); |
| | | Statement stmtSrc = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
| | | |
| | | stmtSrc.setFetchSize(FETCHSIZE); |
| | | ResultSet rsSrc = stmtSrc.executeQuery(fetchSrcStmt); |
| | | try |
| | | { |
| | | int igdsMetaType = rsSrc.getMetaData().getColumnType(1); |
| | | while (rsSrc.next()) |
| | | { |
| | | byte[] raw; |
| | | if (igdsMetaType == Types.BLOB) |
| | | { |
| | | BLOB blob = (BLOB) rsSrc.getBlob(1); |
| | | |
| | | raw = getBytesFromBLOB(blob); |
| | | blob.close(); |
| | | } else |
| | | { |
| | | raw = rsSrc.getBytes(1); |
| | | } |
| | | |
| | | try |
| | | { |
| | | Element element = fetchBinaryElement(raw); |
| | | |
| | | processFeatureElement(elmLogger, element, srcschema); |
| | | } catch (Dgn7fileException e) |
| | | { |
| | | logger.warn("Dgn7Exception", e); |
| | | } |
| | | } |
| | | } finally |
| | | { |
| | | rsSrc.close(); |
| | | stmtSrc.close(); |
| | | } |
| | | } |
| | | |
| | | protected OracleElementLogger createElementLogger(Connection connection, String dataPath) |
| | | { |
| | | |
| | | return new OracleElementLogger(connection, dataPath, MAXELM_LOGCOUNT); |
| | | } |
| | | |
| | | private void processFeatureElement(OracleElementLogger elmLogger, Element element, String currentSchema) |
| | | { |
| | | boolean match = false; |
| | | if (element instanceof ArcElement) |
| | | { |
| | | match = true; |
| | | } else if (element instanceof ComplexChainElement) |
| | | { |
| | | ComplexChainElement complex = (ComplexChainElement) element; |
| | | for (Element subElm : complex) |
| | | { |
| | | if (subElm instanceof ArcElement) |
| | | { |
| | | match = true; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (match) |
| | | elmLogger.logElement(element, currentSchema); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.ximple.eofms; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileNotFoundException; |
| | | import java.io.FilenameFilter; |
| | | import java.io.IOException; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.MalformedURLException; |
| | | import java.net.URL; |
| | | import java.nio.channels.FileChannel; |
| | | import java.nio.charset.Charset; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | | import org.apache.commons.collections.map.MultiValueMap; |
| | | import org.apache.commons.digester.Digester; |
| | | import org.apache.commons.digester.xmlrules.DigesterLoader; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.SimpleFeature; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.FeatureCollection; |
| | | import org.geotools.feature.FeatureCollections; |
| | | import org.geotools.data.FeatureWriter; |
| | | import org.geotools.data.Transaction; |
| | | import org.geotools.data.FeatureStore; |
| | | import org.geotools.data.shapefile.ShapefileDataStore; |
| | | import org.xml.sax.SAXException; |
| | | |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | import com.ximple.eofms.filter.AbstractFLinkageDispatchableFilter; |
| | | import com.ximple.eofms.filter.ElementDispatcher; |
| | | import com.ximple.eofms.jobs.context.postgis.FeatureDgnConvertPostGISJobContext; |
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil; |
| | | import com.ximple.io.dgn7.ComplexElement; |
| | | import com.ximple.io.dgn7.Dgn7fileException; |
| | | import com.ximple.io.dgn7.Dgn7fileReader; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.ElementType; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.io.dgn7.Lock; |
| | | |
| | | public class XElementParser implements Runnable |
| | | { |
| | | static Log logger = LogFactory.getLog(XElementParser.class); |
| | | static final GeometryFactory geometryFactory = new GeometryFactory(); |
| | | |
| | | static final boolean isCompactMode = true; |
| | | static final boolean postOutMode = true; |
| | | |
| | | protected static final String ROOTDATAPATH = "DATAPATH"; |
| | | |
| | | protected static final String DEFAULT_DATAPATH = "G:\\Temp\\JobData\\tctpc"; |
| | | protected static final String DEFAULT_DGNINPATH = "elmin"; |
| | | protected static final String DEFAULT_DGNOUTPATH = "elmout"; |
| | | protected static final String DEFAULT_SHPOUTPATH = "out"; |
| | | |
| | | private HashMap<String, String> dataConfig; |
| | | private ElementDispatcher elementDispatcher; |
| | | private MultiValueMap featuresContext = new MultiValueMap(); |
| | | |
| | | public static void main(String[] args) |
| | | { |
| | | XElementParser parser = new XElementParser(); |
| | | parser.run(); |
| | | } |
| | | |
| | | public XElementParser() |
| | | { |
| | | initializeDataConfig(); |
| | | } |
| | | |
| | | private void initializeDataConfig() |
| | | { |
| | | dataConfig = new HashMap<String, String>(); |
| | | dataConfig.put(ROOTDATAPATH, DEFAULT_DATAPATH); |
| | | |
| | | elementDispatcher = createElementDispatcher(); |
| | | |
| | | FeatureTypeBuilderUtil.setNotAllowNull(true); |
| | | } |
| | | |
| | | private ElementDispatcher createElementDispatcher() |
| | | { |
| | | try |
| | | { |
| | | URL rulesURL = ElementDispatcher.class.getResource("ElementDispatcherRules.xml"); |
| | | assert rulesURL != null; |
| | | Digester digester = DigesterLoader.createDigester(rulesURL); |
| | | URL filterURL; |
| | | |
| | | filterURL = FeatureDgnConvertPostGISJobContext.class.getResource("/conf/DefaultConvertShpFilter.xml"); |
| | | |
| | | assert filterURL != null; |
| | | return (ElementDispatcher) digester.parse(filterURL); |
| | | } catch (UnsupportedEncodingException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } catch (MalformedURLException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } catch (IOException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } catch (SAXException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | public void run() |
| | | { |
| | | File rootDir = new File(dataConfig.get(ROOTDATAPATH)); |
| | | File dataDir = new File(rootDir, DEFAULT_DGNINPATH); |
| | | if ((!dataDir.exists()) || (!dataDir.isDirectory())) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | File[] dataFiles = dataDir.listFiles(new FilenameFilter() { |
| | | public boolean accept(File dir, String name) |
| | | { |
| | | return name.toLowerCase().endsWith(".dgn"); |
| | | } |
| | | }); |
| | | |
| | | for (File dataFile : dataFiles) |
| | | { |
| | | try |
| | | { |
| | | FileInputStream fs = new FileInputStream(dataFile); |
| | | FileChannel fc = fs.getChannel(); |
| | | Dgn7fileReader reader = new Dgn7fileReader(fc, new Lock()); |
| | | 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())) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processFeatureElement(lastComplex); |
| | | lastComplex = null; |
| | | } |
| | | |
| | | processFeatureElement(element); |
| | | } else if (element.isComponentElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | ((ComplexElement) lastComplex).add(element); |
| | | } |
| | | } else if (type.isComplexElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processFeatureElement(lastComplex); |
| | | } |
| | | lastComplex = element; |
| | | } |
| | | } |
| | | count++; |
| | | } |
| | | |
| | | if (lastComplex != null) |
| | | { |
| | | processFeatureElement(lastComplex); |
| | | } |
| | | logger.debug("ElementRecord Count=" + count); |
| | | |
| | | } catch (Dgn7fileException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | } catch (FileNotFoundException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | } catch (IOException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | if (postOutMode) |
| | | { |
| | | try |
| | | { |
| | | postProcessFeatureContext(); |
| | | } catch (IOException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | } catch (IllegalAttributeException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void processFeatureElement(Element element) |
| | | { |
| | | if (element == null) |
| | | { |
| | | logger.warn("Unknown Element:" + null); |
| | | return; |
| | | } |
| | | |
| | | // §PÂ_¬O§_²Å©M±ø¥ó |
| | | Feature feature = elementDispatcher.execute(element, false); |
| | | if (feature == null) |
| | | { |
| | | FrammeAttributeData linkage = |
| | | AbstractFLinkageDispatchableFilter.getFeatureLinkage(element); |
| | | if ((isCompactMode) && (linkage != null)) |
| | | { |
| | | logger.warn("Unknown Element:" + element.getElementType().toString() + |
| | | ":type=" + element.getType() + ":lv=" + element.getLevelIndex() + ":id=" + |
| | | (linkage.getFsc() + "|" + linkage.getComponentID())); |
| | | if (element instanceof ComplexElement) |
| | | { |
| | | ComplexElement complex = (ComplexElement) element; |
| | | logger.warn("----Complex Element size=" + complex.size()); |
| | | } |
| | | |
| | | manualElementProcess(element); |
| | | } else if (!isCompactMode) { |
| | | logger.warn("Unknown Element:" + element.getElementType().toString() + |
| | | ":type=" + element.getType() + ":lv=" + element.getLevelIndex() + ":id=" + |
| | | (linkage == null ? "NULL" : (linkage.getFsc() + "|" + linkage.getComponentID()))); |
| | | |
| | | if (element instanceof ComplexElement) |
| | | { |
| | | ComplexElement complex = (ComplexElement) element; |
| | | logger.warn("----Complex Element size=" + complex.size()); |
| | | } |
| | | } |
| | | |
| | | return; |
| | | } |
| | | |
| | | featuresContext.put(feature.getFeatureType(), feature); |
| | | } |
| | | |
| | | private void manualElementProcess(Element element) |
| | | { |
| | | } |
| | | |
| | | private void postProcessFeatureContext() throws IOException, IllegalAttributeException |
| | | { |
| | | if (featuresContext.size() == 0) return; |
| | | for (Object key : featuresContext.keySet()) |
| | | { |
| | | FeatureType featureType = (FeatureType) key; |
| | | List elements = (List) featuresContext.get(key); |
| | | |
| | | FeatureCollection features = FeatureCollections.newCollection(); |
| | | features.addAll(elements); |
| | | createFeatureStore(featureType).addFeatures(features); |
| | | |
| | | FeatureWriter writer = createFeatureWriter(featureType); |
| | | for (Object v : elements) |
| | | { |
| | | Feature feature1 = (Feature) v; |
| | | Object[] attrs = feature1.getAttributes(null); |
| | | if (attrs != null) |
| | | ((SimpleFeature) writer.next()).setAttributes(attrs); |
| | | |
| | | } |
| | | writer.close(); |
| | | } |
| | | } |
| | | |
| | | private FeatureStore createFeatureStore(FeatureType featureType) throws IOException |
| | | { |
| | | File sfile = new File(getDataOutPath() + File.separator + featureType.getTypeName()); |
| | | |
| | | ShapefileDataStore shapefileDataStore = null; |
| | | boolean existFile = sfile.exists(); |
| | | |
| | | shapefileDataStore = new ShapefileDataStore(sfile.toURI().toURL(), |
| | | true, Charset.forName("UTF-8")); |
| | | |
| | | if (!existFile) |
| | | { |
| | | shapefileDataStore.createSchema(featureType); |
| | | } |
| | | return (FeatureStore) shapefileDataStore.getFeatureSource(featureType.getTypeName()); |
| | | } |
| | | private FeatureWriter createFeatureWriter(FeatureType featureType) throws IOException |
| | | { |
| | | File sfile = new File(getDataOutPath() + File.separator + featureType.getTypeName()); |
| | | |
| | | ShapefileDataStore shapefileDataStore = null; |
| | | boolean existFile = sfile.exists(); |
| | | |
| | | shapefileDataStore = new ShapefileDataStore(sfile.toURI().toURL(), |
| | | true, Charset.forName("UTF-8")); |
| | | |
| | | FeatureWriter writer; |
| | | if (!existFile) |
| | | { |
| | | shapefileDataStore.createSchema(featureType); |
| | | writer = shapefileDataStore.getFeatureWriter(featureType.getTypeName(), Transaction.AUTO_COMMIT); |
| | | } else { |
| | | writer = shapefileDataStore.getFeatureWriterAppend(featureType.getTypeName(), Transaction.AUTO_COMMIT); |
| | | } |
| | | |
| | | return writer; |
| | | } |
| | | |
| | | public String getDataOutPath() |
| | | { |
| | | File rootDir = new File(dataConfig.get(ROOTDATAPATH)); |
| | | File dataDir = new File(rootDir, DEFAULT_SHPOUTPATH); |
| | | return dataDir.toString(); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | # Create stdout appender |
| | | log4j.rootLogger=error, logfile, stdout |
| | | |
| | | # Configure the stdout appender to go to the Console |
| | | log4j.appender.stdout=org.apache.log4j.ConsoleAppender |
| | | |
| | | # Configure stdout appender to use the PatternLayout |
| | | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout |
| | | |
| | | # Pattern output the caller's filename and line # |
| | | log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n |
| | | #log4j.appender.stdout.encoding=UTF-8 |
| | | |
| | | log4j.appender.logfile=org.apache.log4j.FileAppender |
| | | log4j.appender.logfile.file=xelmparser.log |
| | | log4j.appender.logfile.layout=org.apache.log4j.PatternLayout |
| | | log4j.appender.logfile.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n |
| | | #log4j.appender.logfile.encoding=UTF-8 |
| | | |
| | | log4j.appender.remoteout=com.holub.log4j.RemoteAppender |
| | | log4j.appender.remoteout.Port=8011 |
| | | log4j.appender.remoteout.layout=org.apache.log4j.PatternLayout |
| | | log4j.appender.remoteout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n |
| | | #log4j.appender.remoteout.encoding=UTF-8 |
| | | |
| | | # Print messages of level INFO or above for examples |
| | | log4j.logger.org.cavaness.quartzbook=INFO |
| | | log4j.logger.com.ximple.eofms=INFO |
| | | log4j.logger.com.ximple.io.dgn7=INFO |
New file |
| | |
| | | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
| | | <modelVersion>4.0.0</modelVersion> |
| | | |
| | | |
| | | <parent> |
| | | <groupId>com.ximple.eofms</groupId> |
| | | <artifactId>ximple-dgnjobs</artifactId> |
| | | <version>0.9.0</version> |
| | | </parent> |
| | | |
| | | |
| | | <groupId>com.ximple.eofms</groupId> |
| | | <artifactId>ximple-jobcarrier</artifactId> |
| | | <version>0.9.0</version> |
| | | <packaging>jar</packaging> |
| | | <name>ximple-jobcarrier</name> |
| | | <url>http://maven.apache.org</url> |
| | | |
| | | <properties> |
| | | <xdgnio.version>0.9.0</xdgnio.version> |
| | | </properties> |
| | | |
| | | <scm> |
| | | <connection> |
| | | scm:svn:http://www.ximple.com.tw/svn/xeofms/xspatialjob/truck/ |
| | | </connection> |
| | | <url>http://www.ximple.com.tw/svn/xeofms/xspatialjob/truck/</url> |
| | | </scm> |
| | | |
| | | <description> |
| | | Ximple Job Carrier for Quartz |
| | | </description> |
| | | |
| | | <organization> |
| | | <name>Ximple</name> |
| | | <url>http://www.ximple.com.tw</url> |
| | | </organization> |
| | | |
| | | <inceptionYear>2008</inceptionYear> |
| | | |
| | | <developers> |
| | | <developer> |
| | | <name>Kuo-Feng Kao</name> |
| | | <id>ulysseskao</id> |
| | | <email>ulysseskao@ximple.com.tw</email> |
| | | <organization>Ximple</organization> |
| | | <roles> |
| | | <role>Java Developer</role> |
| | | </roles> |
| | | </developer> |
| | | </developers> |
| | | |
| | | <contributors> |
| | | </contributors> |
| | | |
| | | <!-- =========================================================== --> |
| | | <!-- Dependencies to be inherited by all modules. --> |
| | | <!-- =========================================================== --> |
| | | <dependencies> |
| | | <dependency> |
| | | <artifactId>quartz</artifactId> |
| | | <groupId>opensymphony</groupId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>javax.transaction</groupId> |
| | | <artifactId>jta</artifactId> |
| | | <version>1.0.1B</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-shapefile</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-sample-data</artifactId> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-data</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-jdbc</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-postgis</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-oracle-spatial</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-mysql</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- because main and sample-data depend on referencing we need a tie breaker --> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-referencing</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- We need this to make the referencing module useful --> |
| | | <dependency> |
| | | <artifactId>gt2-epsg-hsql</artifactId> |
| | | <groupId>org.geotools</groupId> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <artifactId>jdom</artifactId> |
| | | <groupId>jdom</groupId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.apache.velocity</groupId> |
| | | <artifactId>velocity</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>commons-cli</groupId> |
| | | <artifactId>commons-cli</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- ORACLE --> |
| | | <dependency> |
| | | <groupId>com.oracle</groupId> |
| | | <artifactId>ojdbc5</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.oracle</groupId> |
| | | <artifactId>ojdbc5</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.oracle</groupId> |
| | | <artifactId>sdoapi</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.oracle</groupId> |
| | | <artifactId>sdotype</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.oracle</groupId> |
| | | <artifactId>sdoutl</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>postgresql</groupId> |
| | | <artifactId>postgresql</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.postgis</groupId> |
| | | <artifactId>postgis-driver</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>mysql</groupId> |
| | | <artifactId>mysql-connector-java</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- AWL --> |
| | | <dependency> |
| | | <groupId>org.awl</groupId> |
| | | <artifactId>awl</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- Ximple Library --> |
| | | <dependency> |
| | | <artifactId>ximple-dgnio</artifactId> |
| | | <groupId>com.ximple.eofms</groupId> |
| | | <version>${xdgnio.version}</version> |
| | | </dependency> |
| | | <dependency> |
| | | <artifactId>ximple-spatialjob</artifactId> |
| | | <groupId>com.ximple.eofms</groupId> |
| | | <version>${xdgnio.version}</version> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
| | | <plugins> |
| | | <!-- ======================================================= --> |
| | | <!-- JAR packaging. --> |
| | | <!-- ======================================================= --> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-jar-plugin</artifactId> |
| | | <configuration> |
| | | <archive> |
| | | <manifest> |
| | | <mainClass>com.ximple.eofms.XQuartzJobCarrier</mainClass> |
| | | <addClasspath>true</addClasspath> |
| | | </manifest> |
| | | </archive> |
| | | </configuration> |
| | | </plugin> |
| | | <!-- ======================================================= --> |
| | | <!-- exec jar. --> |
| | | <!-- ======================================================= --> |
| | | <plugin> |
| | | <!-- |
| | | Use maven from the command line: |
| | | mvn exec:java -Dexec.mainClass="com.ximple.eofms.XQuartzJobCarrier" |
| | | --> |
| | | <artifactId>exec-maven-plugin</artifactId> |
| | | <groupId>org.codehaus.mojo</groupId> |
| | | <!-- |
| | | <executions> |
| | | <execution> |
| | | <phase>package</phase> |
| | | <goals> |
| | | <goal>run</goal> |
| | | </goals> |
| | | </execution> |
| | | </executions> |
| | | --> |
| | | <configuration> |
| | | <mainClass>com.ximple.eofms.XQuartzJobCarrier</mainClass> |
| | | <!-- |
| | | <commandlineArgs>-wizard</commandlineArgs> |
| | | --> |
| | | </configuration> |
| | | <!-- |
| | | <dependencies> |
| | | <dependency> |
| | | <groupId>com.ximple.eofms</groupId> |
| | | <artifactId>ximple-jobcarrier</artifactId> |
| | | <version>0.0.1</version> |
| | | <type>jar</type> |
| | | </dependency> |
| | | </dependencies> |
| | | --> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>com.ximple.eofms.maven</groupId> |
| | | <artifactId>ximple-jar-collector</artifactId> |
| | | <version>${project.version}</version> |
| | | <executions> |
| | | <execution> |
| | | <goals> |
| | | <goal>collect</goal> |
| | | </goals> |
| | | </execution> |
| | | </executions> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.codehaus.mojo</groupId> |
| | | <artifactId>native2ascii-maven-plugin</artifactId> |
| | | <version>1.0-alpha-1</version> |
| | | <configuration> |
| | | <dest>target/classes/com/ximple/eofms</dest> |
| | | <src>src/main/resources/com/ximple/eofms</src> |
| | | </configuration> |
| | | <executions> |
| | | <execution> |
| | | <id>native2ascii-utf8</id> |
| | | <goals> |
| | | <goal>native2ascii</goal> |
| | | </goals> |
| | | <configuration> |
| | | <encoding>UTF8</encoding> |
| | | <includes>XQuartzJobWizard_zh*.properties</includes> |
| | | </configuration> |
| | | </execution> |
| | | </executions> |
| | | </plugin> |
| | | </plugins> |
| | | <resources> |
| | | <resource> |
| | | <directory>src/main/resources/com/ximple/eofms</directory> |
| | | <excludes> |
| | | <exclude>XQuartzJobWizard_zh*.properties</exclude> |
| | | </excludes> |
| | | <filtering>true</filtering> |
| | | </resource> |
| | | <resource> |
| | | <directory>src/main/resources</directory> |
| | | <includes> |
| | | <include>log4j.properties</include> |
| | | <include>quartz.properties</include> |
| | | <include>quartz_jobs.xml</include> |
| | | </includes> |
| | | <!-- |
| | | <excludes> |
| | | <exclude>XQuartzJobWizard*.properties</exclude> |
| | | <exclude>quartz_jobs.xml</exclude> |
| | | <exclude>quartz_jobs_shapefiles.xml</exclude> |
| | | </excludes> |
| | | --> |
| | | <filtering>false</filtering> |
| | | </resource> |
| | | </resources> |
| | | </build> |
| | | |
| | | </project> |
New file |
| | |
| | | package com.ximple.eofms; |
| | | |
| | | import java.util.Date; |
| | | import javax.swing.JFrame; |
| | | import javax.swing.SwingUtilities; |
| | | |
| | | import org.apache.commons.cli.CommandLine; |
| | | import org.apache.commons.cli.CommandLineParser; |
| | | import org.apache.commons.cli.HelpFormatter; |
| | | import org.apache.commons.cli.Option; |
| | | import org.apache.commons.cli.OptionBuilder; |
| | | import org.apache.commons.cli.Options; |
| | | import org.apache.commons.cli.ParseException; |
| | | import org.apache.commons.cli.PosixParser; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.awl.Wizard; |
| | | import org.quartz.JobDetail; |
| | | import org.quartz.Scheduler; |
| | | import org.quartz.SchedulerException; |
| | | import org.quartz.Trigger; |
| | | import org.quartz.TriggerUtils; |
| | | import org.quartz.impl.StdSchedulerFactory; |
| | | |
| | | import com.ximple.eofms.jobs.OracleConvertDgn2ShpJob; |
| | | |
| | | /** |
| | | * Hello world! |
| | | */ |
| | | public class XQuartzJobCarrier |
| | | { |
| | | static Log logger = LogFactory.getLog(XQuartzJobCarrier.class); |
| | | static Options options = new Options(); |
| | | |
| | | private static final String VERSION = "0.9.0"; |
| | | |
| | | public static void main(String[] args) |
| | | { |
| | | XQuartzJobCarrier instance = new XQuartzJobCarrier(); |
| | | instance.initializeOption(); |
| | | instance.execute(args); |
| | | } |
| | | |
| | | private void initializeOption() |
| | | { |
| | | Option option; |
| | | option = OptionBuilder.create("help"); |
| | | option.setDescription("print this message"); |
| | | options.addOption(option); |
| | | |
| | | option = OptionBuilder.create("version"); |
| | | option.setDescription("print the version information and exit"); |
| | | options.addOption(option); |
| | | |
| | | option = OptionBuilder.create("wizard"); |
| | | option.setDescription("start wizard mode"); |
| | | options.addOption(option); |
| | | |
| | | option = OptionBuilder.create("verbose"); |
| | | option.setDescription("be extra verbose"); |
| | | options.addOption(option); |
| | | |
| | | option = OptionBuilder.create("debug"); |
| | | option.setDescription("print debugging information"); |
| | | options.addOption(option); |
| | | |
| | | option = OptionBuilder.create("jobfile"); |
| | | option.setDescription("use given jobfile"); |
| | | option.setArgName("file"); |
| | | options.addOption(option); |
| | | |
| | | } |
| | | |
| | | private void execute(String[] args) |
| | | { |
| | | // CommandLineParser parser = new GnuParser(); |
| | | CommandLineParser parser = new PosixParser(); |
| | | CommandLine commandLine = null; |
| | | try |
| | | { |
| | | // parse the command commandLine arguments |
| | | commandLine = parser.parse(options, args); |
| | | } |
| | | catch (ParseException exp) |
| | | { |
| | | // oops, something went wrong |
| | | System.err.println("Parsing failed. Reason: " + exp.getMessage()); |
| | | } |
| | | |
| | | if ((commandLine != null) && (commandLine.getOptions().length > 0)) |
| | | { |
| | | if (commandLine.hasOption("help")) |
| | | { |
| | | printHelpMessage(); |
| | | } else if (commandLine.hasOption("version")) |
| | | { |
| | | printVersionMessage(); |
| | | } else if (commandLine.hasOption("wizard")) |
| | | { |
| | | startWizardMode(); |
| | | } |
| | | return; |
| | | } |
| | | startScheduler(); |
| | | } |
| | | |
| | | private void printHelpMessage() |
| | | { |
| | | HelpFormatter formatter = new HelpFormatter(); |
| | | formatter.printHelp("XQuartzJobCarrier", options); |
| | | } |
| | | |
| | | private void printVersionMessage() |
| | | { |
| | | System.out.println("XQuartzJobCarrier - " + VERSION); |
| | | } |
| | | |
| | | public void startWizardMode() |
| | | { |
| | | Runnable runnable = new Runnable() |
| | | { |
| | | public void run() |
| | | { |
| | | Wizard wizard = new XQuartzJobWizard((JFrame) null); |
| | | |
| | | wizard.pack(); |
| | | wizard.setVisibleOnCenterOfScreen(); |
| | | } |
| | | }; |
| | | try |
| | | { |
| | | SwingUtilities.invokeLater(runnable); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ex.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | public void startScheduler() |
| | | { |
| | | Scheduler scheduler = null; |
| | | boolean shutdown = false; |
| | | |
| | | try |
| | | { |
| | | // Get a Scheduler instance from the Factory |
| | | scheduler = StdSchedulerFactory.getDefaultScheduler(); |
| | | |
| | | // Start the scheduler |
| | | scheduler.start(); |
| | | logger.info("Scheduler started at " + new Date()); |
| | | |
| | | } catch (SchedulerException ex) |
| | | { |
| | | // deal with any exceptions |
| | | logger.error(ex); |
| | | shutdown = true; |
| | | } catch (Throwable throwable) |
| | | { |
| | | logger.error(throwable.getMessage(), throwable); |
| | | shutdown = true; |
| | | } |
| | | if (shutdown) |
| | | { |
| | | try |
| | | { |
| | | scheduler.shutdown(); |
| | | } catch (SchedulerException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /* |
| | | * return an instance of the Scheduler from the factory |
| | | */ |
| | | public Scheduler createScheduler() throws SchedulerException |
| | | { |
| | | return StdSchedulerFactory.getDefaultScheduler(); |
| | | } |
| | | |
| | | // Create and Schedule a ScanDirectoryJob with the Scheduler |
| | | private void scheduleJob(Scheduler scheduler) throws SchedulerException |
| | | { |
| | | |
| | | // Create a JobDetail for the Job |
| | | JobDetail jobDetail = new JobDetail("ScanDirectory", Scheduler.DEFAULT_GROUP, |
| | | OracleConvertDgn2ShpJob.class); |
| | | |
| | | // Configure the directory to scan |
| | | jobDetail.getJobDataMap().put("SCAN_DIR", "c:\\quartz-book\\input"); |
| | | |
| | | // Create a trigger that fires every 10 seconds, forever |
| | | Trigger trigger = TriggerUtils.makeSecondlyTrigger(10); |
| | | trigger.setName("scanTrigger"); |
| | | // Start the trigger firing from now |
| | | trigger.setStartTime(new Date()); |
| | | |
| | | // Associate the trigger with the job in the scheduler |
| | | scheduler.scheduleJob(jobDetail, trigger); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.ximple.eofms; |
| | | |
| | | import java.awt.Dimension; |
| | | import java.awt.GridBagConstraints; |
| | | import java.awt.GridBagLayout; |
| | | import java.awt.event.ActionEvent; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.net.MalformedURLException; |
| | | import java.net.URL; |
| | | import java.util.ResourceBundle; |
| | | import javax.swing.AbstractAction; |
| | | import javax.swing.Action; |
| | | import javax.swing.BorderFactory; |
| | | import javax.swing.BoxLayout; |
| | | import javax.swing.ButtonGroup; |
| | | import javax.swing.ImageIcon; |
| | | import javax.swing.JButton; |
| | | import javax.swing.JEditorPane; |
| | | import javax.swing.JFileChooser; |
| | | import javax.swing.JFrame; |
| | | import javax.swing.JLabel; |
| | | import javax.swing.JPanel; |
| | | import javax.swing.JProgressBar; |
| | | import javax.swing.JRadioButton; |
| | | import javax.swing.JScrollPane; |
| | | import javax.swing.JTextField; |
| | | import javax.swing.JToolBar; |
| | | import javax.swing.SwingConstants; |
| | | import javax.swing.SwingUtilities; |
| | | import javax.swing.event.ChangeEvent; |
| | | import javax.swing.event.ChangeListener; |
| | | import javax.swing.event.DocumentEvent; |
| | | import javax.swing.event.DocumentListener; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.awl.DefaultWizard; |
| | | import org.awl.DefaultWizardPageDescriptor; |
| | | import org.awl.NavigationAuthorization; |
| | | import org.awl.Wizard; |
| | | import org.awl.WizardPageDescriptor; |
| | | import org.awl.demo.AwlDemo; |
| | | import org.awl.header.AbstractWizardHeader; |
| | | import org.awl.header.EclipseWizardHeader; |
| | | import org.awl.message.MessageLevel; |
| | | |
| | | public class XQuartzJobWizard extends DefaultWizard |
| | | { |
| | | static Log logger = LogFactory.getLog(XQuartzJobWizard.class); |
| | | |
| | | /** |
| | | * header type none |
| | | */ |
| | | private static final String HEADER_NONE = "none"; |
| | | |
| | | /** |
| | | * header type classic |
| | | */ |
| | | private static final String HEADER_CLASSIC = "classic"; |
| | | |
| | | /** |
| | | * header type eclipse |
| | | */ |
| | | private static final String HEADER_ECLIPSE = "eclipse"; |
| | | |
| | | /** |
| | | * first page |
| | | */ |
| | | private WizardPageDescriptor firstPage = null; |
| | | |
| | | /** |
| | | * second page |
| | | */ |
| | | private WizardPageDescriptor secondPage = null; |
| | | |
| | | /** |
| | | * third page |
| | | */ |
| | | private WizardPageDescriptor thirdPage = null; |
| | | |
| | | /** |
| | | * forth page |
| | | */ |
| | | private WizardPageDescriptor fourthPage = null; |
| | | |
| | | /** |
| | | * Creates a new instance of AwlDemo |
| | | */ |
| | | public XQuartzJobWizard(JFrame frame) |
| | | { |
| | | super(frame); |
| | | |
| | | AbstractWizardHeader header = new EclipseWizardHeader(); |
| | | header.getIconLabel().setIcon(new ImageIcon(AwlDemo.class.getResource("/org/awl/rc/install.png"))); |
| | | this.setHeader(header); |
| | | |
| | | final ResourceBundle rb = ResourceBundle.getBundle(XQuartzJobWizard.class.getName()); |
| | | |
| | | this.setTitle(rb.getString("title")); |
| | | |
| | | /** first page */ |
| | | this.firstPage = new DefaultWizardPageDescriptor(); |
| | | firstPage.setTitle(rb.getString("first.title")); |
| | | firstPage.setDescription(rb.getString("first.description")); |
| | | |
| | | JLabel firstLabel = new JLabel(rb.getString("first.label.text")); |
| | | firstLabel.setVerticalAlignment(SwingConstants.TOP); |
| | | firstLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
| | | firstPage.setComponent(firstLabel); |
| | | |
| | | firstPage.setNextDescriptorId("2"); |
| | | |
| | | /** second page */ |
| | | this.secondPage = new DefaultWizardPageDescriptor(); |
| | | secondPage.setTitle(rb.getString("second.title")); |
| | | secondPage.setDescription(rb.getString("second.description")); |
| | | |
| | | secondPage.setMessage(rb.getString("second.messageContent"), MessageLevel.INFO); |
| | | |
| | | URL licenseUrl = null; |
| | | try |
| | | { |
| | | licenseUrl = new URL("http://www.gnu.org/licenses/lgpl-2.1.txt"); |
| | | } |
| | | catch (MalformedURLException e) |
| | | { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | JEditorPane licensePane = null; |
| | | if (licenseUrl == null) |
| | | { |
| | | licensePane = new JEditorPane(); |
| | | licensePane.setText("license LGPL 2.1"); |
| | | } else |
| | | { |
| | | try |
| | | { |
| | | licensePane = new JEditorPane(licenseUrl); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | licensePane = new JEditorPane(); |
| | | licensePane.setText("license LGPL 2.1"); |
| | | } |
| | | } |
| | | |
| | | licensePane.setPreferredSize(new Dimension(630, 350)); |
| | | |
| | | final JRadioButton radioAcceptLicense = new JRadioButton(rb.getString("second.licenseAccepted")); |
| | | final JRadioButton radioRefuseLicense = new JRadioButton(rb.getString("second.licenseRefused")); |
| | | |
| | | ButtonGroup licenseButtonGroup = new ButtonGroup(); |
| | | licenseButtonGroup.add(radioAcceptLicense); |
| | | licenseButtonGroup.add(radioRefuseLicense); |
| | | |
| | | ChangeListener changeListener = new ChangeListener() |
| | | { |
| | | public void stateChanged(ChangeEvent e) |
| | | { |
| | | secondPage.setNextPageAuthorization( |
| | | radioAcceptLicense.isSelected() ? NavigationAuthorization.DEFAULT : |
| | | NavigationAuthorization.FORBIDDEN); |
| | | } |
| | | }; |
| | | |
| | | radioAcceptLicense.addChangeListener(changeListener); |
| | | radioRefuseLicense.addChangeListener(changeListener); |
| | | |
| | | radioRefuseLicense.setSelected(true); |
| | | |
| | | JPanel secondPageComponent = new JPanel(); |
| | | GridBagLayout secondPageLayout = new GridBagLayout(); |
| | | secondPageComponent.setLayout(secondPageLayout); |
| | | |
| | | GridBagConstraints gbc = new GridBagConstraints(); |
| | | |
| | | gbc.gridx = 1; |
| | | gbc.gridy = 1; |
| | | gbc.fill = GridBagConstraints.BOTH; |
| | | gbc.weightx = 1.0f; |
| | | gbc.weighty = 1.0f; |
| | | JScrollPane scrollLicense = new JScrollPane(licensePane); |
| | | scrollLicense.setBorder(BorderFactory.createLoweredBevelBorder()); |
| | | secondPageComponent.add(scrollLicense, gbc); |
| | | |
| | | gbc.gridx = 1; |
| | | gbc.gridy = 2; |
| | | gbc.fill = GridBagConstraints.NONE; |
| | | gbc.weightx = 0.0f; |
| | | gbc.weighty = 0.0f; |
| | | secondPageComponent.add(new JToolBar.Separator(new Dimension(10, 10)), gbc); |
| | | |
| | | gbc.gridx = 1; |
| | | gbc.gridy = 3; |
| | | gbc.anchor = GridBagConstraints.WEST; |
| | | secondPageComponent.add(radioAcceptLicense, gbc); |
| | | |
| | | gbc.gridx = 1; |
| | | gbc.gridy = 4; |
| | | secondPageComponent.add(radioRefuseLicense, gbc); |
| | | |
| | | secondPageComponent.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
| | | |
| | | secondPage.setComponent(secondPageComponent); |
| | | |
| | | secondPage.setPreviousDescriptorId("1"); |
| | | secondPage.setNextDescriptorId("3"); |
| | | |
| | | /** third page */ |
| | | final JTextField locationField = new JTextField(20); |
| | | final Action chooseLocation = new AbstractAction() |
| | | { |
| | | public void actionPerformed(ActionEvent e) |
| | | { |
| | | File current = null; |
| | | String text = locationField.getText(); |
| | | if (text != null && text.trim().length() > 0) |
| | | { |
| | | try |
| | | { |
| | | current = new File(text); |
| | | if (!current.exists()) |
| | | { |
| | | current = null; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { } |
| | | } |
| | | |
| | | JFileChooser chooser = new JFileChooser(current); |
| | | chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); |
| | | chooser.setFileFilter(new javax.swing.filechooser.FileFilter() |
| | | { |
| | | public boolean accept(File f) |
| | | { |
| | | boolean result = false; |
| | | |
| | | if (f != null && f.isDirectory()) |
| | | { |
| | | result = true; |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | public String getDescription() |
| | | { |
| | | return rb.getString("third.fileChooser.description"); |
| | | } |
| | | }); |
| | | chooser.setMultiSelectionEnabled(false); |
| | | int answer = chooser.showDialog(XQuartzJobWizard.this, rb.getString("third.fileChooser.selectLabel")); |
| | | |
| | | if (answer == JFileChooser.CANCEL_OPTION) |
| | | { |
| | | locationField.setText(""); |
| | | thirdPage.setMessage(rb.getString("third.messageContent"), MessageLevel.WARN); |
| | | } else // aprove |
| | | { |
| | | locationField.setText(chooser.getSelectedFile().getPath()); |
| | | } |
| | | } |
| | | }; |
| | | this.thirdPage = new DefaultWizardPageDescriptor() |
| | | { |
| | | public void displayingPanel(Wizard wizard) |
| | | { |
| | | /** open file dialog box */ |
| | | if (locationField.getText().trim().length() == 0) |
| | | { |
| | | chooseLocation.actionPerformed(null); |
| | | } |
| | | } |
| | | }; |
| | | chooseLocation.putValue(Action.SMALL_ICON, new ImageIcon(AwlDemo.class.getResource("/org/awl/rc/folder.png"))); |
| | | thirdPage.setNextPageAuthorization(NavigationAuthorization.FORBIDDEN); |
| | | |
| | | locationField.getDocument().addDocumentListener(new DocumentListener() |
| | | { |
| | | public void changedUpdate(DocumentEvent e) |
| | | { } |
| | | |
| | | public void insertUpdate(DocumentEvent e) |
| | | { |
| | | this.changeNavigation(); |
| | | } |
| | | |
| | | public void removeUpdate(DocumentEvent e) |
| | | { |
| | | this.changeNavigation(); |
| | | } |
| | | |
| | | private void changeNavigation() |
| | | { |
| | | thirdPage.setNextPageAuthorization(locationField.getText().trim().length() > 0 ? NavigationAuthorization.DEFAULT : |
| | | NavigationAuthorization.FORBIDDEN); |
| | | } |
| | | }); |
| | | |
| | | thirdPage.setTitle(rb.getString("third.title")); |
| | | thirdPage.setDescription(rb.getString("third.description")); |
| | | |
| | | JPanel thirdSubPanel = new JPanel(); |
| | | |
| | | JPanel thirdPanel = new JPanel(); |
| | | JLabel installLocationLabel = new JLabel(rb.getString("third.label.text")); |
| | | installLocationLabel.setHorizontalAlignment(SwingConstants.LEFT); |
| | | thirdSubPanel.add(installLocationLabel); |
| | | locationField.setEnabled(false); |
| | | locationField.setHorizontalAlignment(SwingConstants.LEFT); |
| | | thirdSubPanel.add(locationField); |
| | | JButton locationButton = new JButton(chooseLocation); |
| | | locationButton.setHorizontalAlignment(SwingConstants.LEFT); |
| | | Dimension buttonPrefSize = new Dimension(locationButton.getPreferredSize()); |
| | | buttonPrefSize.height = locationField.getPreferredSize().height; |
| | | // buttonPrefSize.width = ((Icon)chooseLocation.getValue(Action.SMALL_ICON)).getIconWidth() + 4; |
| | | locationButton.setPreferredSize(buttonPrefSize); |
| | | thirdSubPanel.add(locationButton); |
| | | |
| | | thirdSubPanel.setAlignmentX(0.0f); |
| | | thirdPanel.setAlignmentX(0.0f); |
| | | |
| | | thirdPanel.setLayout(new GridBagLayout()); |
| | | |
| | | gbc.gridx = 1; |
| | | gbc.gridy = 1; |
| | | gbc.weightx = 0.0f; |
| | | gbc.weighty = 0.0f; |
| | | gbc.fill = GridBagConstraints.NONE; |
| | | thirdPanel.add(thirdSubPanel, gbc); |
| | | |
| | | gbc.gridx = 2; |
| | | gbc.gridy = 2; |
| | | gbc.weightx = 1.0f; |
| | | gbc.weighty = 1.0f; |
| | | gbc.fill = GridBagConstraints.BOTH; |
| | | thirdPanel.add(new JToolBar.Separator(new Dimension(5, 5)), gbc); |
| | | |
| | | thirdPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
| | | |
| | | thirdPage.setComponent(thirdPanel); |
| | | |
| | | thirdPage.setPreviousDescriptorId("2"); |
| | | thirdPage.setNextDescriptorId("4"); |
| | | |
| | | /** fourth page */ |
| | | final JProgressBar installProgressBar = new JProgressBar(); |
| | | final JLabel progressLabel = new JLabel(rb.getString("fourth.inProgress.text")); |
| | | |
| | | this.fourthPage = new DefaultWizardPageDescriptor() |
| | | { |
| | | public void displayingPanel(Wizard wizard) |
| | | { |
| | | /* begin installation */ |
| | | this.setPreviousPageAuthorization(NavigationAuthorization.FORBIDDEN); |
| | | this.setFinishAuthorization(NavigationAuthorization.FORBIDDEN); |
| | | |
| | | /* begin new thread */ |
| | | Runnable runnable = new Runnable() |
| | | { |
| | | public void run() |
| | | { |
| | | while (installProgressBar.getValue() < installProgressBar.getMaximum()) |
| | | { |
| | | Runnable r = new Runnable() |
| | | { |
| | | public void run() |
| | | { installProgressBar.setValue(installProgressBar.getValue() + 1); } |
| | | }; |
| | | SwingUtilities.invokeLater(r); |
| | | |
| | | try |
| | | { |
| | | Thread.sleep(50); |
| | | } |
| | | catch (InterruptedException e) |
| | | { |
| | | Runnable r1 = new Runnable() |
| | | { |
| | | public void run() |
| | | { installProgressBar.setValue(installProgressBar.getMaximum()); } |
| | | }; |
| | | SwingUtilities.invokeLater(r1); |
| | | |
| | | break; |
| | | } |
| | | } |
| | | |
| | | Runnable r2 = new Runnable() |
| | | { |
| | | public void run() |
| | | { progressLabel.setText(rb.getString("fourth.finished.text")); } |
| | | }; |
| | | SwingUtilities.invokeLater(r2); |
| | | |
| | | setFinishAuthorization(NavigationAuthorization.DEFAULT); |
| | | setCancelAuthorization(NavigationAuthorization.FORBIDDEN); |
| | | } |
| | | }; |
| | | |
| | | new Thread(runnable).start(); |
| | | } |
| | | }; |
| | | fourthPage.setTitle(rb.getString("fourth.title")); |
| | | fourthPage.setDescription(rb.getString("fourth.description")); |
| | | |
| | | JPanel fourthPanel = new JPanel(); |
| | | BoxLayout fourthLayout = new BoxLayout(fourthPanel, BoxLayout.PAGE_AXIS); |
| | | fourthPanel.setLayout(fourthLayout); |
| | | |
| | | fourthPanel.add(installProgressBar); |
| | | fourthPanel.add(progressLabel); |
| | | |
| | | fourthPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
| | | |
| | | fourthPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
| | | |
| | | fourthPage.setComponent(fourthPanel); |
| | | |
| | | fourthPage.setPreviousDescriptorId("3"); |
| | | |
| | | /** register */ |
| | | this.addPage(firstPage, "1"); |
| | | this.addPage(secondPage, "2"); |
| | | this.addPage(thirdPage, "3"); |
| | | this.addPage(fourthPage, "4"); |
| | | } |
| | | |
| | | public static void main(String[] args) |
| | | { |
| | | Runnable runnable = new Runnable() |
| | | { |
| | | public void run() |
| | | { |
| | | Wizard wizard = new XQuartzJobWizard((JFrame) null); |
| | | |
| | | wizard.pack(); |
| | | wizard.setVisibleOnCenterOfScreen(); |
| | | } |
| | | }; |
| | | |
| | | try |
| | | { |
| | | SwingUtilities.invokeLater(runnable); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ex.printStackTrace(); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | title=Ximple Quartz Job Wizard |
| | | |
| | | first.title=Convert |
| | | first.description=Installation introduction |
| | | first.label.text=<html>This wizard will not install anything on your computer.<br/>It only demonstrates <b>Awl</b> functionnalities.</html> |
| | | |
| | | second.title=License agreement |
| | | second.description=Accept the license of this software |
| | | second.licenseAccepted=I accept the terms of this license agreement |
| | | second.licenseRefused=I do not accept the terms of this license agreement |
| | | second.messageContent=Accept the terms of the license |
| | | |
| | | third.title=Install location |
| | | third.description=Select the location where to install this software |
| | | third.label.text=Install location |
| | | third.fileChooser.selectLabel=Select |
| | | third.fileChooser.description=Select |
| | | third.messageContent=You must choose a valid location |
| | | |
| | | fourth.title=Installation... |
| | | fourth.description=Installation progress |
| | | fourth.inProgress.text=Installation in progress... |
| | | fourth.finished.text=Installation finished |
New file |
| | |
| | | title=Ximple Quartz Job Wizard |
| | | |
| | | first.title=ªÅ¶¡¸ê®ÆÂà´« |
| | | first.description=ªÅ¶¡¸ê®ÆÂà´«±N·|Ū¨ú OMS/CMMS ªÅ¶¡¸ê®Æ®w¤º®eÂà´«¦Ü PostGIS ªÅ¶¡¸ê®Æ®w |
| | | first.label.text=<html>This wizard will not install anything on your computer.<br/>It only demonstrates <b>Awl</b> functionnalities.</html> |
| | | |
| | | second.title=ª©ÅvÁn©ú |
| | | second.description=Accept the license of this software |
| | | second.licenseAccepted=I accept the terms of this license agreement |
| | | second.licenseRefused=I do not accept the terms of this license agreement |
| | | second.messageContent=Accept the terms of the license |
| | | |
| | | third.title=²ÕºA³]©w¦ì¸m |
| | | third.description=Select the location where to install this software |
| | | third.label.text=Install location |
| | | third.fileChooser.selectLabel=Select |
| | | third.fileChooser.description=Select |
| | | third.messageContent=You must choose a valid location |
| | | |
| | | fourth.title=¶}©lÂàÀÉ... |
| | | fourth.description=Installation progress |
| | | fourth.inProgress.text=Installation in progress... |
| | | fourth.finished.text=Installation finished |
New file |
| | |
| | | # Create stdout appender |
| | | log4j.rootLogger=error, logfile, stdout |
| | | |
| | | # Configure the stdout appender to go to the Console |
| | | log4j.appender.stdout=org.apache.log4j.ConsoleAppender |
| | | |
| | | # Configure stdout appender to use the PatternLayout |
| | | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout |
| | | |
| | | # Pattern output the caller's filename and line # |
| | | log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n |
| | | #log4j.appender.stdout.encoding=UTF-8 |
| | | |
| | | log4j.appender.logfile=org.apache.log4j.FileAppender |
| | | log4j.appender.logfile.file=xjobcarrier.log |
| | | log4j.appender.logfile.layout=org.apache.log4j.PatternLayout |
| | | log4j.appender.logfile.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n |
| | | #log4j.appender.logfile.encoding=UTF-8 |
| | | |
| | | log4j.appender.remoteout=com.holub.log4j.RemoteAppender |
| | | log4j.appender.remoteout.Port=8011 |
| | | log4j.appender.remoteout.layout=org.apache.log4j.PatternLayout |
| | | log4j.appender.remoteout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n |
| | | #log4j.appender.remoteout.encoding=UTF-8 |
| | | |
| | | # Print messages of level INFO or above for examples |
| | | log4j.logger.org.cavaness.quartzbook=INFO |
| | | log4j.logger.com.ximple.eofms=INFO |
New file |
| | |
| | | #=============================================================== |
| | | #Configure Main Scheduler Properties |
| | | #=============================================================== |
| | | org.quartz.scheduler.instanceName = QuartzScheduler |
| | | org.quartz.scheduler.instanceId = AUTO |
| | | |
| | | #=============================================================== |
| | | #Configure ThreadPool |
| | | #=============================================================== |
| | | org.quartz.threadPool.threadCount = 5 |
| | | org.quartz.threadPool.threadPriority = 5 |
| | | org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool |
| | | |
| | | #=============================================================== |
| | | #Configure JobStore |
| | | #=============================================================== |
| | | org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore |
| | | |
| | | #=============================================================== |
| | | #Configure Plugins |
| | | #=============================================================== |
| | | org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.JobInitializationPlugin |
| | | |
| | | org.quartz.plugin.jobInitializer.fileName = quartz_jobs.xml |
| | | |
| | | org.quartz.plugin.jobInitializer.overWriteExistingJobs = true |
| | | org.quartz.plugin.jobInitializer.failOnFileNotFound = true |
| | | org.quartz.plugin.jobInitializer.validating=false |
New file |
| | |
| | | <?xml version='1.0' encoding='utf-8'?> |
| | | |
| | | <quartz xmlns="http://www.opensymphony.com/quartz/JobSchedulingData" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://www.opensymphony.com/quartz/JobSchedulingData |
| | | http://www.opensymphony.com/quartz/xml/job_scheduling_data_1_5.xsd" |
| | | version="1.5"> |
| | | |
| | | <job> |
| | | <job-detail> |
| | | <name>ConvertDgn2PostGisIntoPostgre</name> |
| | | <group>DEFAULT</group> |
| | | <description>A job that convert dgn to shapefiles</description> |
| | | <job-class>com.ximple.eofms.jobs.OracleConvertDgn2PostGISJob</job-class> |
| | | <volatility>false</volatility> |
| | | <durability>false</durability> |
| | | <recover>false</recover> |
| | | <job-data-map allows-transient-data="true"> |
| | | <entry> |
| | | <key>JOBDATA_DIR</key> |
| | | <value>G:\Temp\JobData\tctpc</value> |
| | | </entry> |
| | | <entry> |
| | | <key>PGHOST</key> |
| | | <value>192.168.11.200</value> |
| | | </entry> |
| | | <entry> |
| | | <key>PGDDATBASE</key> |
| | | <value>tctpc</value> |
| | | </entry> |
| | | <entry> |
| | | <key>PGPORT</key> |
| | | <value>5432</value> |
| | | </entry> |
| | | <entry> |
| | | <key>PGSCHEMA</key> |
| | | <value>public</value> |
| | | </entry> |
| | | <entry> |
| | | <key>PGUSER</key> |
| | | <value>spatialdb</value> |
| | | </entry> |
| | | <entry> |
| | | <key>PGPASS</key> |
| | | <value>spatialdb000</value> |
| | | </entry> |
| | | <entry> |
| | | <key>ORAHOST</key> |
| | | <value>192.168.11.200</value> |
| | | </entry> |
| | | <entry> |
| | | <key>ORAINST</key> |
| | | <value>tctpc</value> |
| | | </entry> |
| | | <entry> |
| | | <key>ORAPORT</key> |
| | | <value>1521</value> |
| | | </entry> |
| | | <entry> |
| | | <key>ORAUSER</key> |
| | | <value>spatialdb</value> |
| | | </entry> |
| | | <entry> |
| | | <key>ORAPASS</key> |
| | | <value>spatialdb000</value> |
| | | </entry> |
| | | <entry> |
| | | <key>ORGSCHEMA</key> |
| | | <value>SPATIALDB, CMMS_SPATIALDB</value> |
| | | </entry> |
| | | <entry> |
| | | <key>CONVERTDB</key> |
| | | <value>true</value> |
| | | </entry> |
| | | <entry> |
| | | <key>CONVERTFILE</key> |
| | | <value>true</value> |
| | | </entry> |
| | | <entry> |
| | | <key>CONVERTELEMIN</key> |
| | | <value>false</value> |
| | | </entry> |
| | | <entry> |
| | | <key>CREATEDUMMY</key> |
| | | <value>false</value> |
| | | </entry> |
| | | <entry> |
| | | <key>ELEMLOG</key> |
| | | <value>true</value> |
| | | </entry> |
| | | <entry> |
| | | <key>USEWKB</key> |
| | | <value>true</value> |
| | | </entry> |
| | | <entry> |
| | | <key>TESTMODE</key> |
| | | <value>false</value> |
| | | </entry> |
| | | <entry> |
| | | <key>TESTCOUNT</key> |
| | | <value>2</value> |
| | | </entry> |
| | | <entry> |
| | | <key>COPYCONNECTIVITYMODE</key> |
| | | <value>true</value> |
| | | </entry> |
| | | </job-data-map> |
| | | </job-detail> |
| | | |
| | | <trigger> |
| | | <simple> |
| | | <name>convertTrigger</name> |
| | | <group>DEFAULT</group> |
| | | <job-name>ConvertDgn2PostGisIntoPostgre</job-name> |
| | | <job-group>DEFAULT</job-group> |
| | | <start-time>2008-03-01T18:10:00</start-time> |
| | | <!-- repeat indefinitely every 10 seconds --> |
| | | <repeat-count>0</repeat-count> |
| | | <repeat-interval>500</repeat-interval> |
| | | <!-- <repeat-interval>72000000</repeat-interval> --> |
| | | </simple> |
| | | </trigger> |
| | | |
| | | </job> |
| | | </quartz> |
New file |
| | |
| | | <?xml version='1.0' encoding='utf-8'?> |
| | | |
| | | <quartz xmlns="http://www.opensymphony.com/quartz/JobSchedulingData" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://www.opensymphony.com/quartz/JobSchedulingData |
| | | http://www.opensymphony.com/quartz/xml/job_scheduling_data_1_5.xsd" |
| | | version="1.5"> |
| | | |
| | | <job> |
| | | <job-detail> |
| | | <name>ConvertDgn2ShpIntoDirectory</name> |
| | | <group>DEFAULT</group> |
| | | <description>A job that convert dgn to shapefiles</description> |
| | | <job-class>com.ximple.eofms.jobs.OracleConvertDgn2ShpJob</job-class> |
| | | <volatility>false</volatility> |
| | | <durability>false</durability> |
| | | <recover>false</recover> |
| | | <job-data-map allows-transient-data="true"> |
| | | <entry> |
| | | <key>SHPDATA_DIR</key> |
| | | <value>g:\temp\data</value> |
| | | </entry> |
| | | <!-- |
| | | <entry> |
| | | <key>ELMSFILTER_CONF</key> |
| | | <value></value> |
| | | </entry> |
| | | --> |
| | | <entry> |
| | | <key>ORAHOST</key> |
| | | <value>192.168.11.200</value> |
| | | </entry> |
| | | <entry> |
| | | <key>ORAINST</key> |
| | | <value>nntpc</value> |
| | | </entry> |
| | | <entry> |
| | | <key>ORAPORT</key> |
| | | <value>1521</value> |
| | | </entry> |
| | | <entry> |
| | | <key>ORAUSER</key> |
| | | <value>spatialdb</value> |
| | | </entry> |
| | | <entry> |
| | | <key>ORAPASS</key> |
| | | <value>spatialdb000</value> |
| | | </entry> |
| | | <entry> |
| | | <key>ORGSCHEMA</key> |
| | | <value>SPATIALDB, CMMS_SPATIALDB</value> |
| | | </entry> |
| | | <entry> |
| | | <key>CONVERTDB</key> |
| | | <value>false</value> |
| | | </entry> |
| | | <entry> |
| | | <key>CONVERTFILE</key> |
| | | <value>false</value> |
| | | </entry> |
| | | <entry> |
| | | <key>CONVERTELEMIN</key> |
| | | <value>false</value> |
| | | </entry> |
| | | <entry> |
| | | <key>CREATEDUMMY</key> |
| | | <value>true</value> |
| | | </entry> |
| | | <entry> |
| | | <key>ELEMLOG</key> |
| | | <value>true</value> |
| | | </entry> |
| | | <entry> |
| | | <key>TESTMODE</key> |
| | | <value>FALSE</value> |
| | | </entry> |
| | | <entry> |
| | | <key>TESTCOUNT</key> |
| | | <value>2</value> |
| | | </entry> |
| | | </job-data-map> |
| | | </job-detail> |
| | | |
| | | <trigger> |
| | | <simple> |
| | | <name>convertTrigger</name> |
| | | <group>DEFAULT</group> |
| | | <job-name>ConvertDgn2ShpIntoDirectory</job-name> |
| | | <job-group>DEFAULT</job-group> |
| | | <start-time>2008-03-01T18:10:00</start-time> |
| | | <!-- repeat indefinitely every 10 seconds --> |
| | | <repeat-count>0</repeat-count> |
| | | <repeat-interval>500</repeat-interval> |
| | | <!-- <repeat-interval>72000000</repeat-interval> --> |
| | | </simple> |
| | | </trigger> |
| | | |
| | | </job> |
| | | </quartz> |
New file |
| | |
| | | package com.ximple.eofms; |
| | | |
| | | import org.testng.Assert; |
| | | import org.testng.annotations.Test; |
| | | |
| | | /** |
| | | * Unit test for simple App. |
| | | */ |
| | | public class XQuartzJobCarrierTest |
| | | { |
| | | /** |
| | | * Rigourous Test :-) |
| | | */ |
| | | @Test |
| | | public void testApp() |
| | | { |
| | | Assert.assertTrue(true); |
| | | } |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <project xmlns="http://maven.apache.org/POM/4.0.0" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
| | | <modelVersion>4.0.0</modelVersion> |
| | | |
| | | <parent> |
| | | <groupId>com.ximple.eofms</groupId> |
| | | <artifactId>ximple-dgnjobs</artifactId> |
| | | <version>0.9.0</version> |
| | | </parent> |
| | | |
| | | <groupId>com.ximple.eofms</groupId> |
| | | <artifactId>ximple-spatialjob</artifactId> |
| | | <version>0.9.0</version> |
| | | <packaging>jar</packaging> |
| | | <name>ximple-spatialjob</name> |
| | | <url>http://www.ximple.com.tw</url> |
| | | |
| | | <properties> |
| | | <xdgnio.version>0.9.0</xdgnio.version> |
| | | </properties> |
| | | |
| | | <description> |
| | | Ximple Spatial Data Job for Quartz |
| | | </description> |
| | | |
| | | <organization> |
| | | <name>Ximple</name> |
| | | <url>http://www.ximple.com.tw</url> |
| | | </organization> |
| | | |
| | | <inceptionYear>2008</inceptionYear> |
| | | |
| | | <developers> |
| | | <developer> |
| | | <name>Kuo-Feng Kao</name> |
| | | <id>ulysseskao</id> |
| | | <email>ulysseskao@ximple.com.tw</email> |
| | | <organization>Ximple</organization> |
| | | <roles> |
| | | <role>Java Developer</role> |
| | | </roles> |
| | | </developer> |
| | | </developers> |
| | | |
| | | <contributors> |
| | | </contributors> |
| | | |
| | | <!-- =========================================================== --> |
| | | <!-- Dependencies to be inherited by all modules. --> |
| | | <!-- =========================================================== --> |
| | | <dependencies> |
| | | <dependency> |
| | | <artifactId>quartz</artifactId> |
| | | <groupId>opensymphony</groupId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-shapefile</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-sample-data</artifactId> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-data</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-jdbc</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-postgis</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-oracle-spatial</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-mysql</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- because main and sample-data depend on referencing we need a tie breaker --> |
| | | <dependency> |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt2-referencing</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- We need this to make the referencing module useful --> |
| | | <dependency> |
| | | <artifactId>gt2-epsg-hsql</artifactId> |
| | | <groupId>org.geotools</groupId> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <artifactId>jdom</artifactId> |
| | | <groupId>jdom</groupId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <artifactId>velocity</artifactId> |
| | | <groupId>org.apache.velocity</groupId> |
| | | </dependency> |
| | | |
| | | <!-- ORACLE --> |
| | | <dependency> |
| | | <groupId>com.oracle</groupId> |
| | | <artifactId>ojdbc5</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.oracle</groupId> |
| | | <artifactId>sdoapi</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.oracle</groupId> |
| | | <artifactId>sdotype</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.oracle</groupId> |
| | | <artifactId>sdoutl</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>postgresql</groupId> |
| | | <artifactId>postgresql</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.postgis</groupId> |
| | | <artifactId>postgis-driver</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>mysql</groupId> |
| | | <artifactId>mysql-connector-java</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- Ximple Library --> |
| | | <dependency> |
| | | <groupId>com.ximple.eofms</groupId> |
| | | <artifactId>ximple-dgnio</artifactId> |
| | | <version>${xdgnio.version}</version> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
| | | <plugins> |
| | | </plugins> |
| | | <resources> |
| | | </resources> |
| | | </build> |
| | | </project> |
New file |
| | |
| | | package com.ximple.eofms.collector; |
| | | |
| | | import java.util.TreeMap; |
| | | |
| | | public class FeatureClassification |
| | | { |
| | | private TreeMap<String, FeatureTypeCollector> clasificationRules; |
| | | |
| | | public FeatureClassification() |
| | | { |
| | | clasificationRules = new TreeMap<String, FeatureTypeCollector>(); |
| | | } |
| | | |
| | | public void addCollector(FeatureTypeCollector collector) |
| | | { |
| | | collector.getName(); |
| | | } |
| | | |
| | | public boolean containsKey(String typeName) |
| | | { |
| | | return clasificationRules.containsKey(typeName); |
| | | } |
| | | |
| | | public TreeMap<String, FeatureTypeCollector> getClasificationRules() |
| | | { |
| | | return clasificationRules; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.collector; |
| | | |
| | | import java.util.ArrayList; |
| | | |
| | | import com.ximple.eofms.util.StringUtils; |
| | | |
| | | public class FeatureTypeCollector |
| | | { |
| | | private String name; |
| | | private String description; |
| | | private String featuretypeList; |
| | | private ArrayList<String> featureTypeNameList; |
| | | |
| | | public FeatureTypeCollector() |
| | | { |
| | | } |
| | | |
| | | public String getName() |
| | | { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) |
| | | { |
| | | this.name = name; |
| | | } |
| | | |
| | | public String getDescription() |
| | | { |
| | | return description; |
| | | } |
| | | |
| | | public void setDescription(String description) |
| | | { |
| | | this.description = description; |
| | | } |
| | | |
| | | public String getFeaturetypeList() |
| | | { |
| | | return featuretypeList; |
| | | } |
| | | |
| | | public void setFeaturetypeList(String featuretypeList) |
| | | { |
| | | featureTypeNameList = StringUtils.split(featuretypeList, ","); |
| | | this.featuretypeList = featuretypeList; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.filter; |
| | | |
| | | import java.util.LinkedList; |
| | | |
| | | import javax.swing.event.EventListenerList; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | |
| | | import com.ximple.io.dgn7.Element; |
| | | |
| | | public abstract class AbstractDispatchableFilter implements ElementDispatchableFilter |
| | | { |
| | | private String name; |
| | | private String description; |
| | | private LinkedList<ElementTypeCriterion> typeIdCriterions; |
| | | private LinkedList<ElementLevelCriterion> levelCriterions; |
| | | |
| | | protected Log logger = LogFactory.getLog(AbstractFLinkageDispatchableFilter.class); |
| | | |
| | | // Create the listener list |
| | | protected EventListenerList listenerList = new EventListenerList(); |
| | | |
| | | public AbstractDispatchableFilter() |
| | | { |
| | | typeIdCriterions = new LinkedList<ElementTypeCriterion>(); |
| | | levelCriterions = new LinkedList<ElementLevelCriterion>(); |
| | | } |
| | | |
| | | public String getName() |
| | | { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) |
| | | { |
| | | this.name = name; |
| | | } |
| | | |
| | | public String getDescription() |
| | | { |
| | | return description; |
| | | } |
| | | |
| | | public void setDescription(String description) |
| | | { |
| | | this.description = description; |
| | | } |
| | | |
| | | public void addCriterion(ElementTypeCriterion criterion) |
| | | { |
| | | typeIdCriterions.add(criterion); |
| | | } |
| | | |
| | | public void addLevelCriterion(ElementLevelCriterion criterion) |
| | | { |
| | | levelCriterions.add(criterion); |
| | | } |
| | | |
| | | protected int compareType(Element element) |
| | | { |
| | | for (ElementTypeCriterion criterion : typeIdCriterions) |
| | | { |
| | | if (criterion.compareTo(element) == 0) |
| | | return 0; |
| | | } |
| | | return -1; |
| | | } |
| | | |
| | | protected int compareLevel(Element element) |
| | | { |
| | | for (ElementLevelCriterion criterion : levelCriterions) |
| | | { |
| | | if (criterion.compareTo(element) == 0) |
| | | return 0; |
| | | } |
| | | return -1; |
| | | } |
| | | |
| | | public void addCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) |
| | | { |
| | | listenerList.add(CreateFeatureTypeEventListener.class, listener); |
| | | } |
| | | |
| | | public void removeCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) |
| | | { |
| | | listenerList.remove(CreateFeatureTypeEventListener.class, listener); |
| | | } |
| | | |
| | | protected void fireFeatureTypeEvent(FeatureTypeEvent evt) |
| | | { |
| | | Object[] listeners = listenerList.getListenerList(); |
| | | for (int i = 0; i < listeners.length; i += 2) |
| | | { |
| | | if (listeners[i] == CreateFeatureTypeEventListener.class) |
| | | { |
| | | ((CreateFeatureTypeEventListener) listeners[i + 1]).createFeatureTypeOccurred(evt); |
| | | } |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.filter; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.io.dgn7.UserAttributeData; |
| | | |
| | | public abstract class AbstractFLinkageDispatchableFilter extends AbstractDispatchableFilter |
| | | { |
| | | public static FrammeAttributeData getFeatureLinkage(Element element) |
| | | { |
| | | if (!element.hasUserAttributeData()) |
| | | return null; |
| | | |
| | | List<UserAttributeData> usrDatas = element.getUserAttributeData(); |
| | | for (UserAttributeData anUsrData : usrDatas) |
| | | { |
| | | if (anUsrData instanceof FrammeAttributeData) |
| | | { |
| | | return (FrammeAttributeData) anUsrData; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.filter; |
| | | |
| | | import java.util.List; |
| | | import java.util.TreeMap; |
| | | |
| | | import javax.swing.event.EventListenerList; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.FeatureTypeBuilder; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | |
| | | import com.ximple.eofms.util.DefaultColorTable; |
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil; |
| | | import com.ximple.eofms.util.TWD97GeometryConverterDecorator; |
| | | import com.ximple.io.dgn7.ArcElement; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.io.dgn7.UserAttributeData; |
| | | |
| | | public class CreateArcLineStringStrategy implements CreateFeatureTypeStrategy |
| | | { |
| | | static final Log logger = LogFactory.getLog(CreateLineStringStrategy.class); |
| | | GeometryFactory geometryFactory = new GeometryFactory(); |
| | | TreeMap<String, FeatureTypeBuilder> typeBuilders = new TreeMap<String, FeatureTypeBuilder>(); |
| | | TWD97GeometryConverterDecorator convertDecorator = new TWD97GeometryConverterDecorator(); |
| | | |
| | | // Create the listener list |
| | | protected EventListenerList listenerList = new EventListenerList(); |
| | | |
| | | public CreateArcLineStringStrategy() |
| | | { |
| | | } |
| | | |
| | | protected FrammeAttributeData getFeatureLinkage(Element element) |
| | | { |
| | | if (!element.hasUserAttributeData()) |
| | | return null; |
| | | |
| | | List<UserAttributeData> usrDatas = element.getUserAttributeData(); |
| | | for (UserAttributeData anUsrData : usrDatas) |
| | | { |
| | | if (anUsrData instanceof FrammeAttributeData) |
| | | { |
| | | return (FrammeAttributeData) anUsrData; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public FeatureType createFeatureElement(String featureName) throws SchemaException |
| | | { |
| | | if (!typeBuilders.containsKey(featureName)) |
| | | { |
| | | FeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createArcFeatureTypeBuilder(featureName); |
| | | typeBuilders.put(featureName, typeBuilder); |
| | | } |
| | | return typeBuilders.get(featureName).getFeatureType(); |
| | | } |
| | | |
| | | public Feature createFeature(FeatureType featureType, Element element, boolean useTransform) throws IllegalAttributeException |
| | | { |
| | | DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance(); |
| | | FrammeAttributeData fLinkage = getFeatureLinkage(element); |
| | | Feature feature = null; |
| | | if (fLinkage == null) return null; |
| | | if (element instanceof ArcElement) |
| | | { |
| | | ArcElement lineStringElement = (ArcElement) element; |
| | | Geometry gobj; |
| | | if (useTransform) |
| | | { |
| | | convertDecorator.setConverter(lineStringElement); |
| | | gobj = convertDecorator.toGeometry(geometryFactory); |
| | | } else { |
| | | gobj = lineStringElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | feature = featureType.create(new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (short) fLinkage.getComponentID(), |
| | | fLinkage.getOccID(), |
| | | (short) lineStringElement.getLevelIndex(), |
| | | colorTable.getColorCode(lineStringElement.getColorIndex()), |
| | | (short) lineStringElement.getWeight(), |
| | | (short) lineStringElement.getLineStyle() |
| | | }); |
| | | } |
| | | return feature; |
| | | } |
| | | |
| | | public void addCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) |
| | | { |
| | | listenerList.add(CreateFeatureTypeEventListener.class, listener); |
| | | } |
| | | |
| | | public void removeCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) |
| | | { |
| | | listenerList.remove(CreateFeatureTypeEventListener.class, listener); |
| | | } |
| | | |
| | | protected void fireFeatureTypeEvent(FeatureTypeEvent evt) |
| | | { |
| | | Object[] listeners = listenerList.getListenerList(); |
| | | for (int i = 0; i < listeners.length; i += 2) |
| | | { |
| | | if (listeners[i] == CreateFeatureTypeEventListener.class) |
| | | { |
| | | ((CreateFeatureTypeEventListener) listeners[i + 1]).createFeatureTypeOccurred(evt); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
New file |
| | |
| | | package com.ximple.eofms.filter; |
| | | |
| | | import java.util.List; |
| | | import java.util.TreeMap; |
| | | import javax.swing.event.EventListenerList; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.FeatureTypeBuilder; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | import com.vividsolutions.jts.geom.LineString; |
| | | |
| | | import com.ximple.eofms.util.DefaultColorTable; |
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil; |
| | | import com.ximple.eofms.util.TWD97GeometryConverterDecorator; |
| | | import com.ximple.io.dgn7.ArcElement; |
| | | import com.ximple.io.dgn7.ComplexChainElement; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.io.dgn7.LineElement; |
| | | import com.ximple.io.dgn7.LineStringElement; |
| | | import com.ximple.io.dgn7.UserAttributeData; |
| | | |
| | | public class CreateComplexChainStrategy implements CreateFeatureTypeStrategy |
| | | { |
| | | static final Log logger = LogFactory.getLog(CreateLineStringStrategy.class); |
| | | GeometryFactory geometryFactory = new GeometryFactory(); |
| | | TreeMap<String, FeatureTypeBuilder> typeBuilders = new TreeMap<String, FeatureTypeBuilder>(); |
| | | TWD97GeometryConverterDecorator convertDecorator = new TWD97GeometryConverterDecorator(); |
| | | |
| | | // Create the listener list |
| | | protected EventListenerList listenerList = new EventListenerList(); |
| | | |
| | | public CreateComplexChainStrategy() |
| | | { |
| | | } |
| | | |
| | | protected FrammeAttributeData getFeatureLinkage(Element element) |
| | | { |
| | | if (!element.hasUserAttributeData()) |
| | | return null; |
| | | |
| | | List<UserAttributeData> usrDatas = element.getUserAttributeData(); |
| | | for (UserAttributeData anUsrData : usrDatas) |
| | | { |
| | | if (anUsrData instanceof FrammeAttributeData) |
| | | { |
| | | return (FrammeAttributeData) anUsrData; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public FeatureType createFeatureElement(String featureName) throws SchemaException |
| | | { |
| | | if (!typeBuilders.containsKey(featureName)) |
| | | { |
| | | FeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createMultiLineFeatureTypeBuilder(featureName); |
| | | typeBuilders.put(featureName, typeBuilder); |
| | | fireFeatureTypeEvent(new FeatureTypeEvent(this, typeBuilder.getFeatureType())); |
| | | } |
| | | return typeBuilders.get(featureName).getFeatureType(); |
| | | } |
| | | |
| | | public Feature createFeature(FeatureType featureType, Element element, boolean useTransform) throws IllegalAttributeException |
| | | { |
| | | DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance(); |
| | | FrammeAttributeData fLinkage = getFeatureLinkage(element); |
| | | Feature feature = null; |
| | | if (fLinkage == null) return null; |
| | | if (element instanceof LineStringElement) |
| | | { |
| | | LineStringElement lineStringElement = (LineStringElement) element; |
| | | Geometry gobj; |
| | | if (useTransform) |
| | | { |
| | | convertDecorator.setConverter(lineStringElement); |
| | | gobj = convertDecorator.toGeometry(geometryFactory); |
| | | } else |
| | | { |
| | | gobj = lineStringElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj instanceof LineString) |
| | | { |
| | | gobj = geometryFactory.createMultiLineString(new LineString[]{(LineString) gobj}); |
| | | } |
| | | if (gobj != null) |
| | | feature = featureType.create(new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (short) fLinkage.getComponentID(), |
| | | fLinkage.getOccID(), |
| | | (short) lineStringElement.getLevelIndex(), |
| | | colorTable.getColorCode(lineStringElement.getColorIndex()), |
| | | (short) lineStringElement.getWeight(), |
| | | (short) lineStringElement.getLineStyle() |
| | | }); |
| | | } else if (element instanceof ComplexChainElement) |
| | | { |
| | | ComplexChainElement complexChain = (ComplexChainElement) element; |
| | | Geometry gobj; |
| | | if (useTransform) |
| | | { |
| | | convertDecorator.setConverter(complexChain); |
| | | gobj = convertDecorator.toGeometry(geometryFactory); |
| | | } else |
| | | gobj = complexChain.toGeometry(geometryFactory); |
| | | if (gobj instanceof LineString) |
| | | { |
| | | gobj = geometryFactory.createMultiLineString(new LineString[]{(LineString) gobj}); |
| | | } |
| | | if (gobj != null) |
| | | feature = featureType.create(new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (short) fLinkage.getComponentID(), |
| | | fLinkage.getOccID(), |
| | | (short) complexChain.getLevelIndex(), |
| | | colorTable.getColorCode(complexChain.getColorIndex()), |
| | | (short) complexChain.getWeight(), |
| | | (short) complexChain.getLineStyle() |
| | | }); |
| | | } else if (element instanceof LineElement) |
| | | { |
| | | LineElement lineElement = (LineElement) element; |
| | | Geometry gobj; |
| | | if (useTransform) |
| | | { |
| | | convertDecorator.setConverter(lineElement); |
| | | gobj = convertDecorator.toGeometry(geometryFactory); |
| | | } else |
| | | { |
| | | gobj = lineElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj instanceof LineString) |
| | | { |
| | | gobj = geometryFactory.createMultiLineString(new LineString[]{(LineString) gobj}); |
| | | } |
| | | if (gobj != null) |
| | | feature = featureType.create(new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (short) fLinkage.getComponentID(), |
| | | fLinkage.getOccID(), |
| | | (short) lineElement.getLevelIndex(), |
| | | colorTable.getColorCode(lineElement.getColorIndex()), |
| | | (short) lineElement.getWeight(), |
| | | (short) lineElement.getLineStyle() |
| | | }); |
| | | return feature; |
| | | } else if (element instanceof ArcElement) |
| | | { |
| | | ArcElement arcElement = (ArcElement) element; |
| | | Geometry gobj; |
| | | if (useTransform) |
| | | { |
| | | convertDecorator.setConverter(arcElement); |
| | | gobj = convertDecorator.toGeometry(geometryFactory); |
| | | } else |
| | | { |
| | | gobj = arcElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj instanceof LineString) |
| | | { |
| | | gobj = geometryFactory.createMultiLineString(new LineString[]{(LineString) gobj}); |
| | | } |
| | | if (gobj != null) |
| | | feature = featureType.create(new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (short) fLinkage.getComponentID(), |
| | | fLinkage.getOccID(), |
| | | (short) arcElement.getLevelIndex(), |
| | | colorTable.getColorCode(arcElement.getColorIndex()), |
| | | (short) arcElement.getWeight(), |
| | | (short) arcElement.getLineStyle() |
| | | }); |
| | | } |
| | | |
| | | return feature; |
| | | } |
| | | |
| | | public void addCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) |
| | | { |
| | | listenerList.add(CreateFeatureTypeEventListener.class, listener); |
| | | } |
| | | |
| | | public void removeCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) |
| | | { |
| | | listenerList.remove(CreateFeatureTypeEventListener.class, listener); |
| | | } |
| | | |
| | | protected void fireFeatureTypeEvent(FeatureTypeEvent evt) |
| | | { |
| | | Object[] listeners = listenerList.getListenerList(); |
| | | for (int i = 0; i < listeners.length; i += 2) |
| | | { |
| | | if (listeners[i] == CreateFeatureTypeEventListener.class) |
| | | { |
| | | ((CreateFeatureTypeEventListener) listeners[i + 1]).createFeatureTypeOccurred(evt); |
| | | } |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.filter; |
| | | |
| | | import java.util.List; |
| | | import java.util.TreeMap; |
| | | import javax.swing.event.EventListenerList; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.FeatureTypeBuilder; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | import com.ximple.eofms.util.DefaultColorTable; |
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil; |
| | | import com.ximple.eofms.util.TWD97GeometryConverterDecorator; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.EllipseElement; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.io.dgn7.UserAttributeData; |
| | | |
| | | public class CreateEllipseShapeStrategy implements CreateFeatureTypeStrategy |
| | | { |
| | | static final Log logger = LogFactory.getLog(CreateShapeStrategy.class); |
| | | GeometryFactory geometryFactory = new GeometryFactory(); |
| | | TreeMap<String, FeatureTypeBuilder> typeBuilders = new TreeMap<String, FeatureTypeBuilder>(); |
| | | TWD97GeometryConverterDecorator convertDecorator = new TWD97GeometryConverterDecorator(); |
| | | |
| | | // Create the listener list |
| | | protected EventListenerList listenerList = new EventListenerList(); |
| | | |
| | | public CreateEllipseShapeStrategy() |
| | | { |
| | | } |
| | | |
| | | protected FrammeAttributeData getFeatureLinkage(Element element) |
| | | { |
| | | if (!element.hasUserAttributeData()) |
| | | return null; |
| | | |
| | | List<UserAttributeData> usrDatas = element.getUserAttributeData(); |
| | | for (UserAttributeData anUsrData : usrDatas) |
| | | { |
| | | if (anUsrData instanceof FrammeAttributeData) |
| | | { |
| | | return (FrammeAttributeData) anUsrData; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public FeatureType createFeatureElement(String featureName) throws SchemaException |
| | | { |
| | | if (!typeBuilders.containsKey(featureName)) |
| | | { |
| | | FeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createEllipseFeatureTypeBuilder(featureName); |
| | | typeBuilders.put(featureName, typeBuilder); |
| | | } |
| | | return typeBuilders.get(featureName).getFeatureType(); |
| | | } |
| | | |
| | | public Feature createFeature(FeatureType featureType, Element element, boolean useTransform) throws IllegalAttributeException |
| | | { |
| | | DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance(); |
| | | FrammeAttributeData fLinkage = getFeatureLinkage(element); |
| | | Feature feature = null; |
| | | if (fLinkage == null) return null; |
| | | if (element instanceof EllipseElement) |
| | | { |
| | | EllipseElement ellipseElement = (EllipseElement) element; |
| | | Geometry gobj; |
| | | if (useTransform) |
| | | { |
| | | convertDecorator.setConverter(ellipseElement); |
| | | gobj = convertDecorator.toGeometry(geometryFactory); |
| | | } else |
| | | { |
| | | gobj = ellipseElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | feature = featureType.create(new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (short) fLinkage.getComponentID(), |
| | | fLinkage.getOccID(), |
| | | (short) ellipseElement.getLevelIndex(), |
| | | colorTable.getColorCode(ellipseElement.getColorIndex()), |
| | | (short) ellipseElement.getWeight(), |
| | | (short) ellipseElement.getLineStyle() |
| | | }); |
| | | } |
| | | return feature; |
| | | } |
| | | |
| | | public void addCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) |
| | | { |
| | | listenerList.add(CreateFeatureTypeEventListener.class, listener); |
| | | } |
| | | |
| | | public void removeCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) |
| | | { |
| | | listenerList.remove(CreateFeatureTypeEventListener.class, listener); |
| | | } |
| | | |
| | | protected void fireFeatureTypeEvent(FeatureTypeEvent evt) |
| | | { |
| | | Object[] listeners = listenerList.getListenerList(); |
| | | for (int i = 0; i < listeners.length; i += 2) |
| | | { |
| | | if (listeners[i] == CreateFeatureTypeEventListener.class) |
| | | { |
| | | ((CreateFeatureTypeEventListener) listeners[i + 1]).createFeatureTypeOccurred(evt); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
New file |
| | |
| | | package com.ximple.eofms.filter; |
| | | |
| | | import java.util.EventListener; |
| | | |
| | | public interface CreateFeatureTypeEventListener extends EventListener |
| | | { |
| | | public void createFeatureTypeOccurred(FeatureTypeEvent evt); |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.filter; |
| | | |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | |
| | | import com.ximple.io.dgn7.Element; |
| | | |
| | | public interface CreateFeatureTypeStrategy |
| | | { |
| | | public FeatureType createFeatureElement(String featureName) throws SchemaException; |
| | | public Feature createFeature(FeatureType featureType, Element element, boolean useTransform) throws IllegalAttributeException; |
| | | |
| | | public void addCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener); |
| | | public void removeCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener); |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.filter; |
| | | |
| | | import java.util.List; |
| | | import java.util.TreeMap; |
| | | import javax.swing.event.EventListenerList; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.FeatureTypeBuilder; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | |
| | | import com.vividsolutions.jts.geom.CoordinateList; |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | import com.vividsolutions.jts.geom.MultiLineString; |
| | | |
| | | import com.ximple.eofms.util.DefaultColorTable; |
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil; |
| | | import com.ximple.eofms.util.TWD97GeometryConverterDecorator; |
| | | import com.ximple.io.dgn7.ArcElement; |
| | | import com.ximple.io.dgn7.ComplexChainElement; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.io.dgn7.LineElement; |
| | | import com.ximple.io.dgn7.LineStringElement; |
| | | import com.ximple.io.dgn7.UserAttributeData; |
| | | |
| | | public class CreateLineStringStrategy implements CreateFeatureTypeStrategy |
| | | { |
| | | static final Log logger = LogFactory.getLog(CreateLineStringStrategy.class); |
| | | GeometryFactory geometryFactory = new GeometryFactory(); |
| | | TreeMap<String, FeatureTypeBuilder> typeBuilders = new TreeMap<String, FeatureTypeBuilder>(); |
| | | TWD97GeometryConverterDecorator convertDecorator = new TWD97GeometryConverterDecorator(); |
| | | |
| | | // Create the listener list |
| | | protected EventListenerList listenerList = new EventListenerList(); |
| | | |
| | | public CreateLineStringStrategy() |
| | | { |
| | | } |
| | | |
| | | protected FrammeAttributeData getFeatureLinkage(Element element) |
| | | { |
| | | if (!element.hasUserAttributeData()) |
| | | return null; |
| | | |
| | | List<UserAttributeData> usrDatas = element.getUserAttributeData(); |
| | | for (UserAttributeData anUsrData : usrDatas) |
| | | { |
| | | if (anUsrData instanceof FrammeAttributeData) |
| | | { |
| | | return (FrammeAttributeData) anUsrData; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public FeatureType createFeatureElement(String featureName) throws SchemaException |
| | | { |
| | | if (!typeBuilders.containsKey(featureName)) |
| | | { |
| | | FeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createLineFeatureTypeBuilder(featureName); |
| | | typeBuilders.put(featureName, typeBuilder); |
| | | fireFeatureTypeEvent(new FeatureTypeEvent(this, typeBuilder.getFeatureType())); |
| | | } |
| | | return typeBuilders.get(featureName).getFeatureType(); |
| | | } |
| | | |
| | | public Feature createFeature(FeatureType featureType, Element element, boolean useTransform) throws IllegalAttributeException |
| | | { |
| | | DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance(); |
| | | FrammeAttributeData fLinkage = getFeatureLinkage(element); |
| | | Feature feature = null; |
| | | if (fLinkage == null) return null; |
| | | if (element instanceof LineStringElement) |
| | | { |
| | | LineStringElement lineStringElement = (LineStringElement) element; |
| | | Geometry gobj; |
| | | if (useTransform) |
| | | { |
| | | convertDecorator.setConverter(lineStringElement); |
| | | gobj = convertDecorator.toGeometry(geometryFactory); |
| | | } else |
| | | { |
| | | gobj = lineStringElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | feature = featureType.create(new Object[]{ |
| | | convertDecorator.toGeometry(geometryFactory), |
| | | fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (short) fLinkage.getComponentID(), |
| | | fLinkage.getOccID(), |
| | | (short) lineStringElement.getLevelIndex(), |
| | | colorTable.getColorCode(lineStringElement.getColorIndex()), |
| | | (short) lineStringElement.getWeight(), |
| | | (short) lineStringElement.getLineStyle() |
| | | }); |
| | | } else if (element instanceof ComplexChainElement) |
| | | { |
| | | ComplexChainElement complexChain = (ComplexChainElement) element; |
| | | Geometry gobj; |
| | | if (useTransform) |
| | | { |
| | | convertDecorator.setConverter(complexChain); |
| | | gobj = convertDecorator.toGeometry(geometryFactory); |
| | | } else |
| | | { |
| | | gobj = complexChain.toGeometry(geometryFactory); |
| | | } |
| | | if ((gobj != null) && (gobj instanceof MultiLineString)) |
| | | { |
| | | MultiLineString mline = (MultiLineString) gobj; |
| | | CoordinateList coordinateList = new CoordinateList(); |
| | | for (int i = 0; i < mline.getNumGeometries(); i++) |
| | | { |
| | | coordinateList.add(mline.getGeometryN(i).getCoordinates(), true); |
| | | } |
| | | |
| | | gobj = geometryFactory.createLineString(coordinateList.toCoordinateArray()); |
| | | } |
| | | if (gobj != null) |
| | | feature = featureType.create(new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (short) fLinkage.getComponentID(), |
| | | fLinkage.getOccID(), |
| | | (short) complexChain.getLevelIndex(), |
| | | colorTable.getColorCode(complexChain.getColorIndex()), |
| | | (short) complexChain.getWeight(), |
| | | (short) complexChain.getLineStyle() |
| | | }); |
| | | } else if (element instanceof LineElement) |
| | | { |
| | | LineElement lineElement = (LineElement) element; |
| | | Geometry gobj; |
| | | if (useTransform) |
| | | { |
| | | convertDecorator.setConverter(lineElement); |
| | | gobj = convertDecorator.toGeometry(geometryFactory); |
| | | } else |
| | | { |
| | | gobj = lineElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | feature = featureType.create(new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (short) fLinkage.getComponentID(), |
| | | fLinkage.getOccID(), |
| | | (short) lineElement.getLevelIndex(), |
| | | colorTable.getColorCode(lineElement.getColorIndex()), |
| | | (short) lineElement.getWeight(), |
| | | (short) lineElement.getLineStyle() |
| | | }); |
| | | return feature; |
| | | } else if (element instanceof ArcElement) |
| | | { |
| | | ArcElement arcElement = (ArcElement) element; |
| | | Geometry gobj; |
| | | if (useTransform) |
| | | { |
| | | convertDecorator.setConverter(arcElement); |
| | | gobj = convertDecorator.toGeometry(geometryFactory); |
| | | } else |
| | | { |
| | | gobj = arcElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | feature = featureType.create(new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (short) fLinkage.getComponentID(), |
| | | fLinkage.getOccID(), |
| | | (short) arcElement.getLevelIndex(), |
| | | colorTable.getColorCode(arcElement.getColorIndex()), |
| | | (short) arcElement.getWeight(), |
| | | (short) arcElement.getLineStyle() |
| | | }); |
| | | } |
| | | |
| | | return feature; |
| | | } |
| | | |
| | | public void addCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) |
| | | { |
| | | listenerList.add(CreateFeatureTypeEventListener.class, listener); |
| | | } |
| | | |
| | | public void removeCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) |
| | | { |
| | | listenerList.remove(CreateFeatureTypeEventListener.class, listener); |
| | | } |
| | | |
| | | protected void fireFeatureTypeEvent(FeatureTypeEvent evt) |
| | | { |
| | | Object[] listeners = listenerList.getListenerList(); |
| | | for (int i = 0; i < listeners.length; i += 2) |
| | | { |
| | | if (listeners[i] == CreateFeatureTypeEventListener.class) |
| | | { |
| | | ((CreateFeatureTypeEventListener) listeners[i + 1]).createFeatureTypeOccurred(evt); |
| | | } |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.filter; |
| | | |
| | | import java.util.List; |
| | | import java.util.TreeMap; |
| | | |
| | | import javax.swing.event.EventListenerList; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.FeatureTypeBuilder; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | |
| | | import com.vividsolutions.jts.geom.Coordinate; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | import com.vividsolutions.jts.geom.LineString; |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.MultiLineString; |
| | | import com.vividsolutions.jts.geom.CoordinateList; |
| | | |
| | | import com.ximple.eofms.util.DefaultColorTable; |
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil; |
| | | import com.ximple.eofms.util.TWD97GeometryConverterDecorator; |
| | | import com.ximple.eofms.util.TWDDatumConverter; |
| | | import com.ximple.io.dgn7.ComplexChainElement; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.io.dgn7.LineElement; |
| | | import com.ximple.io.dgn7.LineStringElement; |
| | | import com.ximple.io.dgn7.TextElement; |
| | | import com.ximple.io.dgn7.UserAttributeData; |
| | | |
| | | public class CreateLineTextStrategy implements CreateFeatureTypeStrategy |
| | | { |
| | | static final Log logger = LogFactory.getLog(CreateLineTextStrategy.class); |
| | | GeometryFactory geometryFactory = new GeometryFactory(); |
| | | TreeMap<String, FeatureTypeBuilder> typeBuilders = new TreeMap<String, FeatureTypeBuilder>(); |
| | | TWD97GeometryConverterDecorator convertDecorator = new TWD97GeometryConverterDecorator(); |
| | | |
| | | // Create the listener list |
| | | protected EventListenerList listenerList = new EventListenerList(); |
| | | |
| | | public CreateLineTextStrategy() |
| | | { |
| | | } |
| | | |
| | | protected FrammeAttributeData getFeatureLinkage(Element element) |
| | | { |
| | | if (!element.hasUserAttributeData()) |
| | | return null; |
| | | |
| | | List<UserAttributeData> usrDatas = element.getUserAttributeData(); |
| | | for (UserAttributeData anUsrData : usrDatas) |
| | | { |
| | | if (anUsrData instanceof FrammeAttributeData) |
| | | { |
| | | return (FrammeAttributeData) anUsrData; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public FeatureType createFeatureElement(String featureName) throws SchemaException |
| | | { |
| | | if (!typeBuilders.containsKey(featureName)) |
| | | { |
| | | FeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createLineFeatureTypeBuilder(featureName); |
| | | typeBuilders.put(featureName, typeBuilder); |
| | | fireFeatureTypeEvent(new FeatureTypeEvent(this, typeBuilder.getFeatureType())); |
| | | } |
| | | return typeBuilders.get(featureName).getFeatureType(); |
| | | } |
| | | |
| | | public Feature createFeature(FeatureType featureType, Element element, boolean useTransform) throws IllegalAttributeException |
| | | { |
| | | DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance(); |
| | | FrammeAttributeData fLinkage = getFeatureLinkage(element); |
| | | Feature feature = null; |
| | | if (fLinkage == null) return null; |
| | | if (element instanceof LineStringElement) |
| | | { |
| | | LineStringElement lineStringElement = (LineStringElement) element; |
| | | Geometry gobj; |
| | | if (useTransform) |
| | | { |
| | | convertDecorator.setConverter(lineStringElement); |
| | | gobj = convertDecorator.toGeometry(geometryFactory); |
| | | } else { |
| | | gobj = lineStringElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | feature = featureType.create(new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (short) fLinkage.getComponentID(), |
| | | fLinkage.getOccID(), |
| | | (short) lineStringElement.getLevelIndex(), |
| | | colorTable.getColorCode(lineStringElement.getColorIndex()), |
| | | (short) lineStringElement.getWeight(), |
| | | (short) lineStringElement.getLineStyle() |
| | | }); |
| | | } else if (element instanceof TextElement) |
| | | { |
| | | TextElement txtElement = (TextElement) element; |
| | | Coordinate ptOrigin = txtElement.getUserOrigin(); |
| | | Coordinate ptEnd = new Coordinate(); |
| | | ptEnd.x = ptOrigin.x; |
| | | ptEnd.y = ptOrigin.y + txtElement.getTextHeight(); |
| | | Coordinate[] vect = new Coordinate[2]; |
| | | if (useTransform) |
| | | { |
| | | vect[0] = TWDDatumConverter.fromTM2ToTWD97(ptOrigin); |
| | | vect[1] = TWDDatumConverter.fromTM2ToTWD97(ptEnd); |
| | | } else { |
| | | vect[0] = new Coordinate(ptOrigin); |
| | | vect[1] = new Coordinate(ptEnd); |
| | | } |
| | | |
| | | LineString line = geometryFactory.createLineString(vect); |
| | | // convertDecorator.setConverter(txtElement); |
| | | // Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | |
| | | txtElement.getRotationAngle(); |
| | | |
| | | feature = featureType.create(new Object[]{ |
| | | line, |
| | | fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (short) fLinkage.getComponentID(), |
| | | fLinkage.getOccID(), |
| | | (short) txtElement.getLevelIndex(), |
| | | colorTable.getColorCode(txtElement.getColorIndex()), |
| | | (short) txtElement.getWeight(), |
| | | (short) txtElement.getLineStyle() |
| | | }); |
| | | } else if (element instanceof ComplexChainElement) |
| | | { |
| | | ComplexChainElement complexChain = (ComplexChainElement) element; |
| | | Geometry gobj; |
| | | if (useTransform) |
| | | { |
| | | convertDecorator.setConverter(complexChain); |
| | | gobj = convertDecorator.toGeometry(geometryFactory); |
| | | } else { |
| | | gobj = complexChain.toGeometry(geometryFactory); |
| | | } |
| | | if ((gobj != null) && (gobj instanceof MultiLineString)) |
| | | { |
| | | MultiLineString mline = (MultiLineString) gobj; |
| | | CoordinateList coordinateList = new CoordinateList(); |
| | | if (mline.getNumGeometries() == 1) |
| | | { |
| | | for (int i = 0; i < mline.getNumGeometries(); i++) |
| | | { |
| | | coordinateList.add(mline.getGeometryN(i).getCoordinates(), true); |
| | | } |
| | | } |
| | | |
| | | gobj = geometryFactory.createLineString(coordinateList.toCoordinateArray()); |
| | | } |
| | | if (gobj != null) |
| | | feature = featureType.create(new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (short) fLinkage.getComponentID(), |
| | | fLinkage.getOccID(), |
| | | (short) complexChain.getLevelIndex(), |
| | | colorTable.getColorCode(complexChain.getColorIndex()), |
| | | (short) complexChain.getWeight(), |
| | | (short) complexChain.getLineStyle() |
| | | }); |
| | | } else if (element instanceof LineElement) |
| | | { |
| | | LineElement lineElement = (LineElement) element; |
| | | Geometry gobj; |
| | | if (useTransform) |
| | | { |
| | | convertDecorator.setConverter(lineElement); |
| | | gobj = convertDecorator.toGeometry(geometryFactory); |
| | | } else { |
| | | gobj = lineElement.toGeometry(geometryFactory); |
| | | } |
| | | feature = featureType.create(new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (short) fLinkage.getComponentID(), |
| | | fLinkage.getOccID(), |
| | | (short) lineElement.getLevelIndex(), |
| | | colorTable.getColorCode(lineElement.getColorIndex()), |
| | | (short) lineElement.getWeight(), |
| | | (short) lineElement.getLineStyle() |
| | | }); |
| | | } |
| | | |
| | | return feature; |
| | | } |
| | | |
| | | |
| | | public void addCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) |
| | | { |
| | | listenerList.add(CreateFeatureTypeEventListener.class, listener); |
| | | } |
| | | |
| | | public void removeCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) |
| | | { |
| | | listenerList.remove(CreateFeatureTypeEventListener.class, listener); |
| | | } |
| | | |
| | | protected void fireFeatureTypeEvent(FeatureTypeEvent evt) |
| | | { |
| | | Object[] listeners = listenerList.getListenerList(); |
| | | for (int i = 0; i < listeners.length; i += 2) |
| | | { |
| | | if (listeners[i] == CreateFeatureTypeEventListener.class) |
| | | { |
| | | ((CreateFeatureTypeEventListener) listeners[i + 1]).createFeatureTypeOccurred(evt); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
New file |
| | |
| | | package com.ximple.eofms.filter; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.List; |
| | | import java.util.TreeMap; |
| | | import javax.swing.event.EventListenerList; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.FeatureTypeBuilder; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | import com.vividsolutions.jts.geom.CoordinateList; |
| | | import com.vividsolutions.jts.geom.Coordinate; |
| | | import com.vividsolutions.jts.util.Assert; |
| | | |
| | | import com.ximple.eofms.util.DefaultColorTable; |
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil; |
| | | import com.ximple.eofms.util.TWD97GeometryConverterDecorator; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.io.dgn7.GeometryConverter; |
| | | import com.ximple.io.dgn7.TextElement; |
| | | import com.ximple.io.dgn7.TextNodeElement; |
| | | import com.ximple.io.dgn7.UserAttributeData; |
| | | |
| | | public class CreateMultiSymbolStrategy implements CreateFeatureTypeStrategy |
| | | { |
| | | static final Log logger = LogFactory.getLog(CreateMultiSymbolStrategy.class); |
| | | GeometryFactory geometryFactory = new GeometryFactory(); |
| | | TreeMap<String, FeatureTypeBuilder> typeBuilders = new TreeMap<String, FeatureTypeBuilder>(); |
| | | TWD97AnchorGeometryConverterDecorator convertDecorator = new TWD97AnchorGeometryConverterDecorator(); |
| | | |
| | | // Create the listener list |
| | | protected EventListenerList listenerList = new EventListenerList(); |
| | | |
| | | public CreateMultiSymbolStrategy() |
| | | { |
| | | } |
| | | |
| | | protected FrammeAttributeData getFeatureLinkage(Element element) |
| | | { |
| | | if (!element.hasUserAttributeData()) |
| | | return null; |
| | | |
| | | List<UserAttributeData> usrDatas = element.getUserAttributeData(); |
| | | for (UserAttributeData anUsrData : usrDatas) |
| | | { |
| | | if (anUsrData instanceof FrammeAttributeData) |
| | | { |
| | | return (FrammeAttributeData) anUsrData; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public FeatureType createFeatureElement(String featureName) throws SchemaException |
| | | { |
| | | if (!typeBuilders.containsKey(featureName)) |
| | | { |
| | | FeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createMultiSymbolFeatureTypeBuilder(featureName); |
| | | typeBuilders.put(featureName, typeBuilder); |
| | | fireFeatureTypeEvent(new FeatureTypeEvent(this, typeBuilder.getFeatureType())); |
| | | } |
| | | return typeBuilders.get(featureName).getFeatureType(); |
| | | } |
| | | |
| | | public Feature createFeature(FeatureType featureType, Element element, boolean useTransform) throws IllegalAttributeException |
| | | { |
| | | DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance(); |
| | | FrammeAttributeData fLinkage = getFeatureLinkage(element); |
| | | Feature feature = null; |
| | | if (fLinkage == null) return null; |
| | | if (element instanceof TextElement) |
| | | { |
| | | TextElement txtElement = (TextElement) element; |
| | | double angle = txtElement.getRotationAngle(); |
| | | angle = BigDecimal.valueOf(angle).setScale(3, RoundingMode.HALF_UP).doubleValue(); |
| | | if (txtElement.getText().length() == 0) |
| | | { |
| | | logger.info("CreateMultiSymbolStrategy cannot conver " + element.toString() + |
| | | "to Feature - getText() is empty."); |
| | | return null; |
| | | } |
| | | StringBuilder sb = new StringBuilder(); |
| | | sb.append("OCT"); |
| | | char id = txtElement.getText().toCharArray()[0]; |
| | | sb.append(Integer.toOctalString((int) id)); |
| | | sb.append("-"); |
| | | sb.append(txtElement.getFontIndex()); |
| | | |
| | | Geometry gobj; |
| | | if (useTransform) |
| | | { |
| | | convertDecorator.setConverter(txtElement); |
| | | gobj = convertDecorator.toGeometry(geometryFactory); |
| | | } else { |
| | | gobj = txtElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | feature = featureType.create(new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (short) fLinkage.getComponentID(), |
| | | fLinkage.getOccID(), |
| | | (short) txtElement.getLevelIndex(), |
| | | colorTable.getColorCode(txtElement.getColorIndex()), |
| | | (short) txtElement.getWeight(), |
| | | (short) txtElement.getLineStyle(), |
| | | (short) txtElement.getJustification(), |
| | | (float) txtElement.getTextHeight(), |
| | | (float) txtElement.getTextWidth(), |
| | | (float) angle, |
| | | sb.toString() |
| | | }); |
| | | } else if (element instanceof TextNodeElement) |
| | | { |
| | | TextNodeElement nodeElement = (TextNodeElement) element; |
| | | double angle = nodeElement.getRotationAngle(); |
| | | angle = BigDecimal.valueOf(angle).setScale(3, RoundingMode.HALF_UP).doubleValue(); |
| | | if (nodeElement.size() == 0) |
| | | { |
| | | logger.info("CreateMultiSymbolStrategy cannot conver " + element.toString() + |
| | | "to Feature - getText() is empty."); |
| | | return null; |
| | | } |
| | | |
| | | String[] tmpstrs = nodeElement.getTextArray(); |
| | | |
| | | StringBuilder sb = new StringBuilder(); |
| | | sb.append("OCT"); |
| | | char id = tmpstrs[0].toCharArray()[0]; |
| | | sb.append(Integer.toOctalString((int) id)); |
| | | sb.append("-"); |
| | | sb.append(nodeElement.getFontIndex()); |
| | | |
| | | Geometry gobj; |
| | | if (useTransform) |
| | | { |
| | | convertDecorator.setConverter(nodeElement); |
| | | gobj = convertDecorator.toGeometry(geometryFactory); |
| | | } else { |
| | | gobj = nodeElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | feature = featureType.create(new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (short) fLinkage.getComponentID(), |
| | | fLinkage.getOccID(), |
| | | (short) nodeElement.getLevelIndex(), |
| | | colorTable.getColorCode(nodeElement.getColorIndex()), |
| | | (short) nodeElement.getWeight(), |
| | | (short) nodeElement.getLineStyle(), |
| | | (short) nodeElement.getJustification(), |
| | | (float) nodeElement.getTextNodeHeight(), |
| | | (float) nodeElement.getTextNodeLength(), |
| | | (float) angle, |
| | | sb.toString() |
| | | }); |
| | | } else |
| | | { |
| | | logger.info("CreateMultiSymbolStrategy cannot conver " + element.toString() + "to Feature"); |
| | | } |
| | | return feature; |
| | | } |
| | | |
| | | |
| | | public void addCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) |
| | | { |
| | | listenerList.add(CreateFeatureTypeEventListener.class, listener); |
| | | } |
| | | |
| | | public void removeCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) |
| | | { |
| | | listenerList.remove(CreateFeatureTypeEventListener.class, listener); |
| | | } |
| | | |
| | | protected void fireFeatureTypeEvent(FeatureTypeEvent evt) |
| | | { |
| | | Object[] listeners = listenerList.getListenerList(); |
| | | for (int i = 0; i < listeners.length; i += 2) |
| | | { |
| | | if (listeners[i] == CreateFeatureTypeEventListener.class) |
| | | { |
| | | ((CreateFeatureTypeEventListener) listeners[i + 1]).createFeatureTypeOccurred(evt); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private static class TWD97AnchorGeometryConverterDecorator extends TWD97GeometryConverterDecorator |
| | | { |
| | | public Geometry toGeometry(GeometryFactory factory) |
| | | { |
| | | if (getConverter() == null) Assert.shouldNeverReachHere(); |
| | | |
| | | getCoordinatesFilter().reset(); |
| | | |
| | | GeometryConverter converter = getConverter(); |
| | | Geometry geom = null; |
| | | try |
| | | { |
| | | if (converter instanceof TextElement) |
| | | { |
| | | geom = ((TextElement) converter).toAnchorGeometry(factory); |
| | | } else if (converter instanceof TextNodeElement) |
| | | { |
| | | geom = ((TextNodeElement) converter).toAnchorGeometry(factory); |
| | | } |
| | | } catch (ArrayStoreException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | if (converter instanceof TextNodeElement) |
| | | { |
| | | TextNodeElement node = (TextNodeElement) converter; |
| | | CoordinateList pts = new CoordinateList(); |
| | | for (int i = 0; i < node.size(); i++) |
| | | { |
| | | TextElement txtElm = (TextElement) node.get(i); |
| | | Coordinate[] coords = txtElm.toAnchorCoordinates(); |
| | | logger.warn("-coords=[" + coords.length + "]"); |
| | | for (int j = 0; j < coords.length; j++) |
| | | { |
| | | logger.warn("[" + j + "]-" + coords.toString()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if (geom == null) return null; |
| | | geom.apply(getCoordinatesFilter()); |
| | | return geom; |
| | | } |
| | | } |
| | | } |
| | | |
New file |
| | |
| | | package com.ximple.eofms.filter; |
| | | |
| | | import java.util.List; |
| | | import java.util.TreeMap; |
| | | import javax.swing.event.EventListenerList; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.FeatureTypeBuilder; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | import com.ximple.eofms.util.DefaultColorTable; |
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil; |
| | | import com.ximple.eofms.util.TWD97GeometryConverterDecorator; |
| | | import com.ximple.io.dgn7.ComplexShapeElement; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.io.dgn7.ShapeElement; |
| | | import com.ximple.io.dgn7.UserAttributeData; |
| | | |
| | | public class CreateShapeStrategy implements CreateFeatureTypeStrategy |
| | | { |
| | | static final Log logger = LogFactory.getLog(CreateShapeStrategy.class); |
| | | GeometryFactory geometryFactory = new GeometryFactory(); |
| | | TreeMap<String, FeatureTypeBuilder> typeBuilders = new TreeMap<String, FeatureTypeBuilder>(); |
| | | TWD97GeometryConverterDecorator convertDecorator = new TWD97GeometryConverterDecorator(); |
| | | |
| | | // Create the listener list |
| | | protected EventListenerList listenerList = new EventListenerList(); |
| | | |
| | | public CreateShapeStrategy() |
| | | { |
| | | } |
| | | |
| | | protected FrammeAttributeData getFeatureLinkage(Element element) |
| | | { |
| | | if (!element.hasUserAttributeData()) |
| | | return null; |
| | | |
| | | List<UserAttributeData> usrDatas = element.getUserAttributeData(); |
| | | for (UserAttributeData anUsrData : usrDatas) |
| | | { |
| | | if (anUsrData instanceof FrammeAttributeData) |
| | | { |
| | | return (FrammeAttributeData) anUsrData; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public FeatureType createFeatureElement(String featureName) throws SchemaException |
| | | { |
| | | if (!typeBuilders.containsKey(featureName)) |
| | | { |
| | | FeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createPolygonFeatureTypeBuilder(featureName); |
| | | typeBuilders.put(featureName, typeBuilder); |
| | | fireFeatureTypeEvent(new FeatureTypeEvent(this, typeBuilder.getFeatureType())); |
| | | } |
| | | return typeBuilders.get(featureName).getFeatureType(); |
| | | } |
| | | |
| | | public Feature createFeature(FeatureType featureType, Element element, boolean useTransform) throws IllegalAttributeException |
| | | { |
| | | DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance(); |
| | | FrammeAttributeData fLinkage = getFeatureLinkage(element); |
| | | Feature feature = null; |
| | | if (fLinkage == null) return null; |
| | | if (element instanceof ShapeElement) |
| | | { |
| | | ShapeElement shapeElement = (ShapeElement) element; |
| | | Geometry gobj; |
| | | if (useTransform) |
| | | { |
| | | convertDecorator.setConverter(shapeElement); |
| | | gobj = convertDecorator.toGeometry(geometryFactory); |
| | | } else |
| | | { |
| | | gobj = shapeElement.toGeometry(geometryFactory); |
| | | } |
| | | |
| | | if (gobj != null) |
| | | feature = featureType.create(new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (short) fLinkage.getComponentID(), |
| | | fLinkage.getOccID(), |
| | | (short) shapeElement.getLevelIndex(), |
| | | colorTable.getColorCode(shapeElement.getColorIndex()), |
| | | (short) shapeElement.getWeight(), |
| | | (short) shapeElement.getLineStyle() |
| | | }); |
| | | } else if (element instanceof ComplexShapeElement) |
| | | { |
| | | ComplexShapeElement complexShape = (ComplexShapeElement) element; |
| | | Geometry gobj; |
| | | if (useTransform) |
| | | { |
| | | convertDecorator.setConverter(complexShape); |
| | | gobj = convertDecorator.toGeometry(geometryFactory); |
| | | } else |
| | | { |
| | | gobj = complexShape.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | feature = featureType.create(new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (short) fLinkage.getComponentID(), |
| | | fLinkage.getOccID(), |
| | | (short) complexShape.getLevelIndex(), |
| | | colorTable.getColorCode(complexShape.getColorIndex()), |
| | | (short) complexShape.getWeight(), |
| | | (short) complexShape.getLineStyle() |
| | | }); |
| | | } |
| | | return feature; |
| | | } |
| | | |
| | | |
| | | public void addCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) |
| | | { |
| | | listenerList.add(CreateFeatureTypeEventListener.class, listener); |
| | | } |
| | | |
| | | public void removeCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) |
| | | { |
| | | listenerList.remove(CreateFeatureTypeEventListener.class, listener); |
| | | } |
| | | |
| | | protected void fireFeatureTypeEvent(FeatureTypeEvent evt) |
| | | { |
| | | Object[] listeners = listenerList.getListenerList(); |
| | | for (int i = 0; i < listeners.length; i += 2) |
| | | { |
| | | if (listeners[i] == CreateFeatureTypeEventListener.class) |
| | | { |
| | | ((CreateFeatureTypeEventListener) listeners[i + 1]).createFeatureTypeOccurred(evt); |
| | | } |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.filter; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.List; |
| | | import java.util.TreeMap; |
| | | import javax.swing.event.EventListenerList; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.FeatureTypeBuilder; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | import com.ximple.eofms.util.DefaultColorTable; |
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil; |
| | | import com.ximple.eofms.util.TWD97GeometryConverterDecorator; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.io.dgn7.TextElement; |
| | | import com.ximple.io.dgn7.UserAttributeData; |
| | | |
| | | public class CreateSymbolStrategy implements CreateFeatureTypeStrategy |
| | | { |
| | | static final Log logger = LogFactory.getLog(CreateSymbolStrategy.class); |
| | | GeometryFactory geometryFactory = new GeometryFactory(); |
| | | TreeMap<String, FeatureTypeBuilder> typeBuilders = new TreeMap<String, FeatureTypeBuilder>(); |
| | | TWD97GeometryConverterDecorator convertDecorator = new TWD97GeometryConverterDecorator(); |
| | | |
| | | // Create the listener list |
| | | protected EventListenerList listenerList = new EventListenerList(); |
| | | |
| | | public CreateSymbolStrategy() |
| | | { |
| | | } |
| | | |
| | | protected FrammeAttributeData getFeatureLinkage(Element element) |
| | | { |
| | | if (!element.hasUserAttributeData()) |
| | | return null; |
| | | |
| | | List<UserAttributeData> usrDatas = element.getUserAttributeData(); |
| | | for (UserAttributeData anUsrData : usrDatas) |
| | | { |
| | | if (anUsrData instanceof FrammeAttributeData) |
| | | { |
| | | return (FrammeAttributeData) anUsrData; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public FeatureType createFeatureElement(String featureName) throws SchemaException |
| | | { |
| | | if (!typeBuilders.containsKey(featureName)) |
| | | { |
| | | FeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createSymbolFeatureTypeBuilder(featureName); |
| | | typeBuilders.put(featureName, typeBuilder); |
| | | fireFeatureTypeEvent(new FeatureTypeEvent(this, typeBuilder.getFeatureType())); |
| | | } |
| | | return typeBuilders.get(featureName).getFeatureType(); |
| | | } |
| | | |
| | | public Feature createFeature(FeatureType featureType, Element element, boolean useTransform) throws IllegalAttributeException |
| | | { |
| | | DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance(); |
| | | FrammeAttributeData fLinkage = getFeatureLinkage(element); |
| | | Feature feature = null; |
| | | if (fLinkage == null) return null; |
| | | if (element instanceof TextElement) |
| | | { |
| | | TextElement txtElement = (TextElement) element; |
| | | double angle = txtElement.getRotationAngle(); |
| | | angle = BigDecimal.valueOf(angle).setScale(3, RoundingMode.HALF_UP).doubleValue(); |
| | | if (txtElement.getText().length() == 0) |
| | | { |
| | | logger.info("CreateSymbolStrategy cannot conver " + element.toString() + |
| | | "to Feature - getText() is empty."); |
| | | return null; |
| | | } |
| | | StringBuilder sb = new StringBuilder(); |
| | | sb.append("OCT"); |
| | | char id = txtElement.getText().toCharArray()[0]; |
| | | sb.append(Integer.toOctalString((int) id)); |
| | | sb.append("-"); |
| | | sb.append(txtElement.getFontIndex()); |
| | | |
| | | Geometry gobj; |
| | | if (useTransform) |
| | | { |
| | | convertDecorator.setConverter(txtElement); |
| | | gobj = convertDecorator.toGeometry(geometryFactory); |
| | | } else |
| | | { |
| | | gobj = txtElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | feature = featureType.create(new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (short) fLinkage.getComponentID(), |
| | | fLinkage.getOccID(), |
| | | (short) txtElement.getLevelIndex(), |
| | | colorTable.getColorCode(txtElement.getColorIndex()), |
| | | (short) txtElement.getWeight(), |
| | | (short) txtElement.getLineStyle(), |
| | | (short) txtElement.getJustification(), |
| | | (float) txtElement.getTextHeight(), |
| | | (float) txtElement.getTextWidth(), |
| | | (float) angle, |
| | | sb.toString() |
| | | }); |
| | | } else |
| | | { |
| | | logger.info("CreateSymbolStrategy cannot conver " + element.toString() + "to Feature"); |
| | | } |
| | | return feature; |
| | | } |
| | | |
| | | |
| | | public void addCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) |
| | | { |
| | | listenerList.add(CreateFeatureTypeEventListener.class, listener); |
| | | } |
| | | |
| | | public void removeCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) |
| | | { |
| | | listenerList.remove(CreateFeatureTypeEventListener.class, listener); |
| | | } |
| | | |
| | | protected void fireFeatureTypeEvent(FeatureTypeEvent evt) |
| | | { |
| | | Object[] listeners = listenerList.getListenerList(); |
| | | for (int i = 0; i < listeners.length; i += 2) |
| | | { |
| | | if (listeners[i] == CreateFeatureTypeEventListener.class) |
| | | { |
| | | ((CreateFeatureTypeEventListener) listeners[i + 1]).createFeatureTypeOccurred(evt); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
New file |
| | |
| | | package com.ximple.eofms.filter; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.List; |
| | | import java.util.TreeMap; |
| | | import javax.swing.event.EventListenerList; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.FeatureTypeBuilder; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | import com.ximple.eofms.util.DefaultColorTable; |
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil; |
| | | import com.ximple.eofms.util.TWD97GeometryConverterDecorator; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.io.dgn7.TextElement; |
| | | import com.ximple.io.dgn7.TextNodeElement; |
| | | import com.ximple.io.dgn7.UserAttributeData; |
| | | |
| | | public class CreateTextStrategy implements CreateFeatureTypeStrategy |
| | | { |
| | | static final Log logger = LogFactory.getLog(CreateTextStrategy.class); |
| | | GeometryFactory geometryFactory = new GeometryFactory(); |
| | | TreeMap<String, FeatureTypeBuilder> typeBuilders = new TreeMap<String, FeatureTypeBuilder>(); |
| | | TWD97GeometryConverterDecorator convertDecorator = new TWD97GeometryConverterDecorator(); |
| | | |
| | | // Create the listener list |
| | | protected EventListenerList listenerList = new EventListenerList(); |
| | | |
| | | public CreateTextStrategy() |
| | | { |
| | | } |
| | | |
| | | protected FrammeAttributeData getFeatureLinkage(Element element) |
| | | { |
| | | if (!element.hasUserAttributeData()) |
| | | return null; |
| | | |
| | | List<UserAttributeData> usrDatas = element.getUserAttributeData(); |
| | | for (UserAttributeData anUsrData : usrDatas) |
| | | { |
| | | if (anUsrData instanceof FrammeAttributeData) |
| | | { |
| | | return (FrammeAttributeData) anUsrData; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public FeatureType createFeatureElement(String featureName) throws SchemaException |
| | | { |
| | | if (!typeBuilders.containsKey(featureName)) |
| | | { |
| | | FeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createPointFeatureTypeBuilder(featureName); |
| | | typeBuilders.put(featureName, typeBuilder); |
| | | fireFeatureTypeEvent(new FeatureTypeEvent(this, typeBuilder.getFeatureType())); |
| | | } |
| | | return typeBuilders.get(featureName).getFeatureType(); |
| | | } |
| | | |
| | | public Feature createFeature(FeatureType featureType, Element element, boolean useTransform) throws IllegalAttributeException |
| | | { |
| | | DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance(); |
| | | FrammeAttributeData fLinkage = getFeatureLinkage(element); |
| | | Feature feature = null; |
| | | if (fLinkage == null) return null; |
| | | if (element instanceof TextElement) |
| | | { |
| | | TextElement txtElement = (TextElement) element; |
| | | double angle = txtElement.getRotationAngle(); |
| | | angle = BigDecimal.valueOf(angle).setScale(3, RoundingMode.HALF_UP).doubleValue(); |
| | | String content = txtElement.getText(); |
| | | content = content.replace('\u0000', ' '); |
| | | Geometry gobj; |
| | | if (useTransform) |
| | | { |
| | | convertDecorator.setConverter(txtElement); |
| | | gobj = convertDecorator.toGeometry(geometryFactory); |
| | | } else |
| | | { |
| | | gobj = txtElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | feature = featureType.create(new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (short) fLinkage.getComponentID(), |
| | | fLinkage.getOccID(), |
| | | (short) txtElement.getLevelIndex(), |
| | | colorTable.getColorCode(txtElement.getColorIndex()), |
| | | (short) txtElement.getWeight(), |
| | | (short) txtElement.getLineStyle(), |
| | | (short) txtElement.getJustification(), |
| | | (float) txtElement.getTextHeight(), |
| | | (float) txtElement.getTextWidth(), |
| | | (float) angle, |
| | | content |
| | | }); |
| | | } else if (element instanceof TextNodeElement) |
| | | { |
| | | TextNodeElement nodeElement = (TextNodeElement) element; |
| | | String[] texts = nodeElement.getTextArray(); |
| | | StringBuilder sb = new StringBuilder(); |
| | | for (String text : texts) |
| | | { |
| | | if (sb.length() != 0) |
| | | sb.append("\n"); |
| | | String content = text.replace('\u0000', ' '); |
| | | sb.append(content); |
| | | } |
| | | |
| | | double angle = nodeElement.getRotationAngle(); |
| | | angle = BigDecimal.valueOf(angle).setScale(3, RoundingMode.HALF_UP).doubleValue(); |
| | | Geometry gobj; |
| | | if (useTransform) |
| | | { |
| | | convertDecorator.setConverter(nodeElement); |
| | | gobj = convertDecorator.toGeometry(geometryFactory); |
| | | } else |
| | | { |
| | | gobj = nodeElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | feature = featureType.create(new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (short) fLinkage.getComponentID(), |
| | | fLinkage.getOccID(), |
| | | (short) nodeElement.getLevelIndex(), |
| | | colorTable.getColorCode(nodeElement.getColorIndex()), |
| | | (short) nodeElement.getWeight(), |
| | | (short) nodeElement.getLineStyle(), |
| | | (short) nodeElement.getJustification(), |
| | | (float) nodeElement.getTextNodeHeight(), |
| | | (float) nodeElement.getTextNodeLength(), |
| | | (float) angle, |
| | | sb.toString() |
| | | }); |
| | | } |
| | | return feature; |
| | | } |
| | | |
| | | public void addCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) |
| | | { |
| | | listenerList.add(CreateFeatureTypeEventListener.class, listener); |
| | | } |
| | | |
| | | public void removeCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) |
| | | { |
| | | listenerList.remove(CreateFeatureTypeEventListener.class, listener); |
| | | } |
| | | |
| | | protected void fireFeatureTypeEvent(FeatureTypeEvent evt) |
| | | { |
| | | Object[] listeners = listenerList.getListenerList(); |
| | | for (int i = 0; i < listeners.length; i += 2) |
| | | { |
| | | if (listeners[i] == CreateFeatureTypeEventListener.class) |
| | | { |
| | | ((CreateFeatureTypeEventListener) listeners[i + 1]).createFeatureTypeOccurred(evt); |
| | | } |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.filter; |
| | | |
| | | import org.geotools.feature.Feature; |
| | | |
| | | import com.ximple.io.dgn7.Element; |
| | | |
| | | public interface ElementDispatchableFilter |
| | | { |
| | | public boolean isDispatchable(Element element); |
| | | |
| | | public Feature execute(Element element, boolean useTransform); |
| | | |
| | | void setUseLongName(boolean useLongName); |
| | | |
| | | public void addCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener); |
| | | |
| | | public void removeCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener); |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.filter; |
| | | |
| | | import java.util.LinkedList; |
| | | |
| | | import javax.swing.event.EventListenerList; |
| | | |
| | | import org.geotools.feature.Feature; |
| | | |
| | | import com.ximple.io.dgn7.Element; |
| | | |
| | | public class ElementDispatcher implements CreateFeatureTypeEventListener |
| | | { |
| | | private LinkedList<ElementDispatchableFilter> rules; |
| | | private boolean useLongName = false; |
| | | |
| | | // Create the listener list |
| | | protected EventListenerList listenerList = new EventListenerList(); |
| | | |
| | | public ElementDispatcher() |
| | | { |
| | | rules = new LinkedList<ElementDispatchableFilter>(); |
| | | } |
| | | |
| | | public LinkedList<ElementDispatchableFilter> getRules() |
| | | { |
| | | return rules; |
| | | } |
| | | |
| | | public void addRule(ElementDispatchableFilter rule) |
| | | { |
| | | rule.setUseLongName(useLongName); |
| | | rule.addCreateFeatureTypeEventListener(this); |
| | | rules.add(rule); |
| | | } |
| | | |
| | | public boolean isUseLongName() |
| | | { |
| | | return useLongName; |
| | | } |
| | | |
| | | public void setUseLongName(boolean useLongName) |
| | | { |
| | | if (this.useLongName != useLongName) |
| | | { |
| | | this.useLongName = useLongName; |
| | | for (ElementDispatchableFilter filter : rules) |
| | | { |
| | | filter.setUseLongName(useLongName); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public Feature execute(Element element, boolean useTransform) |
| | | { |
| | | for (ElementDispatchableFilter rule : rules) |
| | | { |
| | | if (rule.isDispatchable(element)) |
| | | { |
| | | return rule.execute(element, useTransform); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public void addCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) |
| | | { |
| | | listenerList.add(CreateFeatureTypeEventListener.class, listener); |
| | | } |
| | | |
| | | public void removeCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) |
| | | { |
| | | listenerList.remove(CreateFeatureTypeEventListener.class, listener); |
| | | } |
| | | |
| | | protected void fireFeatureTypeEvent(FeatureTypeEvent evt) |
| | | { |
| | | Object[] listeners = listenerList.getListenerList(); |
| | | for (int i = 0; i < listeners.length; i += 2) |
| | | { |
| | | if (listeners[i] == CreateFeatureTypeEventListener.class) |
| | | { |
| | | ((CreateFeatureTypeEventListener) listeners[i + 1]).createFeatureTypeOccurred(evt); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void createFeatureTypeOccurred(FeatureTypeEvent evt) |
| | | { |
| | | fireFeatureTypeEvent(evt); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.filter; |
| | | |
| | | import java.util.ArrayList; |
| | | |
| | | import com.ximple.io.dgn7.Element; |
| | | |
| | | public class ElementLevelCriterion implements Comparable |
| | | { |
| | | private int elementLevel; |
| | | private ArrayList<Integer> elementLevelArray; |
| | | |
| | | public ElementLevelCriterion() |
| | | { |
| | | elementLevelArray = new ArrayList<Integer>(); |
| | | } |
| | | |
| | | public int compareTo(Object o) |
| | | { |
| | | if (o instanceof Element) |
| | | { |
| | | Element elm = (Element) o; |
| | | |
| | | for (Integer elevel : getElementLevelArray()) |
| | | { |
| | | if (elm.getElementType().id == elevel.intValue()) |
| | | return 0; |
| | | } |
| | | |
| | | } |
| | | return -1; |
| | | } |
| | | |
| | | public int getElementLevel() |
| | | { |
| | | return elementLevel; |
| | | } |
| | | |
| | | public ArrayList<Integer> getElementLevelArray() |
| | | { |
| | | return elementLevelArray; |
| | | } |
| | | |
| | | public void setElementLevel(int iLevel) |
| | | { |
| | | this.elementLevel = iLevel; |
| | | this.elementLevelArray.add(iLevel); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.filter; |
| | | |
| | | import java.util.ArrayList; |
| | | |
| | | import com.ximple.io.dgn7.Element; |
| | | |
| | | public class ElementTypeCriterion implements Comparable |
| | | { |
| | | private int elementType; |
| | | private ArrayList<Integer> elementTypeArray; |
| | | |
| | | public ElementTypeCriterion() |
| | | { |
| | | elementTypeArray = new ArrayList<Integer>(); |
| | | } |
| | | |
| | | public int compareTo(Object o) |
| | | { |
| | | if (o instanceof Element) |
| | | { |
| | | Element elm = (Element) o; |
| | | |
| | | for (Integer etype : getElementTypeArray()) |
| | | { |
| | | if (elm.getElementType().id == etype.intValue()) |
| | | return 0; |
| | | } |
| | | |
| | | } |
| | | return -1; |
| | | } |
| | | |
| | | public int getElementType() |
| | | { |
| | | return elementType; |
| | | } |
| | | |
| | | public ArrayList<Integer> getElementTypeArray() |
| | | { |
| | | return elementTypeArray; |
| | | } |
| | | |
| | | public void setElementType(int itype) |
| | | { |
| | | this.elementType = itype; |
| | | this.elementTypeArray.add(itype); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.filter; |
| | | |
| | | import java.util.EventObject; |
| | | |
| | | import org.geotools.feature.FeatureType; |
| | | |
| | | public class FeatureTypeEvent extends EventObject |
| | | { |
| | | private FeatureType featureType; |
| | | |
| | | /** |
| | | * Constructs a prototypical Event. |
| | | * |
| | | * @param source The object on which the Event initially occurred. |
| | | * @param featureType featureType |
| | | * @throws IllegalArgumentException if source is null. |
| | | */ |
| | | public FeatureTypeEvent(Object source, FeatureType featureType) |
| | | { |
| | | super(source); |
| | | this.featureType = featureType; |
| | | } |
| | | |
| | | public FeatureType getFeatureType() |
| | | { |
| | | return featureType; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.filter; |
| | | |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.eofms.util.StringUtils; |
| | | |
| | | public class TypeCompIdDispatchableFilter extends AbstractFLinkageDispatchableFilter |
| | | implements CreateFeatureTypeEventListener |
| | | { |
| | | private int tid; |
| | | private int cid; |
| | | private CreateFeatureTypeStrategy createStrategy; |
| | | private boolean useLongName = false; |
| | | |
| | | public TypeCompIdDispatchableFilter() |
| | | { |
| | | } |
| | | |
| | | public TypeCompIdDispatchableFilter(String fname, |
| | | CreateFeatureTypeStrategy createStrategy, |
| | | int tid, int compid) |
| | | { |
| | | this.setName(fname); |
| | | this.tid = tid; |
| | | this.cid = compid; |
| | | this.createStrategy = createStrategy; |
| | | this.createStrategy.addCreateFeatureTypeEventListener(this); |
| | | } |
| | | |
| | | public int getTid() |
| | | { |
| | | return tid; |
| | | } |
| | | |
| | | public void setTid(int tid) |
| | | { |
| | | this.tid = tid; |
| | | } |
| | | |
| | | public int getCid() |
| | | { |
| | | return cid; |
| | | } |
| | | |
| | | public void setCid(int cid) |
| | | { |
| | | this.cid = cid; |
| | | } |
| | | |
| | | public CreateFeatureTypeStrategy getCreateStrategy() |
| | | { |
| | | return createStrategy; |
| | | } |
| | | |
| | | public void setCreateStrategy(CreateFeatureTypeStrategy createStrategy) |
| | | { |
| | | if (this.createStrategy != null) |
| | | { |
| | | this.createStrategy.removeCreateFeatureTypeEventListener(this); |
| | | } |
| | | this.createStrategy = createStrategy; |
| | | |
| | | if (this.createStrategy != null) |
| | | { |
| | | this.createStrategy.addCreateFeatureTypeEventListener(this); |
| | | } |
| | | } |
| | | |
| | | public boolean isUseLongName() |
| | | { |
| | | return useLongName; |
| | | } |
| | | |
| | | public void setUseLongName(boolean useLongName) |
| | | { |
| | | this.useLongName = useLongName; |
| | | } |
| | | |
| | | //§PÂ_¬O§_²Å©M±ø¥ó |
| | | public boolean isDispatchable(Element element) |
| | | { |
| | | FrammeAttributeData featureLinkage = getFeatureLinkage(element); |
| | | return featureLinkage != null && tid == featureLinkage.getFsc() && |
| | | (cid == featureLinkage.getComponentID()) && |
| | | (compareType(element) == 0); |
| | | } |
| | | |
| | | public Feature execute(Element element, boolean useTransform) |
| | | { |
| | | try |
| | | { |
| | | String ftName = getFeatureTypeName(element); |
| | | FeatureType ftype = createStrategy.createFeatureElement(ftName); |
| | | return createStrategy.createFeature(ftype, element, useTransform); |
| | | } catch (SchemaException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } catch (IllegalAttributeException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } catch (NullPointerException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public String getFeatureTypeName(Element element) |
| | | { |
| | | StringBuilder sb = new StringBuilder(); |
| | | String name = getName().toLowerCase(); |
| | | String[] pices = StringUtils.splitToArray(name, "."); |
| | | boolean bfirst = true; |
| | | for (String temp : pices) |
| | | { |
| | | if (bfirst) bfirst = false; |
| | | else sb.append('-'); |
| | | sb.append(temp); |
| | | } |
| | | if (useLongName) |
| | | { |
| | | sb.append("_"); |
| | | sb.append(element.getLevelIndex()); |
| | | sb.append("_"); |
| | | sb.append(element.getWeight()); |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | |
| | | public void createFeatureTypeOccurred(FeatureTypeEvent evt) |
| | | { |
| | | fireFeatureTypeEvent(evt); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.filter; |
| | | |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.eofms.util.StringUtils; |
| | | |
| | | public class TypeCompLevelIdDispatchableFilter extends AbstractFLinkageDispatchableFilter |
| | | implements CreateFeatureTypeEventListener |
| | | { |
| | | private int tid; |
| | | private int cid; |
| | | private int lid; |
| | | private CreateFeatureTypeStrategy createStrategy; |
| | | private boolean useLongName = false; |
| | | |
| | | public TypeCompLevelIdDispatchableFilter() |
| | | { |
| | | } |
| | | |
| | | public TypeCompLevelIdDispatchableFilter(String fname, |
| | | CreateFeatureTypeStrategy createStrategy, |
| | | int tid, int compid, int level) |
| | | { |
| | | this.setName(fname); |
| | | this.tid = tid; |
| | | this.cid = compid; |
| | | this.lid = level; |
| | | this.createStrategy = createStrategy; |
| | | this.createStrategy.addCreateFeatureTypeEventListener(this); |
| | | } |
| | | |
| | | public int getTid() |
| | | { |
| | | return tid; |
| | | } |
| | | |
| | | public void setTid(int tid) |
| | | { |
| | | this.tid = tid; |
| | | } |
| | | |
| | | public int getCid() |
| | | { |
| | | return cid; |
| | | } |
| | | |
| | | public void setCid(int cid) |
| | | { |
| | | this.cid = cid; |
| | | } |
| | | |
| | | public int getLid() |
| | | { |
| | | return lid; |
| | | } |
| | | |
| | | public void setLid(int lid) |
| | | { |
| | | this.lid = lid; |
| | | } |
| | | |
| | | public CreateFeatureTypeStrategy getCreateStrategy() |
| | | { |
| | | return createStrategy; |
| | | } |
| | | |
| | | public void setCreateStrategy(CreateFeatureTypeStrategy createStrategy) |
| | | { |
| | | if (this.createStrategy != null) |
| | | { |
| | | this.createStrategy.removeCreateFeatureTypeEventListener(this); |
| | | } |
| | | this.createStrategy = createStrategy; |
| | | |
| | | if (this.createStrategy != null) |
| | | { |
| | | this.createStrategy.addCreateFeatureTypeEventListener(this); |
| | | } |
| | | } |
| | | |
| | | |
| | | public boolean isUseLongName() |
| | | { |
| | | return useLongName; |
| | | } |
| | | |
| | | public void setUseLongName(boolean useLongName) |
| | | { |
| | | this.useLongName = useLongName; |
| | | } |
| | | |
| | | public boolean isDispatchable(Element element) |
| | | { |
| | | FrammeAttributeData featureLinkage = getFeatureLinkage(element); |
| | | return featureLinkage != null && tid == featureLinkage.getFsc() && |
| | | (cid == featureLinkage.getComponentID()) && |
| | | (lid == element.getLevelIndex()) && (compareLevel(element) == 0); |
| | | } |
| | | |
| | | public Feature execute(Element element, boolean useTransform) |
| | | { |
| | | try |
| | | { |
| | | String ftName = getFeatureTypeName(element); |
| | | FeatureType ftype = createStrategy.createFeatureElement(ftName); |
| | | return createStrategy.createFeature(ftype, element, useTransform); |
| | | } catch (SchemaException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } catch (IllegalAttributeException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public String getFeatureTypeName(Element element) |
| | | { |
| | | StringBuilder sb = new StringBuilder(); |
| | | String name = getName().toLowerCase(); |
| | | String[] pices = StringUtils.splitToArray(name, "."); |
| | | boolean bfirst = true; |
| | | for (String temp : pices) |
| | | { |
| | | if (bfirst) bfirst = false; |
| | | else sb.append('-'); |
| | | sb.append(temp); |
| | | } |
| | | if (useLongName) |
| | | { |
| | | sb.append("_"); |
| | | sb.append(element.getLevelIndex()); |
| | | sb.append("_"); |
| | | sb.append(element.getWeight()); |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | |
| | | public void createFeatureTypeOccurred(FeatureTypeEvent evt) |
| | | { |
| | | fireFeatureTypeEvent(evt); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.filter; |
| | | |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.eofms.util.StringUtils; |
| | | |
| | | public class TypeIdDispatchableFilter extends AbstractFLinkageDispatchableFilter implements CreateFeatureTypeEventListener |
| | | { |
| | | private int tid; |
| | | private CreateFeatureTypeStrategy createStrategy; |
| | | private boolean useLongName = false; |
| | | |
| | | public TypeIdDispatchableFilter() |
| | | { |
| | | } |
| | | |
| | | public TypeIdDispatchableFilter(String fname, CreateFeatureTypeStrategy createStrategy, |
| | | int tid) |
| | | { |
| | | this.setName(fname); |
| | | this.tid = tid; |
| | | this.createStrategy = createStrategy; |
| | | this.createStrategy.addCreateFeatureTypeEventListener(this); |
| | | } |
| | | |
| | | public int getTid() |
| | | { |
| | | return tid; |
| | | } |
| | | |
| | | public void setTid(int tid) |
| | | { |
| | | this.tid = tid; |
| | | } |
| | | |
| | | public CreateFeatureTypeStrategy getCreateStrategy() |
| | | { |
| | | return createStrategy; |
| | | } |
| | | |
| | | public void setCreateStrategy(CreateFeatureTypeStrategy createStrategy) |
| | | { |
| | | if (this.createStrategy != null) |
| | | { |
| | | this.createStrategy.removeCreateFeatureTypeEventListener(this); |
| | | } |
| | | this.createStrategy = createStrategy; |
| | | |
| | | if (this.createStrategy != null) |
| | | { |
| | | this.createStrategy.addCreateFeatureTypeEventListener(this); |
| | | } |
| | | } |
| | | |
| | | public boolean isDispatchable(Element element) |
| | | { |
| | | FrammeAttributeData featureLinkage = getFeatureLinkage(element); |
| | | return featureLinkage != null && tid == featureLinkage.getFsc() && |
| | | (compareType(element) == 0); |
| | | } |
| | | |
| | | public Feature execute(Element element, boolean useTransform) |
| | | { |
| | | try |
| | | { |
| | | String ftName = getFeatureTypeName(element); |
| | | FeatureType ftype = createStrategy.createFeatureElement(ftName); |
| | | return createStrategy.createFeature(ftype, element, useTransform); |
| | | } catch (SchemaException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } catch (IllegalAttributeException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public boolean isUseLongName() |
| | | { |
| | | return useLongName; |
| | | } |
| | | |
| | | public void setUseLongName(boolean useLongName) |
| | | { |
| | | this.useLongName = useLongName; |
| | | } |
| | | |
| | | public String getFeatureTypeName(Element element) |
| | | { |
| | | StringBuilder sb = new StringBuilder(); |
| | | String name = getName().toLowerCase(); |
| | | String[] pices = StringUtils.splitToArray(name, "."); |
| | | boolean bfirst = true; |
| | | for (String temp : pices) |
| | | { |
| | | if (bfirst) bfirst = false; |
| | | else sb.append('-'); |
| | | sb.append(temp); |
| | | } |
| | | if (useLongName) |
| | | { |
| | | sb.append("_"); |
| | | sb.append(element.getLevelIndex()); |
| | | sb.append("_"); |
| | | sb.append(element.getWeight()); |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | |
| | | public void createFeatureTypeOccurred(FeatureTypeEvent evt) |
| | | { |
| | | fireFeatureTypeEvent(evt); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.jobs; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.nio.ByteBuffer; |
| | | import java.sql.SQLException; |
| | | import java.util.ArrayList; |
| | | import java.util.Map; |
| | | import java.util.StringTokenizer; |
| | | import java.util.TreeMap; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | | import org.geotools.data.DataStore; |
| | | import org.geotools.data.jdbc.ConnectionPoolManager; |
| | | import org.geotools.data.oracle.OracleDataStore; |
| | | import org.geotools.data.oracle.OracleDataStoreFactory; |
| | | import org.quartz.Job; |
| | | import org.quartz.JobDataMap; |
| | | import org.quartz.JobDetail; |
| | | import org.quartz.JobExecutionContext; |
| | | import org.quartz.JobExecutionException; |
| | | |
| | | import com.vividsolutions.jts.util.Assert; |
| | | |
| | | import oracle.sql.BLOB; |
| | | |
| | | import com.ximple.eofms.jobs.context.AbstractOracleJobContext; |
| | | |
| | | public abstract class AbstractOracleDatabaseJob implements Job |
| | | { |
| | | /** |
| | | * The Oracle driver class name |
| | | */ |
| | | private static final String JDBC_DRIVER = "oracle.jdbc.driver.OracleDriver"; |
| | | |
| | | private static final String ORACLE_URL = "jdbc:oracle:thin:@"; |
| | | private static final String PROPUsrKey = "user"; |
| | | private static final String PROPPassKey = "password"; |
| | | |
| | | private static final String JOBDATA_DIR = "JOBDATA_DIR"; |
| | | private static final String CONFELMSFILTER = "ELMSFILTER_CONF"; |
| | | private static final String SPATAILSCHEMA = "ORGSCHEMA"; |
| | | private static final String CONVERTDB = "CONVERTDB"; |
| | | private static final String CONVERTFILE = "CONVERTFILE"; |
| | | private static final String CONVERTELEMIN = "CONVERTELEMIN"; |
| | | private static final String CREATEDUMMY = "CREATEDUMMY"; |
| | | private static final String ELEMLOG = "ELEMLOG"; |
| | | private static final String ORAHOST = "ORAHOST"; |
| | | private static final String ORAINST = "ORAINST"; |
| | | private static final String ORAPORT = "ORAPORT"; |
| | | private static final String ORAUSER = "ORAUSER"; |
| | | private static final String ORAPASS = "ORAPASS"; |
| | | private static final String TESTMODE = "TESTMODE"; |
| | | private static final String TESTCOUNT = "TESTCOUNT"; |
| | | private static final String COPYCONNECTIVITYMODE = "COPYCONNECTIVITYMODE"; |
| | | |
| | | protected static OracleDataStoreFactory dataStoreFactory = new OracleDataStoreFactory(); |
| | | |
| | | protected String _dataPath; |
| | | protected String _filterPath; |
| | | protected String _oracleHost; |
| | | protected String _oracleInstance; |
| | | protected String _oraclePort; |
| | | protected String _username; |
| | | protected String _password; |
| | | protected String _convertDB; |
| | | protected String _convertFile; |
| | | protected String _convertElementIn; |
| | | protected String _elementLogging; |
| | | protected String _createDummy; |
| | | protected ArrayList<String> _orgSchema = new ArrayList<String>(); |
| | | protected boolean _testMode = false; |
| | | protected boolean _copyConnectivityMode = false; |
| | | protected int _testCount = -1; |
| | | protected OracleDataStore sourceDataStore; |
| | | private boolean driverFound = true; |
| | | |
| | | protected AbstractOracleDatabaseJob() |
| | | { |
| | | try |
| | | { |
| | | Class.forName(JDBC_DRIVER); |
| | | } catch (Throwable t) |
| | | { |
| | | // must be running off dummy jar! |
| | | driverFound = false; |
| | | } |
| | | } |
| | | |
| | | public abstract void execute(JobExecutionContext context) throws JobExecutionException; |
| | | |
| | | public abstract Log getLogger(); |
| | | |
| | | protected void extractJobConfiguration(JobDetail jobDetail) throws JobExecutionException |
| | | { |
| | | // The directory to scan is stored in the job map |
| | | JobDataMap dataMap = jobDetail.getJobDataMap(); |
| | | _dataPath = dataMap.getString(JOBDATA_DIR); |
| | | _filterPath = dataMap.getString(CONFELMSFILTER); |
| | | _oracleHost = dataMap.getString(ORAHOST); |
| | | _oracleInstance = dataMap.getString(ORAINST); |
| | | _oraclePort = dataMap.getString(ORAPORT); |
| | | _username = dataMap.getString(ORAUSER); |
| | | _password = dataMap.getString(ORAPASS); |
| | | _convertDB = dataMap.getString(CONVERTDB); |
| | | _convertFile = dataMap.getString(CONVERTFILE); |
| | | _convertElementIn = dataMap.getString(CONVERTELEMIN); |
| | | _elementLogging = dataMap.getString(ELEMLOG); |
| | | _createDummy = dataMap.getString(CREATEDUMMY); |
| | | |
| | | Log logger = getLogger(); |
| | | /* |
| | | logger.info("JOBDATA_DIR=" + _dataPath); |
| | | logger.info("CONFELMSFILTER=" + _filterPath); |
| | | logger.info("ORAHOST=" + _oracleHost); |
| | | logger.info("ORAINST=" + _oracleInstance); |
| | | logger.info("ORAPORT=" + _oraclePort); |
| | | logger.info("ORAUSER=" + _username); |
| | | logger.info("ORAPASS=" + _password); |
| | | logger.info("CONVERTDB=" + _convertDB); |
| | | logger.info("CONVERTFILE=" + _convertFile); |
| | | logger.info("CONVERTELEMIN=" + _convertElementIn); |
| | | logger.info("ELEMLOG=" + _elementLogging); |
| | | */ |
| | | |
| | | String strSchema = dataMap.getString(SPATAILSCHEMA); |
| | | StringTokenizer st = new StringTokenizer(strSchema, ","); |
| | | while (st.hasMoreTokens()) |
| | | { |
| | | String aSchema = st.nextToken().trim(); |
| | | _orgSchema.add(aSchema); |
| | | } |
| | | _testMode = dataMap.getBooleanFromString(TESTMODE); |
| | | _testCount = dataMap.getIntFromString(TESTCOUNT); |
| | | _copyConnectivityMode = dataMap.getBooleanFromString(COPYCONNECTIVITYMODE); |
| | | |
| | | // Validate the required input |
| | | if (_dataPath == null) |
| | | { |
| | | if (logger != null) |
| | | { |
| | | logger.warn("Cannot found data directory in configarion."); |
| | | } |
| | | throw new JobExecutionException("Directory not configured"); |
| | | } |
| | | |
| | | // Make sure the directory exists |
| | | File dir = new File(_dataPath); |
| | | if (!dir.exists()) |
| | | { |
| | | logger = getLogger(); |
| | | if (logger != null) |
| | | { |
| | | logger.warn("Cannot found data directory in file system.[" + _dataPath + "]"); |
| | | } |
| | | throw new JobExecutionException("Invalid Dir " + _dataPath); |
| | | } |
| | | |
| | | if (_oracleHost == null) |
| | | { |
| | | logger.warn("OracleHOST is null"); |
| | | throw new JobExecutionException("Unknown Oracle Host."); |
| | | } |
| | | if (_oracleInstance == null) |
| | | { |
| | | logger.warn("OracleINSTANCE is null"); |
| | | throw new JobExecutionException("Unknown Oracle Instance."); |
| | | } |
| | | if (_username == null) |
| | | { |
| | | logger.warn("OracleUSER is null"); |
| | | throw new JobExecutionException("Unknown Oracle Username."); |
| | | } |
| | | if (_password == null) |
| | | { |
| | | logger.warn("OraclePASS is null"); |
| | | throw new JobExecutionException("Unknown Oracle Password."); |
| | | } |
| | | if (_orgSchema == null) |
| | | { |
| | | logger.warn("OracleSchema is null"); |
| | | throw new JobExecutionException("Unknown Spatial Database Schema."); |
| | | } |
| | | } |
| | | |
| | | protected abstract AbstractOracleJobContext prepareJobContext(String targetSchemaName, String filterPath); |
| | | |
| | | protected static byte[] getBytesFromBLOB(BLOB blob) throws SQLException |
| | | { |
| | | byte[] raw = null; |
| | | |
| | | // BLOB blob = (BLOB) rs.getBlob(1); |
| | | int optimalSize = blob.getChunkSize(); |
| | | byte[] chunk = new byte[optimalSize]; |
| | | InputStream is = blob.getBinaryStream(0); |
| | | ByteBuffer buffer = null; // ByteBuffer.allocate(optimalSize); |
| | | int len; |
| | | |
| | | try |
| | | { |
| | | while ((len = (is.read(chunk))) != -1) |
| | | { |
| | | if (buffer != null) |
| | | { |
| | | buffer.limit(buffer.limit() + len); |
| | | } else |
| | | { |
| | | buffer = ByteBuffer.allocate(len); |
| | | } |
| | | |
| | | buffer.put(chunk); |
| | | } |
| | | |
| | | is.close(); |
| | | |
| | | assert buffer != null; |
| | | buffer.position(0); |
| | | raw = buffer.array(); |
| | | } catch (IOException e) |
| | | { |
| | | e.printStackTrace(); // To change body of catch statement use File | Settings | File Templates. |
| | | Assert.shouldNeverReachHere(); |
| | | } |
| | | |
| | | return raw; |
| | | } |
| | | |
| | | public boolean isDriverFound() |
| | | { |
| | | return driverFound; |
| | | } |
| | | |
| | | public String getDataPath() |
| | | { |
| | | return _dataPath; |
| | | } |
| | | |
| | | public String getFilterPath() |
| | | { |
| | | return _filterPath; |
| | | } |
| | | |
| | | public String getOracleHost() |
| | | { |
| | | return _oracleHost; |
| | | } |
| | | |
| | | public String getOracleInstance() |
| | | { |
| | | return _oracleInstance; |
| | | } |
| | | |
| | | public String getOraclePort() |
| | | { |
| | | return _oraclePort; |
| | | } |
| | | |
| | | public String getUsername() |
| | | { |
| | | return _username; |
| | | } |
| | | |
| | | public String getPassword() |
| | | { |
| | | return _password; |
| | | } |
| | | |
| | | public ArrayList<String> getOriginSchema() |
| | | { |
| | | return _orgSchema; |
| | | } |
| | | |
| | | public boolean isTestMode() |
| | | { |
| | | return _testMode; |
| | | } |
| | | |
| | | public int getTestCount() |
| | | { |
| | | return _testCount; |
| | | } |
| | | |
| | | public String getConvertDB() |
| | | { |
| | | return _convertDB; |
| | | } |
| | | |
| | | public void setConvertDB(String convertDB) |
| | | { |
| | | _convertDB = convertDB; |
| | | } |
| | | |
| | | public String getConvertFile() |
| | | { |
| | | return _convertFile; |
| | | } |
| | | |
| | | public void setConvertFile(String convertFile) |
| | | { |
| | | _convertFile = convertFile; |
| | | } |
| | | |
| | | public String getConvertElementIn() |
| | | { |
| | | return _convertElementIn; |
| | | } |
| | | |
| | | public void setConvertElementIn(String convertElementIn) |
| | | { |
| | | _convertElementIn = convertElementIn; |
| | | } |
| | | |
| | | public boolean checkConvertDB() |
| | | { |
| | | return _convertDB != null && !_convertDB.equalsIgnoreCase("false") && |
| | | !_convertDB.equalsIgnoreCase("no") && !_convertDB.equalsIgnoreCase("0"); |
| | | } |
| | | |
| | | public boolean checkConvertFile() |
| | | { |
| | | return _convertFile != null && !_convertFile.equalsIgnoreCase("false") && |
| | | !_convertFile.equalsIgnoreCase("no") && !_convertFile.equalsIgnoreCase("0"); |
| | | } |
| | | |
| | | public boolean checkConvertElementIn() |
| | | { |
| | | return _convertElementIn != null && !_convertElementIn.equalsIgnoreCase("false") && |
| | | !_convertElementIn.equalsIgnoreCase("no") && !_convertElementIn.equalsIgnoreCase("0"); |
| | | } |
| | | |
| | | public String getElementLogging() |
| | | { |
| | | return _elementLogging; |
| | | } |
| | | |
| | | public void setElementLogging(String elementLogging) |
| | | { |
| | | this._elementLogging = elementLogging; |
| | | } |
| | | |
| | | public boolean checkElementLogging() |
| | | { |
| | | return _elementLogging != null && !_elementLogging.equalsIgnoreCase("false") && |
| | | !_elementLogging.equalsIgnoreCase("no") && !_elementLogging.equalsIgnoreCase("0"); |
| | | } |
| | | |
| | | public boolean checkCreateDummy() |
| | | { |
| | | return _createDummy != null && !_createDummy.equalsIgnoreCase("false") && |
| | | !_createDummy.equalsIgnoreCase("no") && !_createDummy.equalsIgnoreCase("0"); |
| | | } |
| | | |
| | | public boolean isCopyConnectivityMode() |
| | | { |
| | | return _copyConnectivityMode; |
| | | } |
| | | |
| | | public DataStore getSourceDataStore() |
| | | { |
| | | return sourceDataStore; |
| | | } |
| | | |
| | | protected void createSourceDataStore() throws JobExecutionException |
| | | { |
| | | if (sourceDataStore != null) |
| | | { |
| | | sourceDataStore.dispose(); |
| | | sourceDataStore = null; |
| | | } |
| | | |
| | | if (!isDriverFound()) |
| | | { |
| | | throw new JobExecutionException("Oracle JDBC Driver not found.-" + JDBC_DRIVER); |
| | | } |
| | | Map<String, String> map = new TreeMap<String, String>(); |
| | | map.put("host", _oracleHost); |
| | | map.put("port", _oraclePort); |
| | | map.put("instance", _oracleInstance); |
| | | map.put("user", _username); |
| | | map.put("passwd", _password); |
| | | map.put("dbtype", "oracle"); |
| | | map.put("alias", _oracleInstance); |
| | | map.put("namespace", null); |
| | | if (!map.containsKey(OracleDataStoreFactory.MAXCONN.key)) |
| | | { |
| | | map.put(OracleDataStoreFactory.MAXCONN.key, "10"); |
| | | } |
| | | if (!map.containsKey(OracleDataStoreFactory.MINCONN.key)) |
| | | { |
| | | map.put(OracleDataStoreFactory.MINCONN.key, "1"); |
| | | } |
| | | |
| | | if (!dataStoreFactory.canProcess(map)) |
| | | { |
| | | getLogger().warn("cannot process properties-"); |
| | | throw new JobExecutionException("cannot process properties-"); |
| | | } |
| | | try |
| | | { |
| | | sourceDataStore = (OracleDataStore) dataStoreFactory.createDataStore(map); |
| | | } catch (IOException e) |
| | | { |
| | | getLogger().warn(e.getMessage(), e); |
| | | throw new JobExecutionException(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | protected void disconnect() |
| | | { |
| | | ConnectionPoolManager manager = ConnectionPoolManager.getInstance(); |
| | | manager.closeAll(); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.jobs; |
| | | |
| | | public interface DataReposVersionManager |
| | | { |
| | | public static final String XGVERSIONTABLE_NAME = "xgeos_vsversion"; |
| | | public static final String[] DEFAULTXGVERSIONSCHEMA_NAMES = new String[] { |
| | | "gisrepo1", "gisrepo2" |
| | | }; |
| | | |
| | | public static final short VSSTATUS_AVAILABLE= 0x0000; |
| | | public static final short VSSTATUS_USING = 0x0100; |
| | | public static final short VSSTATUS_CONFIG = 0x0020; |
| | | public static final short VSSTATUS_LINKVIEW = 0x0010; |
| | | public static final short VSSTATUS_READY = 0x0002; |
| | | public static final short VSSTATUS_COVERT = 0x0001; |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.jobs; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.MalformedURLException; |
| | | import java.net.URL; |
| | | import java.nio.charset.Charset; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | |
| | | import org.apache.commons.digester.Digester; |
| | | import org.apache.commons.digester.xmlrules.DigesterLoader; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.apache.commons.transaction.memory.PessimisticMapWrapper; |
| | | import org.apache.commons.transaction.util.CommonsLoggingLogger; |
| | | import org.apache.commons.transaction.util.LoggerFacade; |
| | | import org.geotools.data.FeatureWriter; |
| | | import org.geotools.data.Transaction; |
| | | import org.geotools.data.shapefile.ShapefileDataStore; |
| | | import org.geotools.data.shapefile.indexed.IndexedShapefileDataStore; |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | import org.geotools.feature.SimpleFeature; |
| | | import org.xml.sax.SAXException; |
| | | |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | import com.ximple.eofms.filter.AbstractFLinkageDispatchableFilter; |
| | | import com.ximple.eofms.filter.ElementDispatchableFilter; |
| | | import com.ximple.eofms.filter.ElementDispatcher; |
| | | import com.ximple.eofms.filter.TypeCompIdDispatchableFilter; |
| | | import com.ximple.eofms.filter.TypeCompLevelIdDispatchableFilter; |
| | | import com.ximple.eofms.filter.TypeIdDispatchableFilter; |
| | | import com.ximple.eofms.jobs.context.AbstractDgnFileJobContext; |
| | | import com.ximple.io.dgn7.ComplexElement; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.io.dgn7.UserAttributeData; |
| | | |
| | | public class DummyFeatureConvertJobContext extends AbstractDgnFileJobContext |
| | | { |
| | | static final Log logger = LogFactory.getLog(DummyFeatureConvertJobContext.class); |
| | | static final LoggerFacade sLogger = new CommonsLoggingLogger(logger); |
| | | static final GeometryFactory geometryFactory = new GeometryFactory(); |
| | | static final String SHPOUTPATH = "shpout"; |
| | | |
| | | private String dataOut = null; |
| | | |
| | | private HashMap<String, ArrayList<Feature>> featuresContext = new HashMap<String, ArrayList<Feature>>(); |
| | | private HashMap<String, FeatureWriter> featuresWriterContext = new HashMap<String, FeatureWriter>(); |
| | | |
| | | private PessimisticMapWrapper txFeaturesContext; |
| | | |
| | | private ElementDispatcher elementDispatcher; |
| | | private String _filterConfig; |
| | | |
| | | public DummyFeatureConvertJobContext(String dataPath, String filterConfig) |
| | | { |
| | | super(dataPath); |
| | | txFeaturesContext = new PessimisticMapWrapper(featuresContext, sLogger); |
| | | _filterConfig = filterConfig; |
| | | elementDispatcher = createElementDispatcher(); |
| | | } |
| | | |
| | | private ElementDispatcher createElementDispatcher() |
| | | { |
| | | try |
| | | { |
| | | URL rulesURL = ElementDispatcher.class.getResource("ElementDispatcherRules.xml"); |
| | | assert rulesURL != null; |
| | | Digester digester = DigesterLoader.createDigester(rulesURL); |
| | | URL filterURL = null; |
| | | if (_filterConfig != null) |
| | | { |
| | | File config = new File(_filterConfig); |
| | | if (config.exists()) |
| | | { |
| | | filterURL = config.toURI().toURL(); |
| | | } |
| | | } |
| | | if (filterURL == null) |
| | | { |
| | | // config = new File("conf/DefaultConvertShpFilter.xml"); |
| | | filterURL = this.getClass().getResource("/conf/DefaultConvertShpFilter.xml"); |
| | | // filterURL = this.getClass().getResource("/conf/ConvertShpFilterForLevel.xml"); |
| | | } |
| | | assert filterURL != null; |
| | | return (ElementDispatcher) digester.parse(filterURL); |
| | | } catch (UnsupportedEncodingException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } catch (MalformedURLException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } catch (IOException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } catch (SAXException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | public void putFeatureCollection(Element element) throws IllegalAttributeException, SchemaException |
| | | { |
| | | assert elementDispatcher != null; |
| | | |
| | | if (element == null) |
| | | { |
| | | logger.warn("Unknown Element:" + null); |
| | | return; |
| | | } |
| | | |
| | | // §PÂ_¬O§_²Å©M±ø¥ó |
| | | Feature feature = elementDispatcher.execute(element, true); |
| | | if (feature == null) |
| | | { |
| | | FrammeAttributeData linkage = |
| | | AbstractFLinkageDispatchableFilter.getFeatureLinkage(element); |
| | | logger.warn("Unknown Element:" + element.getElementType().toString() + |
| | | ":type=" + element.getType() + ":lv=" + element.getLevelIndex() + ":id=" + |
| | | (linkage == null ? "NULL" : (linkage.getFsc() + "|" + linkage.getComponentID()))); |
| | | if (element instanceof ComplexElement) |
| | | { |
| | | ComplexElement complex = (ComplexElement) element; |
| | | logger.warn("----Complex Element size=" + complex.size()); |
| | | } |
| | | |
| | | return; |
| | | } |
| | | |
| | | if (!txFeaturesContext.containsKey(feature.getFeatureType())) |
| | | { |
| | | txFeaturesContext.put(feature.getFeatureType(), new ArrayList()); |
| | | } |
| | | ArrayList arrayList = (ArrayList) txFeaturesContext.get(feature.getFeatureType()); |
| | | arrayList.add(feature); |
| | | } |
| | | |
| | | public void startTransaction() |
| | | { |
| | | assert elementDispatcher != null; |
| | | for (ElementDispatchableFilter filter : elementDispatcher.getRules()) |
| | | { |
| | | if (filter instanceof TypeCompIdDispatchableFilter) |
| | | { |
| | | ((TypeCompIdDispatchableFilter) filter).getCreateStrategy(); |
| | | } else if (filter instanceof TypeCompLevelIdDispatchableFilter) |
| | | { |
| | | ((TypeCompIdDispatchableFilter) filter).getCreateStrategy(); |
| | | } else if (filter instanceof TypeIdDispatchableFilter) |
| | | { |
| | | ((TypeCompIdDispatchableFilter) filter).getCreateStrategy(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void commitTransaction() |
| | | { |
| | | if (!txFeaturesContext.isEmpty()) |
| | | { |
| | | logger.debug("Transaction size = " + txFeaturesContext.size()); |
| | | //txFeaturesContext.commitTransaction(); |
| | | } else |
| | | { |
| | | logger.debug("Transaction is empty."); |
| | | } |
| | | |
| | | if (!featuresContext.isEmpty()) |
| | | { |
| | | updateDataStore(); |
| | | } |
| | | } |
| | | |
| | | public void rollbackTransaction() |
| | | { |
| | | //txFeaturesContext.rollbackTransaction(); |
| | | if (!featuresContext.isEmpty()) |
| | | { |
| | | updateDataStore(); |
| | | } |
| | | } |
| | | |
| | | private void updateDataStore() |
| | | { |
| | | Iterator it = featuresContext.keySet().iterator(); |
| | | |
| | | try |
| | | { |
| | | while (it.hasNext()) |
| | | { |
| | | FeatureType featureType = (FeatureType) it.next(); |
| | | File sfile = new File(getDataOutPath() + File.separator + featureType.getTypeName()); |
| | | logger.debug("Begin Save shapefile:" + sfile.toURI()); |
| | | |
| | | FeatureWriter writer; |
| | | if (featuresWriterContext.containsKey(featureType.getTypeName())) |
| | | { |
| | | writer = featuresWriterContext.get(featureType.getTypeName()); |
| | | } else |
| | | { |
| | | // ShapefileDataStore shapefileDataStore = new ShapefileDataStore(sfile.toURI().toURL()); |
| | | /* |
| | | ShapefileDataStore shapefileDataStore = new ShapefileDataStore(sfile.toURI().toURL(), |
| | | true, Charset.forName("UTF-8")); |
| | | */ |
| | | if (!sfile.exists()) |
| | | { |
| | | ShapefileDataStore shapefileDataStore = new IndexedShapefileDataStore(sfile.toURI().toURL(), |
| | | null, true, true, IndexedShapefileDataStore.TREE_QIX, Charset.forName("UTF-8")); |
| | | shapefileDataStore.createSchema(featureType); |
| | | writer = shapefileDataStore.getFeatureWriter(featureType.getTypeName(), |
| | | Transaction.AUTO_COMMIT); |
| | | } else |
| | | { |
| | | ShapefileDataStore shapefileDataStore = new IndexedShapefileDataStore(sfile.toURI().toURL(), |
| | | null, true, true, IndexedShapefileDataStore.TREE_QIX, Charset.forName("UTF-8")); |
| | | writer = shapefileDataStore.getFeatureWriterAppend(featureType.getTypeName(), |
| | | Transaction.AUTO_COMMIT); |
| | | } |
| | | featuresWriterContext.put(featureType.getTypeName(), writer); |
| | | } |
| | | |
| | | ArrayList<Feature> features = featuresContext.get(featureType); |
| | | Iterator itFeature = features.iterator(); |
| | | while (itFeature.hasNext()) |
| | | { |
| | | Feature feature = (Feature) itFeature.next(); |
| | | ((SimpleFeature) writer.next()).setAttributes(feature.getAttributes(null)); |
| | | } |
| | | //writer.close(); |
| | | logger.debug("End Save shapefile:" + sfile.toURI()); |
| | | } |
| | | featuresContext.clear(); |
| | | } catch (MalformedURLException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } catch (IllegalAttributeException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } catch (IOException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | public String getDataOutPath() |
| | | { |
| | | if (dataOut == null) |
| | | { |
| | | File outPath = new File(getDataPath(), SHPOUTPATH); |
| | | if (!outPath.exists()) |
| | | { |
| | | outPath.mkdir(); |
| | | } else if (!outPath.isDirectory()) |
| | | { |
| | | outPath.mkdir(); |
| | | } |
| | | dataOut = outPath.toString(); |
| | | } |
| | | return dataOut; |
| | | } |
| | | |
| | | public void closeFeatureWriter() throws IOException |
| | | { |
| | | |
| | | for (FeatureWriter featureWriter : this.featuresWriterContext.values()) |
| | | { |
| | | featureWriter.close(); |
| | | } |
| | | |
| | | this.featuresWriterContext.clear(); |
| | | } |
| | | |
| | | protected FrammeAttributeData getFeatureLinkage(Element element) |
| | | { |
| | | if (!element.hasUserAttributeData()) |
| | | return null; |
| | | |
| | | List<UserAttributeData> usrDatas = element.getUserAttributeData(); |
| | | for (UserAttributeData anUsrData : usrDatas) |
| | | { |
| | | if (anUsrData instanceof FrammeAttributeData) |
| | | { |
| | | return (FrammeAttributeData) anUsrData; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public Log getLogger() |
| | | { |
| | | return logger; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.jobs; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileNotFoundException; |
| | | import java.io.FilenameFilter; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.ByteOrder; |
| | | import java.nio.channels.FileChannel; |
| | | import java.sql.ResultSet; |
| | | import java.sql.SQLException; |
| | | import java.sql.Statement; |
| | | import java.sql.Types; |
| | | import java.sql.Connection; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | import java.util.TreeMap; |
| | | |
| | | import org.apache.commons.collections.OrderedMap; |
| | | import org.apache.commons.collections.OrderedMapIterator; |
| | | import org.apache.commons.collections.map.LinkedMap; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.geotools.data.DataStore; |
| | | import org.geotools.data.mysql.MySQLDataStore; |
| | | import org.geotools.data.mysql.MySQLDataStoreFactory; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | import org.quartz.JobDataMap; |
| | | import org.quartz.JobDetail; |
| | | import org.quartz.JobExecutionContext; |
| | | import org.quartz.JobExecutionException; |
| | | |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | import oracle.jdbc.OracleConnection; |
| | | import oracle.jdbc.OracleResultSet; |
| | | import oracle.sql.ARRAY; |
| | | import oracle.sql.BLOB; |
| | | |
| | | import com.ximple.eofms.jobs.context.AbstractOracleJobContext; |
| | | import com.ximple.eofms.jobs.context.mysql.OracleConvertMySQLJobContext; |
| | | import com.ximple.eofms.jobs.context.mysql.IndexDgnConvertMySQLJobContext; |
| | | import com.ximple.eofms.jobs.context.mysql.GeneralDgnConvertMySQLJobContext; |
| | | import com.ximple.eofms.jobs.context.mysql.FeatureDgnConvertMySQLJobContext; |
| | | import com.ximple.eofms.util.BinConverter; |
| | | import com.ximple.eofms.util.ByteArrayCompressor; |
| | | import com.ximple.eofms.util.StringUtils; |
| | | import com.ximple.io.dgn7.ComplexElement; |
| | | import com.ximple.io.dgn7.Dgn7fileException; |
| | | import com.ximple.io.dgn7.Dgn7fileReader; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.ElementType; |
| | | import com.ximple.io.dgn7.IElementHandler; |
| | | import com.ximple.io.dgn7.Lock; |
| | | import com.ximple.io.dgn7.TextElement; |
| | | import com.ximple.util.PrintfFormat; |
| | | |
| | | public class OracleConvertDgn2MySQLJob extends AbstractOracleDatabaseJob |
| | | { |
| | | final static Log logger = LogFactory.getLog(OracleConvertDgn2PostGISJob.class); |
| | | |
| | | private static final String MYHOST = "MYHOST"; |
| | | private static final String MYDATBASE = "MYDATBASE"; |
| | | private static final String MYPORT = "MYPORT"; |
| | | private static final String MYSCHEMA = "MYSCHEMA"; |
| | | private static final String MYUSER = "MYUSER"; |
| | | private static final String MYPASS = "MYPASS"; |
| | | private static final String USEWKB = "USEWKB"; |
| | | |
| | | private static final int FETCHSIZE = 30; |
| | | private static final int COMMITSIZE = 20; |
| | | |
| | | class Pair |
| | | { |
| | | Object first; |
| | | Object second; |
| | | |
| | | public Pair(Object first, Object second) |
| | | { |
| | | this.first = first; |
| | | this.second = second; |
| | | } |
| | | } |
| | | |
| | | protected static MySQLDataStoreFactory dataStoreFactory = new MySQLDataStoreFactory(); |
| | | |
| | | GeometryFactory _geomFactory = new GeometryFactory(); |
| | | protected String _myHost; |
| | | protected String _myDatabase; |
| | | protected String _myPort; |
| | | protected String _mySchema; |
| | | protected String _myUsername; |
| | | protected String _myPassword; |
| | | protected String _myUseWKB; |
| | | |
| | | protected Map<String, String> myProperties; |
| | | protected MySQLDataStore targetDataStore; |
| | | |
| | | public Log getLogger() |
| | | { |
| | | return logger; |
| | | } |
| | | |
| | | protected AbstractOracleJobContext prepareJobContext(String targetSchemaName, String filterPath) |
| | | { |
| | | return new OracleConvertMySQLJobContext(getDataPath(), getTargetDataStore(), filterPath); |
| | | } |
| | | |
| | | protected void extractJobConfiguration(JobDetail jobDetail) throws JobExecutionException |
| | | { |
| | | super.extractJobConfiguration(jobDetail); |
| | | JobDataMap dataMap = jobDetail.getJobDataMap(); |
| | | _myHost = dataMap.getString(MYHOST); |
| | | _myDatabase = dataMap.getString(MYDATBASE); |
| | | _myPort = dataMap.getString(MYPORT); |
| | | _mySchema = dataMap.getString(MYSCHEMA); |
| | | _myUsername = dataMap.getString(MYUSER); |
| | | _myPassword = dataMap.getString(MYPASS); |
| | | _myUseWKB = dataMap.getString(USEWKB); |
| | | |
| | | Log logger = getLogger(); |
| | | /* |
| | | logger.info("MYHOST=" + _myHost); |
| | | logger.info("MYDATBASE=" + _myDatabase); |
| | | logger.info("MYPORT=" + _myPort); |
| | | logger.info("MYSCHEMA=" + _mySchema); |
| | | logger.info("MYUSER=" + _myUsername); |
| | | logger.info("MYPASS=" + _myPassword); |
| | | logger.info("USEWKB=" + _myUseWKB); |
| | | */ |
| | | |
| | | if (_myHost == null) |
| | | { |
| | | logger.warn("MYHOST is null"); |
| | | throw new JobExecutionException("Unknown PostGIS host."); |
| | | } |
| | | if (_myDatabase == null) |
| | | { |
| | | logger.warn("PGDATABASE is null"); |
| | | throw new JobExecutionException("Unknown PostGIS database."); |
| | | } |
| | | if (_myPort == null) |
| | | { |
| | | logger.warn("MYPORT is null"); |
| | | throw new JobExecutionException("Unknown PostGIS port."); |
| | | } |
| | | if (_mySchema == null) |
| | | { |
| | | logger.warn("MYSCHEMA is null"); |
| | | throw new JobExecutionException("Unknown PostGIS schema."); |
| | | } |
| | | if (_myUsername == null) |
| | | { |
| | | logger.warn("PGUSERNAME is null"); |
| | | throw new JobExecutionException("Unknown PostGIS username."); |
| | | } |
| | | if (_myPassword == null) |
| | | { |
| | | logger.warn("PGPASSWORD is null"); |
| | | throw new JobExecutionException("Unknown PostGIS password."); |
| | | } |
| | | |
| | | Map<String, String> remote = new TreeMap<String, String>(); |
| | | remote.put("dbtype", "postgis"); |
| | | remote.put("charset", "UTF-8"); |
| | | remote.put("host", _myHost); |
| | | remote.put("port", _myPort); |
| | | remote.put("database", _myDatabase); |
| | | remote.put("user", _myUsername); |
| | | remote.put("passwd", _myPassword); |
| | | remote.put("namespace", null); |
| | | myProperties = remote; |
| | | } |
| | | |
| | | public void execute(JobExecutionContext context) throws JobExecutionException |
| | | { |
| | | // Every job has its own job detail |
| | | JobDetail jobDetail = context.getJobDetail(); |
| | | |
| | | // The name is defined in the job definition |
| | | String jobName = jobDetail.getName(); |
| | | String targetSchemaName = null; |
| | | |
| | | // Log the time the job started |
| | | logger.info(jobName + " fired at " + new Date()); |
| | | extractJobConfiguration(jobDetail); |
| | | createSourceDataStore(); |
| | | createTargetDataStore(); |
| | | if (getSourceDataStore() == null) |
| | | { |
| | | logger.warn("Cannot connect source oracle database."); |
| | | throw new JobExecutionException("Cannot connect source oracle database."); |
| | | } |
| | | |
| | | if (getTargetDataStore() == null) |
| | | { |
| | | logger.warn("Cannot connect source postgreSQL database."); |
| | | throw new JobExecutionException("Cannot connect source postgreSQL database."); |
| | | } |
| | | |
| | | long t1 = System.currentTimeMillis(); |
| | | try |
| | | { |
| | | logger.info("-- step:clearOutputDatabase --"); |
| | | clearOutputDatabase(); |
| | | boolean bFirst = isCopyConnectivityMode(); |
| | | if (checkConvertDB()) |
| | | { |
| | | logger.info("-- step:convertOracleDB --"); |
| | | |
| | | for (String orgSchema : _orgSchema) |
| | | { |
| | | OracleConvertMySQLJobContext jobContext = |
| | | (OracleConvertMySQLJobContext) prepareJobContext(targetSchemaName, _filterPath); |
| | | jobContext.setSourceDataStore(getSourceDataStore()); |
| | | // jobContext.setConvertElementIn(_convertElementIn); |
| | | jobContext.setElementLogging(checkElementLogging()); |
| | | jobContext.setExecutionContext(context); |
| | | |
| | | if (bFirst) |
| | | copyConnectivity(jobContext); |
| | | else |
| | | bFirst = false; |
| | | |
| | | logger.info("----- start schema:" + orgSchema + " -----"); |
| | | exetcuteConvert(jobContext, orgSchema, _dataPath); |
| | | |
| | | //close all open filewriter instance |
| | | jobContext.closeFeatureWriter(); |
| | | } |
| | | } |
| | | |
| | | if (checkConvertFile()) |
| | | { |
| | | logger.info("-- step:convertIndexDesignFile --"); |
| | | convertIndexDesignFile(context); |
| | | logger.info("-- step:convertOtherDesignFile --"); |
| | | convertOtherDesignFile(context); |
| | | } |
| | | |
| | | if (checkConvertElementIn()) |
| | | { |
| | | logger.info("-- step:convertFeatureDesignFile --"); |
| | | convertFeatureDesignFile(context); |
| | | } |
| | | |
| | | if (checkCreateDummy()) |
| | | { |
| | | logger.info("-- step:createDummyFeatureFile --"); |
| | | createDummyFeatureFile(context); |
| | | } |
| | | |
| | | disconnect(); |
| | | long t2 = System.currentTimeMillis(); |
| | | // public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss"; |
| | | // SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW); |
| | | logger.warn("use time = " + ((t2 - t1) / 60000.0) + " min"); |
| | | } catch (SQLException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | throw new JobExecutionException("Database error. " + e.getMessage(), e); |
| | | } catch (IOException ex) |
| | | { |
| | | logger.warn(ex.getMessage(), ex); |
| | | throw new JobExecutionException("IO error. " + ex.getMessage(), ex); |
| | | } |
| | | logger.warn(jobName + " end at " + new Date()); |
| | | } |
| | | |
| | | /** |
| | | * Connectivity½Æ»s¤@Óª©¥»¡A¦b¬d¸ß¹q¬y¤è¦V®É¥Î¨Ó¤ñ¹ïOMS¸ê®Æ®wªº¹q¾¹³s±µ©Ê(Connectivity) |
| | | * |
| | | * @param jobContext job context |
| | | * @throws SQLException sql exception |
| | | */ |
| | | private void copyConnectivity(OracleConvertMySQLJobContext jobContext) throws SQLException |
| | | { |
| | | Connection connection = jobContext.getOracleConnection(); |
| | | Statement stmt = connection.createStatement(); |
| | | stmt.execute(AbstractOracleJobContext.TRUNCATE_CONNECTIVITY_WEBCHECK); |
| | | stmt.execute(AbstractOracleJobContext.COPY_CONNECTIVITY_TO_WEBCHECK); |
| | | } |
| | | |
| | | private void exetcuteConvert(OracleConvertMySQLJobContext jobContext, |
| | | String querySchema, String dataPath) throws SQLException |
| | | { |
| | | int order = 0; |
| | | OrderedMap map = getBlobStorageList(jobContext.getOracleConnection(), querySchema, "SD$SPACENODES" |
| | | , null); |
| | | |
| | | logger.info("begin convert job:[" + map.size() + "]:testmode=" + _testMode); |
| | | |
| | | int total = map.size(); //spacenodes count |
| | | int step = total / 100; |
| | | int current = 0; |
| | | |
| | | //jobContext.startTransaction(); |
| | | jobContext.setCurrentSchema(querySchema); |
| | | jobContext.getExecutionContext().put("ConvertDgn2PostGISJobProgress", 0); |
| | | for (OrderedMapIterator it = map.orderedMapIterator(); it.hasNext();) |
| | | { |
| | | it.next(); |
| | | |
| | | Pair pair = (Pair) it.getValue(); |
| | | String tableSrc = (String) pair.first; |
| | | |
| | | logger.info("begin convert:[" + order + "]-" + tableSrc); |
| | | queryIgsetElement(jobContext, querySchema, tableSrc); |
| | | |
| | | order++; |
| | | |
| | | if (_testMode) |
| | | { |
| | | if ((_testCount < 0) || (order >= _testCount)) |
| | | break; |
| | | } |
| | | |
| | | if ((order % COMMITSIZE) == 0) |
| | | { |
| | | // OracleConnection connection = jobContext.getOracleConnection(); |
| | | // connection.commitTransaction(); |
| | | jobContext.commitTransaction(); |
| | | //jobContext.startTransaction(); |
| | | System.gc(); |
| | | System.runFinalization(); |
| | | } |
| | | |
| | | int now = order % step; |
| | | if (now != current) |
| | | { |
| | | current = now; |
| | | jobContext.getExecutionContext().put("ConvertDgn2PostGISJobProgress", current); |
| | | |
| | | } |
| | | } |
| | | jobContext.getExecutionContext().put("ConvertDgn2PostGISJobProgress", 100); |
| | | |
| | | jobContext.commitTransaction(); |
| | | |
| | | logger.info("end convert job:[" + order + "]"); |
| | | System.gc(); |
| | | System.runFinalization(); |
| | | } |
| | | |
| | | protected OrderedMap getBlobStorageList(Connection connection, String schemaSrc, String tableSrc, |
| | | OrderedMap orderedMap) throws SQLException |
| | | { |
| | | if (orderedMap == null) |
| | | orderedMap = new LinkedMap(99); |
| | | String fetchStmtFmt = "SELECT SNID, SPACETABLE FROM \"%s\".\"%s\""; |
| | | PrintfFormat spf = new PrintfFormat(fetchStmtFmt); |
| | | String fetchStmt = spf.sprintf(new Object[]{schemaSrc, tableSrc}); |
| | | Statement stmt = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
| | | ResultSet rs = null; |
| | | |
| | | stmt.setFetchSize(FETCHSIZE); |
| | | |
| | | try |
| | | { |
| | | rs = stmt.executeQuery(fetchStmt); |
| | | int size = rs.getMetaData().getColumnCount(); |
| | | while (rs.next()) |
| | | { |
| | | Object[] values = new Object[size]; |
| | | |
| | | for (int i = 0; i < size; i++) |
| | | { |
| | | values[i] = rs.getObject(i + 1); |
| | | } |
| | | |
| | | Integer key = ((BigDecimal) values[0]).intValue(); |
| | | String name = (String) values[1]; |
| | | |
| | | Pair pair = (Pair) orderedMap.get(key); |
| | | if (pair == null) |
| | | orderedMap.put(key, new Pair(name, null)); |
| | | else |
| | | pair.first = name; |
| | | } |
| | | } catch (SQLException e) |
| | | { |
| | | logger.error(e.toString(), e); |
| | | logger.error("stmt=" + fetchStmt); |
| | | throw e; |
| | | } finally |
| | | { |
| | | if (rs != null) rs.close(); |
| | | stmt.close(); |
| | | } |
| | | |
| | | return orderedMap; |
| | | } |
| | | |
| | | protected OrderedMap getRawFormatStorageList(OracleConnection connection, String schemaSrc, String tableSrc, |
| | | OrderedMap orderedMap) throws SQLException |
| | | { |
| | | if (orderedMap == null) |
| | | orderedMap = new LinkedMap(99); |
| | | String fetchStmtFmt = "SELECT RNID, SPACETABLE FROM \"%s\".\"%s\""; |
| | | PrintfFormat spf = new PrintfFormat(fetchStmtFmt); |
| | | String fetchStmt = spf.sprintf(new Object[]{schemaSrc, tableSrc}); |
| | | Statement stmt = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
| | | |
| | | stmt.setFetchSize(FETCHSIZE); |
| | | |
| | | ResultSet rs = stmt.executeQuery(fetchStmt); |
| | | int size = rs.getMetaData().getColumnCount(); |
| | | while (rs.next()) |
| | | { |
| | | Object[] values = new Object[size]; |
| | | |
| | | for (int i = 0; i < size; i++) |
| | | { |
| | | values[i] = rs.getObject(i + 1); |
| | | } |
| | | |
| | | Integer key = ((BigDecimal) values[0]).intValue(); |
| | | String name = (String) values[1]; |
| | | |
| | | Pair pair = (Pair) orderedMap.get(key); |
| | | if (pair == null) |
| | | orderedMap.put(key, new Pair(null, name)); |
| | | else |
| | | pair.second = name; |
| | | } |
| | | |
| | | rs.close(); |
| | | stmt.close(); |
| | | |
| | | return orderedMap; |
| | | } |
| | | |
| | | protected void queryIgsetElement(OracleConvertMySQLJobContext jobContext, |
| | | String srcschema, String srctable) throws SQLException |
| | | { |
| | | Connection connection = jobContext.getOracleConnection(); |
| | | String fetchSrcStmtFmt = "SELECT IGDSELM FROM \"%s\".\"%s\" ORDER BY ROWID"; |
| | | PrintfFormat spf = new PrintfFormat(fetchSrcStmtFmt); |
| | | String fetchSrcStmt = spf.sprintf(new Object[]{srcschema, srctable}); |
| | | Statement stmtSrc = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
| | | |
| | | stmtSrc.setFetchSize(FETCHSIZE); |
| | | |
| | | ResultSet rsSrc = stmtSrc.executeQuery(fetchSrcStmt); |
| | | int igdsMetaType = rsSrc.getMetaData().getColumnType(1); |
| | | while (rsSrc.next()) |
| | | { |
| | | byte[] raw; |
| | | |
| | | if (igdsMetaType == Types.BLOB) |
| | | { |
| | | BLOB blob = (BLOB) rsSrc.getBlob(1); |
| | | |
| | | raw = getBytesFromBLOB(blob); |
| | | blob.close(); |
| | | } else |
| | | { |
| | | raw = rsSrc.getBytes(1); |
| | | } |
| | | |
| | | try |
| | | { |
| | | Element element = fetchBinaryElement(raw); |
| | | jobContext.putFeatureCollection(element); |
| | | } catch (Dgn7fileException e) |
| | | { |
| | | logger.warn("Dgn7Exception", e); |
| | | } |
| | | } |
| | | |
| | | rsSrc.close(); |
| | | stmtSrc.close(); |
| | | } |
| | | |
| | | protected void queryRawElement(OracleConvertMySQLJobContext jobContext, |
| | | String srcschema, String srctable) throws SQLException |
| | | { |
| | | Connection connection = jobContext.getOracleConnection(); |
| | | String fetchDestStmtFmt = "SELECT ELEMENT FROM \"%s\".\"%s\" ORDER BY ROWID"; |
| | | PrintfFormat spf = new PrintfFormat(fetchDestStmtFmt); |
| | | String fetchDestStmt = spf.sprintf(new Object[]{srcschema, srctable}); |
| | | Statement stmtDest = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
| | | |
| | | stmtDest.setFetchSize(FETCHSIZE); |
| | | |
| | | ResultSet rsDest = stmtDest.executeQuery(fetchDestStmt); |
| | | |
| | | while (rsDest.next()) |
| | | { |
| | | ARRAY rawsValue = ((OracleResultSet) rsDest).getARRAY(1); |
| | | long[] rawData = rawsValue.getLongArray(); |
| | | byte[] comparessedValue; |
| | | |
| | | /* |
| | | if (dataMode == TransferTask.DataMode.Normal) |
| | | { |
| | | comparessedValue = BinConverter.unmarshalByteArray(rawData, true); |
| | | } else |
| | | { |
| | | comparessedValue = BinConverter.unmarshalCompactByteArray(rawData); |
| | | } |
| | | */ |
| | | comparessedValue = BinConverter.unmarshalByteArray(rawData, true); |
| | | |
| | | byte[] rawDest = ByteArrayCompressor.decompressByteArray(comparessedValue); |
| | | |
| | | |
| | | try |
| | | { |
| | | Element element = fetchBinaryElement(rawDest); |
| | | jobContext.putFeatureCollection(element); |
| | | } catch (Dgn7fileException e) |
| | | { |
| | | logger.warn("Dgn7Exception:" + e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | rsDest.close(); |
| | | stmtDest.close(); |
| | | } |
| | | |
| | | // Binary to Element |
| | | private Element fetchBinaryElement(byte[] raws) throws Dgn7fileException |
| | | { |
| | | ByteBuffer buffer = ByteBuffer.wrap(raws); |
| | | buffer.order(ByteOrder.LITTLE_ENDIAN); |
| | | short signature = buffer.getShort(); |
| | | |
| | | // byte type = (byte) (buffer.get() & 0x7f); |
| | | byte type = (byte) ((signature >>> 8) & 0x007f); |
| | | |
| | | // silly Bentley say contentLength is in 2-byte words |
| | | // and ByteByffer uses raws. |
| | | // track the record location |
| | | int elementLength = (buffer.getShort() * 2) + 4; |
| | | ElementType recordType = ElementType.forID(type); |
| | | IElementHandler handler; |
| | | |
| | | handler = recordType.getElementHandler(); |
| | | |
| | | Element dgnElement = (Element) handler.read(buffer, signature, elementLength); |
| | | if (recordType.isComplexElement() && (elementLength < raws.length)) |
| | | { |
| | | int offset = elementLength; |
| | | while (offset < (raws.length - 4)) |
| | | { |
| | | buffer.position(offset); |
| | | signature = buffer.getShort(); |
| | | type = (byte) ((signature >>> 8) & 0x007f); |
| | | elementLength = (buffer.getShort() * 2) + 4; |
| | | if (raws.length < (offset + elementLength)) |
| | | { |
| | | System.out.println("Length not match:" + offset + ":" + buffer.position() + ":" + buffer.limit()); |
| | | break; |
| | | } |
| | | recordType = ElementType.forID(type); |
| | | handler = recordType.getElementHandler(); |
| | | if (handler != null) |
| | | { |
| | | Element subElement = (Element) handler.read(buffer, signature, elementLength); |
| | | ((ComplexElement) dgnElement).add(subElement); |
| | | offset += elementLength; |
| | | } else |
| | | { |
| | | byte[] remain = new byte[buffer.remaining()]; |
| | | System.arraycopy(raws, offset, remain, 0, buffer.remaining()); |
| | | for (int i = 0; i < remain.length; i++) |
| | | { |
| | | if (remain[i] != 0) |
| | | { |
| | | logger.info("fetch element has some error. index=" + (offset + i) + ":value=" + remain[i]); |
| | | System.out.println("fetch element has some error. index=" + (offset + i) + ":value=" + remain[i]); |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return dgnElement; |
| | | } |
| | | |
| | | /** |
| | | * °õ¦æÂà´«¯Á¤Þ¹ÏÀɪº¤u§@ |
| | | * |
| | | * @param context ¤u§@°õ¦æÀô¹Ò |
| | | * @throws org.quartz.JobExecutionException |
| | | * exception |
| | | */ |
| | | private void convertIndexDesignFile(JobExecutionContext context) throws JobExecutionException |
| | | { |
| | | File indexDir = new File(getDataPath(), "index"); |
| | | if (!indexDir.exists()) |
| | | { |
| | | logger.info("index dir=" + indexDir + " not exist."); |
| | | return; |
| | | } |
| | | |
| | | if (!indexDir.isDirectory()) |
| | | { |
| | | logger.info("index dir=" + indexDir + " is not a directory."); |
| | | } |
| | | |
| | | File[] dgnFiles = indexDir.listFiles(new FilenameFilter() |
| | | { |
| | | public boolean accept(File dir, String name) |
| | | { |
| | | return name.toLowerCase().endsWith(".dgn"); |
| | | } |
| | | }); |
| | | |
| | | for (File dgnFile : dgnFiles) |
| | | { |
| | | IndexDgnConvertMySQLJobContext convertContext = |
| | | new IndexDgnConvertMySQLJobContext(getDataPath(), getTargetDataStore()); |
| | | logger.debug("--- start dgnfile-" + dgnFile.toString() + " ---"); |
| | | try |
| | | { |
| | | convertContext.setExecutionContext(context); |
| | | String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.separator); |
| | | convertContext.setFilename(dgnPaths[dgnPaths.length - 1]); |
| | | convertContext.startTransaction(); |
| | | |
| | | FileInputStream fs = new FileInputStream(dgnFile); |
| | | FileChannel fc = fs.getChannel(); |
| | | Dgn7fileReader reader = new Dgn7fileReader(fc, new Lock()); |
| | | convertContext.setReader(reader); |
| | | |
| | | scanIndexDgnElement(convertContext); |
| | | |
| | | convertContext.commitTransaction(); |
| | | convertContext.closeFeatureWriter(); |
| | | System.gc(); |
| | | System.runFinalization(); |
| | | } 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); |
| | | } |
| | | } |
| | | } |
| | | |
| | | protected void scanIndexDgnElement(IndexDgnConvertMySQLJobContext 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())) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processIndexElement(lastComplex, convertContext); |
| | | lastComplex = null; |
| | | } |
| | | |
| | | processIndexElement(element, convertContext); |
| | | } else if (element.isComponentElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | ((ComplexElement) lastComplex).add(element); |
| | | } |
| | | } else if (type.isComplexElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processIndexElement(lastComplex, convertContext); |
| | | } |
| | | lastComplex = element; |
| | | } |
| | | } |
| | | count++; |
| | | } |
| | | |
| | | if (lastComplex != null) |
| | | { |
| | | processIndexElement(lastComplex, convertContext); |
| | | } |
| | | logger.debug("ElementRecord Count=" + count); |
| | | } |
| | | |
| | | private void processIndexElement(Element element, IndexDgnConvertMySQLJobContext convertContext) |
| | | throws IllegalAttributeException, SchemaException |
| | | { |
| | | if (element instanceof TextElement) |
| | | { |
| | | convertContext.putFeatureCollection(element); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * °õ¦æÂà´«¨ä¥L³]p¹ÏÀɪº¤u§@ |
| | | * |
| | | * @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("other dir=" + otherDir + " not exist."); |
| | | return; |
| | | } |
| | | |
| | | if (!otherDir.isDirectory()) |
| | | { |
| | | logger.info("other dir=" + otherDir + " is not a directory."); |
| | | } |
| | | |
| | | File[] dgnFiles = otherDir.listFiles(new FilenameFilter() |
| | | { |
| | | public boolean accept(File dir, String name) |
| | | { |
| | | return name.toLowerCase().endsWith(".dgn"); |
| | | } |
| | | }); |
| | | |
| | | for (File dgnFile : dgnFiles) |
| | | { |
| | | GeneralDgnConvertMySQLJobContext convertContext = |
| | | new GeneralDgnConvertMySQLJobContext(getDataPath(), getTargetDataStore()); |
| | | logger.info("--- start dgnfile-" + dgnFile.toString() + " ---"); |
| | | try |
| | | { |
| | | convertContext.setExecutionContext(context); |
| | | String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.separator); |
| | | convertContext.setFilename(dgnPaths[dgnPaths.length - 1]); |
| | | convertContext.startTransaction(); |
| | | |
| | | FileInputStream fs = new FileInputStream(dgnFile); |
| | | FileChannel fc = fs.getChannel(); |
| | | Dgn7fileReader reader = new Dgn7fileReader(fc, new Lock()); |
| | | convertContext.setReader(reader); |
| | | |
| | | scanOtherDgnElement(convertContext); |
| | | |
| | | convertContext.commitTransaction(); |
| | | convertContext.closeFeatureWriter(); |
| | | System.gc(); |
| | | System.runFinalization(); |
| | | } 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 scanOtherDgnElement(GeneralDgnConvertMySQLJobContext 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())) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processOtherElement(lastComplex, convertContext); |
| | | lastComplex = null; |
| | | } |
| | | |
| | | processOtherElement(element, convertContext); |
| | | } else if (element.isComponentElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | ((ComplexElement) lastComplex).add(element); |
| | | } |
| | | } else if (type.isComplexElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processOtherElement(lastComplex, convertContext); |
| | | } |
| | | lastComplex = element; |
| | | } |
| | | } |
| | | count++; |
| | | } |
| | | |
| | | if (lastComplex != null) |
| | | { |
| | | processOtherElement(lastComplex, convertContext); |
| | | } |
| | | logger.debug("ElementRecord Count=" + count); |
| | | } |
| | | |
| | | private void processOtherElement(Element element, GeneralDgnConvertMySQLJobContext convertContext) |
| | | throws IllegalAttributeException, SchemaException |
| | | { |
| | | convertContext.putFeatureCollection(element); |
| | | } |
| | | |
| | | private void clearOutputDatabase() |
| | | { |
| | | /* |
| | | File outDataPath = new File(getDataPath(), OracleConvertPostGISJobContext.SHPOUTPATH); |
| | | if (outDataPath.exists() && outDataPath.isDirectory()) |
| | | { |
| | | deleteFilesInPath(outDataPath); |
| | | } |
| | | outDataPath = new File(getDataPath(), IndexDgnConvertShpJobContext.SHPOUTPATH); |
| | | if (outDataPath.exists() && outDataPath.isDirectory()) |
| | | { |
| | | deleteFilesInPath(outDataPath); |
| | | } |
| | | outDataPath = new File(getDataPath(), GeneralDgnConvertShpJobContext.SHPOUTPATH); |
| | | if (outDataPath.exists() && outDataPath.isDirectory()) |
| | | { |
| | | deleteFilesInPath(outDataPath); |
| | | } |
| | | */ |
| | | } |
| | | |
| | | private void deleteFilesInPath(File outDataPath) |
| | | { |
| | | deleteFilesInPath(outDataPath, true); |
| | | } |
| | | |
| | | private void deleteFilesInPath(File outDataPath, boolean removeSubDir) |
| | | { |
| | | if (!outDataPath.isDirectory()) |
| | | { |
| | | return; |
| | | } |
| | | File[] files = outDataPath.listFiles(); |
| | | for (File file : files) |
| | | { |
| | | if (file.isFile()) |
| | | { |
| | | if (!file.delete()) |
| | | { |
| | | logger.info("Cannot delete file-" + file.toString()); |
| | | } |
| | | } else if (file.isDirectory()) |
| | | { |
| | | deleteFilesInPath(file, removeSubDir); |
| | | if (removeSubDir) |
| | | { |
| | | if (file.delete()) |
| | | { |
| | | logger.info("Cannot delete dir-" + file.toString()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | 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) |
| | | { |
| | | FeatureDgnConvertMySQLJobContext convertContext = |
| | | new FeatureDgnConvertMySQLJobContext(getDataPath(), getTargetDataStore(), _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]); |
| | | convertContext.startTransaction(); |
| | | |
| | | 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(); |
| | | System.runFinalization(); |
| | | } 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(FeatureDgnConvertMySQLJobContext 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())) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processFeatureElement(lastComplex, convertContext); |
| | | lastComplex = null; |
| | | } |
| | | |
| | | processFeatureElement(element, convertContext); |
| | | } else if (element.isComponentElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | ((ComplexElement) lastComplex).add(element); |
| | | } |
| | | } else if (type.isComplexElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processFeatureElement(lastComplex, convertContext); |
| | | } |
| | | lastComplex = element; |
| | | } |
| | | } |
| | | count++; |
| | | } |
| | | |
| | | if (lastComplex != null) |
| | | { |
| | | processFeatureElement(lastComplex, convertContext); |
| | | } |
| | | logger.debug("ElementRecord Count=" + count); |
| | | } |
| | | |
| | | private void processFeatureElement(Element element, FeatureDgnConvertMySQLJobContext convertContext) |
| | | throws IllegalAttributeException, SchemaException |
| | | { |
| | | convertContext.putFeatureCollection(element); |
| | | } |
| | | |
| | | private void createDummyFeatureFile(JobExecutionContext context) throws JobExecutionException |
| | | { |
| | | /* |
| | | DummyFeatureConvertShpJobContext convertContext = new DummyFeatureConvertShpJobContext(getDataPath(), _filterPath); |
| | | try { |
| | | convertContext.startTransaction(); |
| | | convertContext.commitTransaction(); |
| | | convertContext.closeFeatureWriter(); |
| | | } catch (IOException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | throw new JobExecutionException(e.getMessage(), e); |
| | | } |
| | | */ |
| | | } |
| | | |
| | | public DataStore getTargetDataStore() |
| | | { |
| | | return targetDataStore; |
| | | } |
| | | |
| | | protected void createTargetDataStore() throws JobExecutionException |
| | | { |
| | | if (targetDataStore != null) |
| | | { |
| | | targetDataStore.dispose(); |
| | | targetDataStore = null; |
| | | } |
| | | |
| | | /* |
| | | if (!isDriverFound()) |
| | | { |
| | | throw new JobExecutionException("Oracle JDBC Driver not found.-" + JDBC_DRIVER); |
| | | } |
| | | */ |
| | | |
| | | if (!myProperties.containsKey("max connections" /*MySQLDataStoreFactory.MAXCONN.key */)) |
| | | { |
| | | myProperties.put("max connections", "2"); |
| | | } |
| | | |
| | | if (!myProperties.containsKey("min connections" /* MySQLDataStoreFactory.MINCONN.key */)) |
| | | { |
| | | myProperties.put("min connections", "1"); |
| | | } |
| | | |
| | | if (!myProperties.containsKey(MySQLDataStoreFactory.WKBENABLED.key)) |
| | | { |
| | | myProperties.put(MySQLDataStoreFactory.WKBENABLED.key, "true"); |
| | | } |
| | | |
| | | if (!dataStoreFactory.canProcess(myProperties)) |
| | | { |
| | | getLogger().warn("cannot process properties-"); |
| | | throw new JobExecutionException("cannot process properties-"); |
| | | } |
| | | try |
| | | { |
| | | targetDataStore = (MySQLDataStore) dataStoreFactory.createDataStore(myProperties); |
| | | } catch (IOException e) |
| | | { |
| | | getLogger().warn(e.getMessage(), e); |
| | | throw new JobExecutionException(e.getMessage(), e); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.jobs; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileNotFoundException; |
| | | import java.io.FilenameFilter; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.ByteOrder; |
| | | import java.nio.channels.FileChannel; |
| | | import java.sql.ResultSet; |
| | | import java.sql.SQLException; |
| | | import java.sql.Statement; |
| | | import java.sql.Types; |
| | | import java.sql.Connection; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | import java.util.TreeMap; |
| | | |
| | | import org.apache.commons.collections.OrderedMap; |
| | | import org.apache.commons.collections.OrderedMapIterator; |
| | | import org.apache.commons.collections.map.LinkedMap; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.geotools.data.DataStore; |
| | | import org.geotools.data.oracle.OracleDataStore; |
| | | import org.geotools.data.oracle.OracleDataStoreFactory; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | import org.quartz.JobDataMap; |
| | | import org.quartz.JobDetail; |
| | | import org.quartz.JobExecutionContext; |
| | | import org.quartz.JobExecutionException; |
| | | |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | import oracle.jdbc.OracleConnection; |
| | | import oracle.jdbc.OracleResultSet; |
| | | import oracle.sql.ARRAY; |
| | | import oracle.sql.BLOB; |
| | | |
| | | import com.ximple.eofms.jobs.context.AbstractOracleJobContext; |
| | | import com.ximple.eofms.jobs.context.orasdo.FeatureDgnConvertOraSDOJobContext; |
| | | import com.ximple.eofms.jobs.context.orasdo.GeneralDgnConvertOraSDOJobContext; |
| | | import com.ximple.eofms.jobs.context.orasdo.IndexDgnConvertOraSDOJobContext; |
| | | import com.ximple.eofms.jobs.context.orasdo.OracleConvertOraSDOJobContext; |
| | | import com.ximple.eofms.util.BinConverter; |
| | | import com.ximple.eofms.util.ByteArrayCompressor; |
| | | import com.ximple.eofms.util.StringUtils; |
| | | import com.ximple.io.dgn7.ComplexElement; |
| | | import com.ximple.io.dgn7.Dgn7fileException; |
| | | import com.ximple.io.dgn7.Dgn7fileReader; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.ElementType; |
| | | import com.ximple.io.dgn7.IElementHandler; |
| | | import com.ximple.io.dgn7.Lock; |
| | | import com.ximple.io.dgn7.TextElement; |
| | | import com.ximple.util.PrintfFormat; |
| | | |
| | | public class OracleConvertDgn2OraSDOJob extends AbstractOracleDatabaseJob |
| | | { |
| | | final static Log logger = LogFactory.getLog(OracleConvertDgn2OraSDOJob.class); |
| | | |
| | | private static final String SDOHOST = "SDOHOST"; |
| | | private static final String SDODDATBASE = "SDODDATBASE"; |
| | | private static final String SDOPORT = "SDOPORT"; |
| | | private static final String SDOSCHEMA = "SDOSCHEMA"; |
| | | private static final String SDOUSER = "SDOUSER"; |
| | | private static final String SDOPASS = "SDOPASS"; |
| | | private static final String USEWKB = "USEWKB"; |
| | | |
| | | private static final int FETCHSIZE = 30; |
| | | private static final int COMMITSIZE = 20; |
| | | |
| | | class Pair |
| | | { |
| | | Object first; |
| | | Object second; |
| | | |
| | | public Pair(Object first, Object second) |
| | | { |
| | | this.first = first; |
| | | this.second = second; |
| | | } |
| | | } |
| | | |
| | | protected static OracleDataStoreFactory dataStoreFactory = new OracleDataStoreFactory(); |
| | | |
| | | GeometryFactory _geomFactory = new GeometryFactory(); |
| | | protected String _sdoHost; |
| | | protected String _sdoDatabase; |
| | | protected String _sdoPort; |
| | | protected String _sdoSchema; |
| | | protected String _sdoUsername; |
| | | protected String _sdoPassword; |
| | | protected String _sdoUseWKB; |
| | | |
| | | protected Map<String, String> sdoProperties; |
| | | protected OracleDataStore targetDataStore; |
| | | |
| | | public Log getLogger() |
| | | { |
| | | return logger; |
| | | } |
| | | |
| | | protected AbstractOracleJobContext prepareJobContext(String targetSchemaName, String filterPath) |
| | | { |
| | | return new OracleConvertOraSDOJobContext(getDataPath(), getTargetDataStore(), filterPath); |
| | | } |
| | | |
| | | protected void extractJobConfiguration(JobDetail jobDetail) throws JobExecutionException |
| | | { |
| | | super.extractJobConfiguration(jobDetail); |
| | | JobDataMap dataMap = jobDetail.getJobDataMap(); |
| | | _sdoHost = dataMap.getString(SDOHOST); |
| | | _sdoDatabase = dataMap.getString(SDODDATBASE); |
| | | _sdoPort = dataMap.getString(SDOPORT); |
| | | _sdoSchema = dataMap.getString(SDOSCHEMA); |
| | | _sdoUsername = dataMap.getString(SDOUSER); |
| | | _sdoPassword = dataMap.getString(SDOPASS); |
| | | _sdoUseWKB = dataMap.getString(USEWKB); |
| | | |
| | | Log logger = getLogger(); |
| | | /* |
| | | logger.info("SDOHOST=" + _myHost); |
| | | logger.info("SDODDATBASE=" + _myDatabase); |
| | | logger.info("SDOPORT=" + _myPort); |
| | | logger.info("SDOSCHEMA=" + _mySchema); |
| | | logger.info("SDOUSER=" + _myUsername); |
| | | logger.info("SDOPASS=" + _myPassword); |
| | | logger.info("USEWKB=" + _myUseWKB); |
| | | */ |
| | | |
| | | if (_sdoHost == null) |
| | | { |
| | | logger.warn("SDOHOST is null"); |
| | | throw new JobExecutionException("Unknown OraSDO host."); |
| | | } |
| | | if (_sdoDatabase == null) |
| | | { |
| | | logger.warn("PGDATABASE is null"); |
| | | throw new JobExecutionException("Unknown OraSDO database."); |
| | | } |
| | | if (_sdoPort == null) |
| | | { |
| | | logger.warn("SDOPORT is null"); |
| | | throw new JobExecutionException("Unknown OraSDO port."); |
| | | } |
| | | if (_sdoSchema == null) |
| | | { |
| | | logger.warn("SDOSCHEMA is null"); |
| | | throw new JobExecutionException("Unknown OraSDO schema."); |
| | | } |
| | | if (_sdoUsername == null) |
| | | { |
| | | logger.warn("PGUSERNAME is null"); |
| | | throw new JobExecutionException("Unknown OraSDO username."); |
| | | } |
| | | if (_sdoPassword == null) |
| | | { |
| | | logger.warn("PGPASSWORD is null"); |
| | | throw new JobExecutionException("Unknown OraSDO password."); |
| | | } |
| | | |
| | | Map<String, String> remote = new TreeMap<String, String>(); |
| | | remote.put("dbtype", "OraSDO"); |
| | | remote.put("charset", "UTF-8"); |
| | | remote.put("host", _sdoHost); |
| | | remote.put("port", _sdoPort); |
| | | remote.put("database", _sdoDatabase); |
| | | remote.put("user", _sdoUsername); |
| | | remote.put("passwd", _sdoPassword); |
| | | remote.put("namespace", null); |
| | | sdoProperties = remote; |
| | | } |
| | | |
| | | public void execute(JobExecutionContext context) throws JobExecutionException |
| | | { |
| | | // Every job has its own job detail |
| | | JobDetail jobDetail = context.getJobDetail(); |
| | | |
| | | // The name is defined in the job definition |
| | | String jobName = jobDetail.getName(); |
| | | String targetSchemaName = null; |
| | | |
| | | // Log the time the job started |
| | | logger.info(jobName + " fired at " + new Date()); |
| | | extractJobConfiguration(jobDetail); |
| | | createSourceDataStore(); |
| | | createTargetDataStore(); |
| | | if (getSourceDataStore() == null) |
| | | { |
| | | logger.warn("Cannot connect source oracle database."); |
| | | throw new JobExecutionException("Cannot connect source oracle database."); |
| | | } |
| | | |
| | | if (getTargetDataStore() == null) |
| | | { |
| | | logger.warn("Cannot connect source postgreSQL database."); |
| | | throw new JobExecutionException("Cannot connect source postgreSQL database."); |
| | | } |
| | | |
| | | long t1 = System.currentTimeMillis(); |
| | | try |
| | | { |
| | | logger.info("-- step:clearOutputDatabase --"); |
| | | clearOutputDatabase(); |
| | | boolean bFirst = isCopyConnectivityMode(); |
| | | if (checkConvertDB()) |
| | | { |
| | | logger.info("-- step:convertOracleDB --"); |
| | | |
| | | for (String orgSchema : _orgSchema) |
| | | { |
| | | OracleConvertOraSDOJobContext jobContext = |
| | | (OracleConvertOraSDOJobContext) prepareJobContext(targetSchemaName, _filterPath); |
| | | jobContext.setSourceDataStore(getSourceDataStore()); |
| | | // jobContext.setConvertElementIn(_convertElementIn); |
| | | jobContext.setElementLogging(checkElementLogging()); |
| | | jobContext.setExecutionContext(context); |
| | | |
| | | if (bFirst) |
| | | copyConnectivity(jobContext); |
| | | else |
| | | bFirst = false; |
| | | |
| | | logger.info("----- start schema:" + orgSchema + " -----"); |
| | | exetcuteConvert(jobContext, orgSchema, _dataPath); |
| | | |
| | | //close all open filewriter instance |
| | | jobContext.closeFeatureWriter(); |
| | | } |
| | | } |
| | | |
| | | if (checkConvertFile()) |
| | | { |
| | | logger.info("-- step:convertIndexDesignFile --"); |
| | | convertIndexDesignFile(context); |
| | | logger.info("-- step:convertOtherDesignFile --"); |
| | | convertOtherDesignFile(context); |
| | | } |
| | | |
| | | if (checkConvertElementIn()) |
| | | { |
| | | logger.info("-- step:convertFeatureDesignFile --"); |
| | | convertFeatureDesignFile(context); |
| | | } |
| | | |
| | | if (checkCreateDummy()) |
| | | { |
| | | logger.info("-- step:createDummyFeatureFile --"); |
| | | createDummyFeatureFile(context); |
| | | } |
| | | |
| | | disconnect(); |
| | | long t2 = System.currentTimeMillis(); |
| | | // public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss"; |
| | | // SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW); |
| | | logger.warn("use time = " + ((t2 - t1) / 60000.0) + " min"); |
| | | } catch (SQLException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | throw new JobExecutionException("Database error. " + e.getMessage(), e); |
| | | } catch (IOException ex) |
| | | { |
| | | logger.warn(ex.getMessage(), ex); |
| | | throw new JobExecutionException("IO error. " + ex.getMessage(), ex); |
| | | } |
| | | logger.warn(jobName + " end at " + new Date()); |
| | | } |
| | | |
| | | /** |
| | | * Connectivity½Æ»s¤@Óª©¥»¡A¦b¬d¸ß¹q¬y¤è¦V®É¥Î¨Ó¤ñ¹ïOMS¸ê®Æ®wªº¹q¾¹³s±µ©Ê(Connectivity) |
| | | * |
| | | * @param jobContext job context |
| | | * @throws SQLException sql exception |
| | | */ |
| | | private void copyConnectivity(OracleConvertOraSDOJobContext jobContext) throws SQLException |
| | | { |
| | | Connection connection = jobContext.getOracleConnection(); |
| | | Statement stmt = connection.createStatement(); |
| | | stmt.execute(AbstractOracleJobContext.TRUNCATE_CONNECTIVITY_WEBCHECK); |
| | | stmt.execute(AbstractOracleJobContext.COPY_CONNECTIVITY_TO_WEBCHECK); |
| | | } |
| | | |
| | | private void exetcuteConvert(OracleConvertOraSDOJobContext jobContext, |
| | | String querySchema, String dataPath) throws SQLException |
| | | { |
| | | int order = 0; |
| | | OrderedMap map = getBlobStorageList(jobContext.getOracleConnection(), querySchema, "SD$SPACENODES" |
| | | , null); |
| | | |
| | | logger.info("begin convert job:[" + map.size() + "]:testmode=" + _testMode); |
| | | |
| | | int total = map.size(); //spacenodes count |
| | | int step = total / 100; |
| | | int current = 0; |
| | | |
| | | //jobContext.startTransaction(); |
| | | jobContext.setCurrentSchema(querySchema); |
| | | jobContext.getExecutionContext().put("ConvertDgn2OraSDOJobProgress", 0); |
| | | for (OrderedMapIterator it = map.orderedMapIterator(); it.hasNext();) |
| | | { |
| | | it.next(); |
| | | |
| | | Pair pair = (Pair) it.getValue(); |
| | | String tableSrc = (String) pair.first; |
| | | |
| | | logger.info("begin convert:[" + order + "]-" + tableSrc); |
| | | queryIgsetElement(jobContext, querySchema, tableSrc); |
| | | |
| | | order++; |
| | | |
| | | if (_testMode) |
| | | { |
| | | if ((_testCount < 0) || (order >= _testCount)) |
| | | break; |
| | | } |
| | | |
| | | if ((order % COMMITSIZE) == 0) |
| | | { |
| | | // OracleConnection connection = jobContext.getOracleConnection(); |
| | | // connection.commitTransaction(); |
| | | jobContext.commitTransaction(); |
| | | //jobContext.startTransaction(); |
| | | System.gc(); |
| | | System.runFinalization(); |
| | | } |
| | | |
| | | int now = order % step; |
| | | if (now != current) |
| | | { |
| | | current = now; |
| | | jobContext.getExecutionContext().put("ConvertDgn2OraSDOJobProgress", current); |
| | | |
| | | } |
| | | } |
| | | jobContext.getExecutionContext().put("ConvertDgn2OraSDOJobProgress", 100); |
| | | |
| | | jobContext.commitTransaction(); |
| | | |
| | | logger.info("end convert job:[" + order + "]"); |
| | | System.gc(); |
| | | System.runFinalization(); |
| | | } |
| | | |
| | | protected OrderedMap getBlobStorageList(Connection connection, String schemaSrc, String tableSrc, |
| | | OrderedMap orderedMap) throws SQLException |
| | | { |
| | | if (orderedMap == null) |
| | | orderedMap = new LinkedMap(99); |
| | | String fetchStmtFmt = "SELECT SNID, SPACETABLE FROM \"%s\".\"%s\""; |
| | | PrintfFormat spf = new PrintfFormat(fetchStmtFmt); |
| | | String fetchStmt = spf.sprintf(new Object[]{schemaSrc, tableSrc}); |
| | | Statement stmt = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
| | | ResultSet rs = null; |
| | | |
| | | stmt.setFetchSize(FETCHSIZE); |
| | | |
| | | try |
| | | { |
| | | rs = stmt.executeQuery(fetchStmt); |
| | | int size = rs.getMetaData().getColumnCount(); |
| | | while (rs.next()) |
| | | { |
| | | Object[] values = new Object[size]; |
| | | |
| | | for (int i = 0; i < size; i++) |
| | | { |
| | | values[i] = rs.getObject(i + 1); |
| | | } |
| | | |
| | | Integer key = ((BigDecimal) values[0]).intValue(); |
| | | String name = (String) values[1]; |
| | | |
| | | Pair pair = (Pair) orderedMap.get(key); |
| | | if (pair == null) |
| | | orderedMap.put(key, new Pair(name, null)); |
| | | else |
| | | pair.first = name; |
| | | } |
| | | } catch (SQLException e) |
| | | { |
| | | logger.error(e.toString(), e); |
| | | logger.error("stmt=" + fetchStmt); |
| | | throw e; |
| | | } finally |
| | | { |
| | | if (rs != null) rs.close(); |
| | | stmt.close(); |
| | | } |
| | | |
| | | return orderedMap; |
| | | } |
| | | |
| | | protected OrderedMap getRawFormatStorageList(OracleConnection connection, String schemaSrc, String tableSrc, |
| | | OrderedMap orderedMap) throws SQLException |
| | | { |
| | | if (orderedMap == null) |
| | | orderedMap = new LinkedMap(99); |
| | | String fetchStmtFmt = "SELECT RNID, SPACETABLE FROM \"%s\".\"%s\""; |
| | | PrintfFormat spf = new PrintfFormat(fetchStmtFmt); |
| | | String fetchStmt = spf.sprintf(new Object[]{schemaSrc, tableSrc}); |
| | | Statement stmt = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
| | | |
| | | stmt.setFetchSize(FETCHSIZE); |
| | | |
| | | ResultSet rs = stmt.executeQuery(fetchStmt); |
| | | int size = rs.getMetaData().getColumnCount(); |
| | | while (rs.next()) |
| | | { |
| | | Object[] values = new Object[size]; |
| | | |
| | | for (int i = 0; i < size; i++) |
| | | { |
| | | values[i] = rs.getObject(i + 1); |
| | | } |
| | | |
| | | Integer key = ((BigDecimal) values[0]).intValue(); |
| | | String name = (String) values[1]; |
| | | |
| | | Pair pair = (Pair) orderedMap.get(key); |
| | | if (pair == null) |
| | | orderedMap.put(key, new Pair(null, name)); |
| | | else |
| | | pair.second = name; |
| | | } |
| | | |
| | | rs.close(); |
| | | stmt.close(); |
| | | |
| | | return orderedMap; |
| | | } |
| | | |
| | | protected void queryIgsetElement(OracleConvertOraSDOJobContext jobContext, |
| | | String srcschema, String srctable) throws SQLException |
| | | { |
| | | Connection connection = jobContext.getOracleConnection(); |
| | | String fetchSrcStmtFmt = "SELECT IGDSELM FROM \"%s\".\"%s\" ORDER BY ROWID"; |
| | | PrintfFormat spf = new PrintfFormat(fetchSrcStmtFmt); |
| | | String fetchSrcStmt = spf.sprintf(new Object[]{srcschema, srctable}); |
| | | Statement stmtSrc = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
| | | |
| | | stmtSrc.setFetchSize(FETCHSIZE); |
| | | |
| | | ResultSet rsSrc = stmtSrc.executeQuery(fetchSrcStmt); |
| | | int igdsMetaType = rsSrc.getMetaData().getColumnType(1); |
| | | while (rsSrc.next()) |
| | | { |
| | | byte[] raw; |
| | | if (igdsMetaType == Types.BLOB) |
| | | { |
| | | BLOB blob = (BLOB) rsSrc.getBlob(1); |
| | | |
| | | raw = getBytesFromBLOB(blob); |
| | | blob.close(); |
| | | } else |
| | | { |
| | | raw = rsSrc.getBytes(1); |
| | | } |
| | | |
| | | try |
| | | { |
| | | Element element = fetchBinaryElement(raw); |
| | | jobContext.putFeatureCollection(element); |
| | | } catch (Dgn7fileException e) |
| | | { |
| | | logger.warn("Dgn7Exception", e); |
| | | } |
| | | } |
| | | |
| | | rsSrc.close(); |
| | | stmtSrc.close(); |
| | | } |
| | | |
| | | protected void queryRawElement(OracleConvertOraSDOJobContext jobContext, |
| | | String srcschema, String srctable) throws SQLException |
| | | { |
| | | Connection connection = jobContext.getOracleConnection(); |
| | | String fetchDestStmtFmt = "SELECT ELEMENT FROM \"%s\".\"%s\" ORDER BY ROWID"; |
| | | PrintfFormat spf = new PrintfFormat(fetchDestStmtFmt); |
| | | String fetchDestStmt = spf.sprintf(new Object[]{srcschema, srctable}); |
| | | Statement stmtDest = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
| | | |
| | | stmtDest.setFetchSize(FETCHSIZE); |
| | | |
| | | ResultSet rsDest = stmtDest.executeQuery(fetchDestStmt); |
| | | |
| | | while (rsDest.next()) |
| | | { |
| | | ARRAY rawsValue = ((OracleResultSet) rsDest).getARRAY(1); |
| | | long[] rawData = rawsValue.getLongArray(); |
| | | byte[] comparessedValue; |
| | | |
| | | /* |
| | | if (dataMode == TransferTask.DataMode.Normal) |
| | | { |
| | | comparessedValue = BinConverter.unmarshalByteArray(rawData, true); |
| | | } else |
| | | { |
| | | comparessedValue = BinConverter.unmarshalCompactByteArray(rawData); |
| | | } |
| | | */ |
| | | comparessedValue = BinConverter.unmarshalByteArray(rawData, true); |
| | | |
| | | byte[] rawDest = ByteArrayCompressor.decompressByteArray(comparessedValue); |
| | | |
| | | |
| | | try |
| | | { |
| | | Element element = fetchBinaryElement(rawDest); |
| | | jobContext.putFeatureCollection(element); |
| | | } catch (Dgn7fileException e) |
| | | { |
| | | logger.warn("Dgn7Exception:" + e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | rsDest.close(); |
| | | stmtDest.close(); |
| | | } |
| | | |
| | | // Binary to Element |
| | | private Element fetchBinaryElement(byte[] raws) throws Dgn7fileException |
| | | { |
| | | ByteBuffer buffer = ByteBuffer.wrap(raws); |
| | | buffer.order(ByteOrder.LITTLE_ENDIAN); |
| | | short signature = buffer.getShort(); |
| | | |
| | | // byte type = (byte) (buffer.get() & 0x7f); |
| | | byte type = (byte) ((signature >>> 8) & 0x007f); |
| | | |
| | | // silly Bentley say contentLength is in 2-byte words |
| | | // and ByteByffer uses raws. |
| | | // track the record location |
| | | int elementLength = (buffer.getShort() * 2) + 4; |
| | | ElementType recordType = ElementType.forID(type); |
| | | IElementHandler handler; |
| | | |
| | | handler = recordType.getElementHandler(); |
| | | |
| | | Element dgnElement = (Element) handler.read(buffer, signature, elementLength); |
| | | if (recordType.isComplexElement() && (elementLength < raws.length)) |
| | | { |
| | | int offset = elementLength; |
| | | while (offset < (raws.length - 4)) |
| | | { |
| | | buffer.position(offset); |
| | | signature = buffer.getShort(); |
| | | type = (byte) ((signature >>> 8) & 0x007f); |
| | | elementLength = (buffer.getShort() * 2) + 4; |
| | | if (raws.length < (offset + elementLength)) |
| | | { |
| | | System.out.println("Length not match:" + offset + ":" + buffer.position() + ":" + buffer.limit()); |
| | | break; |
| | | } |
| | | recordType = ElementType.forID(type); |
| | | handler = recordType.getElementHandler(); |
| | | if (handler != null) |
| | | { |
| | | Element subElement = (Element) handler.read(buffer, signature, elementLength); |
| | | ((ComplexElement) dgnElement).add(subElement); |
| | | offset += elementLength; |
| | | } else |
| | | { |
| | | byte[] remain = new byte[buffer.remaining()]; |
| | | System.arraycopy(raws, offset, remain, 0, buffer.remaining()); |
| | | for (int i = 0; i < remain.length; i++) |
| | | { |
| | | if (remain[i] != 0) |
| | | { |
| | | logger.info("fetch element has some error. index=" + (offset + i) + ":value=" + remain[i]); |
| | | System.out.println("fetch element has some error. index=" + (offset + i) + ":value=" + remain[i]); |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return dgnElement; |
| | | } |
| | | |
| | | /** |
| | | * °õ¦æÂà´«¯Á¤Þ¹ÏÀɪº¤u§@ |
| | | * |
| | | * @param context ¤u§@°õ¦æÀô¹Ò |
| | | * @throws org.quartz.JobExecutionException |
| | | * exception |
| | | */ |
| | | private void convertIndexDesignFile(JobExecutionContext context) throws JobExecutionException |
| | | { |
| | | File indexDir = new File(getDataPath(), "index"); |
| | | if (!indexDir.exists()) |
| | | { |
| | | logger.info("index dir=" + indexDir + " not exist."); |
| | | return; |
| | | } |
| | | |
| | | if (!indexDir.isDirectory()) |
| | | { |
| | | logger.info("index dir=" + indexDir + " is not a directory."); |
| | | } |
| | | |
| | | File[] dgnFiles = indexDir.listFiles(new FilenameFilter() |
| | | { |
| | | public boolean accept(File dir, String name) |
| | | { |
| | | return name.toLowerCase().endsWith(".dgn"); |
| | | } |
| | | }); |
| | | |
| | | for (File dgnFile : dgnFiles) |
| | | { |
| | | IndexDgnConvertOraSDOJobContext convertContext = |
| | | new IndexDgnConvertOraSDOJobContext(getDataPath(), getTargetDataStore()); |
| | | logger.debug("--- start dgnfile-" + dgnFile.toString() + " ---"); |
| | | try |
| | | { |
| | | convertContext.setExecutionContext(context); |
| | | String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.separator); |
| | | convertContext.setFilename(dgnPaths[dgnPaths.length - 1]); |
| | | convertContext.startTransaction(); |
| | | |
| | | FileInputStream fs = new FileInputStream(dgnFile); |
| | | FileChannel fc = fs.getChannel(); |
| | | Dgn7fileReader reader = new Dgn7fileReader(fc, new Lock()); |
| | | convertContext.setReader(reader); |
| | | |
| | | scanIndexDgnElement(convertContext); |
| | | |
| | | convertContext.commitTransaction(); |
| | | convertContext.closeFeatureWriter(); |
| | | System.gc(); |
| | | System.runFinalization(); |
| | | } 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); |
| | | } |
| | | } |
| | | } |
| | | |
| | | protected void scanIndexDgnElement(IndexDgnConvertOraSDOJobContext 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())) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processIndexElement(lastComplex, convertContext); |
| | | lastComplex = null; |
| | | } |
| | | |
| | | processIndexElement(element, convertContext); |
| | | } else if (element.isComponentElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | ((ComplexElement) lastComplex).add(element); |
| | | } |
| | | } else if (type.isComplexElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processIndexElement(lastComplex, convertContext); |
| | | } |
| | | lastComplex = element; |
| | | } |
| | | } |
| | | count++; |
| | | } |
| | | |
| | | if (lastComplex != null) |
| | | { |
| | | processIndexElement(lastComplex, convertContext); |
| | | } |
| | | logger.debug("ElementRecord Count=" + count); |
| | | } |
| | | |
| | | private void processIndexElement(Element element, IndexDgnConvertOraSDOJobContext convertContext) |
| | | throws IllegalAttributeException, SchemaException |
| | | { |
| | | if (element instanceof TextElement) |
| | | { |
| | | convertContext.putFeatureCollection(element); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * °õ¦æÂà´«¨ä¥L³]p¹ÏÀɪº¤u§@ |
| | | * |
| | | * @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("other dir=" + otherDir + " not exist."); |
| | | return; |
| | | } |
| | | |
| | | if (!otherDir.isDirectory()) |
| | | { |
| | | logger.info("other dir=" + otherDir + " is not a directory."); |
| | | } |
| | | |
| | | File[] dgnFiles = otherDir.listFiles(new FilenameFilter() |
| | | { |
| | | public boolean accept(File dir, String name) |
| | | { |
| | | return name.toLowerCase().endsWith(".dgn"); |
| | | } |
| | | }); |
| | | |
| | | for (File dgnFile : dgnFiles) |
| | | { |
| | | GeneralDgnConvertOraSDOJobContext convertContext = |
| | | new GeneralDgnConvertOraSDOJobContext(getDataPath(), getTargetDataStore()); |
| | | logger.info("--- start dgnfile-" + dgnFile.toString() + " ---"); |
| | | try |
| | | { |
| | | convertContext.setExecutionContext(context); |
| | | String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.separator); |
| | | convertContext.setFilename(dgnPaths[dgnPaths.length - 1]); |
| | | convertContext.startTransaction(); |
| | | |
| | | FileInputStream fs = new FileInputStream(dgnFile); |
| | | FileChannel fc = fs.getChannel(); |
| | | Dgn7fileReader reader = new Dgn7fileReader(fc, new Lock()); |
| | | convertContext.setReader(reader); |
| | | |
| | | scanOtherDgnElement(convertContext); |
| | | |
| | | convertContext.commitTransaction(); |
| | | convertContext.closeFeatureWriter(); |
| | | System.gc(); |
| | | System.runFinalization(); |
| | | } 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 scanOtherDgnElement(GeneralDgnConvertOraSDOJobContext 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())) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processOtherElement(lastComplex, convertContext); |
| | | lastComplex = null; |
| | | } |
| | | |
| | | processOtherElement(element, convertContext); |
| | | } else if (element.isComponentElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | ((ComplexElement) lastComplex).add(element); |
| | | } |
| | | } else if (type.isComplexElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processOtherElement(lastComplex, convertContext); |
| | | } |
| | | lastComplex = element; |
| | | } |
| | | } |
| | | count++; |
| | | } |
| | | |
| | | if (lastComplex != null) |
| | | { |
| | | processOtherElement(lastComplex, convertContext); |
| | | } |
| | | logger.debug("ElementRecord Count=" + count); |
| | | } |
| | | |
| | | private void processOtherElement(Element element, GeneralDgnConvertOraSDOJobContext convertContext) |
| | | throws IllegalAttributeException, SchemaException |
| | | { |
| | | convertContext.putFeatureCollection(element); |
| | | } |
| | | |
| | | private void clearOutputDatabase() |
| | | { |
| | | /* |
| | | File outDataPath = new File(getDataPath(), OracleConvertOraSDOJobContext.SHPOUTPATH); |
| | | if (outDataPath.exists() && outDataPath.isDirectory()) |
| | | { |
| | | deleteFilesInPath(outDataPath); |
| | | } |
| | | outDataPath = new File(getDataPath(), IndexDgnConvertShpJobContext.SHPOUTPATH); |
| | | if (outDataPath.exists() && outDataPath.isDirectory()) |
| | | { |
| | | deleteFilesInPath(outDataPath); |
| | | } |
| | | outDataPath = new File(getDataPath(), GeneralDgnConvertShpJobContext.SHPOUTPATH); |
| | | if (outDataPath.exists() && outDataPath.isDirectory()) |
| | | { |
| | | deleteFilesInPath(outDataPath); |
| | | } |
| | | */ |
| | | } |
| | | |
| | | private void deleteFilesInPath(File outDataPath) |
| | | { |
| | | deleteFilesInPath(outDataPath, true); |
| | | } |
| | | |
| | | private void deleteFilesInPath(File outDataPath, boolean removeSubDir) |
| | | { |
| | | if (!outDataPath.isDirectory()) |
| | | { |
| | | return; |
| | | } |
| | | File[] files = outDataPath.listFiles(); |
| | | for (File file : files) |
| | | { |
| | | if (file.isFile()) |
| | | { |
| | | if (!file.delete()) |
| | | { |
| | | logger.info("Cannot delete file-" + file.toString()); |
| | | } |
| | | } else if (file.isDirectory()) |
| | | { |
| | | deleteFilesInPath(file, removeSubDir); |
| | | if (removeSubDir) |
| | | { |
| | | if (file.delete()) |
| | | { |
| | | logger.info("Cannot delete dir-" + file.toString()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | 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) |
| | | { |
| | | FeatureDgnConvertOraSDOJobContext convertContext = |
| | | new FeatureDgnConvertOraSDOJobContext(getDataPath(), getTargetDataStore(), _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]); |
| | | convertContext.startTransaction(); |
| | | |
| | | 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(); |
| | | System.runFinalization(); |
| | | } 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(FeatureDgnConvertOraSDOJobContext 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())) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processFeatureElement(lastComplex, convertContext); |
| | | lastComplex = null; |
| | | } |
| | | |
| | | processFeatureElement(element, convertContext); |
| | | } else if (element.isComponentElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | ((ComplexElement) lastComplex).add(element); |
| | | } |
| | | } else if (type.isComplexElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processFeatureElement(lastComplex, convertContext); |
| | | } |
| | | lastComplex = element; |
| | | } |
| | | } |
| | | count++; |
| | | } |
| | | |
| | | if (lastComplex != null) |
| | | { |
| | | processFeatureElement(lastComplex, convertContext); |
| | | } |
| | | logger.debug("ElementRecord Count=" + count); |
| | | } |
| | | |
| | | private void processFeatureElement(Element element, FeatureDgnConvertOraSDOJobContext convertContext) |
| | | throws IllegalAttributeException, SchemaException |
| | | { |
| | | convertContext.putFeatureCollection(element); |
| | | } |
| | | |
| | | private void createDummyFeatureFile(JobExecutionContext context) throws JobExecutionException |
| | | { |
| | | /* |
| | | DummyFeatureConvertShpJobContext convertContext = new DummyFeatureConvertShpJobContext(getDataPath(), _filterPath); |
| | | try { |
| | | convertContext.startTransaction(); |
| | | convertContext.commitTransaction(); |
| | | convertContext.closeFeatureWriter(); |
| | | } catch (IOException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | throw new JobExecutionException(e.getMessage(), e); |
| | | } |
| | | */ |
| | | } |
| | | |
| | | public DataStore getTargetDataStore() |
| | | { |
| | | return targetDataStore; |
| | | } |
| | | |
| | | protected void createTargetDataStore() throws JobExecutionException |
| | | { |
| | | if (targetDataStore != null) |
| | | { |
| | | targetDataStore.dispose(); |
| | | targetDataStore = null; |
| | | } |
| | | |
| | | /* |
| | | if (!isDriverFound()) |
| | | { |
| | | throw new JobExecutionException("Oracle JDBC Driver not found.-" + JDBC_DRIVER); |
| | | } |
| | | */ |
| | | |
| | | if (!sdoProperties.containsKey(OracleDataStoreFactory.MAXCONN.key)) |
| | | { |
| | | sdoProperties.put(OracleDataStoreFactory.MAXCONN.key, "2"); |
| | | } |
| | | |
| | | if (!sdoProperties.containsKey(OracleDataStoreFactory.MINCONN.key)) |
| | | { |
| | | sdoProperties.put(OracleDataStoreFactory.MINCONN.key, "1"); |
| | | } |
| | | |
| | | /* |
| | | if (!sdoProperties.containsKey(OracleDataStoreFactory.WKBENABLED.key)) |
| | | { |
| | | sdoProperties.put(OracleDataStoreFactory.WKBENABLED.key, "true"); |
| | | } |
| | | */ |
| | | |
| | | if (!dataStoreFactory.canProcess(sdoProperties)) |
| | | { |
| | | getLogger().warn("cannot process properties-"); |
| | | throw new JobExecutionException("cannot process properties-"); |
| | | } |
| | | try |
| | | { |
| | | targetDataStore = (OracleDataStore) dataStoreFactory.createDataStore(sdoProperties); |
| | | } catch (IOException e) |
| | | { |
| | | getLogger().warn(e.getMessage(), e); |
| | | throw new JobExecutionException(e.getMessage(), e); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.jobs; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileNotFoundException; |
| | | import java.io.FilenameFilter; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.ByteOrder; |
| | | import java.nio.channels.FileChannel; |
| | | import java.sql.Connection; |
| | | import java.sql.ResultSet; |
| | | import java.sql.SQLException; |
| | | import java.sql.Statement; |
| | | import java.sql.Types; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | import java.util.TreeMap; |
| | | import java.util.ArrayList; |
| | | |
| | | import org.apache.commons.collections.OrderedMap; |
| | | import org.apache.commons.collections.OrderedMapIterator; |
| | | import org.apache.commons.collections.map.LinkedMap; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.geotools.data.DataStore; |
| | | import org.geotools.data.Transaction; |
| | | import org.geotools.data.postgis.PostgisDataStore; |
| | | import org.geotools.data.postgis.PostgisDataStoreFactory; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | import org.quartz.JobDataMap; |
| | | import org.quartz.JobDetail; |
| | | import org.quartz.JobExecutionContext; |
| | | import org.quartz.JobExecutionException; |
| | | |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | import oracle.jdbc.OracleConnection; |
| | | import oracle.jdbc.OracleResultSet; |
| | | import oracle.sql.ARRAY; |
| | | import oracle.sql.BLOB; |
| | | |
| | | import com.ximple.eofms.jobs.context.AbstractOracleJobContext; |
| | | import com.ximple.eofms.jobs.context.postgis.FeatureDgnConvertPostGISJobContext; |
| | | import com.ximple.eofms.jobs.context.postgis.GeneralDgnConvertPostGISJobContext; |
| | | import com.ximple.eofms.jobs.context.postgis.IndexDgnConvertPostGISJobContext; |
| | | import com.ximple.eofms.jobs.context.postgis.OracleConvertPostGISJobContext; |
| | | import com.ximple.eofms.util.BinConverter; |
| | | import com.ximple.eofms.util.ByteArrayCompressor; |
| | | import com.ximple.eofms.util.StringUtils; |
| | | import com.ximple.io.dgn7.ComplexElement; |
| | | import com.ximple.io.dgn7.Dgn7fileException; |
| | | import com.ximple.io.dgn7.Dgn7fileReader; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.ElementType; |
| | | import com.ximple.io.dgn7.IElementHandler; |
| | | import com.ximple.io.dgn7.Lock; |
| | | import com.ximple.io.dgn7.TextElement; |
| | | import com.ximple.io.dgn7.ShapeElement; |
| | | import com.ximple.util.PrintfFormat; |
| | | |
| | | public class OracleConvertDgn2PostGISJob extends AbstractOracleDatabaseJob |
| | | { |
| | | final static Log logger = LogFactory.getLog(OracleConvertDgn2PostGISJob.class); |
| | | |
| | | private static final String PGHOST = "PGHOST"; |
| | | private static final String PGDDATBASE = "PGDDATBASE"; |
| | | private static final String PGPORT = "PGPORT"; |
| | | private static final String PGSCHEMA = "PGSCHEMA"; |
| | | private static final String PGUSER = "PGUSER"; |
| | | private static final String PGPASS = "PGPASS"; |
| | | private static final String USEWKB = "USEWKB"; |
| | | |
| | | private static final boolean useTpclidText = false; |
| | | |
| | | private static final int FETCHSIZE = 30; |
| | | private static final int COMMITSIZE = 100; |
| | | |
| | | protected static class Pair |
| | | { |
| | | Object first; |
| | | Object second; |
| | | |
| | | public Pair(Object first, Object second) |
| | | { |
| | | this.first = first; |
| | | this.second = second; |
| | | } |
| | | } |
| | | |
| | | protected static PostgisDataStoreFactory dataStoreFactory = new PostgisDataStoreFactory(); |
| | | |
| | | GeometryFactory _geomFactory = new GeometryFactory(); |
| | | protected String _pgHost; |
| | | protected String _pgDatabase; |
| | | protected String _pgPort; |
| | | protected String _pgSchema; |
| | | protected String _pgUsername; |
| | | protected String _pgPassword; |
| | | protected String _pgUseWKB; |
| | | |
| | | protected Map<String, String> pgProperties; |
| | | protected PostgisDataStore targetDataStore; |
| | | // protected OracleConvertPostGISJobContext oracleJobContext; |
| | | |
| | | public Log getLogger() |
| | | { |
| | | return logger; |
| | | } |
| | | |
| | | protected AbstractOracleJobContext prepareJobContext(String targetSchemaName, String filterPath) |
| | | { |
| | | return new OracleConvertPostGISJobContext(getDataPath(), getTargetDataStore(), targetSchemaName, filterPath); |
| | | } |
| | | |
| | | protected void extractJobConfiguration(JobDetail jobDetail) throws JobExecutionException |
| | | { |
| | | super.extractJobConfiguration(jobDetail); |
| | | JobDataMap dataMap = jobDetail.getJobDataMap(); |
| | | _pgHost = dataMap.getString(PGHOST); |
| | | _pgDatabase = dataMap.getString(PGDDATBASE); |
| | | _pgPort = dataMap.getString(PGPORT); |
| | | _pgSchema = dataMap.getString(PGSCHEMA); |
| | | _pgUsername = dataMap.getString(PGUSER); |
| | | _pgPassword = dataMap.getString(PGPASS); |
| | | _pgUseWKB = dataMap.getString(USEWKB); |
| | | |
| | | Log logger = getLogger(); |
| | | /* |
| | | logger.info("PGHOST=" + _myHost); |
| | | logger.info("PGDDATBASE=" + _myDatabase); |
| | | logger.info("PGPORT=" + _myPort); |
| | | logger.info("PGSCHEMA=" + _mySchema); |
| | | logger.info("PGUSER=" + _myUsername); |
| | | logger.info("PGPASS=" + _myPassword); |
| | | logger.info("USEWKB=" + _myUseWKB); |
| | | */ |
| | | |
| | | if (_pgHost == null) |
| | | { |
| | | logger.warn("PGHOST is null"); |
| | | throw new JobExecutionException("Unknown PostGIS host."); |
| | | } |
| | | if (_pgDatabase == null) |
| | | { |
| | | logger.warn("PGDATABASE is null"); |
| | | throw new JobExecutionException("Unknown PostGIS database."); |
| | | } |
| | | if (_pgPort == null) |
| | | { |
| | | logger.warn("PGPORT is null"); |
| | | throw new JobExecutionException("Unknown PostGIS port."); |
| | | } |
| | | if (_pgSchema == null) |
| | | { |
| | | logger.warn("PGSCHEMA is null"); |
| | | throw new JobExecutionException("Unknown PostGIS schema."); |
| | | } |
| | | if (_pgUsername == null) |
| | | { |
| | | logger.warn("PGUSERNAME is null"); |
| | | throw new JobExecutionException("Unknown PostGIS username."); |
| | | } |
| | | if (_pgPassword == null) |
| | | { |
| | | logger.warn("PGPASSWORD is null"); |
| | | throw new JobExecutionException("Unknown PostGIS password."); |
| | | } |
| | | |
| | | Map<String, String> remote = new TreeMap<String, String>(); |
| | | remote.put("dbtype", "postgis"); |
| | | remote.put("charset", "UTF-8"); |
| | | remote.put("host", _pgHost); |
| | | remote.put("port", _pgPort); |
| | | remote.put("database", _pgDatabase); |
| | | remote.put("user", _pgUsername); |
| | | remote.put("passwd", _pgPassword); |
| | | remote.put("namespace", null); |
| | | pgProperties = remote; |
| | | } |
| | | |
| | | public void execute(JobExecutionContext context) throws JobExecutionException |
| | | { |
| | | // Every job has its own job detail |
| | | JobDetail jobDetail = context.getJobDetail(); |
| | | |
| | | // The name is defined in the job definition |
| | | String jobName = jobDetail.getName(); |
| | | |
| | | // Log the time the job started |
| | | logger.info(jobName + " fired at " + new Date()); |
| | | extractJobConfiguration(jobDetail); |
| | | createSourceDataStore(); |
| | | createTargetDataStore(); |
| | | if (getSourceDataStore() == null) |
| | | { |
| | | logger.warn("Cannot connect source oracle database."); |
| | | throw new JobExecutionException("Cannot connect source oracle database."); |
| | | } |
| | | |
| | | if (getTargetDataStore() == null) |
| | | { |
| | | logger.warn("Cannot connect source postgreSQL database."); |
| | | throw new JobExecutionException("Cannot connect source postgreSQL database."); |
| | | } |
| | | |
| | | long t1 = System.currentTimeMillis(); |
| | | String targetSchemaName = null; |
| | | try |
| | | { |
| | | logger.info("-- step:clearOutputDatabase --"); |
| | | clearOutputDatabase(); |
| | | targetSchemaName = determineTargetSchemaName(); |
| | | |
| | | if (checkConvertDB()) |
| | | { |
| | | logger.info("-- step:convertOracleDB --"); |
| | | |
| | | OracleConvertPostGISJobContext jobContext = |
| | | (OracleConvertPostGISJobContext) prepareJobContext(targetSchemaName, _filterPath); |
| | | jobContext.setSourceDataStore(getSourceDataStore()); |
| | | // jobContext.setConvertElementIn(_convertElementIn); |
| | | jobContext.setElementLogging(checkElementLogging()); |
| | | jobContext.setExecutionContext(context); |
| | | if (isCopyConnectivityMode()) |
| | | copyConnectivity(jobContext); |
| | | |
| | | |
| | | for (String orgSchema : _orgSchema) |
| | | { |
| | | logger.info("----- start schema:" + orgSchema + " -----"); |
| | | exetcuteConvert(jobContext, orgSchema, _dataPath); |
| | | |
| | | //close all open filewriter instance |
| | | jobContext.closeFeatureWriter(); |
| | | } |
| | | } |
| | | |
| | | if (checkConvertFile()) |
| | | { |
| | | logger.info("-- step:convertIndexDesignFile --"); |
| | | convertIndexDesignFile(context, targetSchemaName); |
| | | logger.info("-- step:convertOtherDesignFile --"); |
| | | convertOtherDesignFile(context, targetSchemaName); |
| | | } |
| | | |
| | | if (checkConvertElementIn()) |
| | | { |
| | | logger.info("-- step:convertFeatureDesignFile --"); |
| | | convertFeatureDesignFile(context, targetSchemaName); |
| | | } |
| | | |
| | | if (checkCreateDummy()) |
| | | { |
| | | logger.info("-- step:createDummyFeatureFile --"); |
| | | createDummyFeatureFile(context); |
| | | } |
| | | |
| | | disconnect(); |
| | | long t2 = System.currentTimeMillis(); |
| | | // public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss"; |
| | | // SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW); |
| | | logger.warn("use time = " + ((int) ((t2 - t1) / 60000.0)) + " min - " + |
| | | (((int) ((t2 - t1) % 60000.0)) / 1000) + " sec"); |
| | | } catch (SQLException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | throw new JobExecutionException("Database error. " + e.getMessage(), e); |
| | | } catch (IOException ex) |
| | | { |
| | | logger.warn(ex.getMessage(), ex); |
| | | throw new JobExecutionException("IO error. " + ex.getMessage(), ex); |
| | | } |
| | | updateRepoStatusToReady(targetSchemaName); |
| | | logger.warn(jobName + " end at " + new Date()); |
| | | } |
| | | |
| | | /** |
| | | * Connectivity½Æ»s¤@Óª©¥»¡A¦b¬d¸ß¹q¬y¤è¦V®É¥Î¨Ó¤ñ¹ïOMS¸ê®Æ®wªº¹q¾¹³s±µ©Ê(Connectivity) |
| | | * |
| | | * @param jobContext job context |
| | | * @throws SQLException sql exception |
| | | */ |
| | | private void copyConnectivity(OracleConvertPostGISJobContext jobContext) throws SQLException |
| | | { |
| | | Connection connection = jobContext.getOracleConnection(); |
| | | ResultSet rsMeta = connection.getMetaData().getTables(null, "BASEDB", |
| | | AbstractOracleJobContext.CONNECTIVITY_WEBCHECK_NAME + "%", |
| | | new String[]{"TABLE"}); |
| | | |
| | | boolean found = false; |
| | | try |
| | | { |
| | | while (rsMeta.next()) |
| | | { |
| | | String tablename = rsMeta.getString(3); |
| | | if (AbstractOracleJobContext.CONNECTIVITY_WEBCHECK_NAME.equalsIgnoreCase(tablename)) |
| | | { |
| | | found = true; |
| | | break; |
| | | } |
| | | } |
| | | // } catch (SQLException e) |
| | | } finally |
| | | { |
| | | if (rsMeta != null) |
| | | { |
| | | rsMeta.close(); |
| | | rsMeta = null; |
| | | } |
| | | } |
| | | Statement stmt = connection.createStatement(); |
| | | if (found) |
| | | { |
| | | stmt.execute(AbstractOracleJobContext.TRUNCATE_CONNECTIVITY_WEBCHECK); |
| | | } else { |
| | | logger.info("Create CONNECTIVITY_WEBCHECK table."); |
| | | stmt.execute(AbstractOracleJobContext.CREATE_CONNECTIVITY_WEBCHECK); |
| | | stmt.execute(AbstractOracleJobContext.CREATE_CONNECTIVITY_WEBCHECK_INDEX_1); |
| | | stmt.execute(AbstractOracleJobContext.CREATE_CONNECTIVITY_WEBCHECK_INDEX_2); |
| | | stmt.execute(AbstractOracleJobContext.CREATE_CONNECTIVITY_WEBCHECK_INDEX_3); |
| | | stmt.execute(AbstractOracleJobContext.CREATE_CONNECTIVITY_WEBCHECK_INDEX_4); |
| | | stmt.execute(AbstractOracleJobContext.CREATE_CONNECTIVITY_WEBCHECK_INDEX_5); |
| | | stmt.execute(AbstractOracleJobContext.CREATE_CONNECTIVITY_WEBCHECK_INDEX_6); |
| | | stmt.execute(AbstractOracleJobContext.ALTER_CONNECTIVITY_WEBCHECK_1); |
| | | stmt.execute(AbstractOracleJobContext.ALTER_CONNECTIVITY_WEBCHECK_2); |
| | | } |
| | | |
| | | stmt.execute(AbstractOracleJobContext.COPY_CONNECTIVITY_TO_WEBCHECK); |
| | | stmt.close(); |
| | | } |
| | | |
| | | private void exetcuteConvert(OracleConvertPostGISJobContext jobContext, |
| | | String querySchema, String targetSchemaName) throws SQLException |
| | | { |
| | | int order = 0; |
| | | OrderedMap map = getBlobStorageList(jobContext.getOracleConnection(), |
| | | querySchema, "SD$SPACENODES", null); |
| | | |
| | | logger.info("begin convert job:[" + map.size() + "]:testmode=" + _testMode); |
| | | |
| | | int total = map.size(); //spacenodes count |
| | | int step = total / 100; |
| | | int current = 0; |
| | | |
| | | //jobContext.startTransaction(); |
| | | jobContext.setCurrentSchema(querySchema); |
| | | jobContext.getExecutionContext().put("ConvertDgn2PostGISJobProgress", 0); |
| | | for (OrderedMapIterator it = map.orderedMapIterator(); it.hasNext();) |
| | | { |
| | | it.next(); |
| | | |
| | | Pair pair = (Pair) it.getValue(); |
| | | String tableSrc = (String) pair.first; |
| | | |
| | | logger.info("begin convert:[" + order + "]-" + tableSrc); |
| | | queryIgsetElement(jobContext, querySchema, tableSrc); |
| | | |
| | | order++; |
| | | |
| | | if (_testMode) |
| | | { |
| | | if ((_testCount < 0) || (order >= _testCount)) |
| | | break; |
| | | } |
| | | |
| | | if ((order % COMMITSIZE) == 0) |
| | | { |
| | | // OracleConnection connection = jobContext.getOracleConnection(); |
| | | // connection.commitTransaction(); |
| | | jobContext.commitTransaction(); |
| | | //jobContext.startTransaction(); |
| | | System.gc(); |
| | | System.runFinalization(); |
| | | } |
| | | |
| | | int now = order % step; |
| | | if (now != current) |
| | | { |
| | | current = now; |
| | | jobContext.getExecutionContext().put("ConvertDgn2PostGISJobProgress", current); |
| | | |
| | | } |
| | | } |
| | | jobContext.getExecutionContext().put("ConvertDgn2PostGISJobProgress", 100); |
| | | |
| | | jobContext.commitTransaction(); |
| | | jobContext.resetFeatureContext(); |
| | | logger.info("end convert job:[" + order + "]"); |
| | | System.gc(); |
| | | System.runFinalization(); |
| | | } |
| | | |
| | | protected OrderedMap getBlobStorageList(Connection connection, String schemaSrc, String tableSrc, |
| | | OrderedMap orderedMap) throws SQLException |
| | | { |
| | | if (orderedMap == null) |
| | | orderedMap = new LinkedMap(99); |
| | | String fetchStmtFmt = "SELECT SNID, SPACETABLE FROM \"%s\".\"%s\""; |
| | | PrintfFormat spf = new PrintfFormat(fetchStmtFmt); |
| | | String fetchStmt = spf.sprintf(new Object[]{schemaSrc, tableSrc}); |
| | | Statement stmt = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
| | | ResultSet rs = null; |
| | | |
| | | stmt.setFetchSize(FETCHSIZE); |
| | | try |
| | | { |
| | | rs = stmt.executeQuery(fetchStmt); |
| | | int size = rs.getMetaData().getColumnCount(); |
| | | |
| | | while (rs.next()) |
| | | { |
| | | Object[] values = new Object[size]; |
| | | |
| | | for (int i = 0; i < size; i++) |
| | | { |
| | | values[i] = rs.getObject(i + 1); |
| | | } |
| | | |
| | | Integer key = ((BigDecimal) values[0]).intValue(); |
| | | String name = (String) values[1]; |
| | | |
| | | Pair pair = (Pair) orderedMap.get(key); |
| | | if (pair == null) |
| | | orderedMap.put(key, new Pair(name, null)); |
| | | else |
| | | pair.first = name; |
| | | } |
| | | } catch (SQLException e) |
| | | { |
| | | logger.error(e.toString(), e); |
| | | logger.error("stmt=" + fetchStmt); |
| | | throw e; |
| | | } finally |
| | | { |
| | | if (rs != null) rs.close(); |
| | | stmt.close(); |
| | | } |
| | | |
| | | return orderedMap; |
| | | } |
| | | |
| | | protected OrderedMap getRawFormatStorageList(OracleConnection connection, String schemaSrc, String tableSrc, |
| | | OrderedMap orderedMap) throws SQLException |
| | | { |
| | | if (orderedMap == null) |
| | | orderedMap = new LinkedMap(99); |
| | | String fetchStmtFmt = "SELECT RNID, SPACETABLE FROM \"%s\".\"%s\""; |
| | | PrintfFormat spf = new PrintfFormat(fetchStmtFmt); |
| | | String fetchStmt = spf.sprintf(new Object[]{schemaSrc, tableSrc}); |
| | | Statement stmt = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
| | | |
| | | stmt.setFetchSize(FETCHSIZE); |
| | | ResultSet rs = stmt.executeQuery(fetchStmt); |
| | | try |
| | | { |
| | | int size = rs.getMetaData().getColumnCount(); |
| | | while (rs.next()) |
| | | { |
| | | Object[] values = new Object[size]; |
| | | |
| | | for (int i = 0; i < size; i++) |
| | | { |
| | | values[i] = rs.getObject(i + 1); |
| | | } |
| | | |
| | | Integer key = ((BigDecimal) values[0]).intValue(); |
| | | String name = (String) values[1]; |
| | | |
| | | Pair pair = (Pair) orderedMap.get(key); |
| | | if (pair == null) |
| | | orderedMap.put(key, new Pair(null, name)); |
| | | else |
| | | pair.second = name; |
| | | } |
| | | } finally |
| | | { |
| | | rs.close(); |
| | | stmt.close(); |
| | | } |
| | | return orderedMap; |
| | | } |
| | | |
| | | protected void queryIgsetElement(OracleConvertPostGISJobContext jobContext, |
| | | String srcschema, String srctable) throws SQLException |
| | | { |
| | | Connection connection = jobContext.getOracleConnection(); |
| | | String fetchSrcStmtFmt = "SELECT IGDSELM FROM \"%s\".\"%s\" ORDER BY ROWID"; |
| | | PrintfFormat spf = new PrintfFormat(fetchSrcStmtFmt); |
| | | String fetchSrcStmt = spf.sprintf(new Object[]{srcschema, srctable}); |
| | | Statement stmtSrc = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
| | | |
| | | stmtSrc.setFetchSize(FETCHSIZE); |
| | | ResultSet rsSrc = stmtSrc.executeQuery(fetchSrcStmt); |
| | | int igdsMetaType = rsSrc.getMetaData().getColumnType(1); |
| | | while (rsSrc.next()) |
| | | { |
| | | byte[] raw; |
| | | if (igdsMetaType == Types.BLOB) |
| | | { |
| | | BLOB blob = (BLOB) rsSrc.getBlob(1); |
| | | |
| | | raw = getBytesFromBLOB(blob); |
| | | blob.close(); |
| | | } else |
| | | { |
| | | raw = rsSrc.getBytes(1); |
| | | } |
| | | |
| | | try |
| | | { |
| | | Element element = fetchBinaryElement(raw); |
| | | jobContext.putFeatureCollection(element); |
| | | } catch (Dgn7fileException e) |
| | | { |
| | | logger.warn("Dgn7Exception", e); |
| | | } |
| | | } |
| | | |
| | | rsSrc.close(); |
| | | stmtSrc.close(); |
| | | } |
| | | |
| | | protected void queryRawElement(OracleConvertPostGISJobContext jobContext, |
| | | String srcschema, String srctable) throws SQLException |
| | | { |
| | | Connection connection = jobContext.getOracleConnection(); |
| | | String fetchDestStmtFmt = "SELECT ELEMENT FROM \"%s\".\"%s\" ORDER BY ROWID"; |
| | | PrintfFormat spf = new PrintfFormat(fetchDestStmtFmt); |
| | | String fetchDestStmt = spf.sprintf(new Object[]{srcschema, srctable}); |
| | | Statement stmtDest = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
| | | |
| | | stmtDest.setFetchSize(FETCHSIZE); |
| | | ResultSet rsDest = stmtDest.executeQuery(fetchDestStmt); |
| | | |
| | | try |
| | | { |
| | | while (rsDest.next()) |
| | | { |
| | | ARRAY rawsValue = ((OracleResultSet) rsDest).getARRAY(1); |
| | | long[] rawData = rawsValue.getLongArray(); |
| | | byte[] comparessedValue; |
| | | |
| | | /* |
| | | if (dataMode == TransferTask.DataMode.Normal) |
| | | { |
| | | comparessedValue = BinConverter.unmarshalByteArray(rawData, true); |
| | | } else |
| | | { |
| | | comparessedValue = BinConverter.unmarshalCompactByteArray(rawData); |
| | | } |
| | | */ |
| | | comparessedValue = BinConverter.unmarshalByteArray(rawData, true); |
| | | |
| | | byte[] rawDest = ByteArrayCompressor.decompressByteArray(comparessedValue); |
| | | |
| | | |
| | | try |
| | | { |
| | | Element element = fetchBinaryElement(rawDest); |
| | | jobContext.putFeatureCollection(element); |
| | | } catch (Dgn7fileException e) |
| | | { |
| | | logger.warn("Dgn7Exception:" + e.getMessage(), e); |
| | | } |
| | | } |
| | | } finally |
| | | { |
| | | rsDest.close(); |
| | | stmtDest.close(); |
| | | } |
| | | } |
| | | |
| | | // Binary to Element |
| | | private Element fetchBinaryElement(byte[] raws) throws Dgn7fileException |
| | | { |
| | | ByteBuffer buffer = ByteBuffer.wrap(raws); |
| | | buffer.order(ByteOrder.LITTLE_ENDIAN); |
| | | short signature = buffer.getShort(); |
| | | |
| | | // byte type = (byte) (buffer.get() & 0x7f); |
| | | byte type = (byte) ((signature >>> 8) & 0x007f); |
| | | |
| | | // silly Bentley say contentLength is in 2-byte words |
| | | // and ByteByffer uses raws. |
| | | // track the record location |
| | | int elementLength = (buffer.getShort() * 2) + 4; |
| | | ElementType recordType = ElementType.forID(type); |
| | | IElementHandler handler; |
| | | |
| | | handler = recordType.getElementHandler(); |
| | | |
| | | Element dgnElement = (Element) handler.read(buffer, signature, elementLength); |
| | | if (recordType.isComplexElement() && (elementLength < raws.length)) |
| | | { |
| | | int offset = elementLength; |
| | | while (offset < (raws.length - 4)) |
| | | { |
| | | buffer.position(offset); |
| | | signature = buffer.getShort(); |
| | | type = (byte) ((signature >>> 8) & 0x007f); |
| | | elementLength = (buffer.getShort() * 2) + 4; |
| | | if (raws.length < (offset + elementLength)) |
| | | { |
| | | System.out.println("Length not match:" + offset + ":" + buffer.position() + ":" + buffer.limit()); |
| | | break; |
| | | } |
| | | recordType = ElementType.forID(type); |
| | | handler = recordType.getElementHandler(); |
| | | if (handler != null) |
| | | { |
| | | Element subElement = (Element) handler.read(buffer, signature, elementLength); |
| | | ((ComplexElement) dgnElement).add(subElement); |
| | | offset += elementLength; |
| | | } else |
| | | { |
| | | byte[] remain = new byte[buffer.remaining()]; |
| | | System.arraycopy(raws, offset, remain, 0, buffer.remaining()); |
| | | for (int i = 0; i < remain.length; i++) |
| | | { |
| | | if (remain[i] != 0) |
| | | { |
| | | logger.info("fetch element has some error. index=" + (offset + i) + ":value=" + remain[i]); |
| | | System.out.println("fetch element has some error. index=" + (offset + i) + ":value=" + remain[i]); |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return dgnElement; |
| | | } |
| | | |
| | | /** |
| | | * °õ¦æÂà´«¯Á¤Þ¹ÏÀɪº¤u§@ |
| | | * |
| | | * @param context ¤u§@°õ¦æÀô¹Ò |
| | | * @throws org.quartz.JobExecutionException |
| | | * exception |
| | | */ |
| | | private void convertIndexDesignFile(JobExecutionContext context, String targetSchemaName) throws JobExecutionException |
| | | { |
| | | File indexDir = new File(getDataPath(), "index"); |
| | | if (!indexDir.exists()) |
| | | { |
| | | logger.info("index dir=" + indexDir + " not exist."); |
| | | return; |
| | | } |
| | | |
| | | if (!indexDir.isDirectory()) |
| | | { |
| | | logger.info("index dir=" + indexDir + " is not a directory."); |
| | | } |
| | | |
| | | File[] dgnFiles = indexDir.listFiles(new FilenameFilter() |
| | | { |
| | | public boolean accept(File dir, String name) |
| | | { |
| | | return name.toLowerCase().endsWith(".dgn"); |
| | | } |
| | | }); |
| | | |
| | | for (File dgnFile : dgnFiles) |
| | | { |
| | | IndexDgnConvertPostGISJobContext convertContext = |
| | | new IndexDgnConvertPostGISJobContext(getDataPath(), getTargetDataStore(), targetSchemaName); |
| | | logger.debug("--- start dgnfile-" + dgnFile.toString() + " ---"); |
| | | try |
| | | { |
| | | convertContext.clearOutputDatabase(); |
| | | convertContext.setExecutionContext(context); |
| | | String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.separator); |
| | | convertContext.setFilename(dgnPaths[dgnPaths.length - 1]); |
| | | convertContext.startTransaction(); |
| | | |
| | | FileInputStream fs = new FileInputStream(dgnFile); |
| | | FileChannel fc = fs.getChannel(); |
| | | Dgn7fileReader reader = new Dgn7fileReader(fc, new Lock()); |
| | | convertContext.setReader(reader); |
| | | |
| | | scanIndexDgnElement(convertContext); |
| | | |
| | | convertContext.commitTransaction(); |
| | | convertContext.closeFeatureWriter(); |
| | | System.gc(); |
| | | System.runFinalization(); |
| | | } 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); |
| | | } |
| | | } |
| | | } |
| | | |
| | | protected void scanIndexDgnElement(IndexDgnConvertPostGISJobContext 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())) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processIndexElement(lastComplex, convertContext); |
| | | lastComplex = null; |
| | | } |
| | | |
| | | processIndexElement(element, convertContext); |
| | | } else if (element.isComponentElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | ((ComplexElement) lastComplex).add(element); |
| | | } |
| | | } else if (type.isComplexElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processIndexElement(lastComplex, convertContext); |
| | | } |
| | | lastComplex = element; |
| | | } |
| | | } |
| | | count++; |
| | | } |
| | | |
| | | if (lastComplex != null) |
| | | { |
| | | processIndexElement(lastComplex, convertContext); |
| | | } |
| | | logger.debug("ElementRecord Count=" + count); |
| | | } |
| | | |
| | | private void processIndexElement(Element element, IndexDgnConvertPostGISJobContext convertContext) |
| | | throws IllegalAttributeException, SchemaException |
| | | { |
| | | if (useTpclidText) |
| | | { |
| | | if (element instanceof TextElement) |
| | | { |
| | | convertContext.putFeatureCollection(element); |
| | | } |
| | | } else { |
| | | if (element instanceof ShapeElement) |
| | | { |
| | | convertContext.putFeatureCollection(element); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * °õ¦æÂà´«¨ä¥L³]p¹ÏÀɪº¤u§@ |
| | | * |
| | | * @param context jobContext |
| | | * @throws org.quartz.JobExecutionException |
| | | * exception |
| | | */ |
| | | private void convertOtherDesignFile(JobExecutionContext context, String targetSchemaName) throws JobExecutionException |
| | | { |
| | | File otherDir = new File(getDataPath(), "other"); |
| | | if (!otherDir.exists()) |
| | | { |
| | | logger.info("other dir=" + otherDir + " not exist."); |
| | | return; |
| | | } |
| | | |
| | | if (!otherDir.isDirectory()) |
| | | { |
| | | logger.info("other dir=" + otherDir + " is not a directory."); |
| | | } |
| | | |
| | | File[] dgnFiles = otherDir.listFiles(new FilenameFilter() |
| | | { |
| | | public boolean accept(File dir, String name) |
| | | { |
| | | return name.toLowerCase().endsWith(".dgn"); |
| | | } |
| | | }); |
| | | |
| | | for (File dgnFile : dgnFiles) |
| | | { |
| | | GeneralDgnConvertPostGISJobContext convertContext = |
| | | new GeneralDgnConvertPostGISJobContext(getDataPath(), getTargetDataStore(), targetSchemaName); |
| | | logger.info("--- start dgnfile-" + dgnFile.toString() + " ---"); |
| | | try |
| | | { |
| | | convertContext.setExecutionContext(context); |
| | | String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.separator); |
| | | convertContext.setFilename(dgnPaths[dgnPaths.length - 1]); |
| | | convertContext.startTransaction(); |
| | | |
| | | FileInputStream fs = new FileInputStream(dgnFile); |
| | | FileChannel fc = fs.getChannel(); |
| | | Dgn7fileReader reader = new Dgn7fileReader(fc, new Lock()); |
| | | convertContext.setReader(reader); |
| | | |
| | | scanOtherDgnElement(convertContext); |
| | | |
| | | convertContext.commitTransaction(); |
| | | convertContext.closeFeatureWriter(); |
| | | System.gc(); |
| | | System.runFinalization(); |
| | | } 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 scanOtherDgnElement(GeneralDgnConvertPostGISJobContext 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())) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processOtherElement(lastComplex, convertContext); |
| | | lastComplex = null; |
| | | } |
| | | |
| | | processOtherElement(element, convertContext); |
| | | } else if (element.isComponentElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | ((ComplexElement) lastComplex).add(element); |
| | | } |
| | | } else if (type.isComplexElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processOtherElement(lastComplex, convertContext); |
| | | } |
| | | lastComplex = element; |
| | | } |
| | | } |
| | | count++; |
| | | } |
| | | |
| | | if (lastComplex != null) |
| | | { |
| | | processOtherElement(lastComplex, convertContext); |
| | | } |
| | | logger.debug("ElementRecord Count=" + count); |
| | | } |
| | | |
| | | private void processOtherElement(Element element, GeneralDgnConvertPostGISJobContext convertContext) |
| | | throws IllegalAttributeException, SchemaException |
| | | { |
| | | convertContext.putFeatureCollection(element); |
| | | } |
| | | |
| | | private void clearOutputDatabase() |
| | | { |
| | | /* |
| | | File outDataPath = new File(getDataPath(), OracleConvertPostGISJobContext.SHPOUTPATH); |
| | | if (outDataPath.exists() && outDataPath.isDirectory()) |
| | | { |
| | | deleteFilesInPath(outDataPath); |
| | | } |
| | | outDataPath = new File(getDataPath(), IndexDgnConvertShpJobContext.SHPOUTPATH); |
| | | if (outDataPath.exists() && outDataPath.isDirectory()) |
| | | { |
| | | deleteFilesInPath(outDataPath); |
| | | } |
| | | outDataPath = new File(getDataPath(), GeneralDgnConvertShpJobContext.SHPOUTPATH); |
| | | if (outDataPath.exists() && outDataPath.isDirectory()) |
| | | { |
| | | deleteFilesInPath(outDataPath); |
| | | } |
| | | */ |
| | | } |
| | | |
| | | private void deleteFilesInPath(File outDataPath) |
| | | { |
| | | deleteFilesInPath(outDataPath, true); |
| | | } |
| | | |
| | | private void deleteFilesInPath(File outDataPath, boolean removeSubDir) |
| | | { |
| | | if (!outDataPath.isDirectory()) |
| | | { |
| | | return; |
| | | } |
| | | File[] files = outDataPath.listFiles(); |
| | | for (File file : files) |
| | | { |
| | | if (file.isFile()) |
| | | { |
| | | if (!file.delete()) |
| | | { |
| | | logger.info("Cannot delete file-" + file.toString()); |
| | | } |
| | | } else if (file.isDirectory()) |
| | | { |
| | | deleteFilesInPath(file, removeSubDir); |
| | | if (removeSubDir) |
| | | { |
| | | if (file.delete()) |
| | | { |
| | | logger.info("Cannot delete dir-" + file.toString()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void convertFeatureDesignFile(JobExecutionContext context, String targetSchemaName) 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) |
| | | { |
| | | FeatureDgnConvertPostGISJobContext convertContext = |
| | | new FeatureDgnConvertPostGISJobContext(getDataPath(), getTargetDataStore(), targetSchemaName, _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]); |
| | | convertContext.startTransaction(); |
| | | |
| | | 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(); |
| | | System.runFinalization(); |
| | | } 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(FeatureDgnConvertPostGISJobContext 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())) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processFeatureElement(lastComplex, convertContext); |
| | | lastComplex = null; |
| | | } |
| | | |
| | | processFeatureElement(element, convertContext); |
| | | } else if (element.isComponentElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | ((ComplexElement) lastComplex).add(element); |
| | | } |
| | | } else if (type.isComplexElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processFeatureElement(lastComplex, convertContext); |
| | | } |
| | | lastComplex = element; |
| | | } |
| | | } |
| | | count++; |
| | | } |
| | | |
| | | if (lastComplex != null) |
| | | { |
| | | processFeatureElement(lastComplex, convertContext); |
| | | } |
| | | logger.debug("ElementRecord Count=" + count); |
| | | } |
| | | |
| | | private void processFeatureElement(Element element, FeatureDgnConvertPostGISJobContext convertContext) |
| | | throws IllegalAttributeException, SchemaException |
| | | { |
| | | convertContext.putFeatureCollection(element); |
| | | } |
| | | |
| | | private void createDummyFeatureFile(JobExecutionContext context) throws JobExecutionException |
| | | { |
| | | /* |
| | | DummyFeatureConvertShpJobContext convertContext = new DummyFeatureConvertShpJobContext(getDataPath(), _filterPath); |
| | | try { |
| | | convertContext.startTransaction(); |
| | | convertContext.commitTransaction(); |
| | | convertContext.closeFeatureWriter(); |
| | | } catch (IOException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | throw new JobExecutionException(e.getMessage(), e); |
| | | } |
| | | */ |
| | | } |
| | | |
| | | public DataStore getTargetDataStore() |
| | | { |
| | | return targetDataStore; |
| | | } |
| | | |
| | | protected void createTargetDataStore() throws JobExecutionException |
| | | { |
| | | if (targetDataStore != null) |
| | | { |
| | | targetDataStore.dispose(); |
| | | targetDataStore = null; |
| | | } |
| | | |
| | | /* |
| | | if (!isDriverFound()) |
| | | { |
| | | throw new JobExecutionException("Oracle JDBC Driver not found.-" + JDBC_DRIVER); |
| | | } |
| | | */ |
| | | |
| | | if (!pgProperties.containsKey(PostgisDataStoreFactory.MAXCONN.key)) |
| | | { |
| | | pgProperties.put(PostgisDataStoreFactory.MAXCONN.key, "10"); |
| | | } |
| | | |
| | | if (!pgProperties.containsKey(PostgisDataStoreFactory.MINCONN.key)) |
| | | { |
| | | pgProperties.put(PostgisDataStoreFactory.MINCONN.key, "1"); |
| | | } |
| | | |
| | | if (!pgProperties.containsKey(PostgisDataStoreFactory.WKBENABLED.key)) |
| | | { |
| | | pgProperties.put(PostgisDataStoreFactory.WKBENABLED.key, "true"); |
| | | } |
| | | |
| | | if (!dataStoreFactory.canProcess(pgProperties)) |
| | | { |
| | | getLogger().warn("cannot process properties-"); |
| | | throw new JobExecutionException("cannot process properties-"); |
| | | } |
| | | try |
| | | { |
| | | targetDataStore = (PostgisDataStore) dataStoreFactory.createDataStore(pgProperties); |
| | | } catch (IOException e) |
| | | { |
| | | getLogger().warn(e.getMessage(), e); |
| | | throw new JobExecutionException(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | private String determineTargetSchemaName() throws IOException |
| | | { |
| | | if (targetDataStore == null) return null; |
| | | Connection connection = null; |
| | | Statement stmt = null; |
| | | ResultSet rs = null; |
| | | String targetSchema = null; |
| | | boolean needCreate = false; |
| | | try |
| | | { |
| | | connection = targetDataStore.getConnection(Transaction.AUTO_COMMIT); |
| | | rs = connection.getMetaData().getTables(null, _pgSchema, DataReposVersionManager.XGVERSIONTABLE_NAME, new String[] {"TABLE"}); |
| | | if (!rs.next()) needCreate = true; |
| | | if (needCreate) |
| | | createXGeosVersionTable(connection, _pgSchema); |
| | | rs.close(); |
| | | rs = null; |
| | | |
| | | StringBuilder sbSQL = new StringBuilder("SELECT "); |
| | | sbSQL.append("vsschema, vsstatus FROM "); |
| | | sbSQL.append(encodeSchemaTableName(_pgSchema, DataReposVersionManager.XGVERSIONTABLE_NAME)).append(' '); |
| | | sbSQL.append("ORDER BY vsid"); |
| | | stmt = connection.createStatement(); |
| | | rs = stmt.executeQuery(sbSQL.toString()); |
| | | ArrayList<Object[]> tmpSchemas = new ArrayList<Object[]>(); |
| | | int i = 0; |
| | | int current = -1; |
| | | while (rs.next()) |
| | | { |
| | | Object[] values = new Object[2]; |
| | | values[0] = rs.getString("vsschema"); |
| | | values[1] = rs.getShort("vsstatus"); |
| | | tmpSchemas.add(values); |
| | | if ((((Short)values[1]) & DataReposVersionManager.VSSTATUS_USING) != 0) |
| | | { |
| | | current = i; |
| | | } |
| | | i++; |
| | | } |
| | | |
| | | if (current == -1) |
| | | { |
| | | Object[] values = tmpSchemas.get(0); |
| | | targetSchema = (String) values[0]; |
| | | } else if (current < (tmpSchemas.size() - 1)) |
| | | { |
| | | Object[] values = tmpSchemas.get(current + 1); |
| | | targetSchema = (String) values[0]; |
| | | } else { |
| | | Object[] values = tmpSchemas.get(0); |
| | | targetSchema = (String) values[0]; |
| | | } |
| | | |
| | | sbSQL = new StringBuilder("UPDATE "); |
| | | sbSQL.append(encodeSchemaTableName(_pgSchema, DataReposVersionManager.XGVERSIONTABLE_NAME)).append(' '); |
| | | sbSQL.append(" SET vsstatus = "); |
| | | sbSQL.append(DataReposVersionManager.VSSTATUS_COVERT); |
| | | sbSQL.append(" WHERE vsschema = '"); |
| | | sbSQL.append(targetSchema).append("'"); |
| | | int count = stmt.executeUpdate(sbSQL.toString()); |
| | | if (count != 1) |
| | | { |
| | | logger.info("update status for " + targetSchema + " update result count=" |
| | | + count); |
| | | } |
| | | } catch (SQLException e) { |
| | | logger.warn(e.getMessage(), e); |
| | | } finally { |
| | | if (rs != null) try { rs.close(); } catch (SQLException e) {}; |
| | | if (stmt != null) try { stmt.close(); } catch (SQLException e) {}; |
| | | if (connection != null) try { connection.close(); } catch (SQLException e) {}; |
| | | } |
| | | return targetSchema; |
| | | } |
| | | |
| | | public String encodeSchemaTableName(String schemaName, String tableName) |
| | | { |
| | | return "\"" + schemaName + "\".\"" + tableName + "\""; |
| | | } |
| | | |
| | | private void createXGeosVersionTable(Connection connection, String pgSchema) throws SQLException |
| | | { |
| | | Statement stmt = null; |
| | | StringBuilder sql = new StringBuilder("CREATE TABLE "); |
| | | sql.append(encodeSchemaTableName(pgSchema, DataReposVersionManager.XGVERSIONTABLE_NAME)); |
| | | sql.append(" ( vsid serial PRIMARY KEY, "); |
| | | sql.append(" vsschema character varying(64) NOT NULL, "); |
| | | sql.append(" vsstatus smallint NOT NULL, "); |
| | | sql.append(" vstimestamp timestamp with time zone ) "); |
| | | try |
| | | { |
| | | stmt = connection.createStatement(); |
| | | stmt.executeUpdate(sql.toString()); |
| | | |
| | | sql = new StringBuilder("ALTER TABLE "); |
| | | sql.append(encodeSchemaTableName(pgSchema, DataReposVersionManager.XGVERSIONTABLE_NAME)); |
| | | sql.append(" OWNER TO spatialdb"); |
| | | stmt.executeUpdate(sql.toString()); |
| | | |
| | | sql = new StringBuilder("GRANT ALL ON TABLE "); |
| | | sql.append(encodeSchemaTableName(pgSchema, DataReposVersionManager.XGVERSIONTABLE_NAME)); |
| | | sql.append(" TO public"); |
| | | stmt.executeUpdate(sql.toString()); |
| | | |
| | | for (String schemaName : DataReposVersionManager.DEFAULTXGVERSIONSCHEMA_NAMES) |
| | | { |
| | | sql = new StringBuilder("INSERT INTO "); |
| | | sql.append(encodeSchemaTableName(pgSchema, DataReposVersionManager.XGVERSIONTABLE_NAME)); |
| | | sql.append(" (vsschema, vsstatus) VALUES ('"); |
| | | sql.append(schemaName).append("', "); |
| | | sql.append(DataReposVersionManager.VSSTATUS_AVAILABLE).append(" )"); |
| | | stmt.executeUpdate(sql.toString()); |
| | | |
| | | createIfNotExistNewSchema(connection, schemaName); |
| | | } |
| | | |
| | | } finally { |
| | | if (stmt != null) stmt.close(); |
| | | } |
| | | } |
| | | |
| | | private void updateRepoStatusToReady(String targetSchema) |
| | | { |
| | | if (targetDataStore == null) return; |
| | | Connection connection = null; |
| | | Statement stmt = null; |
| | | ResultSet rs = null; |
| | | boolean needCreate = false; |
| | | try |
| | | { |
| | | StringBuilder sbSQL = new StringBuilder("UPDATE "); |
| | | sbSQL.append(encodeSchemaTableName(_pgSchema, DataReposVersionManager.XGVERSIONTABLE_NAME)).append(' '); |
| | | sbSQL.append(" SET vsstatus = "); |
| | | sbSQL.append(DataReposVersionManager.VSSTATUS_READY); |
| | | sbSQL.append(" WHERE vsschema = '"); |
| | | sbSQL.append(targetSchema).append("'"); |
| | | |
| | | connection = targetDataStore.getConnection(Transaction.AUTO_COMMIT); |
| | | stmt = connection.createStatement(); |
| | | int count = stmt.executeUpdate(sbSQL.toString()); |
| | | if (count != 1) |
| | | { |
| | | logger.info("update status for " + targetSchema + " update result count=" |
| | | + count); |
| | | } |
| | | } catch (SQLException e) { |
| | | logger.warn(e.getMessage(), e); |
| | | } catch (IOException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | } finally { |
| | | if (rs != null) try { rs.close(); } catch (SQLException e) {}; |
| | | if (stmt != null) try { stmt.close(); } catch (SQLException e) {}; |
| | | if (connection != null) try { connection.close(); } catch (SQLException e) {}; |
| | | } |
| | | } |
| | | |
| | | private void createIfNotExistNewSchema(Connection connection, String s) throws SQLException |
| | | { |
| | | Statement stmt = null; |
| | | ResultSet rs = null; |
| | | try |
| | | { |
| | | /* |
| | | rs = connection.getMetaData().getSchemas(null, s); |
| | | if (rs.next()) return; |
| | | rs.close(); |
| | | rs = null; |
| | | */ |
| | | |
| | | StringBuilder sbSQL = new StringBuilder("CREATE SCHEMA "); |
| | | sbSQL.append(s).append(' '); |
| | | sbSQL.append("AUTHORIZATION spatialdb"); |
| | | stmt = connection.createStatement(); |
| | | stmt.executeUpdate(sbSQL.toString()); |
| | | |
| | | sbSQL = new StringBuilder("GRANT ALL ON SCHEMA "); |
| | | sbSQL.append(s).append(' '); |
| | | sbSQL.append("TO public"); |
| | | stmt.executeUpdate(sbSQL.toString()); |
| | | } catch (SQLException e) |
| | | { |
| | | logger.info("create schema:" + s + " has exception."); |
| | | logger.info(e.getMessage(), e); |
| | | } finally { |
| | | if (rs != null) rs.close(); |
| | | if (stmt != null) stmt.close(); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.jobs; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileNotFoundException; |
| | | import java.io.FilenameFilter; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.ByteOrder; |
| | | import java.nio.channels.FileChannel; |
| | | import java.sql.ResultSet; |
| | | import java.sql.SQLException; |
| | | import java.sql.Statement; |
| | | import java.sql.Types; |
| | | import java.sql.Connection; |
| | | import java.util.Date; |
| | | |
| | | import org.apache.commons.collections.OrderedMap; |
| | | import org.apache.commons.collections.OrderedMapIterator; |
| | | import org.apache.commons.collections.map.LinkedMap; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | import org.quartz.JobDetail; |
| | | import org.quartz.JobExecutionContext; |
| | | import org.quartz.JobExecutionException; |
| | | |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | import oracle.jdbc.OracleConnection; |
| | | import oracle.jdbc.OracleResultSet; |
| | | import oracle.sql.ARRAY; |
| | | import oracle.sql.BLOB; |
| | | |
| | | import com.ximple.eofms.jobs.context.AbstractOracleJobContext; |
| | | import com.ximple.eofms.jobs.context.shapefile.FeatureDgnConvertShpJobContext; |
| | | import com.ximple.eofms.jobs.context.shapefile.GeneralDgnConvertShpJobContext; |
| | | import com.ximple.eofms.jobs.context.shapefile.IndexDgnConvertShpJobContext; |
| | | import com.ximple.eofms.jobs.context.shapefile.OracleConvertShapefilesJobContext; |
| | | import com.ximple.eofms.util.BinConverter; |
| | | import com.ximple.eofms.util.ByteArrayCompressor; |
| | | import com.ximple.eofms.util.StringUtils; |
| | | import com.ximple.io.dgn7.ComplexElement; |
| | | import com.ximple.io.dgn7.Dgn7fileException; |
| | | import com.ximple.io.dgn7.Dgn7fileReader; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.ElementType; |
| | | import com.ximple.io.dgn7.IElementHandler; |
| | | import com.ximple.io.dgn7.Lock; |
| | | import com.ximple.io.dgn7.TextElement; |
| | | import com.ximple.util.PrintfFormat; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | public class OracleConvertDgn2ShpJob extends AbstractOracleDatabaseJob |
| | | { |
| | | final static Log logger = LogFactory.getLog(OracleConvertDgn2ShpJob.class); |
| | | |
| | | private static final int FETCHSIZE = 30; |
| | | private static final int COMMITSIZE = 20; |
| | | |
| | | class Pair |
| | | { |
| | | Object first; |
| | | Object second; |
| | | |
| | | public Pair(Object first, Object second) |
| | | { |
| | | this.first = first; |
| | | this.second = second; |
| | | } |
| | | } |
| | | |
| | | GeometryFactory _geomFactory = new GeometryFactory(); |
| | | |
| | | public Log getLogger() |
| | | { |
| | | return logger; |
| | | } |
| | | |
| | | protected AbstractOracleJobContext prepareJobContext(String targetSchemaName, String filterPath) |
| | | { |
| | | return new OracleConvertShapefilesJobContext(filterPath); |
| | | } |
| | | |
| | | protected void extractJobConfiguration(JobDetail jobDetail) throws JobExecutionException |
| | | { |
| | | super.extractJobConfiguration(jobDetail); |
| | | } |
| | | |
| | | public void execute(JobExecutionContext context) throws JobExecutionException |
| | | { |
| | | // Every job has its own job detail |
| | | JobDetail jobDetail = context.getJobDetail(); |
| | | |
| | | // The name is defined in the job definition |
| | | String jobName = jobDetail.getName(); |
| | | |
| | | String targetSchemaName = null; |
| | | |
| | | // Log the time the job started |
| | | logger.info(jobName + " fired at " + new Date()); |
| | | extractJobConfiguration(jobDetail); |
| | | createSourceDataStore(); |
| | | if (getSourceDataStore() == null) |
| | | { |
| | | throw new JobExecutionException("Cannot connect source oracle database."); |
| | | } |
| | | |
| | | try |
| | | { |
| | | logger.info("-- step:clearOutputDirectory --"); |
| | | clearOutputDirectory(); |
| | | boolean bFirst = isCopyConnectivityMode(); |
| | | if (checkConvertDB()) |
| | | { |
| | | logger.info("-- step:convertOracleDB --"); |
| | | |
| | | for (String orgSchema : _orgSchema) |
| | | { |
| | | OracleConvertShapefilesJobContext jobContext = (OracleConvertShapefilesJobContext) prepareJobContext(targetSchemaName, _filterPath); |
| | | jobContext.setSourceDataStore(getSourceDataStore()); |
| | | jobContext.setDataPath(_dataPath); |
| | | jobContext.setConvertElementIn(_convertElementIn); |
| | | jobContext.setElementLogging(checkElementLogging()); |
| | | jobContext.setExecutionContext(context); |
| | | |
| | | if (bFirst) |
| | | { |
| | | copyConnectivity(jobContext); |
| | | bFirst = false; |
| | | } |
| | | |
| | | logger.info("----- start schema:" + orgSchema + " -----"); |
| | | exetcuteConvert(jobContext, orgSchema, _dataPath); |
| | | |
| | | //close all open filewriter instance |
| | | jobContext.closeFeatureWriter(); |
| | | } |
| | | } |
| | | |
| | | if (checkConvertFile()) |
| | | { |
| | | logger.info("-- step:convertIndexDesignFile --"); |
| | | convertIndexDesignFile(context); |
| | | logger.info("-- step:convertOtherDesignFile --"); |
| | | convertOtherDesignFile(context); |
| | | } |
| | | |
| | | if (checkConvertElementIn()) |
| | | { |
| | | logger.info("-- step:convertFeatureDesignFile --"); |
| | | convertFeatureDesignFile(context); |
| | | } |
| | | |
| | | if (checkCreateDummy()) |
| | | { |
| | | logger.info("-- step:createDummyFeatureFile --"); |
| | | createDummyFeatureFile(context); |
| | | } |
| | | |
| | | disconnect(); |
| | | } catch (SQLException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | throw new JobExecutionException("Database error. " + e.getMessage(), e); |
| | | } catch (IOException ex) |
| | | { |
| | | logger.warn(ex.getMessage(), ex); |
| | | throw new JobExecutionException("IO error. " + ex.getMessage(), ex); |
| | | } |
| | | logger.warn(jobName + " end at " + new Date()); |
| | | } |
| | | |
| | | /** |
| | | * Connectivity½Æ»s¤@Óª©¥»¡A¦b¬d¸ß¹q¬y¤è¦V®É¥Î¨Ó¤ñ¹ïOMS¸ê®Æ®wªº¹q¾¹³s±µ©Ê(Connectivity) |
| | | * |
| | | * @param jobContext job context |
| | | * @throws SQLException sql exception |
| | | */ |
| | | private void copyConnectivity(OracleConvertShapefilesJobContext jobContext) throws SQLException |
| | | { |
| | | Connection connection = jobContext.getOracleConnection(); |
| | | Statement stmt = connection.createStatement(); |
| | | stmt.execute(OracleConvertShapefilesJobContext.TRUNCATE_CONNECTIVITY_WEBCHECK); |
| | | stmt.execute(OracleConvertShapefilesJobContext.COPY_CONNECTIVITY_TO_WEBCHECK); |
| | | } |
| | | |
| | | private void exetcuteConvert(OracleConvertShapefilesJobContext jobContext, |
| | | String querySchema, String dataPath) throws SQLException |
| | | { |
| | | int order = 0; |
| | | OrderedMap map = getBlobStorageList(jobContext.getOracleConnection(), querySchema, "SD$SPACENODES" |
| | | , null); |
| | | |
| | | logger.info("begin convert job:[" + map.size() + "]:testmode=" + _testMode); |
| | | |
| | | int total = map.size(); //spacenodes count |
| | | int step = total / 100; |
| | | int current = 0; |
| | | |
| | | //jobContext.startTransaction(); |
| | | jobContext.setCurrentSchema(querySchema); |
| | | jobContext.getExecutionContext().put("ConvertDgn2ShpJobProgress", 0); |
| | | for (OrderedMapIterator it = map.orderedMapIterator(); it.hasNext();) |
| | | { |
| | | it.next(); |
| | | |
| | | Pair pair = (Pair) it.getValue(); |
| | | String tableSrc = (String) pair.first; |
| | | |
| | | logger.info("begin convert:[" + order + "]-" + tableSrc); |
| | | queryIgsetElement(jobContext, querySchema, tableSrc); |
| | | |
| | | order++; |
| | | |
| | | if (_testMode) |
| | | { |
| | | if ((_testCount < 0) || (order >= _testCount)) |
| | | break; |
| | | } |
| | | |
| | | if ((order % COMMITSIZE) == 0) |
| | | { |
| | | // OracleConnection connection = jobContext.getOracleConnection(); |
| | | // connection.commitTransaction(); |
| | | jobContext.commitTransaction(); |
| | | //jobContext.startTransaction(); |
| | | System.gc(); |
| | | System.runFinalization(); |
| | | } |
| | | |
| | | int now = order % step; |
| | | if (now != current) |
| | | { |
| | | current = now; |
| | | jobContext.getExecutionContext().put("ConvertDgn2ShpJobProgress", current); |
| | | |
| | | } |
| | | } |
| | | jobContext.getExecutionContext().put("ConvertDgn2ShpJobProgress", 100); |
| | | |
| | | jobContext.commitTransaction(); |
| | | |
| | | logger.info("end convert job:[" + order + "]"); |
| | | System.gc(); |
| | | System.runFinalization(); |
| | | } |
| | | |
| | | protected OrderedMap getBlobStorageList(Connection connection, String schemaSrc, String tableSrc, |
| | | OrderedMap orderedMap) throws SQLException |
| | | { |
| | | if (orderedMap == null) |
| | | orderedMap = new LinkedMap(99); |
| | | String fetchStmtFmt = "SELECT SNID, SPACETABLE FROM \"%s\".\"%s\""; |
| | | PrintfFormat spf = new PrintfFormat(fetchStmtFmt); |
| | | String fetchStmt = spf.sprintf(new Object[]{schemaSrc, tableSrc}); |
| | | Statement stmt = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
| | | ResultSet rs = null; |
| | | |
| | | stmt.setFetchSize(FETCHSIZE); |
| | | |
| | | try |
| | | { |
| | | rs = stmt.executeQuery(fetchStmt); |
| | | int size = rs.getMetaData().getColumnCount(); |
| | | |
| | | while (rs.next()) |
| | | { |
| | | Object[] values = new Object[size]; |
| | | |
| | | for (int i = 0; i < size; i++) |
| | | { |
| | | values[i] = rs.getObject(i + 1); |
| | | } |
| | | |
| | | Integer key = ((BigDecimal) values[0]).intValue(); |
| | | String name = (String) values[1]; |
| | | |
| | | Pair pair = (Pair) orderedMap.get(key); |
| | | if (pair == null) |
| | | orderedMap.put(key, new Pair(name, null)); |
| | | else |
| | | pair.first = name; |
| | | } |
| | | } catch (SQLException e) |
| | | { |
| | | logger.error(e.toString(), e); |
| | | logger.error("stmt=" + fetchStmt); |
| | | throw e; |
| | | } finally |
| | | { |
| | | if (rs != null) rs.close(); |
| | | stmt.close(); |
| | | } |
| | | |
| | | return orderedMap; |
| | | } |
| | | |
| | | protected OrderedMap getRawFormatStorageList(OracleConnection connection, String schemaSrc, String tableSrc, |
| | | OrderedMap orderedMap) throws SQLException |
| | | { |
| | | if (orderedMap == null) |
| | | orderedMap = new LinkedMap(99); |
| | | String fetchStmtFmt = "SELECT RNID, SPACETABLE FROM \"%s\".\"%s\""; |
| | | PrintfFormat spf = new PrintfFormat(fetchStmtFmt); |
| | | String fetchStmt = spf.sprintf(new Object[]{schemaSrc, tableSrc}); |
| | | Statement stmt = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
| | | |
| | | stmt.setFetchSize(FETCHSIZE); |
| | | ResultSet rs = stmt.executeQuery(fetchStmt); |
| | | int size = rs.getMetaData().getColumnCount(); |
| | | |
| | | while (rs.next()) |
| | | { |
| | | Object[] values = new Object[size]; |
| | | |
| | | for (int i = 0; i < size; i++) |
| | | { |
| | | values[i] = rs.getObject(i + 1); |
| | | } |
| | | |
| | | Integer key = ((BigDecimal) values[0]).intValue(); |
| | | String name = (String) values[1]; |
| | | |
| | | Pair pair = (Pair) orderedMap.get(key); |
| | | if (pair == null) |
| | | orderedMap.put(key, new Pair(null, name)); |
| | | else |
| | | pair.second = name; |
| | | } |
| | | |
| | | rs.close(); |
| | | stmt.close(); |
| | | |
| | | return orderedMap; |
| | | } |
| | | |
| | | protected void queryIgsetElement(OracleConvertShapefilesJobContext jobContext, |
| | | String srcschema, String srctable) throws SQLException |
| | | { |
| | | Connection connection = jobContext.getOracleConnection(); |
| | | String fetchSrcStmtFmt = "SELECT IGDSELM FROM \"%s\".\"%s\" ORDER BY ROWID"; |
| | | PrintfFormat spf = new PrintfFormat(fetchSrcStmtFmt); |
| | | String fetchSrcStmt = spf.sprintf(new Object[]{srcschema, srctable}); |
| | | Statement stmtSrc = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
| | | |
| | | stmtSrc.setFetchSize(FETCHSIZE); |
| | | |
| | | ResultSet rsSrc = stmtSrc.executeQuery(fetchSrcStmt); |
| | | int igdsMetaType = rsSrc.getMetaData().getColumnType(1); |
| | | while (rsSrc.next()) |
| | | { |
| | | byte[] raw; |
| | | |
| | | if (igdsMetaType == Types.BLOB) |
| | | { |
| | | BLOB blob = (BLOB) rsSrc.getBlob(1); |
| | | |
| | | raw = getBytesFromBLOB(blob); |
| | | blob.close(); |
| | | } else |
| | | { |
| | | raw = rsSrc.getBytes(1); |
| | | } |
| | | |
| | | try |
| | | { |
| | | Element element = fetchBinaryElement(raw); |
| | | jobContext.putFeatureCollection(element); |
| | | } catch (Dgn7fileException e) |
| | | { |
| | | logger.warn("Dgn7Exception", e); |
| | | } |
| | | } |
| | | |
| | | rsSrc.close(); |
| | | stmtSrc.close(); |
| | | } |
| | | |
| | | protected void queryRawElement(OracleConvertShapefilesJobContext jobContext, |
| | | String srcschema, String srctable) throws SQLException |
| | | { |
| | | Connection connection = jobContext.getOracleConnection(); |
| | | String fetchDestStmtFmt = "SELECT ELEMENT FROM \"%s\".\"%s\" ORDER BY ROWID"; |
| | | PrintfFormat spf = new PrintfFormat(fetchDestStmtFmt); |
| | | String fetchDestStmt = spf.sprintf(new Object[]{srcschema, srctable}); |
| | | Statement stmtDest = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
| | | |
| | | stmtDest.setFetchSize(FETCHSIZE); |
| | | |
| | | ResultSet rsDest = stmtDest.executeQuery(fetchDestStmt); |
| | | |
| | | while (rsDest.next()) |
| | | { |
| | | ARRAY rawsValue = ((OracleResultSet) rsDest).getARRAY(1); |
| | | long[] rawData = rawsValue.getLongArray(); |
| | | byte[] comparessedValue; |
| | | |
| | | /* |
| | | if (dataMode == TransferTask.DataMode.Normal) |
| | | { |
| | | comparessedValue = BinConverter.unmarshalByteArray(rawData, true); |
| | | } else |
| | | { |
| | | comparessedValue = BinConverter.unmarshalCompactByteArray(rawData); |
| | | } |
| | | */ |
| | | comparessedValue = BinConverter.unmarshalByteArray(rawData, true); |
| | | |
| | | byte[] rawDest = ByteArrayCompressor.decompressByteArray(comparessedValue); |
| | | |
| | | |
| | | try |
| | | { |
| | | Element element = fetchBinaryElement(rawDest); |
| | | jobContext.putFeatureCollection(element); |
| | | } catch (Dgn7fileException e) |
| | | { |
| | | logger.warn("Dgn7Exception:" + e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | rsDest.close(); |
| | | stmtDest.close(); |
| | | } |
| | | |
| | | // Binary to Element |
| | | private Element fetchBinaryElement(byte[] raws) throws Dgn7fileException |
| | | { |
| | | ByteBuffer buffer = ByteBuffer.wrap(raws); |
| | | buffer.order(ByteOrder.LITTLE_ENDIAN); |
| | | short signature = buffer.getShort(); |
| | | |
| | | // byte type = (byte) (buffer.get() & 0x7f); |
| | | byte type = (byte) ((signature >>> 8) & 0x007f); |
| | | |
| | | // silly Bentley say contentLength is in 2-byte words |
| | | // and ByteByffer uses raws. |
| | | // track the record location |
| | | int elementLength = (buffer.getShort() * 2) + 4; |
| | | ElementType recordType = ElementType.forID(type); |
| | | IElementHandler handler; |
| | | |
| | | handler = recordType.getElementHandler(); |
| | | |
| | | Element dgnElement = (Element) handler.read(buffer, signature, elementLength); |
| | | if (recordType.isComplexElement() && (elementLength < raws.length)) |
| | | { |
| | | int offset = elementLength; |
| | | while (offset < (raws.length - 4)) |
| | | { |
| | | buffer.position(offset); |
| | | signature = buffer.getShort(); |
| | | type = (byte) ((signature >>> 8) & 0x007f); |
| | | elementLength = (buffer.getShort() * 2) + 4; |
| | | if (raws.length < (offset + elementLength)) |
| | | { |
| | | System.out.println("Length not match:" + offset + ":" + buffer.position() + ":" + buffer.limit()); |
| | | break; |
| | | } |
| | | recordType = ElementType.forID(type); |
| | | handler = recordType.getElementHandler(); |
| | | if (handler != null) |
| | | { |
| | | Element subElement = (Element) handler.read(buffer, signature, elementLength); |
| | | ((ComplexElement) dgnElement).add(subElement); |
| | | offset += elementLength; |
| | | } else |
| | | { |
| | | byte[] remain = new byte[buffer.remaining()]; |
| | | System.arraycopy(raws, offset, remain, 0, buffer.remaining()); |
| | | for (int i = 0; i < remain.length; i++) |
| | | { |
| | | if (remain[i] != 0) |
| | | { |
| | | logger.info("fetch element has some error. index=" + (offset + i) + ":value=" + remain[i]); |
| | | System.out.println("fetch element has some error. index=" + (offset + i) + ":value=" + remain[i]); |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return dgnElement; |
| | | } |
| | | |
| | | /** |
| | | * °õ¦æÂà´«¯Á¤Þ¹ÏÀɪº¤u§@ |
| | | * |
| | | * @param context ¤u§@°õ¦æÀô¹Ò |
| | | * @throws org.quartz.JobExecutionException |
| | | * exception |
| | | */ |
| | | private void convertIndexDesignFile(JobExecutionContext context) throws JobExecutionException |
| | | { |
| | | File indexDir = new File(getDataPath(), "index"); |
| | | if (!indexDir.exists()) |
| | | { |
| | | logger.info("index dir=" + indexDir + " not exist."); |
| | | return; |
| | | } |
| | | |
| | | if (!indexDir.isDirectory()) |
| | | { |
| | | logger.info("index dir=" + indexDir + " is not a directory."); |
| | | } |
| | | |
| | | File[] dgnFiles = indexDir.listFiles(new FilenameFilter() |
| | | { |
| | | public boolean accept(File dir, String name) |
| | | { |
| | | return name.toLowerCase().endsWith(".dgn"); |
| | | } |
| | | }); |
| | | |
| | | for (File dgnFile : dgnFiles) |
| | | { |
| | | IndexDgnConvertShpJobContext convertContext = new IndexDgnConvertShpJobContext(getDataPath()); |
| | | logger.debug("--- start dgnfile-" + dgnFile.toString() + " ---"); |
| | | try |
| | | { |
| | | convertContext.setExecutionContext(context); |
| | | String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.separator); |
| | | convertContext.setFilename(dgnPaths[dgnPaths.length - 1]); |
| | | convertContext.startTransaction(); |
| | | |
| | | FileInputStream fs = new FileInputStream(dgnFile); |
| | | FileChannel fc = fs.getChannel(); |
| | | Dgn7fileReader reader = new Dgn7fileReader(fc, new Lock()); |
| | | convertContext.setReader(reader); |
| | | |
| | | scanIndexDgnElement(convertContext); |
| | | |
| | | convertContext.commitTransaction(); |
| | | convertContext.closeFeatureWriter(); |
| | | System.gc(); |
| | | System.runFinalization(); |
| | | } 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); |
| | | } |
| | | } |
| | | } |
| | | |
| | | protected void scanIndexDgnElement(IndexDgnConvertShpJobContext 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())) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processIndexElement(lastComplex, convertContext); |
| | | lastComplex = null; |
| | | } |
| | | |
| | | processIndexElement(element, convertContext); |
| | | } else if (element.isComponentElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | ((ComplexElement) lastComplex).add(element); |
| | | } |
| | | } else if (type.isComplexElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processIndexElement(lastComplex, convertContext); |
| | | } |
| | | lastComplex = element; |
| | | } |
| | | } |
| | | count++; |
| | | } |
| | | |
| | | if (lastComplex != null) |
| | | { |
| | | processIndexElement(lastComplex, convertContext); |
| | | } |
| | | |
| | | logger.debug("ElementRecord Count=" + count); |
| | | } |
| | | |
| | | private void processIndexElement(Element element, IndexDgnConvertShpJobContext convertContext) throws IllegalAttributeException, SchemaException |
| | | { |
| | | if (element instanceof TextElement) |
| | | { |
| | | convertContext.putFeatureCollection(element); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * °õ¦æÂà´«¨ä¥L³]p¹ÏÀɪº¤u§@ |
| | | * |
| | | * @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("other dir=" + otherDir + " not exist."); |
| | | return; |
| | | } |
| | | |
| | | if (!otherDir.isDirectory()) |
| | | { |
| | | logger.info("other dir=" + otherDir + " is not a directory."); |
| | | } |
| | | |
| | | File[] dgnFiles = otherDir.listFiles(new FilenameFilter() |
| | | { |
| | | public boolean accept(File dir, String name) |
| | | { |
| | | return name.toLowerCase().endsWith(".dgn"); |
| | | } |
| | | }); |
| | | |
| | | for (File dgnFile : dgnFiles) |
| | | { |
| | | GeneralDgnConvertShpJobContext convertContext = new GeneralDgnConvertShpJobContext(getDataPath()); |
| | | logger.info("--- start dgnfile-" + dgnFile.toString() + " ---"); |
| | | try |
| | | { |
| | | convertContext.setExecutionContext(context); |
| | | String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.separator); |
| | | convertContext.setFilename(dgnPaths[dgnPaths.length - 1]); |
| | | convertContext.startTransaction(); |
| | | |
| | | FileInputStream fs = new FileInputStream(dgnFile); |
| | | FileChannel fc = fs.getChannel(); |
| | | Dgn7fileReader reader = new Dgn7fileReader(fc, new Lock()); |
| | | convertContext.setReader(reader); |
| | | |
| | | scanOtherDgnElement(convertContext); |
| | | |
| | | convertContext.commitTransaction(); |
| | | convertContext.closeFeatureWriter(); |
| | | System.gc(); |
| | | System.runFinalization(); |
| | | } 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 scanOtherDgnElement(GeneralDgnConvertShpJobContext 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())) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processOtherElement(lastComplex, convertContext); |
| | | lastComplex = null; |
| | | } |
| | | |
| | | processOtherElement(element, convertContext); |
| | | } else if (element.isComponentElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | ((ComplexElement) lastComplex).add(element); |
| | | } |
| | | } else if (type.isComplexElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processOtherElement(lastComplex, convertContext); |
| | | } |
| | | lastComplex = element; |
| | | } |
| | | } |
| | | count++; |
| | | } |
| | | |
| | | if (lastComplex != null) |
| | | { |
| | | processOtherElement(lastComplex, convertContext); |
| | | } |
| | | |
| | | logger.debug("ElementRecord Count=" + count); |
| | | } |
| | | |
| | | private void processOtherElement(Element element, GeneralDgnConvertShpJobContext convertContext) |
| | | throws IllegalAttributeException, SchemaException |
| | | { |
| | | convertContext.putFeatureCollection(element); |
| | | } |
| | | |
| | | private void clearOutputDirectory() |
| | | { |
| | | File outDataPath = new File(getDataPath(), OracleConvertShapefilesJobContext.SHPOUTPATH); |
| | | if (outDataPath.exists() && outDataPath.isDirectory()) |
| | | { |
| | | deleteFilesInPath(outDataPath); |
| | | } |
| | | outDataPath = new File(getDataPath(), IndexDgnConvertShpJobContext.SHPOUTPATH); |
| | | if (outDataPath.exists() && outDataPath.isDirectory()) |
| | | { |
| | | deleteFilesInPath(outDataPath); |
| | | } |
| | | outDataPath = new File(getDataPath(), GeneralDgnConvertShpJobContext.SHPOUTPATH); |
| | | if (outDataPath.exists() && outDataPath.isDirectory()) |
| | | { |
| | | deleteFilesInPath(outDataPath); |
| | | } |
| | | } |
| | | |
| | | private void deleteFilesInPath(File outDataPath) |
| | | { |
| | | deleteFilesInPath(outDataPath, true); |
| | | } |
| | | |
| | | private void deleteFilesInPath(File outDataPath, boolean removeSubDir) |
| | | { |
| | | if (!outDataPath.isDirectory()) |
| | | { |
| | | return; |
| | | } |
| | | File[] files = outDataPath.listFiles(); |
| | | for (File file : files) |
| | | { |
| | | if (file.isFile()) |
| | | { |
| | | if (!file.delete()) |
| | | { |
| | | logger.info("Cannot delete file-" + file.toString()); |
| | | } |
| | | } else if (file.isDirectory()) |
| | | { |
| | | deleteFilesInPath(file, removeSubDir); |
| | | if (removeSubDir) |
| | | { |
| | | if (file.delete()) |
| | | { |
| | | logger.info("Cannot delete dir-" + file.toString()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | 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) |
| | | { |
| | | FeatureDgnConvertShpJobContext convertContext = new FeatureDgnConvertShpJobContext(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]); |
| | | convertContext.startTransaction(); |
| | | |
| | | 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(); |
| | | System.runFinalization(); |
| | | } 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(FeatureDgnConvertShpJobContext 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())) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processFeatureElement(lastComplex, convertContext); |
| | | lastComplex = null; |
| | | } |
| | | |
| | | processFeatureElement(element, convertContext); |
| | | } else if (element.isComponentElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | ((ComplexElement) lastComplex).add(element); |
| | | } |
| | | } else if (type.isComplexElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | processFeatureElement(lastComplex, convertContext); |
| | | } |
| | | lastComplex = element; |
| | | } |
| | | } |
| | | count++; |
| | | } |
| | | |
| | | if (lastComplex != null) |
| | | { |
| | | processFeatureElement(lastComplex, convertContext); |
| | | } |
| | | logger.debug("ElementRecord Count=" + count); |
| | | } |
| | | |
| | | private void processFeatureElement(Element element, FeatureDgnConvertShpJobContext convertContext) |
| | | throws IllegalAttributeException, SchemaException |
| | | { |
| | | convertContext.putFeatureCollection(element); |
| | | } |
| | | |
| | | private void createDummyFeatureFile(JobExecutionContext context) throws JobExecutionException |
| | | { |
| | | /* |
| | | DummyFeatureConvertShpJobContext convertContext = new DummyFeatureConvertShpJobContext(getDataPath(), _filterPath); |
| | | try { |
| | | convertContext.startTransaction(); |
| | | convertContext.commitTransaction(); |
| | | convertContext.closeFeatureWriter(); |
| | | } catch (IOException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | throw new JobExecutionException(e.getMessage(), e); |
| | | } |
| | | */ |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.jobs; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.channels.FileChannel; |
| | | import java.sql.Connection; |
| | | import java.sql.ResultSet; |
| | | import java.sql.SQLException; |
| | | import java.sql.Statement; |
| | | import java.sql.Types; |
| | | import java.util.ArrayList; |
| | | import java.util.ListIterator; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | |
| | | import com.vividsolutions.jts.util.Assert; |
| | | |
| | | import oracle.sql.BLOB; |
| | | |
| | | import com.ximple.eofms.util.PrintfFormat; |
| | | import com.ximple.io.dgn7.ArcElement; |
| | | import com.ximple.io.dgn7.ComplexChainElement; |
| | | import com.ximple.io.dgn7.ComplexShapeElement; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.EllipseElement; |
| | | import com.ximple.io.dgn7.LineElement; |
| | | import com.ximple.io.dgn7.LineStringElement; |
| | | import com.ximple.io.dgn7.ShapeElement; |
| | | import com.ximple.io.dgn7.TextElement; |
| | | import com.ximple.io.dgn7.TextNodeElement; |
| | | import com.ximple.io.dgn7.IElementHandler; |
| | | import com.ximple.io.dgn7.Dgn7fileException; |
| | | |
| | | public class OracleElementLogger |
| | | { |
| | | static Log logger = LogFactory.getLog(OracleElementLogger.class); |
| | | private static final String DEFAULT_ELMOUTPATH = "elmout"; |
| | | private static final String TAB_IGDSSEED = "SD$IGDSSET_SEED"; |
| | | |
| | | private Connection connection; |
| | | private String dataOut = null; |
| | | private String dataPath; |
| | | private String currentSchema; |
| | | private boolean schemaChanged; |
| | | private FileOutputStream fos = null; |
| | | private FileChannel fch = null; |
| | | private int logCount = 0; |
| | | private int elmCount = 0; |
| | | private int maxElmCount = 3000; |
| | | private boolean useElementCount = true; |
| | | private ArrayList<byte[]> dgnFileHeader = null; |
| | | private String elmOutPath; |
| | | private String prefix = null; |
| | | |
| | | public OracleElementLogger(Connection connection) |
| | | { |
| | | this.connection = connection; |
| | | elmOutPath = DEFAULT_ELMOUTPATH; |
| | | } |
| | | |
| | | public OracleElementLogger(Connection connection, String elmOutPath) |
| | | { |
| | | this.connection = connection; |
| | | this.elmOutPath = elmOutPath; |
| | | } |
| | | |
| | | public OracleElementLogger(Connection connection, int maxCount) |
| | | { |
| | | this.connection = connection; |
| | | elmOutPath = DEFAULT_ELMOUTPATH; |
| | | this.maxElmCount = maxCount; |
| | | } |
| | | |
| | | public OracleElementLogger(Connection connection, String elmOutPath, int maxCount) |
| | | { |
| | | this.connection = connection; |
| | | this.elmOutPath = elmOutPath; |
| | | this.maxElmCount = maxCount; |
| | | } |
| | | |
| | | public String getDataOutPath() |
| | | { |
| | | if (dataOut == null) |
| | | { |
| | | File outPath = new File(getDataPath(), elmOutPath); |
| | | if (!outPath.exists()) |
| | | { |
| | | outPath.mkdir(); |
| | | } else if (!outPath.isDirectory()) |
| | | { |
| | | outPath.mkdir(); |
| | | } |
| | | dataOut = outPath.toString(); |
| | | } |
| | | return dataOut; |
| | | } |
| | | |
| | | public String getDataPath() |
| | | { |
| | | return dataPath; |
| | | } |
| | | |
| | | public void setDataPath(String dataPath) |
| | | { |
| | | this.dataPath = dataPath; |
| | | } |
| | | |
| | | public void logElement(Element element, String currentSchema) |
| | | { |
| | | if ((this.currentSchema == null) || |
| | | (!this.currentSchema.equalsIgnoreCase(currentSchema))) |
| | | { |
| | | schemaChanged = true; |
| | | this.currentSchema = currentSchema; |
| | | try |
| | | { |
| | | createNewStream(); |
| | | } catch (IOException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | return; |
| | | } catch (SQLException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | return; |
| | | } |
| | | } else |
| | | { |
| | | if (fch == null) |
| | | { |
| | | try |
| | | { |
| | | createNewStream(); |
| | | } catch (IOException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | return; |
| | | } catch (SQLException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | |
| | | ArrayList<ByteBuffer> subBuffers = new ArrayList<ByteBuffer>(); |
| | | if (fch != null) |
| | | { |
| | | ByteBuffer buf = null; |
| | | if (element instanceof LineElement) |
| | | { |
| | | int size = LineElement.ElementHandler.getInstance().getLength(element); |
| | | buf = ByteBuffer.allocate(size * 2); |
| | | LineElement.ElementHandler.getInstance().write(buf, element); |
| | | } else if (element instanceof ShapeElement) |
| | | { |
| | | int size = ShapeElement.ElementHandler.getInstance().getLength(element); |
| | | buf = ByteBuffer.allocate(size * 2); |
| | | ShapeElement.ElementHandler.getInstance().write(buf, element); |
| | | } else if (element instanceof LineStringElement) |
| | | { |
| | | int size = LineStringElement.ElementHandler.getInstance().getLength(element); |
| | | buf = ByteBuffer.allocate(size * 2); |
| | | LineStringElement.ElementHandler.getInstance().write(buf, element); |
| | | } else if (element instanceof ComplexChainElement) |
| | | { |
| | | int size = ComplexChainElement.ElementHandler.getInstance().getLength(element); |
| | | buf = ByteBuffer.allocate(size * 2); |
| | | ComplexChainElement.ElementHandler.getInstance().write(buf, element); |
| | | ComplexChainElement complexElement = (ComplexChainElement) element; |
| | | ListIterator it = complexElement.listIterator(); |
| | | while (it.hasNext()) |
| | | { |
| | | Element subElm = (Element) it.next(); |
| | | try |
| | | { |
| | | IElementHandler handler = subElm.getElementType().getElementHandler(); |
| | | size = handler.getLength(subElm); |
| | | ByteBuffer subBuf = ByteBuffer.allocate(size * 2); |
| | | handler.write(subBuf, subElm); |
| | | subBuffers.add(subBuf); |
| | | } catch (Dgn7fileException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | } |
| | | } |
| | | } else if (element instanceof ComplexShapeElement) |
| | | { |
| | | int size = ComplexShapeElement.ElementHandler.getInstance().getLength(element); |
| | | buf = ByteBuffer.allocate(size * 2); |
| | | ComplexShapeElement.ElementHandler.getInstance().write(buf, element); |
| | | ComplexShapeElement complexElement = (ComplexShapeElement) element; |
| | | ListIterator it = complexElement.listIterator(); |
| | | while (it.hasNext()) |
| | | { |
| | | Element subElm = (Element) it.next(); |
| | | try |
| | | { |
| | | IElementHandler handler = subElm.getElementType().getElementHandler(); |
| | | size = handler.getLength(subElm); |
| | | ByteBuffer subBuf = ByteBuffer.allocate(size * 2); |
| | | handler.write(subBuf, subElm); |
| | | subBuffers.add(subBuf); |
| | | } catch (Dgn7fileException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | } |
| | | } |
| | | } else if (element instanceof ArcElement) |
| | | { |
| | | int size = ArcElement.ElementHandler.getInstance().getLength(element); |
| | | buf = ByteBuffer.allocate(size * 2); |
| | | ArcElement.ElementHandler.getInstance().write(buf, element); |
| | | } else if (element instanceof EllipseElement) |
| | | { |
| | | int size = EllipseElement.ElementHandler.getInstance().getLength(element); |
| | | buf = ByteBuffer.allocate(size * 2); |
| | | EllipseElement.ElementHandler.getInstance().write(buf, element); |
| | | } else if (element instanceof TextElement) |
| | | { |
| | | int size = TextElement.ElementHandler.getInstance().getLength(element); |
| | | buf = ByteBuffer.allocate(size * 2); |
| | | TextElement.ElementHandler.getInstance().write(buf, element); |
| | | } else if (element instanceof TextNodeElement) |
| | | { |
| | | int size = TextNodeElement.ElementHandler.getInstance().getLength(element); |
| | | buf = ByteBuffer.allocate(size * 2); |
| | | TextNodeElement.ElementHandler.getInstance().write(buf, element); |
| | | TextNodeElement nodeElement = (TextNodeElement) element; |
| | | ListIterator it = nodeElement.listIterator(); |
| | | while (it.hasNext()) |
| | | { |
| | | Element subElm = (Element) it.next(); |
| | | try |
| | | { |
| | | IElementHandler handler = subElm.getElementType().getElementHandler(); |
| | | size = handler.getLength(subElm); |
| | | ByteBuffer subBuf = ByteBuffer.allocate(size * 2); |
| | | handler.write(subBuf, subElm); |
| | | subBuffers.add(subBuf); |
| | | } catch (Dgn7fileException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if ((buf != null) && (fch != null)) |
| | | { |
| | | try |
| | | { |
| | | buf.position(0); |
| | | int size = fch.write(buf); |
| | | if (size != buf.limit()) |
| | | { |
| | | long position = fch.position(); |
| | | logger.info("Pos:" + position); |
| | | } |
| | | } catch (IOException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | elmCount++; |
| | | if ((subBuffers.size() != 0) && (fch != null)) |
| | | { |
| | | for (ByteBuffer buf : subBuffers) |
| | | { |
| | | try |
| | | { |
| | | buf.position(0); |
| | | int size = fch.write(buf); |
| | | if (size != buf.limit()) |
| | | { |
| | | long position = fch.position(); |
| | | logger.info("Pos:" + position); |
| | | } |
| | | } catch (IOException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void createNewStream() throws IOException, SQLException |
| | | { |
| | | if (fos != null) |
| | | { |
| | | putEndOfFileElement(); |
| | | fos.close(); |
| | | fos = null; |
| | | fch = null; |
| | | } |
| | | |
| | | String outLogName = currentSchema + ".dgn"; |
| | | if (prefix != null) |
| | | { |
| | | outLogName = prefix + outLogName; |
| | | } |
| | | File logFile = new File(getDataOutPath(), outLogName); |
| | | while (logFile.exists()) |
| | | { |
| | | outLogName = this.currentSchema + "-" + (++logCount) + ".dgn"; |
| | | if (prefix != null) |
| | | { |
| | | outLogName = prefix + outLogName; |
| | | } |
| | | |
| | | logFile = new File(getDataOutPath(), outLogName); |
| | | } |
| | | |
| | | logger.warn("Create Dgn Logging File:" + logFile.toString()); |
| | | fos = new FileOutputStream(logFile); |
| | | fch = fos.getChannel(); |
| | | prepareOutputElementStream(); |
| | | schemaChanged = false; |
| | | elmCount = 0; |
| | | } |
| | | |
| | | private void putEndOfFileElement() throws IOException |
| | | { |
| | | if (fch == null) |
| | | return; |
| | | ByteBuffer bf = ByteBuffer.allocate(4); |
| | | bf.putInt(-1); |
| | | fch.write(bf); |
| | | } |
| | | |
| | | private void prepareOutputElementStream() throws SQLException, IOException |
| | | { |
| | | if (connection == null) |
| | | { |
| | | logger.warn("connection is null"); |
| | | return; |
| | | } |
| | | |
| | | if (dgnFileHeader != null) |
| | | { |
| | | for (byte[] raw : dgnFileHeader) |
| | | { |
| | | putElementIntoStream(raw); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | dgnFileHeader = new ArrayList<byte[]>(); |
| | | String fetchSrcStmtFmt = "SELECT IGDSELM FROM \"%s\".\"%s\" ORDER BY ROWID"; |
| | | PrintfFormat spf = new PrintfFormat(fetchSrcStmtFmt); |
| | | String fetchSrcStmt = spf.sprintf(new Object[]{currentSchema, TAB_IGDSSEED}); |
| | | Statement stmtSrc = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
| | | ResultSet rsSrc = stmtSrc.executeQuery(fetchSrcStmt); |
| | | int igdsMetaType = rsSrc.getMetaData().getColumnType(1); |
| | | |
| | | while (rsSrc.next()) |
| | | { |
| | | byte[] raw; |
| | | |
| | | if (igdsMetaType == Types.BLOB) |
| | | { |
| | | BLOB blob = (BLOB) rsSrc.getBlob(1); |
| | | |
| | | raw = getBytesFromBLOB(blob); |
| | | blob.close(); |
| | | } else |
| | | { |
| | | raw = rsSrc.getBytes(1); |
| | | } |
| | | |
| | | if (raw != null) |
| | | { |
| | | dgnFileHeader.add(raw); |
| | | putElementIntoStream(raw); |
| | | } |
| | | } |
| | | rsSrc.close(); |
| | | stmtSrc.close(); |
| | | } |
| | | |
| | | private void putElementIntoStream(byte[] raw) throws IOException |
| | | { |
| | | if (fch != null) |
| | | fch.write(ByteBuffer.wrap(raw)); |
| | | } |
| | | |
| | | protected static byte[] getBytesFromBLOB(BLOB blob) throws SQLException |
| | | { |
| | | byte[] raw = null; |
| | | |
| | | int optimalSize = blob.getChunkSize(); |
| | | byte[] chunk = new byte[optimalSize]; |
| | | InputStream is = blob.getBinaryStream(0); |
| | | ByteBuffer buffer = null; // ByteBuffer.allocate(optimalSize); |
| | | int len; |
| | | |
| | | try |
| | | { |
| | | while ((len = (is.read(chunk))) != -1) |
| | | { |
| | | if (buffer != null) |
| | | { |
| | | buffer.limit(buffer.limit() + len); |
| | | } else |
| | | { |
| | | buffer = ByteBuffer.allocate(len); |
| | | } |
| | | |
| | | buffer.put(chunk); |
| | | } |
| | | |
| | | is.close(); |
| | | assert buffer != null; |
| | | buffer.position(0); |
| | | raw = buffer.array(); |
| | | } catch (IOException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | Assert.shouldNeverReachHere(); |
| | | } |
| | | return raw; |
| | | } |
| | | |
| | | public void flashLogging() |
| | | { |
| | | if ((useElementCount) && (elmCount < maxElmCount)) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | if (fos != null) |
| | | { |
| | | try |
| | | { |
| | | putEndOfFileElement(); |
| | | fos.close(); |
| | | } catch (IOException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | } |
| | | fos = null; |
| | | fch = null; |
| | | elmCount = 0; |
| | | } |
| | | } |
| | | |
| | | public boolean isSchemaChanged() |
| | | { |
| | | return schemaChanged; |
| | | } |
| | | |
| | | public boolean isUseElementCount() |
| | | { |
| | | return useElementCount; |
| | | } |
| | | |
| | | public void setUseElementCount(boolean useElementCount) |
| | | { |
| | | this.useElementCount = useElementCount; |
| | | } |
| | | |
| | | public int getElmCount() |
| | | { |
| | | return elmCount; |
| | | } |
| | | |
| | | public int getMaxElmCount() |
| | | { |
| | | return maxElmCount; |
| | | } |
| | | |
| | | public void setMaxElmCount(int maxElmCount) |
| | | { |
| | | this.maxElmCount = maxElmCount; |
| | | } |
| | | |
| | | public String getLogPrefix() |
| | | { |
| | | return prefix; |
| | | } |
| | | |
| | | public void setLogPrefix(String prefix) |
| | | { |
| | | this.prefix = prefix; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.jobs; |
| | | |
| | | import java.sql.SQLException; |
| | | import java.sql.Connection; |
| | | import java.util.Date; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.quartz.JobDetail; |
| | | import org.quartz.JobExecutionContext; |
| | | import org.quartz.JobExecutionException; |
| | | |
| | | import oracle.jdbc.OracleConnection; |
| | | import oracle.jdbc.OracleDatabaseMetaData; |
| | | import oracle.jdbc.OracleStatement; |
| | | |
| | | import com.ximple.eofms.jobs.context.AbstractOracleJobContext; |
| | | import com.ximple.eofms.jobs.context.OracleUpgradeJobContext; |
| | | |
| | | public class OracleUpgradeBlob2UDTJob extends AbstractOracleDatabaseJob |
| | | { |
| | | static Log logger = LogFactory.getLog(OracleUpgradeBlob2UDTJob.class); |
| | | |
| | | public void execute(JobExecutionContext context) throws JobExecutionException |
| | | { |
| | | // Every job has its own job detail |
| | | JobDetail jobDetail = context.getJobDetail(); |
| | | |
| | | // The name is defined in the job definition |
| | | String jobName = jobDetail.getName(); |
| | | String targetSchemaName = null; |
| | | |
| | | // Log the time the job started |
| | | logger.info(jobName + " fired at " + new Date()); |
| | | extractJobConfiguration(jobDetail); |
| | | createSourceDataStore(); |
| | | if (getSourceDataStore() == null) |
| | | { |
| | | throw new JobExecutionException("Cannot connect source oracle database."); |
| | | } |
| | | |
| | | AbstractOracleJobContext jobContext = prepareJobContext(targetSchemaName, _filterPath); |
| | | jobContext.setSourceDataStore(getSourceDataStore()); |
| | | |
| | | try |
| | | { |
| | | for (String orgSchema : _orgSchema) |
| | | { |
| | | exetcuteConvert(jobContext, orgSchema, _dataPath); |
| | | } |
| | | } catch (SQLException e) |
| | | { |
| | | throw new JobExecutionException("Database error.", e); |
| | | } |
| | | } |
| | | |
| | | public Log getLogger() |
| | | { |
| | | return logger; |
| | | } |
| | | |
| | | protected AbstractOracleJobContext prepareJobContext(String targetSchemaName, String filterPath) |
| | | { |
| | | return new OracleUpgradeJobContext(); |
| | | } |
| | | |
| | | private void exetcuteConvert(AbstractOracleJobContext jobContext, |
| | | String orgSchema, String dataPath) throws SQLException |
| | | { |
| | | Connection connection = jobContext.getOracleConnection(); |
| | | OracleDatabaseMetaData metaData = (OracleDatabaseMetaData) connection.getMetaData(); |
| | | OracleStatement statement = (OracleStatement) connection.createStatement(); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.jobs.context;
|
| | |
|
| | | import java.util.Map;
|
| | |
|
| | | import org.apache.commons.logging.Log;
|
| | | import org.quartz.JobExecutionContext;
|
| | |
|
| | | import com.ximple.io.dgn7.Dgn7fileReader;
|
| | |
|
| | | public abstract class AbstractDgnFileJobContext
|
| | | {
|
| | | /**
|
| | | * Encoding of URL path.
|
| | | */
|
| | | protected static final String ENCODING = "UTF-8";
|
| | |
|
| | | private JobExecutionContext executionContext = null;
|
| | |
|
| | | protected String _dataPath = null;
|
| | | protected Map properties = null;
|
| | |
|
| | | private Dgn7fileReader reader = null;
|
| | | private String filename = null;
|
| | | private boolean _elementLogging;
|
| | |
|
| | | public AbstractDgnFileJobContext(String dataPath)
|
| | | {
|
| | | _dataPath = dataPath;
|
| | | }
|
| | |
|
| | | public String getDataPath()
|
| | | {
|
| | | return _dataPath;
|
| | | }
|
| | |
|
| | | public JobExecutionContext getExecutionContext()
|
| | | {
|
| | | return executionContext;
|
| | | }
|
| | |
|
| | | public void setExecutionContext(JobExecutionContext context)
|
| | | {
|
| | | executionContext = context;
|
| | | }
|
| | |
|
| | | public abstract void startTransaction();
|
| | |
|
| | | public abstract void commitTransaction();
|
| | |
|
| | | public abstract void rollbackTransaction();
|
| | |
|
| | | public Dgn7fileReader getReader()
|
| | | {
|
| | | return this.reader;
|
| | | }
|
| | |
|
| | | public void setReader(Dgn7fileReader reader)
|
| | | {
|
| | | this.reader = reader;
|
| | | }
|
| | |
|
| | | public String getFilename()
|
| | | {
|
| | | return filename;
|
| | | }
|
| | |
|
| | | public void setFilename(String filename)
|
| | | {
|
| | | this.filename = filename;
|
| | | }
|
| | |
|
| | | public boolean getElementLogging()
|
| | | {
|
| | | return _elementLogging;
|
| | | }
|
| | |
|
| | | public void setElementLogging(boolean elementLogging)
|
| | | {
|
| | | this._elementLogging = elementLogging;
|
| | | }
|
| | |
|
| | | public abstract Log getLogger();
|
| | | }
|
New file |
| | |
| | | package com.ximple.eofms.jobs.context; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.Properties; |
| | | import java.sql.Connection; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | | import org.geotools.data.DataStore; |
| | | import org.geotools.data.Transaction; |
| | | import org.geotools.data.oracle.OracleDataStore; |
| | | |
| | | import oracle.jdbc.OracleConnection; |
| | | |
| | | public abstract class AbstractOracleJobContext |
| | | { |
| | | /** |
| | | * Table Prefiex |
| | | */ |
| | | protected static final String TABLE_PREFIX = "GEO$"; |
| | | protected static final String UDT_SCHEMA = "SPATIALDB"; |
| | | /** |
| | | * User Types |
| | | */ |
| | | protected static final String UDT_RAWS = "CREATE OR REPLACE TYPE \"" + UDT_SCHEMA + "\".\"RAWS\" AS VARRAY (1048576) OF NUMBER(38)"; |
| | | protected static final String UDT_OFMID = "CREATE OR REPLACE TYPE \"" + UDT_SCHEMA + "\".\"OFMID\" AS OBJECT (" |
| | | + "\"CLSID\" NUMBER(5), \"OID\" NUMBER(10), \"STATUS\" NUMBER(5), \"COMPID\" NUMBER(3), " |
| | | + "\"RULEID\" NUMBER(3), \"OCCID\" NUMBER(3))"; |
| | | protected static final String UDT_RAWSNAME = "RAWS"; |
| | | protected static final String UDT_OFMIDNAME = "OFMID"; |
| | | /** |
| | | * Utility SQL |
| | | */ |
| | | protected static final String TAB_DROP = "DROP TABLE %s.%s CASCADE CONSTRAINTS"; |
| | | protected static final String TAB_DELETE = "DELETE FROM %s.%s"; |
| | | /** |
| | | * Table Schema |
| | | */ |
| | | protected static final String TAB_RANGENODEINDEX_1 = "CREATE TABLE \"%s\".\"%s\"\n" |
| | | + " ( \"RNID\" INTEGER NOT NULL ENABLE,\n" |
| | | + " \"RPID\" INTEGER NOT NULL ENABLE,\n" |
| | | + " \"RNG_LOWX\" BINARY_DOUBLE NOT NULL ENABLE,\n" |
| | | + " \"RNG_LOWY\" BINARY_DOUBLE NOT NULL ENABLE,\n" |
| | | + " \"RNG_HIGHX\" BINARY_DOUBLE NOT NULL ENABLE,\n" |
| | | + " \"RNG_HIGHY\" BINARY_DOUBLE NOT NULL ENABLE,\n" |
| | | + " \"EXTENTS\" MDSYS.SDO_GEOMETRY,\n" |
| | | + " \"RNDESCR\" VARCHAR2(255), \n" |
| | | + " PRIMARY KEY ( \"RNID\" ) ENABLE )"; |
| | | protected static final String TAB_RANGENODEINDEX = "CREATE TABLE \"%s\".\"%s\"\n" |
| | | + " ( \"RNID\" INTEGER NOT NULL ENABLE,\n" |
| | | + " \"RPID\" INTEGER NOT NULL ENABLE,\n" |
| | | + " \"RNG_LOWX\" FLOAT NOT NULL ENABLE,\n" |
| | | + " \"RNG_LOWY\" FLOAT NOT NULL ENABLE,\n" |
| | | + " \"RNG_HIGHX\" FLOAT NOT NULL ENABLE,\n" |
| | | + " \"RNG_HIGHY\" FLOAT NOT NULL ENABLE,\n" |
| | | + " \"RNDESCR\" VARCHAR2(255), \n" |
| | | + " PRIMARY KEY ( \"RNID\" ) ENABLE )"; |
| | | protected static final String TAB_RANGENODESTORAGE = "CREATE TABLE \"%s\".\"%s\"\n" |
| | | + " ( \"RNID\" INTEGER NOT NULL ENABLE,\n" |
| | | + " \"LAYERID\" NUMBER(5,0) NOT NULL ENABLE,\n" |
| | | + " \"LASTUPDATE\" DATE NOT NULL ENABLE,\n" |
| | | + " \"SPACETABLE\" VARCHAR2(255)\n" + " )"; |
| | | protected static final String TAB_ELEMENTINDEX_1 = "CREATE TABLE %s.%s (\n" |
| | | + " \"ELMNO\" INTEGER NOT NULL ENABLE,\n" |
| | | + " \"TYPE\" NUMBER(5) NOT NULL ENABLE,\n" |
| | | + " \"XLOW\" BINARY_DOUBLE NOT NULL ENABLE,\n" |
| | | + " \"YLOW\" BINARY_DOUBLE NOT NULL ENABLE,\n" |
| | | + " \"ZLOW\" BINARY_DOUBLE NOT NULL ENABLE,\n" |
| | | + " \"XHIGH\" BINARY_DOUBLE NOT NULL ENABLE,\n" |
| | | + " \"YHIGH\" BINARY_DOUBLE NOT NULL ENABLE,\n" |
| | | + " \"ZHIGH\" BINARY_DOUBLE NOT NULL ENABLE,\n" |
| | | + " \"TAG_LUFID\" NUMBER(10) NOT NULL ENABLE,\n" |
| | | + " \"TAG_SFSC\" NUMBER(5) NOT NULL ENABLE,\n" |
| | | + " \"TAG_SSTAT\" NUMBER(5) NOT NULL ENABLE,\n" |
| | | + " \"TAG_BCOMPID\" NUMBER(3) NOT NULL ENABLE,\n" |
| | | + " \"TAG_BRULENO\" NUMBER(3) NOT NULL ENABLE,\n" |
| | | + " \"TAG_SOCCID\" NUMBER(5) NOT NULL ENABLE,\n" |
| | | + " \"SPACENAME\" VARCHAR2(255) NOT NULL ENABLE,\n" |
| | | + " PRIMARY KEY (\"ELMNO\") ENABLE\n" |
| | | + " )"; |
| | | protected static final String TAB_ELEMENTINDEX = "CREATE TABLE %s.%s (\n" |
| | | + " \"ELMNO\" INTEGER NOT NULL ENABLE,\n" |
| | | + " \"TYPE\" NUMBER(5) NOT NULL ENABLE,\n" |
| | | + " \"XLOW\" FLOAT NOT NULL ENABLE,\n" |
| | | + " \"YLOW\" FLOAT NOT NULL ENABLE,\n" |
| | | + " \"ZLOW\" FLOAT NOT NULL ENABLE,\n" |
| | | + " \"XHIGH\" FLOAT NOT NULL ENABLE,\n" |
| | | + " \"YHIGH\" FLOAT NOT NULL ENABLE,\n" |
| | | + " \"ZHIGH\" FLOAT NOT NULL ENABLE,\n" |
| | | + " \"TAG_LUFID\" NUMBER(10) NOT NULL ENABLE,\n" |
| | | + " \"TAG_SFSC\" NUMBER(5) NOT NULL ENABLE,\n" |
| | | + " \"TAG_SSTAT\" NUMBER(5) NOT NULL ENABLE,\n" |
| | | + " \"TAG_BCOMPID\" NUMBER(3) NOT NULL ENABLE,\n" |
| | | + " \"TAG_BRULENO\" NUMBER(3) NOT NULL ENABLE,\n" |
| | | + " \"TAG_SOCCID\" NUMBER(5) NOT NULL ENABLE,\n" |
| | | + " \"SPACENAME\" VARCHAR2(255) NOT NULL ENABLE,\n" |
| | | + " PRIMARY KEY (\"ELMNO\") ENABLE\n" |
| | | + " )"; |
| | | protected static final String TAB_IGDSSEED = "CREATE TABLE %s.%s (\n" |
| | | + " \"ELMNO\" INTEGER NOT NULL ENABLE,\n" |
| | | + " \"SEEDELM\" \"" + UDT_SCHEMA |
| | | + "\".\"RAWS\" NOT NULL ENABLE\n" + " )"; |
| | | protected static final String TAB_STORAGE_1 = "CREATE TABLE %s.%s (\n" + |
| | | " \"ELMNO\" INTEGER NOT NULL ENABLE,\n" + |
| | | " \"XLOW\" BINARY_DOUBLE NOT NULL ENABLE,\n" + |
| | | " \"YLOW\" BINARY_DOUBLE NOT NULL ENABLE,\n" + |
| | | " \"XHIGH\" BINARY_DOUBLE NOT NULL ENABLE,\n" + |
| | | " \"YHIGH\" BINARY_DOUBLE NOT NULL ENABLE,\n" + |
| | | " \"EXTENTS\" MDSYS.SDO_GEOMETRY, \n" + |
| | | " \"PROPS\" INTEGER NOT NULL ENABLE,\n" + |
| | | " \"TAG_LUFID\" NUMBER(10) NOT NULL ENABLE,\n" + |
| | | " \"TAG_SFSC\" NUMBER(5) NOT NULL ENABLE,\n" + |
| | | " \"TAG_SSTAT\" NUMBER(5) NOT NULL ENABLE,\n" + |
| | | " \"TAG_BCOMPID\" NUMBER(3) NOT NULL ENABLE,\n" + |
| | | " \"TAG_BRULENO\" NUMBER(3) NOT NULL ENABLE,\n" + |
| | | " \"TAG_SOCCID\" NUMBER(5) NOT NULL ENABLE,\n" + |
| | | " \"LAYERID\" NUMBER(5) NOT NULL ENABLE,\n" + |
| | | " \"ELEMENT\" \"" + UDT_SCHEMA + "\".\"RAWS\" NOT NULL ENABLE, \n" + |
| | | " \"GEOM\" MDSYS.SDO_GEOMETRY \n" + |
| | | " )"; |
| | | protected static final String TAB_STORAGE = "CREATE TABLE %s.%s (\n" + |
| | | " \"ELMNO\" INTEGER NOT NULL ENABLE,\n" + |
| | | " \"XLOW\" FLOAT NOT NULL ENABLE,\n" + |
| | | " \"YLOW\" FLOAT NOT NULL ENABLE,\n" + |
| | | " \"XHIGH\" FLOAT NOT NULL ENABLE,\n" + |
| | | " \"YHIGH\" FLOAT NOT NULL ENABLE,\n" + |
| | | " \"PROPS\" INTEGER NOT NULL ENABLE,\n" + |
| | | " \"TAG_LUFID\" NUMBER(10) NOT NULL ENABLE,\n" + |
| | | " \"TAG_SFSC\" NUMBER(5) NOT NULL ENABLE,\n" + |
| | | " \"TAG_SSTAT\" NUMBER(5) NOT NULL ENABLE,\n" + |
| | | " \"TAG_BCOMPID\" NUMBER(3) NOT NULL ENABLE,\n" + |
| | | " \"TAG_BRULENO\" NUMBER(3) NOT NULL ENABLE,\n" + |
| | | " \"TAG_SOCCID\" NUMBER(5) NOT NULL ENABLE,\n" + |
| | | " \"LAYERID\" NUMBER(5) NOT NULL ENABLE,\n" + |
| | | " \"ELEMENT\" \"" + UDT_SCHEMA + "\".\"RAWS\" NOT NULL ENABLE \n" + |
| | | " )"; |
| | | protected static final String TAB_STORAGE2 = "CREATE TABLE %s.%s (\n" + |
| | | " \"ELMNO\" INTEGER NOT NULL ENABLE,\n" + |
| | | " \"XLOW\" BINARY_DOUBLE NOT NULL ENABLE,\n" + |
| | | " \"YLOW\" BINARY_DOUBLE NOT NULL ENABLE,\n" + |
| | | " \"XHIGH\" BINARY_DOUBLE NOT NULL ENABLE,\n" + |
| | | " \"YHIGH\" BINARY_DOUBLE NOT NULL ENABLE,\n" + |
| | | " \"EXTENTS\" MDSYS.SDO_GEOMETRY, \n" + |
| | | " \"PROPS\" INTEGER NOT NULL ENABLE,\n" + |
| | | " \"ID\" " + UDT_SCHEMA + ".OFMID NOT NULL ENABLE,\n" + |
| | | " \"LAYERID\" NUMBER(5) NOT NULL ENABLE,\n" + |
| | | " \"ELEMENT\" \"" + UDT_SCHEMA + "\".\"RAWS\" NOT NULL ENABLE \n" + |
| | | " )"; |
| | | /** |
| | | * Trigger |
| | | */ |
| | | protected static final String TRG_SPACENODE = "CREATE OR REPLACE TRIGGER \"%s\".\"%s\"\n" |
| | | + " AFTER DELETE OR INSERT OR UPDATE ON \"%s\".\"%s\"\n" + " BEGIN\n" |
| | | + " UPDATE SPACENODES SET LASTUPDATE = SYSDATE\n" + " WHERE SNID = \"%d\";\n" |
| | | + " END;"; |
| | | protected static final String TRG_ELMINDEX = |
| | | "CREATE OR REPLACE TRIGGER \"%s\".\"%s\"\n" |
| | | + " AFTER INSERT OR UPDATE OR DELETE ON \"%s\".\"%s\"\n" |
| | | + " REFERENCING OLD AS OLD NEW AS NEW FOR EACH ROW\n" |
| | | + " BEGIN\n" |
| | | + " IF INSERTING THEN\n" |
| | | + " INSERT INTO \"%s\".\"%s\" (ELMNO, TYPE, XLOW, YLOW, XHIGH, YHIGH,\n" |
| | | + " UFID, FSC, COMPID, OCCID, SPACENAME)\n" |
| | | + " VALUES (SD$ELEMENTNUMBER_SEQ.NEXTVAL, :new.ELMTYPE, :new.XLOW, :new.YLOW, :new.XHIGH, :new.YHIGH,\n" |
| | | + " :new.UFID, :new.FSC, :new.COMPID, :new.OCCID, '%s');\n" |
| | | + " ELSIF DELETING THEN\n" |
| | | + " DELETE FROM \"%s\".\"%s\"\n" |
| | | + " WHERE \"%s\".UFID = :old.UFID AND\n" |
| | | + " \"%s\".FSC = :old.FSC AND\n" |
| | | + " \"%s\".COMPID = :old.COMPID AND\n" |
| | | + " \"%s\".OCCID = :old.OCCID;\n" |
| | | + " ELSE\n" + " UPDATE \"%s\"\n" |
| | | + " SET XLOW = :new.XLOW, YLOW = :new.YLOW, XHIGH = :new.XHIGH, YHIGH = :new.YHIGH\n" |
| | | + " WHERE FSC = :new.FSC AND UFID = :new.UFID AND COMPID = :new.COMPID AND OCCID = :new.OCCID;\n" |
| | | + " END IF;\n" + " END;"; |
| | | |
| | | /** |
| | | * copy connectivity to connectivity_webcheck sql |
| | | */ |
| | | public static final String CONNECTIVITY_WEBCHECK_NAME = "CONNECTIVITY_WEBCHECK"; |
| | | public static final String TRUNCATE_CONNECTIVITY_WEBCHECK = "TRUNCATE TABLE BASEDB.CONNECTIVITY_WEBCHECK"; |
| | | public static final String CREATE_CONNECTIVITY_WEBCHECK = "CREATE TABLE BASEDB.CONNECTIVITY_WEBCHECK (\n" + |
| | | " \"FSC\" NUMBER(5) NOT NULL," + |
| | | " \"UFID\" NUMBER(10) NOT NULL," + |
| | | " \"N1\" NUMBER(10)," + |
| | | " \"N2\" NUMBER(10)," + |
| | | " \"FDR1\" NUMBER(5)," + |
| | | " \"FDR2\" NUMBER(5)," + |
| | | " \"DIR\" NUMBER(3)," + |
| | | " \"OHUG\" NUMBER(3)," + |
| | | " \"OSTATUS\" NUMBER(3)," + |
| | | " \"PHASE\" NUMBER(3)," + |
| | | " \"X\" NUMBER(10,3) NOT NULL," + |
| | | " \"Y\" NUMBER(10,3) NOT NULL" + |
| | | ")"; |
| | | |
| | | |
| | | public static final String COPY_CONNECTIVITY_TO_WEBCHECK = "INSERT /*+ APPEND */ INTO BASEDB.CONNECTIVITY_WEBCHECK\n" + |
| | | "(FSC, UFID, N1, N2, FDR1, FDR2, DIR, OHUG,OSTATUS, PHASE, X, Y)\n" + |
| | | "SELECT FSC, UFID, N1, N2, FDR1, FDR2, DIR, OHUG, OSTATUS, PHASE, X, Y FROM BASEDB.CONNECTIVITY "; |
| | | |
| | | public static final String CREATE_CONNECTIVITY_WEBCHECK_INDEX_1 = |
| | | "CREATE INDEX BASEDB.CONNECTIVITY_FDR1_WEB ON BASEDB.CONNECTIVITY_WEBCHECK (FDR1)"; |
| | | |
| | | public static final String CREATE_CONNECTIVITY_WEBCHECK_INDEX_2 = |
| | | "CREATE INDEX BASEDB.CONNECTIVITY_FSCUFID_INDEX_WEB ON BASEDB.CONNECTIVITY_WEBCHECK (FSC, UFID)"; |
| | | |
| | | public static final String CREATE_CONNECTIVITY_WEBCHECK_INDEX_3 = |
| | | "CREATE INDEX BASEDB.CONNECTIVITY_N1TON2_WEB ON BASEDB.CONNECTIVITY_WEBCHECK (N1, N2)"; |
| | | |
| | | public static final String CREATE_CONNECTIVITY_WEBCHECK_INDEX_4 = |
| | | "CREATE INDEX BASEDB.CONNECTIVITY_N1_INDEX_WEB ON BASEDB.CONNECTIVITY_WEBCHECK (N1)"; |
| | | |
| | | public static final String CREATE_CONNECTIVITY_WEBCHECK_INDEX_5 = |
| | | "CREATE INDEX BASEDB.CONNECTIVITY_N2TON1_WEB ON BASEDB.CONNECTIVITY_WEBCHECK (N2, N1)"; |
| | | |
| | | public static final String CREATE_CONNECTIVITY_WEBCHECK_INDEX_6 = |
| | | "CREATE INDEX BASEDB.CONNECTIVITY_N2_INDEX_WEB ON BASEDB.CONNECTIVITY_WEBCHECK (N2)"; |
| | | |
| | | public static final String ALTER_CONNECTIVITY_WEBCHECK_1 = |
| | | "ALTER TABLE BASEDB.CONNECTIVITY_WEBCHECK ADD (\n" + |
| | | " CONSTRAINT CONNECT_UNI_WEB UNIQUE (FSC,UFID))"; |
| | | |
| | | public static final String ALTER_CONNECTIVITY_WEBCHECK_2 = |
| | | "ALTER TABLE BASEDB.CONNECTIVITY_WEBCHECK ADD (\n" + |
| | | " CONSTRAINT CONN_N1N2_WEB UNIQUE (N1,N2))"; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | protected static final String TAB_ELEMENTSET_PREFIX = "ELMSET_"; |
| | | protected static final String STMT_CLEARCYCLEBIN = "PURGE RECYCLEBIN"; |
| | | protected static final String SMTM_GRANTOBJECTTYPE = "GRANT EXECUTE ANY TYPE TO \"" + UDT_SCHEMA + "\""; |
| | | protected static final long TIMEOUT = Long.MAX_VALUE; |
| | | |
| | | /** |
| | | * Encoding of URL path. |
| | | */ |
| | | protected static final String ENCODING = "UTF-8"; |
| | | protected OracleDataStore sourceDataStore; |
| | | |
| | | protected String _dataPath; |
| | | protected Properties properties; |
| | | protected boolean _elementLogging; |
| | | private Connection connection = null; |
| | | |
| | | public OracleDataStore getSourceDataStore() |
| | | { |
| | | return sourceDataStore; |
| | | } |
| | | |
| | | public void setSourceDataStore(DataStore sourceDataStore) |
| | | { |
| | | if ((sourceDataStore != null) && (sourceDataStore instanceof OracleDataStore)) |
| | | { |
| | | this.sourceDataStore = (OracleDataStore) sourceDataStore; |
| | | } else |
| | | { |
| | | assert sourceDataStore != null; |
| | | getLogger().warn("setSourceDataStore(datastore) need OracleDataStore but got " + |
| | | sourceDataStore.getClass().getName()); |
| | | } |
| | | } |
| | | |
| | | public Connection getOracleConnection() |
| | | { |
| | | if (connection != null) return connection; |
| | | try |
| | | { |
| | | if (sourceDataStore != null) |
| | | { |
| | | connection = sourceDataStore.getConnection(Transaction.AUTO_COMMIT); |
| | | } |
| | | |
| | | } catch (IOException e) |
| | | { |
| | | getLogger().warn(e.getMessage(), e); |
| | | } |
| | | |
| | | return connection; |
| | | } |
| | | |
| | | public void setDataPath(String dataPath) |
| | | { |
| | | _dataPath = dataPath; |
| | | } |
| | | |
| | | public String getDataPath() |
| | | { |
| | | return _dataPath; |
| | | } |
| | | |
| | | public boolean getElementLogging() |
| | | { |
| | | return _elementLogging; |
| | | } |
| | | |
| | | public void setElementLogging(boolean elementLogging) |
| | | { |
| | | _elementLogging = elementLogging; |
| | | } |
| | | |
| | | public abstract void startTransaction(); |
| | | |
| | | public abstract void commitTransaction(); |
| | | |
| | | public abstract void rollbackTransaction(); |
| | | |
| | | protected abstract Log getLogger(); |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.jobs.context; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | | |
| | | public class OracleUpgradeJobContext extends AbstractOracleJobContext |
| | | { |
| | | public void startTransaction() |
| | | { |
| | | } |
| | | |
| | | public void commitTransaction() |
| | | { |
| | | } |
| | | |
| | | public void rollbackTransaction() |
| | | { |
| | | } |
| | | |
| | | protected Log getLogger() |
| | | { |
| | | return null; //To change body of implemented methods use File | Settings | File Templates. |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.jobs.context.mysql; |
| | | |
| | | import java.io.IOException; |
| | | import java.sql.Connection; |
| | | |
| | | import org.geotools.data.DataStore; |
| | | import org.geotools.data.Transaction; |
| | | import org.geotools.data.SchemaNotFoundException; |
| | | import org.geotools.data.mysql.MySQLDataStore; |
| | | import org.geotools.feature.FeatureType; |
| | | |
| | | import com.ximple.eofms.jobs.context.AbstractDgnFileJobContext; |
| | | |
| | | public abstract class AbstractDgnToMySQLJobContext extends AbstractDgnFileJobContext |
| | | { |
| | | protected MySQLDataStore targetDataStore; |
| | | |
| | | public AbstractDgnToMySQLJobContext(String dataPath, DataStore targetDataStore) |
| | | { |
| | | super(dataPath); |
| | | this.targetDataStore = (MySQLDataStore) targetDataStore; |
| | | } |
| | | |
| | | public MySQLDataStore getTargetDataStore() |
| | | { |
| | | return targetDataStore; |
| | | } |
| | | |
| | | public void setTargetDataStore(MySQLDataStore targetDataStore) |
| | | { |
| | | this.targetDataStore = targetDataStore; |
| | | } |
| | | |
| | | public Connection getConnection() |
| | | { |
| | | if (targetDataStore != null) |
| | | { |
| | | try |
| | | { |
| | | return targetDataStore.getConnection(Transaction.AUTO_COMMIT); |
| | | } catch (IOException e) |
| | | { |
| | | getLogger().warn(e.getMessage(), e); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | protected boolean isExistFeature(FeatureType featureType) |
| | | { |
| | | try |
| | | { |
| | | FeatureType existFeatureType = targetDataStore.getSchema(featureType.getTypeName()); |
| | | return existFeatureType != null && existFeatureType.equals(featureType); |
| | | } catch (SchemaNotFoundException e) |
| | | { |
| | | return false; |
| | | } catch (IOException e) |
| | | { |
| | | getLogger().info(e.getMessage(), e); |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | |
New file |
| | |
| | | package com.ximple.eofms.jobs.context.mysql; |
| | | |
| | | import java.io.IOException; |
| | | import java.sql.Connection; |
| | | |
| | | import org.geotools.data.DataStore; |
| | | import org.geotools.data.Transaction; |
| | | import org.geotools.data.SchemaNotFoundException; |
| | | import org.geotools.data.mysql.MySQLDataStore; |
| | | import org.geotools.feature.FeatureType; |
| | | |
| | | import com.ximple.eofms.jobs.context.AbstractOracleJobContext; |
| | | |
| | | public abstract class AbstractOracleToMySQLJobContext extends AbstractOracleJobContext |
| | | { |
| | | protected MySQLDataStore targetDataStore; |
| | | |
| | | public AbstractOracleToMySQLJobContext(String dataPath, DataStore targetDataStore) |
| | | { |
| | | if ((targetDataStore != null) && (targetDataStore instanceof MySQLDataStore)) |
| | | { |
| | | this.targetDataStore = (MySQLDataStore) targetDataStore; |
| | | } else |
| | | { |
| | | getLogger().info("targetDataStore has wrong."); |
| | | } |
| | | setDataPath(dataPath); |
| | | } |
| | | |
| | | public MySQLDataStore getTargetDataStore() |
| | | { |
| | | return targetDataStore; |
| | | } |
| | | |
| | | public void setTargetDataStore(MySQLDataStore targetDataStore) |
| | | { |
| | | this.targetDataStore = targetDataStore; |
| | | } |
| | | |
| | | public Connection getConnection() |
| | | { |
| | | if (targetDataStore != null) |
| | | { |
| | | try |
| | | { |
| | | return targetDataStore.getConnection(Transaction.AUTO_COMMIT); |
| | | } catch (IOException e) |
| | | { |
| | | getLogger().warn(e.getMessage(), e); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | protected boolean isExistFeature(FeatureType featureType) |
| | | { |
| | | try |
| | | { |
| | | FeatureType existFeatureType = targetDataStore.getSchema(featureType.getTypeName()); |
| | | return existFeatureType != null && existFeatureType.equals(featureType); |
| | | } catch (SchemaNotFoundException e) |
| | | { |
| | | return false; |
| | | } catch (IOException e) |
| | | { |
| | | getLogger().info(e.getMessage(), e); |
| | | return false; |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.jobs.context.mysql; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.net.URL; |
| | | import java.net.MalformedURLException; |
| | | import java.io.File; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.io.IOException; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.apache.commons.transaction.util.LoggerFacade; |
| | | import org.apache.commons.transaction.util.CommonsLoggingLogger; |
| | | import org.apache.commons.transaction.memory.PessimisticMapWrapper; |
| | | import org.apache.commons.digester.Digester; |
| | | import org.apache.commons.digester.xmlrules.DigesterLoader; |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.SimpleFeature; |
| | | import org.geotools.data.FeatureWriter; |
| | | import org.geotools.data.DataStore; |
| | | import org.geotools.data.Transaction; |
| | | import org.xml.sax.SAXException; |
| | | |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | import com.ximple.eofms.filter.ElementDispatcher; |
| | | import com.ximple.eofms.filter.AbstractFLinkageDispatchableFilter; |
| | | import com.ximple.eofms.filter.ElementDispatchableFilter; |
| | | import com.ximple.eofms.filter.TypeCompIdDispatchableFilter; |
| | | import com.ximple.eofms.filter.TypeCompLevelIdDispatchableFilter; |
| | | import com.ximple.eofms.filter.TypeIdDispatchableFilter; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.io.dgn7.ComplexElement; |
| | | import com.ximple.io.dgn7.UserAttributeData; |
| | | |
| | | public class DummyFeatureConvertMySQlJobContext extends AbstractDgnToMySQLJobContext |
| | | { |
| | | static final Log logger = LogFactory.getLog(DummyFeatureConvertMySQlJobContext.class); |
| | | static final LoggerFacade sLogger = new CommonsLoggingLogger(logger); |
| | | static final GeometryFactory geometryFactory = new GeometryFactory(); |
| | | static final String SHPOUTPATH = "shpout"; |
| | | |
| | | private String dataOut = null; |
| | | |
| | | private HashMap<String, ArrayList<Feature>> featuresContext = new HashMap<String, ArrayList<Feature>>(); |
| | | private HashMap<String, FeatureWriter> featuresWriterContext = new HashMap<String, FeatureWriter>(); |
| | | |
| | | private PessimisticMapWrapper txFeaturesContext; |
| | | |
| | | private ElementDispatcher elementDispatcher; |
| | | private String _filterConfig; |
| | | private boolean withIndex = false; |
| | | |
| | | public DummyFeatureConvertMySQlJobContext(String dataPath, DataStore targetDataStore, String filterConfig) |
| | | { |
| | | super(dataPath, targetDataStore); |
| | | txFeaturesContext = new PessimisticMapWrapper(featuresContext, sLogger); |
| | | _filterConfig = filterConfig; |
| | | elementDispatcher = createElementDispatcher(); |
| | | } |
| | | |
| | | private ElementDispatcher createElementDispatcher() |
| | | { |
| | | try |
| | | { |
| | | URL rulesURL = ElementDispatcher.class.getResource("ElementDispatcherRules.xml"); |
| | | assert rulesURL != null; |
| | | Digester digester = DigesterLoader.createDigester(rulesURL); |
| | | URL filterURL = null; |
| | | if (_filterConfig != null) |
| | | { |
| | | File config = new File(_filterConfig); |
| | | if (config.exists()) |
| | | { |
| | | filterURL = config.toURI().toURL(); |
| | | } |
| | | } |
| | | if (filterURL == null) |
| | | { |
| | | // config = new File("conf/DefaultConvertShpFilter.xml"); |
| | | filterURL = this.getClass().getResource("/conf/DefaultConvertShpFilter.xml"); |
| | | // filterURL = this.getClass().getResource("/conf/ConvertShpFilterForLevel.xml"); |
| | | } |
| | | assert filterURL != null; |
| | | return (ElementDispatcher) digester.parse(filterURL); |
| | | } catch (UnsupportedEncodingException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } catch (MalformedURLException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } catch (IOException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } catch (SAXException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | public void putFeatureCollection(Element element) throws IllegalAttributeException, SchemaException |
| | | { |
| | | assert elementDispatcher != null; |
| | | |
| | | if (element == null) |
| | | { |
| | | logger.warn("Unknown Element:" + null); |
| | | return; |
| | | } |
| | | |
| | | // §PÂ_¬O§_²Å©M±ø¥ó |
| | | Feature feature = elementDispatcher.execute(element, true); |
| | | if (feature == null) |
| | | { |
| | | FrammeAttributeData linkage = |
| | | AbstractFLinkageDispatchableFilter.getFeatureLinkage(element); |
| | | logger.warn("Unknown Element:" + element.getElementType().toString() + |
| | | ":type=" + element.getType() + ":lv=" + element.getLevelIndex() + ":id=" + |
| | | (linkage == null ? "NULL" : (linkage.getFsc() + "|" + linkage.getComponentID()))); |
| | | if (element instanceof ComplexElement) |
| | | { |
| | | ComplexElement complex = (ComplexElement) element; |
| | | logger.warn("----Complex Element size=" + complex.size()); |
| | | } |
| | | |
| | | return; |
| | | } |
| | | |
| | | if (!txFeaturesContext.containsKey(feature.getFeatureType())) |
| | | { |
| | | txFeaturesContext.put(feature.getFeatureType(), new ArrayList()); |
| | | } |
| | | ArrayList arrayList = (ArrayList) txFeaturesContext.get(feature.getFeatureType()); |
| | | arrayList.add(feature); |
| | | } |
| | | |
| | | public void startTransaction() |
| | | { |
| | | assert elementDispatcher != null; |
| | | for (ElementDispatchableFilter filter : elementDispatcher.getRules()) |
| | | { |
| | | if (filter instanceof TypeCompIdDispatchableFilter) |
| | | { |
| | | ((TypeCompIdDispatchableFilter) filter).getCreateStrategy(); |
| | | } else if (filter instanceof TypeCompLevelIdDispatchableFilter) |
| | | { |
| | | ((TypeCompIdDispatchableFilter) filter).getCreateStrategy(); |
| | | } else if (filter instanceof TypeIdDispatchableFilter) |
| | | { |
| | | ((TypeCompIdDispatchableFilter) filter).getCreateStrategy(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void commitTransaction() |
| | | { |
| | | if (!txFeaturesContext.isEmpty()) |
| | | { |
| | | logger.debug("Transaction size = " + txFeaturesContext.size()); |
| | | //txFeaturesContext.commitTransaction(); |
| | | } else |
| | | { |
| | | logger.debug("Transaction is empty."); |
| | | } |
| | | |
| | | if (!featuresContext.isEmpty()) |
| | | { |
| | | updateDataStore(); |
| | | } |
| | | } |
| | | |
| | | public void rollbackTransaction() |
| | | { |
| | | //txFeaturesContext.rollbackTransaction(); |
| | | if (!featuresContext.isEmpty()) |
| | | { |
| | | updateDataStore(); |
| | | } |
| | | } |
| | | |
| | | private void updateDataStore() |
| | | { |
| | | Iterator it = featuresContext.keySet().iterator(); |
| | | |
| | | try |
| | | { |
| | | while (it.hasNext()) |
| | | { |
| | | FeatureType featureType = (FeatureType) it.next(); |
| | | logger.debug("Begin Save OracleSDO:" + featureType.getTypeName()); |
| | | |
| | | FeatureWriter writer; |
| | | if (featuresWriterContext.containsKey(featureType.getTypeName())) |
| | | { |
| | | writer = featuresWriterContext.get(featureType.getTypeName()); |
| | | } else |
| | | { |
| | | if (!isExistFeature(featureType)) |
| | | { |
| | | targetDataStore.createSchema(featureType); |
| | | writer = targetDataStore.getFeatureWriter(featureType.getTypeName(), Transaction.AUTO_COMMIT); |
| | | } else |
| | | { |
| | | writer = targetDataStore.getFeatureWriterAppend(featureType.getTypeName(), Transaction.AUTO_COMMIT); |
| | | } |
| | | featuresWriterContext.put(featureType.getTypeName(), writer); |
| | | } |
| | | |
| | | ArrayList<Feature> features = featuresContext.get(featureType); |
| | | Iterator itFeature = features.iterator(); |
| | | while (itFeature.hasNext()) |
| | | { |
| | | Feature feature = (Feature) itFeature.next(); |
| | | ((SimpleFeature) writer.next()).setAttributes(feature.getAttributes(null)); |
| | | } |
| | | //writer.close(); |
| | | logger.debug("End Save OracleSDO:" + featureType.getTypeName()); |
| | | } |
| | | featuresContext.clear(); |
| | | } catch (MalformedURLException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } catch (IllegalAttributeException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } catch (IOException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | public String getDataOutPath() |
| | | { |
| | | if (dataOut == null) |
| | | { |
| | | File outPath = new File(getDataPath(), SHPOUTPATH); |
| | | if (!outPath.exists()) |
| | | { |
| | | outPath.mkdir(); |
| | | } else if (!outPath.isDirectory()) |
| | | { |
| | | outPath.mkdir(); |
| | | } |
| | | dataOut = outPath.toString(); |
| | | } |
| | | return dataOut; |
| | | } |
| | | |
| | | public void closeFeatureWriter() throws IOException |
| | | { |
| | | |
| | | for (FeatureWriter featureWriter : this.featuresWriterContext.values()) |
| | | { |
| | | featureWriter.close(); |
| | | } |
| | | |
| | | this.featuresWriterContext.clear(); |
| | | } |
| | | |
| | | protected FrammeAttributeData getFeatureLinkage(Element element) |
| | | { |
| | | if (!element.hasUserAttributeData()) |
| | | return null; |
| | | |
| | | List<UserAttributeData> usrDatas = element.getUserAttributeData(); |
| | | for (UserAttributeData anUsrData : usrDatas) |
| | | { |
| | | if (anUsrData instanceof FrammeAttributeData) |
| | | { |
| | | return (FrammeAttributeData) anUsrData; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | public boolean isWithIndex() |
| | | { |
| | | return withIndex; |
| | | } |
| | | |
| | | public void setWithIndex(boolean withIndex) |
| | | { |
| | | this.withIndex = withIndex; |
| | | } |
| | | |
| | | public Log getLogger() |
| | | { |
| | | return logger; |
| | | } |
| | | } |
| | | |
New file |
| | |
| | | package com.ximple.eofms.jobs.context.mysql; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.net.URL; |
| | | import java.net.MalformedURLException; |
| | | import java.io.File; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.io.IOException; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.apache.commons.transaction.util.LoggerFacade; |
| | | import org.apache.commons.transaction.util.CommonsLoggingLogger; |
| | | import org.apache.commons.transaction.memory.PessimisticMapWrapper; |
| | | import org.apache.commons.digester.Digester; |
| | | import org.apache.commons.digester.xmlrules.DigesterLoader; |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.SimpleFeature; |
| | | import org.geotools.data.FeatureWriter; |
| | | import org.geotools.data.DataStore; |
| | | import org.geotools.data.Transaction; |
| | | import org.xml.sax.SAXException; |
| | | |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | import com.ximple.eofms.filter.ElementDispatcher; |
| | | import com.ximple.eofms.filter.AbstractFLinkageDispatchableFilter; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.io.dgn7.ComplexElement; |
| | | import com.ximple.io.dgn7.UserAttributeData; |
| | | |
| | | public class FeatureDgnConvertMySQLJobContext extends AbstractDgnToMySQLJobContext |
| | | { |
| | | static final Log logger = LogFactory.getLog(FeatureDgnConvertMySQLJobContext.class); |
| | | static final LoggerFacade sLogger = new CommonsLoggingLogger(logger); |
| | | static final GeometryFactory geometryFactory = new GeometryFactory(); |
| | | |
| | | private HashMap<String, ArrayList<Feature>> featuresContext = new HashMap<String, ArrayList<Feature>>(); |
| | | private HashMap<String, FeatureWriter> featuresWriterContext = new HashMap<String, FeatureWriter>(); |
| | | |
| | | private PessimisticMapWrapper txFeaturesContext; |
| | | |
| | | private ElementDispatcher elementDispatcher; |
| | | private String _filterConfig; |
| | | private boolean withIndex = false; |
| | | |
| | | public FeatureDgnConvertMySQLJobContext(String dataPath, DataStore targetDataStore, String filterConfig) |
| | | { |
| | | super(dataPath, targetDataStore); |
| | | txFeaturesContext = new PessimisticMapWrapper(featuresContext, sLogger); |
| | | _filterConfig = filterConfig; |
| | | elementDispatcher = createElementDispatcher(); |
| | | } |
| | | |
| | | private ElementDispatcher createElementDispatcher() |
| | | { |
| | | try |
| | | { |
| | | URL rulesURL = ElementDispatcher.class.getResource("ElementDispatcherRules.xml"); |
| | | assert rulesURL != null; |
| | | Digester digester = DigesterLoader.createDigester(rulesURL); |
| | | URL filterURL = null; |
| | | if (_filterConfig != null) |
| | | { |
| | | File config = new File(_filterConfig); |
| | | if (config.exists()) |
| | | { |
| | | filterURL = config.toURI().toURL(); |
| | | } |
| | | } |
| | | if (filterURL == null) |
| | | { |
| | | // config = new File("conf/DefaultConvertShpFilter.xml"); |
| | | filterURL = this.getClass().getResource("/conf/DefaultConvertShpFilter.xml"); |
| | | // filterURL = this.getClass().getResource("/conf/ConvertShpFilterForLevel.xml"); |
| | | } |
| | | assert filterURL != null; |
| | | return (ElementDispatcher) digester.parse(filterURL); |
| | | } catch (UnsupportedEncodingException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } catch (MalformedURLException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } catch (IOException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } catch (SAXException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | public void putFeatureCollection(Element element) throws IllegalAttributeException, SchemaException |
| | | { |
| | | assert elementDispatcher != null; |
| | | |
| | | if (element == null) |
| | | { |
| | | logger.warn("Unknown Element:" + null); |
| | | return; |
| | | } |
| | | |
| | | // §PÂ_¬O§_²Å©M±ø¥ó |
| | | Feature feature = elementDispatcher.execute(element, true); |
| | | if (feature == null) |
| | | { |
| | | FrammeAttributeData linkage = |
| | | AbstractFLinkageDispatchableFilter.getFeatureLinkage(element); |
| | | logger.warn("Unknown Element:" + element.getElementType().toString() + |
| | | ":type=" + element.getType() + ":lv=" + element.getLevelIndex() + ":id=" + |
| | | (linkage == null ? "NULL" : (linkage.getFsc() + "|" + linkage.getComponentID()))); |
| | | if (element instanceof ComplexElement) |
| | | { |
| | | ComplexElement complex = (ComplexElement) element; |
| | | logger.warn("----Complex Element size=" + complex.size()); |
| | | } |
| | | |
| | | return; |
| | | } |
| | | |
| | | if (!txFeaturesContext.containsKey(feature.getFeatureType())) |
| | | { |
| | | txFeaturesContext.put(feature.getFeatureType(), new ArrayList()); |
| | | } |
| | | ArrayList arrayList = (ArrayList) txFeaturesContext.get(feature.getFeatureType()); |
| | | arrayList.add(feature); |
| | | } |
| | | |
| | | public void startTransaction() |
| | | { |
| | | } |
| | | |
| | | public void commitTransaction() |
| | | { |
| | | if (!txFeaturesContext.isEmpty()) |
| | | { |
| | | logger.debug("Transaction size = " + txFeaturesContext.size()); |
| | | //txFeaturesContext.commitTransaction(); |
| | | } else |
| | | { |
| | | logger.debug("Transaction is empty."); |
| | | } |
| | | |
| | | if (!featuresContext.isEmpty()) |
| | | { |
| | | updateDataStore(); |
| | | } |
| | | } |
| | | |
| | | public void rollbackTransaction() |
| | | { |
| | | //txFeaturesContext.rollbackTransaction(); |
| | | if (!featuresContext.isEmpty()) |
| | | { |
| | | updateDataStore(); |
| | | } |
| | | } |
| | | |
| | | private void updateDataStore() |
| | | { |
| | | Iterator it = featuresContext.keySet().iterator(); |
| | | |
| | | try |
| | | { |
| | | while (it.hasNext()) |
| | | { |
| | | FeatureType featureType = (FeatureType) it.next(); |
| | | logger.debug("Begin Save OracleSDO:" + featureType.getTypeName()); |
| | | |
| | | FeatureWriter writer; |
| | | if (featuresWriterContext.containsKey(featureType.getTypeName())) |
| | | { |
| | | writer = featuresWriterContext.get(featureType.getTypeName()); |
| | | } else |
| | | { |
| | | if (!isExistFeature(featureType)) |
| | | { |
| | | targetDataStore.createSchema(featureType); |
| | | writer = targetDataStore.getFeatureWriter(featureType.getTypeName(), |
| | | Transaction.AUTO_COMMIT); |
| | | } else |
| | | { |
| | | writer = targetDataStore.getFeatureWriterAppend(featureType.getTypeName(), |
| | | Transaction.AUTO_COMMIT); |
| | | } |
| | | featuresWriterContext.put(featureType.getTypeName(), writer); |
| | | } |
| | | |
| | | ArrayList<Feature> features = featuresContext.get(featureType); |
| | | Iterator itFeature = features.iterator(); |
| | | while (itFeature.hasNext()) |
| | | { |
| | | Feature feature = (Feature) itFeature.next(); |
| | | ((SimpleFeature) writer.next()).setAttributes(feature.getAttributes(null)); |
| | | } |
| | | //writer.close(); |
| | | logger.debug("End Save OracleSDO:" + featureType.getTypeName()); |
| | | } |
| | | featuresContext.clear(); |
| | | } catch (MalformedURLException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } catch (IllegalAttributeException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } catch (IOException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | public void closeFeatureWriter() throws IOException |
| | | { |
| | | |
| | | for (FeatureWriter featureWriter : this.featuresWriterContext.values()) |
| | | { |
| | | featureWriter.close(); |
| | | } |
| | | |
| | | this.featuresWriterContext.clear(); |
| | | } |
| | | |
| | | protected FrammeAttributeData getFeatureLinkage(Element element) |
| | | { |
| | | if (!element.hasUserAttributeData()) |
| | | return null; |
| | | |
| | | List<UserAttributeData> usrDatas = element.getUserAttributeData(); |
| | | for (UserAttributeData anUsrData : usrDatas) |
| | | { |
| | | if (anUsrData instanceof FrammeAttributeData) |
| | | { |
| | | return (FrammeAttributeData) anUsrData; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | public boolean isWithIndex() |
| | | { |
| | | return withIndex; |
| | | } |
| | | |
| | | public void setWithIndex(boolean withIndex) |
| | | { |
| | | this.withIndex = withIndex; |
| | | } |
| | | |
| | | public Log getLogger() |
| | | { |
| | | return logger; |
| | | } |
| | | } |
| | | |
| | | |
New file |
| | |
| | | package com.ximple.eofms.jobs.context.mysql; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.TreeMap; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.net.MalformedURLException; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.apache.commons.transaction.util.LoggerFacade; |
| | | import org.apache.commons.transaction.util.CommonsLoggingLogger; |
| | | import org.apache.commons.transaction.memory.PessimisticMapWrapper; |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.FeatureTypeBuilder; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | import org.geotools.feature.SimpleFeature; |
| | | import org.geotools.data.FeatureWriter; |
| | | import org.geotools.data.DataStore; |
| | | import org.geotools.data.Transaction; |
| | | |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | |
| | | import com.ximple.eofms.util.TWD97GeometryConverterDecorator; |
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil; |
| | | import com.ximple.eofms.util.DefaultColorTable; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.TextElement; |
| | | import com.ximple.io.dgn7.ShapeElement; |
| | | import com.ximple.io.dgn7.LineStringElement; |
| | | import com.ximple.io.dgn7.ArcElement; |
| | | import com.ximple.io.dgn7.TextNodeElement; |
| | | import com.ximple.io.dgn7.LineElement; |
| | | import com.ximple.io.dgn7.EllipseElement; |
| | | import com.ximple.io.dgn7.ComplexChainElement; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.io.dgn7.UserAttributeData; |
| | | |
| | | public class GeneralDgnConvertMySQLJobContext extends AbstractDgnToMySQLJobContext |
| | | { |
| | | static final Log logger = LogFactory.getLog(GeneralDgnConvertMySQLJobContext.class); |
| | | static final LoggerFacade sLogger = new CommonsLoggingLogger(logger); |
| | | static final GeometryFactory geometryFactory = new GeometryFactory(); |
| | | |
| | | private String dataOut = null; |
| | | |
| | | private HashMap<String, ArrayList<Feature>> featuresContext = new HashMap<String, ArrayList<Feature>>(); |
| | | private HashMap<String, FeatureWriter> featuresWriterContext = new HashMap<String, FeatureWriter>(); |
| | | |
| | | private PessimisticMapWrapper txFeaturesContext; |
| | | private TreeMap<String, FeatureTypeBuilder> typeBuilders = new TreeMap<String, FeatureTypeBuilder>(); |
| | | private TreeMap<String, FeatureType> featureTypes = new TreeMap<String, FeatureType>(); |
| | | |
| | | private TWD97GeometryConverterDecorator convertDecorator = null; |
| | | private String featureBaseName = null; |
| | | private boolean withIndex = false; |
| | | |
| | | public GeneralDgnConvertMySQLJobContext(String dataPath, DataStore targetDataStore) |
| | | { |
| | | super(dataPath, targetDataStore); |
| | | txFeaturesContext = new PessimisticMapWrapper(featuresContext, sLogger); |
| | | convertDecorator = new TWD97GeometryConverterDecorator(); |
| | | } |
| | | |
| | | public void putFeatureCollection(Element element) throws IllegalAttributeException, SchemaException |
| | | { |
| | | FeatureType ft = lookupFeatureType(element); |
| | | if (ft != null) |
| | | { |
| | | Feature feature = createFeature(ft, element); |
| | | if (feature == null) |
| | | { |
| | | if (element instanceof TextElement) |
| | | logger.info("cannot craete feature." + element.toString() + "'" + |
| | | ((TextElement) element).getText() + "'"); |
| | | else if (element instanceof ShapeElement) |
| | | logger.info("cannot craete feature." + element.toString() + "'" + |
| | | ((ShapeElement) element).getVerticeSize() + "'" + |
| | | ((ShapeElement) element).getStartPoint()); |
| | | else if (element instanceof LineStringElement) |
| | | logger.info("cannot craete feature." + element.toString() + "'" + |
| | | ((LineStringElement) element).getVerticeSize() + "'" + |
| | | ((LineStringElement) element).getStartPoint()); |
| | | else if (element instanceof ArcElement) |
| | | logger.info("cannot craete feature." + element.toString() + "'" + |
| | | ((ArcElement) element).getOrigin().toString() + "'" + |
| | | ((ArcElement) element).getRotationAngle()); |
| | | |
| | | return; |
| | | } |
| | | |
| | | if (!txFeaturesContext.containsKey(feature.getFeatureType())) |
| | | { |
| | | txFeaturesContext.put(feature.getFeatureType(), new ArrayList<Feature>()); |
| | | } |
| | | ArrayList<Feature> arrayList = (ArrayList<Feature>) txFeaturesContext.get(feature.getFeatureType()); |
| | | arrayList.add(feature); |
| | | } else |
| | | { |
| | | logger.info("Unknown Element :" + element.getType() + ", lv=" + element.getLevelIndex()); |
| | | } |
| | | } |
| | | |
| | | public void startTransaction() |
| | | { |
| | | } |
| | | |
| | | public void commitTransaction() |
| | | { |
| | | if (!txFeaturesContext.isEmpty()) |
| | | { |
| | | logger.debug("Transaction size = " + txFeaturesContext.size()); |
| | | //txFeaturesContext.commitTransaction(); |
| | | } else |
| | | { |
| | | logger.debug("Transaction is empty."); |
| | | } |
| | | |
| | | if (!featuresContext.isEmpty()) |
| | | { |
| | | updateDataStore(); |
| | | } |
| | | } |
| | | |
| | | public void rollbackTransaction() |
| | | { |
| | | //txFeaturesContext.rollbackTransaction(); |
| | | if (!featuresContext.isEmpty()) |
| | | { |
| | | updateDataStore(); |
| | | } |
| | | } |
| | | |
| | | private void updateDataStore() |
| | | { |
| | | Iterator it = featuresContext.keySet().iterator(); |
| | | |
| | | try |
| | | { |
| | | while (it.hasNext()) |
| | | { |
| | | FeatureType featureType = (FeatureType) it.next(); |
| | | logger.debug("Begin Save into OracleSDO:" + featureType.getTypeName()); |
| | | |
| | | FeatureWriter writer; |
| | | if (featuresWriterContext.containsKey(featureType.getTypeName())) |
| | | { |
| | | writer = featuresWriterContext.get(featureType.getTypeName()); |
| | | } else |
| | | { |
| | | if (!isExistFeature(featureType)) |
| | | { |
| | | targetDataStore.createSchema(featureType); |
| | | writer = targetDataStore.getFeatureWriter(featureType.getTypeName(), |
| | | Transaction.AUTO_COMMIT); |
| | | } else |
| | | { |
| | | writer = targetDataStore.getFeatureWriterAppend(featureType.getTypeName(), |
| | | Transaction.AUTO_COMMIT); |
| | | } |
| | | featuresWriterContext.put(featureType.getTypeName(), writer); |
| | | } |
| | | |
| | | ArrayList<Feature> features = featuresContext.get(featureType); |
| | | Iterator itFeature = features.iterator(); |
| | | while (itFeature.hasNext()) |
| | | { |
| | | Feature feature = (Feature) itFeature.next(); |
| | | ((SimpleFeature) writer.next()).setAttributes(feature.getAttributes(null)); |
| | | } |
| | | //writer.close(); |
| | | logger.debug("End Save into OracleSDO:" + featureType.getTypeName()); |
| | | } |
| | | featuresContext.clear(); |
| | | } catch (MalformedURLException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } catch (IllegalAttributeException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } catch (IOException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | public void closeFeatureWriter() throws IOException |
| | | { |
| | | |
| | | for (FeatureWriter featureWriter : this.featuresWriterContext.values()) |
| | | { |
| | | featureWriter.close(); |
| | | } |
| | | |
| | | this.featuresWriterContext.clear(); |
| | | } |
| | | |
| | | public FeatureType createPointFeatureElement(String featureName) throws SchemaException |
| | | { |
| | | if (!typeBuilders.containsKey(featureName)) |
| | | { |
| | | FeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createNormalPointFeatureTypeBuilder(featureName); |
| | | typeBuilders.put(featureName, typeBuilder); |
| | | } |
| | | return typeBuilders.get(featureName).getFeatureType(); |
| | | } |
| | | |
| | | public FeatureType createLineFeatureElement(String featureName) throws SchemaException |
| | | { |
| | | if (!typeBuilders.containsKey(featureName)) |
| | | { |
| | | FeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createNormalLineFeatureTypeBuilder(featureName); |
| | | typeBuilders.put(featureName, typeBuilder); |
| | | } |
| | | return typeBuilders.get(featureName).getFeatureType(); |
| | | } |
| | | |
| | | public FeatureType createArcFeatureElement(String featureName) throws SchemaException |
| | | { |
| | | if (!typeBuilders.containsKey(featureName)) |
| | | { |
| | | FeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createNormalArcFeatureTypeBuilder(featureName); |
| | | typeBuilders.put(featureName, typeBuilder); |
| | | } |
| | | return typeBuilders.get(featureName).getFeatureType(); |
| | | } |
| | | |
| | | public FeatureType createEllipseFeatureElement(String featureName) throws SchemaException |
| | | { |
| | | if (!typeBuilders.containsKey(featureName)) |
| | | { |
| | | FeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createNormalEllipseFeatureTypeBuilder(featureName); |
| | | typeBuilders.put(featureName, typeBuilder); |
| | | } |
| | | return typeBuilders.get(featureName).getFeatureType(); |
| | | } |
| | | |
| | | public Feature createFeature(FeatureType featureType, Element element) throws IllegalAttributeException |
| | | { |
| | | DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance(); |
| | | if (element instanceof TextElement) |
| | | { |
| | | TextElement textElement = (TextElement) element; |
| | | convertDecorator.setConverter(textElement); |
| | | |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | double angle = textElement.getRotationAngle(); |
| | | String content = textElement.getText(); |
| | | angle = BigDecimal.valueOf(angle).setScale(3, RoundingMode.HALF_UP).doubleValue(); |
| | | if (geom != null) |
| | | { |
| | | return featureType.create(new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(textElement.getColorIndex()), |
| | | textElement.getFontIndex(), |
| | | textElement.getJustification(), |
| | | textElement.getTextHeight(), |
| | | textElement.getTextWidth(), |
| | | angle, |
| | | content |
| | | }); |
| | | } else |
| | | { |
| | | logger.info("geometry is null." + element.toString()); |
| | | } |
| | | return null; |
| | | } else if (element instanceof TextNodeElement) |
| | | { |
| | | TextNodeElement textNodeElement = (TextNodeElement) element; |
| | | convertDecorator.setConverter(textNodeElement); |
| | | |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | double angle = textNodeElement.getRotationAngle(); |
| | | angle = BigDecimal.valueOf(angle).setScale(3, RoundingMode.HALF_UP).doubleValue(); |
| | | String[] texts = textNodeElement.getTextArray(); |
| | | StringBuilder sb = new StringBuilder(); |
| | | for (String text : texts) |
| | | { |
| | | if (sb.length() != 0) |
| | | sb.append("\n"); |
| | | sb.append(text); |
| | | } |
| | | |
| | | if (geom != null) |
| | | { |
| | | return featureType.create(new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(textNodeElement.getColorIndex()), |
| | | textNodeElement.getFontIndex(), |
| | | textNodeElement.getJustification(), |
| | | textNodeElement.getTextNodeHeight(), |
| | | textNodeElement.getTextNodeLength(), |
| | | angle, |
| | | sb.toString() |
| | | }); |
| | | } else |
| | | { |
| | | logger.info("geometry is null." + element.toString()); |
| | | } |
| | | return null; |
| | | } else if (element instanceof ShapeElement) |
| | | { |
| | | ShapeElement shapeElement = (ShapeElement) element; |
| | | convertDecorator.setConverter(shapeElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) |
| | | { |
| | | return featureType.create(new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(shapeElement.getColorIndex()), |
| | | shapeElement.getWeight(), |
| | | shapeElement.getLineStyle() |
| | | }); |
| | | } else |
| | | { |
| | | logger.info("geometry is null." + element.toString()); |
| | | } |
| | | return null; |
| | | } else if (element instanceof LineStringElement) |
| | | { |
| | | LineStringElement linestring = (LineStringElement) element; |
| | | convertDecorator.setConverter(linestring); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) |
| | | return featureType.create(new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(linestring.getColorIndex()), |
| | | linestring.getWeight(), |
| | | linestring.getLineStyle() |
| | | }); |
| | | return null; |
| | | } else if (element instanceof LineElement) |
| | | { |
| | | LineElement line = (LineElement) element; |
| | | convertDecorator.setConverter(line); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) |
| | | return featureType.create(new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(line.getColorIndex()), |
| | | line.getWeight(), |
| | | line.getLineStyle() |
| | | }); |
| | | return null; |
| | | } else if (element instanceof ArcElement) |
| | | { |
| | | ArcElement arcElement = (ArcElement) element; |
| | | /* |
| | | logger.fatal("" + arcElement.getPrimary() + ":" + arcElement.getSecondary() + |
| | | "-" + arcElement.getStartAngle() + ":" + arcElement.getSweepAngle() + ":" + |
| | | arcElement.getRotationAngle() + ":" + arcElement.getOrigin()); |
| | | */ |
| | | convertDecorator.setConverter(arcElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) |
| | | return featureType.create(new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(arcElement.getColorIndex()), |
| | | arcElement.getWeight(), |
| | | arcElement.getLineStyle() |
| | | }); |
| | | return null; |
| | | } else if (element instanceof EllipseElement) |
| | | { |
| | | EllipseElement arcElement = (EllipseElement) element; |
| | | convertDecorator.setConverter(arcElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) |
| | | return featureType.create(new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(arcElement.getColorIndex()), |
| | | arcElement.getWeight(), |
| | | arcElement.getLineStyle() |
| | | }); |
| | | return null; |
| | | } else if (element instanceof ComplexChainElement) |
| | | { |
| | | ComplexChainElement complexChainElement = (ComplexChainElement) element; |
| | | convertDecorator.setConverter(complexChainElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) |
| | | return featureType.create(new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(complexChainElement.getColorIndex()), |
| | | complexChainElement.getWeight(), |
| | | complexChainElement.getLineStyle() |
| | | }); |
| | | return null; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private String getFeatureBaseName() |
| | | { |
| | | if (featureBaseName == null) |
| | | { |
| | | String dgnname = getFilename().toLowerCase(); |
| | | int i = dgnname.lastIndexOf("."); |
| | | if (i != -1) |
| | | { |
| | | dgnname = dgnname.substring(0, i); |
| | | } |
| | | featureBaseName = dgnname; |
| | | } |
| | | return featureBaseName; |
| | | } |
| | | |
| | | private FeatureType lookupFeatureType(Element element) throws SchemaException, IllegalAttributeException |
| | | { |
| | | String typeName; |
| | | if (element instanceof TextElement) |
| | | { |
| | | typeName = getFeatureBaseName() + "_P"; |
| | | if (!featureTypes.containsKey(typeName)) |
| | | { |
| | | featureTypes.put(typeName, createPointFeatureElement(typeName)); |
| | | } |
| | | return featureTypes.get(typeName); |
| | | } else if (element instanceof TextNodeElement) |
| | | { |
| | | typeName = getFeatureBaseName() + "_P"; |
| | | if (!featureTypes.containsKey(typeName)) |
| | | { |
| | | featureTypes.put(typeName, createPointFeatureElement(typeName)); |
| | | } |
| | | return featureTypes.get(typeName); |
| | | } else if (element instanceof LineStringElement) |
| | | { |
| | | if (element instanceof ShapeElement) |
| | | { |
| | | typeName = getFeatureBaseName() + "_R"; |
| | | if (!featureTypes.containsKey(typeName)) |
| | | { |
| | | featureTypes.put(typeName, createLineFeatureElement(typeName)); |
| | | } |
| | | return featureTypes.get(typeName); |
| | | } else |
| | | { |
| | | typeName = getFeatureBaseName() + "_L"; |
| | | if (!featureTypes.containsKey(typeName)) |
| | | { |
| | | featureTypes.put(typeName, createLineFeatureElement(typeName)); |
| | | } |
| | | return featureTypes.get(typeName); |
| | | } |
| | | } else if (element instanceof LineElement) |
| | | { |
| | | typeName = getFeatureBaseName() + "_L"; |
| | | if (!featureTypes.containsKey(typeName)) |
| | | { |
| | | featureTypes.put(typeName, createLineFeatureElement(typeName)); |
| | | } |
| | | return featureTypes.get(typeName); |
| | | } else if (element instanceof ComplexChainElement) |
| | | { |
| | | typeName = getFeatureBaseName() + "_ML"; |
| | | if (!featureTypes.containsKey(typeName)) |
| | | { |
| | | featureTypes.put(typeName, createLineFeatureElement(typeName)); |
| | | } |
| | | return featureTypes.get(typeName); |
| | | } else if (element instanceof ArcElement) |
| | | { |
| | | typeName = getFeatureBaseName() + "_A"; |
| | | if (!featureTypes.containsKey(typeName)) |
| | | { |
| | | featureTypes.put(typeName, createArcFeatureElement(typeName)); |
| | | } |
| | | return featureTypes.get(typeName); |
| | | } else if (element instanceof EllipseElement) |
| | | { |
| | | typeName = getFeatureBaseName() + "_R"; |
| | | if (!featureTypes.containsKey(typeName)) |
| | | { |
| | | featureTypes.put(typeName, createEllipseFeatureElement(typeName)); |
| | | } |
| | | return featureTypes.get(typeName); |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | protected FrammeAttributeData getFeatureLinkage(Element element) |
| | | { |
| | | if (!element.hasUserAttributeData()) |
| | | return null; |
| | | |
| | | List<UserAttributeData> usrDatas = element.getUserAttributeData(); |
| | | for (UserAttributeData anUsrData : usrDatas) |
| | | { |
| | | if (anUsrData instanceof FrammeAttributeData) |
| | | { |
| | | return (FrammeAttributeData) anUsrData; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | public boolean isWithIndex() |
| | | { |
| | | return withIndex; |
| | | } |
| | | |
| | | public void setWithIndex(boolean withIndex) |
| | | { |
| | | this.withIndex = withIndex; |
| | | } |
| | | |
| | | public Log getLogger() |
| | | { |
| | | return logger; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.jobs.context.mysql; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.net.MalformedURLException; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.apache.commons.transaction.util.LoggerFacade; |
| | | import org.apache.commons.transaction.util.CommonsLoggingLogger; |
| | | import org.apache.commons.transaction.memory.PessimisticMapWrapper; |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.FeatureTypeBuilder; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | import org.geotools.feature.SimpleFeature; |
| | | import org.geotools.data.FeatureWriter; |
| | | import org.geotools.data.DataStore; |
| | | import org.geotools.data.Transaction; |
| | | |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | import com.vividsolutions.jts.geom.Envelope; |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.Coordinate; |
| | | |
| | | import com.ximple.eofms.util.TWD97GeometryConverterDecorator; |
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil; |
| | | import com.ximple.eofms.util.DefaultColorTable; |
| | | import com.ximple.eofms.util.TPCLIDConverter; |
| | | import com.ximple.eofms.util.TWDDatumConverter; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.TextElement; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.io.dgn7.UserAttributeData; |
| | | |
| | | public class IndexDgnConvertMySQLJobContext extends AbstractDgnToMySQLJobContext |
| | | { |
| | | static final Log logger = LogFactory.getLog(IndexDgnConvertMySQLJobContext.class); |
| | | static final LoggerFacade sLogger = new CommonsLoggingLogger(logger); |
| | | static final GeometryFactory geometryFactory = new GeometryFactory(); |
| | | TWD97GeometryConverterDecorator convertDecorator = new TWD97GeometryConverterDecorator(); |
| | | |
| | | private HashMap<String, ArrayList<Feature>> featuresContext = new HashMap<String, ArrayList<Feature>>(); |
| | | private HashMap<String, FeatureWriter> featuresWriterContext = new HashMap<String, FeatureWriter>(); |
| | | |
| | | private PessimisticMapWrapper txFeaturesContext; |
| | | private FeatureTypeBuilder typeBuilderPnt = null; |
| | | private FeatureTypeBuilder typeBuilderRect = null; |
| | | private FeatureType featureType = null; |
| | | private FeatureType featureType2 = null; |
| | | private FeatureType featureType3 = null; |
| | | |
| | | public IndexDgnConvertMySQLJobContext(String dataPath, DataStore targetDataStore) |
| | | { |
| | | super(dataPath, targetDataStore); |
| | | txFeaturesContext = new PessimisticMapWrapper(featuresContext, sLogger); |
| | | } |
| | | |
| | | public void putFeatureCollection(Element element) throws IllegalAttributeException, SchemaException |
| | | { |
| | | if (!(element instanceof TextElement)) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | Feature feature = createFeature((TextElement) element); |
| | | if (feature == null) |
| | | { |
| | | logger.info("cannot craete feature." + element.toString() + "'" + |
| | | ((TextElement) element).getText() + "'"); |
| | | return; |
| | | } |
| | | |
| | | if (!txFeaturesContext.containsKey(feature.getFeatureType())) |
| | | { |
| | | txFeaturesContext.put(feature.getFeatureType(), new ArrayList()); |
| | | } |
| | | ArrayList arrayList = (ArrayList) txFeaturesContext.get(feature.getFeatureType()); |
| | | arrayList.add(feature); |
| | | |
| | | feature = createFeature2((TextElement) element); |
| | | if (feature == null) |
| | | { |
| | | logger.info("cannot craete feature2." + element.toString() + "'" + |
| | | ((TextElement) element).getText() + "'"); |
| | | return; |
| | | } |
| | | |
| | | if (!txFeaturesContext.containsKey(feature.getFeatureType())) |
| | | { |
| | | txFeaturesContext.put(feature.getFeatureType(), new ArrayList()); |
| | | } |
| | | arrayList = (ArrayList) txFeaturesContext.get(feature.getFeatureType()); |
| | | arrayList.add(feature); |
| | | } |
| | | |
| | | public void startTransaction() |
| | | { |
| | | } |
| | | |
| | | public void commitTransaction() |
| | | { |
| | | if (!txFeaturesContext.isEmpty()) |
| | | { |
| | | logger.debug("Transaction size = " + txFeaturesContext.size()); |
| | | //txFeaturesContext.commitTransaction(); |
| | | } else |
| | | { |
| | | logger.debug("Transaction is empty."); |
| | | } |
| | | |
| | | if (!featuresContext.isEmpty()) |
| | | { |
| | | updateDataStore(); |
| | | } |
| | | } |
| | | |
| | | public void rollbackTransaction() |
| | | { |
| | | //txFeaturesContext.rollbackTransaction(); |
| | | if (!featuresContext.isEmpty()) |
| | | { |
| | | updateDataStore(); |
| | | } |
| | | } |
| | | |
| | | private void updateDataStore() |
| | | { |
| | | Iterator it = featuresContext.keySet().iterator(); |
| | | |
| | | try |
| | | { |
| | | while (it.hasNext()) |
| | | { |
| | | FeatureType featureType = (FeatureType) it.next(); |
| | | logger.debug("Begin Save OracleSDO:" + featureType.getTypeName()); |
| | | |
| | | FeatureWriter writer; |
| | | if (featuresWriterContext.containsKey(featureType.getTypeName())) |
| | | { |
| | | writer = featuresWriterContext.get(featureType.getTypeName()); |
| | | } else |
| | | { |
| | | if (!isExistFeature(featureType)) |
| | | { |
| | | targetDataStore.createSchema(featureType); |
| | | writer = targetDataStore.getFeatureWriter(featureType.getTypeName(), Transaction.AUTO_COMMIT); |
| | | } else |
| | | { |
| | | writer = targetDataStore.getFeatureWriterAppend(featureType.getTypeName(), Transaction.AUTO_COMMIT); |
| | | } |
| | | featuresWriterContext.put(featureType.getTypeName(), writer); |
| | | } |
| | | |
| | | ArrayList<Feature> features = featuresContext.get(featureType); |
| | | for (Feature feature1 : features) |
| | | { |
| | | ((SimpleFeature) writer.next()).setAttributes(feature1.getAttributes(null)); |
| | | } |
| | | //writer.close(); |
| | | logger.debug("End Save OracleSDO:" + featureType.getTypeName()); |
| | | } |
| | | featuresContext.clear(); |
| | | } catch (MalformedURLException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } catch (IllegalAttributeException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } catch (IOException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | public void closeFeatureWriter() throws IOException |
| | | { |
| | | |
| | | for (FeatureWriter featureWriter : this.featuresWriterContext.values()) |
| | | { |
| | | featureWriter.close(); |
| | | } |
| | | |
| | | this.featuresWriterContext.clear(); |
| | | } |
| | | |
| | | public FeatureType createFeatureElement(String featureName) throws SchemaException |
| | | { |
| | | if (typeBuilderRect == null) |
| | | { |
| | | typeBuilderRect = FeatureTypeBuilderUtil.createNormalIndexFeatureTypeBuilder(featureName); |
| | | } |
| | | return typeBuilderRect.getFeatureType(); |
| | | } |
| | | |
| | | public FeatureType createFeatureElement2(String featureName) throws SchemaException |
| | | { |
| | | if (typeBuilderPnt == null) |
| | | { |
| | | typeBuilderPnt = FeatureTypeBuilderUtil.createNormalIndexTextFeatureTypeBuilder(featureName); |
| | | } |
| | | return typeBuilderPnt.getFeatureType(); |
| | | } |
| | | |
| | | public Feature createFeature(FeatureType featureType, Element element) throws IllegalAttributeException |
| | | { |
| | | DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance(); |
| | | if (element instanceof TextElement) |
| | | { |
| | | TextElement textElement = (TextElement) element; |
| | | String tpclid = textElement.getText(); |
| | | |
| | | Envelope extent = TPCLIDConverter.convertTpclIdToEnvelope(tpclid); |
| | | Geometry geom = geometryFactory.createLinearRing(new Coordinate[] |
| | | { |
| | | TWDDatumConverter.fromTM2ToTWD97(new Coordinate(extent.getMinX(), extent.getMinY())), |
| | | TWDDatumConverter.fromTM2ToTWD97(new Coordinate(extent.getMaxX(), extent.getMinY())), |
| | | TWDDatumConverter.fromTM2ToTWD97(new Coordinate(extent.getMaxX(), extent.getMaxY())), |
| | | TWDDatumConverter.fromTM2ToTWD97(new Coordinate(extent.getMinX(), extent.getMaxY())), |
| | | TWDDatumConverter.fromTM2ToTWD97(new Coordinate(extent.getMinX(), extent.getMinY())), |
| | | }); |
| | | |
| | | return featureType.create(new Object[]{ |
| | | geom, |
| | | extent.getMinX(), |
| | | extent.getMinY(), |
| | | extent.getMaxX(), |
| | | extent.getMaxY(), |
| | | tpclid, |
| | | colorTable.getColorCode(textElement.getColorIndex()), |
| | | textElement.getWeight(), |
| | | textElement.getLineStyle() |
| | | }); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public Feature createFeature2(FeatureType featureType, Element element) throws IllegalAttributeException |
| | | { |
| | | DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance(); |
| | | if (element instanceof TextElement) |
| | | { |
| | | TextElement txtElement = (TextElement) element; |
| | | double angle = txtElement.getRotationAngle(); |
| | | angle = BigDecimal.valueOf(angle).setScale(3, RoundingMode.HALF_UP).doubleValue(); |
| | | convertDecorator.setConverter(txtElement); |
| | | Feature feature = featureType.create(new Object[]{ |
| | | convertDecorator.toGeometry(geometryFactory), |
| | | colorTable.getColorCode(txtElement.getColorIndex()), |
| | | txtElement.getWeight(), |
| | | txtElement.getLineStyle(), |
| | | txtElement.getJustification(), |
| | | txtElement.getTextHeight(), |
| | | txtElement.getTextWidth(), |
| | | angle, |
| | | txtElement.getText() |
| | | }); |
| | | return feature; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public Feature[] createFeature3(FeatureType featureType, Element element) throws IllegalAttributeException |
| | | { |
| | | DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance(); |
| | | if (element instanceof TextElement) |
| | | { |
| | | TextElement textElement = (TextElement) element; |
| | | String tpclid = textElement.getText(); |
| | | Feature[] result = new Feature[4]; |
| | | |
| | | Envelope extent = TPCLIDConverter.convertTpclIdToEnvelope(tpclid); |
| | | |
| | | for (int i = 0; i < 4; i++) |
| | | { |
| | | char mapSubId = TPCLIDConverter.intToAscii(65 + i); |
| | | int dx = (i % 2) * TPCLIDConverter.SX600; |
| | | int dy = (i / 2) * TPCLIDConverter.SY600; |
| | | |
| | | Geometry geom = geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[] |
| | | { |
| | | TWDDatumConverter.fromTM2ToTWD97(new Coordinate( |
| | | extent.getMinX() + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)), |
| | | TWDDatumConverter.fromTM2ToTWD97(new Coordinate( |
| | | extent.getMinX() + TPCLIDConverter.SX600 + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)), |
| | | TWDDatumConverter.fromTM2ToTWD97(new Coordinate( |
| | | extent.getMinX() + TPCLIDConverter.SX600 + dx, extent.getMaxY() - dy)), |
| | | TWDDatumConverter.fromTM2ToTWD97(new Coordinate( |
| | | extent.getMinX() + dx, extent.getMaxY() - dy)), |
| | | TWDDatumConverter.fromTM2ToTWD97(new Coordinate( |
| | | extent.getMinX() + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)), |
| | | }), null); |
| | | |
| | | result[i] = featureType.create(new Object[]{ |
| | | geom, |
| | | extent.getMinX(), |
| | | extent.getMinY(), |
| | | extent.getMaxX(), |
| | | extent.getMaxY(), |
| | | tpclid + mapSubId, |
| | | colorTable.getColorCode(textElement.getColorIndex()), |
| | | textElement.getWeight(), |
| | | textElement.getLineStyle() |
| | | }); |
| | | |
| | | } |
| | | return result; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private Feature createFeature(TextElement element) throws SchemaException, IllegalAttributeException |
| | | { |
| | | if (featureType == null) |
| | | { |
| | | String dgnname = getFilename().toLowerCase(); |
| | | int i = dgnname.lastIndexOf("."); |
| | | if (i != -1) |
| | | { |
| | | dgnname = dgnname.substring(0, i); |
| | | } |
| | | featureType = createFeatureElement(dgnname); |
| | | } |
| | | return createFeature(featureType, element); |
| | | } |
| | | |
| | | private Feature createFeature2(TextElement element) throws SchemaException, IllegalAttributeException |
| | | { |
| | | if (featureType2 == null) |
| | | { |
| | | String dgnname = getFilename().toLowerCase(); |
| | | int i = dgnname.lastIndexOf("."); |
| | | if (i != -1) |
| | | { |
| | | dgnname = dgnname.substring(0, i); |
| | | } |
| | | dgnname = dgnname + "P"; |
| | | featureType2 = createFeatureElement2(dgnname); |
| | | } |
| | | return createFeature2(featureType2, element); |
| | | } |
| | | |
| | | private Feature[] createFeature3(TextElement element) throws SchemaException, IllegalAttributeException |
| | | { |
| | | if (featureType3 == null) |
| | | { |
| | | String dgnname = getFilename().toLowerCase(); |
| | | int i = dgnname.lastIndexOf("."); |
| | | if (i != -1) |
| | | { |
| | | dgnname = dgnname.substring(0, i); |
| | | } |
| | | dgnname = dgnname + "_s"; |
| | | featureType3 = createFeatureElement(dgnname.toLowerCase()); |
| | | } |
| | | return createFeature3(featureType3, element); |
| | | } |
| | | |
| | | protected FrammeAttributeData getFeatureLinkage(Element element) |
| | | { |
| | | if (!element.hasUserAttributeData()) |
| | | return null; |
| | | |
| | | List<UserAttributeData> usrDatas = element.getUserAttributeData(); |
| | | for (UserAttributeData anUsrData : usrDatas) |
| | | { |
| | | if (anUsrData instanceof FrammeAttributeData) |
| | | { |
| | | return (FrammeAttributeData) anUsrData; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public Log getLogger() |
| | | { |
| | | return logger; |
| | | } |
| | | } |
| | | |
New file |
| | |
| | | package com.ximple.eofms.jobs.context.mysql; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.MalformedURLException; |
| | | import java.net.URL; |
| | | import java.sql.DriverManager; |
| | | import java.sql.SQLException; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | |
| | | import org.apache.commons.digester.Digester; |
| | | import org.apache.commons.digester.xmlrules.DigesterLoader; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.apache.commons.transaction.memory.PessimisticMapWrapper; |
| | | import org.apache.commons.transaction.util.CommonsLoggingLogger; |
| | | import org.apache.commons.transaction.util.LoggerFacade; |
| | | import org.geotools.data.DataStore; |
| | | import org.geotools.data.FeatureWriter; |
| | | import org.geotools.data.Transaction; |
| | | import org.geotools.data.mysql.MySQLDataStoreFactory; |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SimpleFeature; |
| | | import org.quartz.JobExecutionContext; |
| | | import org.xml.sax.SAXException; |
| | | |
| | | import com.vividsolutions.jts.util.Assert; |
| | | |
| | | import com.ximple.eofms.filter.AbstractFLinkageDispatchableFilter; |
| | | import com.ximple.eofms.filter.ElementDispatcher; |
| | | import com.ximple.eofms.jobs.OracleElementLogger; |
| | | import com.ximple.io.dgn7.ComplexElement; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | |
| | | public class OracleConvertMySQLJobContext extends AbstractOracleToMySQLJobContext |
| | | { |
| | | static Log logger = LogFactory.getLog(OracleConvertMySQLJobContext.class); |
| | | static final LoggerFacade sLogger = new CommonsLoggingLogger(logger); |
| | | |
| | | static MySQLDataStoreFactory dataStoreFactory = new MySQLDataStoreFactory(); |
| | | |
| | | private OracleElementLogger elmLogger = null; |
| | | |
| | | static |
| | | { |
| | | try |
| | | { |
| | | DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); |
| | | } catch (SQLException e) |
| | | { |
| | | Assert.shouldNeverReachHere(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | private String _filterConfig; |
| | | |
| | | private ElementDispatcher elementDispatcher; |
| | | |
| | | private HashMap featuresContext = new HashMap(); |
| | | private HashMap<String, FeatureWriter> featuresWriterContext = new HashMap<String, FeatureWriter>(); |
| | | private PessimisticMapWrapper txFeaturesContext; |
| | | |
| | | private JobExecutionContext executionContext; |
| | | |
| | | private String currentSchema = null; |
| | | private String mysqlCurrentSchema = null; |
| | | private boolean schemaChanged = false; |
| | | // private String _convertElementIn = null; |
| | | |
| | | public OracleConvertMySQLJobContext(String dataPath, DataStore oraDS, String filterConfig) |
| | | { |
| | | super(dataPath, oraDS); |
| | | _filterConfig = filterConfig; |
| | | elementDispatcher = createElementDispatcher(); |
| | | txFeaturesContext = new PessimisticMapWrapper(featuresContext, sLogger); |
| | | } |
| | | |
| | | private ElementDispatcher createElementDispatcher() |
| | | { |
| | | try |
| | | { |
| | | URL rulesURL = ElementDispatcher.class.getResource("ElementDispatcherRules.xml"); |
| | | assert rulesURL != null; |
| | | Digester digester = DigesterLoader.createDigester(rulesURL); |
| | | URL filterURL = null; |
| | | if (_filterConfig != null) |
| | | { |
| | | File config = new File(_filterConfig); |
| | | if (config.exists()) |
| | | { |
| | | filterURL = config.toURI().toURL(); |
| | | } |
| | | } |
| | | if (filterURL == null) |
| | | { |
| | | // config = new File("conf/DefaultConvertShpFilter.xml"); |
| | | filterURL = this.getClass().getResource("/conf/DefaultConvertShpFilter.xml"); |
| | | // filterURL = this.getClass().getResource("/conf/ConvertShpFilterForLevel.xml"); |
| | | } |
| | | assert filterURL != null; |
| | | return (ElementDispatcher) digester.parse(filterURL); |
| | | } catch (UnsupportedEncodingException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } catch (MalformedURLException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } catch (IOException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } catch (SAXException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | throw new RuntimeException(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | public void putFeatureCollection(Element element) |
| | | { |
| | | assert elementDispatcher != null; |
| | | // §PÂ_¬O§_²Å©M±ø¥ó |
| | | Feature feature = elementDispatcher.execute(element, true); |
| | | if (feature == null) |
| | | { |
| | | boolean isEmptySize = false; |
| | | FrammeAttributeData linkage = |
| | | AbstractFLinkageDispatchableFilter.getFeatureLinkage(element); |
| | | logger.warn("Unknown Element:" + element.getElementType().toString() + |
| | | ":type=" + element.getType() + ":lv=" + element.getLevelIndex() + ":id=" + |
| | | (linkage == null ? "NULL" : (linkage.getFsc() + "|" + linkage.getComponentID()))); |
| | | |
| | | if (element instanceof ComplexElement) |
| | | { |
| | | ComplexElement complex = (ComplexElement) element; |
| | | logger.warn("----Complex Element size=" + complex.size() + ":" + |
| | | (linkage == null ? "NULL" : (linkage.getUfid()))); |
| | | isEmptySize = true; |
| | | } |
| | | |
| | | if (getElementLogging() && (!isEmptySize)) |
| | | { |
| | | getElementLogger().logElement(element, getCurrentSchema()); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | if (!txFeaturesContext.containsKey(feature.getFeatureType())) |
| | | { |
| | | txFeaturesContext.put(feature.getFeatureType(), new ArrayList()); |
| | | } |
| | | ArrayList arrayList = (ArrayList) txFeaturesContext.get(feature.getFeatureType()); |
| | | arrayList.add(feature); |
| | | } |
| | | |
| | | public void startTransaction() |
| | | { |
| | | //txFeaturesContext.startTransaction(); |
| | | } |
| | | |
| | | public void commitTransaction() |
| | | { |
| | | if (!txFeaturesContext.isEmpty()) |
| | | { |
| | | logger.debug("Transaction size = " + txFeaturesContext.size()); |
| | | //txFeaturesContext.commitTransaction(); |
| | | } else |
| | | { |
| | | logger.debug("Transaction is empty."); |
| | | } |
| | | |
| | | if (!featuresContext.isEmpty()) |
| | | { |
| | | updateDataStore(); |
| | | } |
| | | |
| | | if (this.getElementLogger() != null) |
| | | this.getElementLogger().flashLogging(); |
| | | } |
| | | |
| | | public void rollbackTransaction() |
| | | { |
| | | //txFeaturesContext.rollbackTransaction(); |
| | | if (!featuresContext.isEmpty()) |
| | | { |
| | | updateDataStore(); |
| | | } |
| | | } |
| | | |
| | | private void updateDataStore() |
| | | { |
| | | Iterator it = featuresContext.keySet().iterator(); |
| | | |
| | | try |
| | | { |
| | | while (it.hasNext()) |
| | | { |
| | | FeatureType featureType = (FeatureType) it.next(); |
| | | FeatureWriter writer = null; |
| | | if (featuresWriterContext.containsKey(featureType.getTypeName())) |
| | | { |
| | | writer = featuresWriterContext.get(featureType.getTypeName()); |
| | | } else |
| | | { |
| | | DataStore postGisDataStore = null; |
| | | postGisDataStore = dataStoreFactory.createDataStore(properties); |
| | | |
| | | boolean existTable = isExistFeature(featureType); |
| | | |
| | | if (!existTable) |
| | | { |
| | | postGisDataStore.createSchema(featureType); |
| | | writer = postGisDataStore.getFeatureWriter(featureType.getTypeName(), |
| | | Transaction.AUTO_COMMIT); |
| | | } else |
| | | { |
| | | writer = postGisDataStore.getFeatureWriterAppend(featureType.getTypeName(), |
| | | Transaction.AUTO_COMMIT); |
| | | } |
| | | featuresWriterContext.put(featureType.getTypeName(), writer); |
| | | } |
| | | |
| | | ArrayList features = (ArrayList) featuresContext.get(featureType); |
| | | Iterator itFeature = features.iterator(); |
| | | while (itFeature.hasNext()) |
| | | { |
| | | Feature feature = (Feature) itFeature.next(); |
| | | ((SimpleFeature) writer.next()).setAttributes(feature.getAttributes(null)); |
| | | } |
| | | //writer.close(); |
| | | logger.debug("End Save OracleSDO:" + featureType.getTypeName()); |
| | | } |
| | | featuresContext.clear(); |
| | | } catch (MalformedURLException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } catch (IllegalAttributeException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } catch (IOException e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | } |
| | | |
| | | } |
| | | |
| | | public JobExecutionContext getExecutionContext() |
| | | { |
| | | return executionContext; |
| | | } |
| | | |
| | | public void setExecutionContext(JobExecutionContext context) |
| | | { |
| | | executionContext = context; |
| | | } |
| | | |
| | | /** |
| | | * Ãö³¬³]³Æ¼g¤J¾¹ |
| | | * |
| | | * @throws IOException IOµo¥Í¿ù»~ |
| | | */ |
| | | public void closeFeatureWriter() throws IOException |
| | | { |
| | | |
| | | for (FeatureWriter featureWriter : this.featuresWriterContext.values()) |
| | | { |
| | | featureWriter.close(); |
| | | } |
| | | |
| | | this.featuresWriterContext.clear(); |
| | | } |
| | | |
| | | protected OracleElementLogger getElementLogger() |
| | | { |
| | | if (elmLogger == null) |
| | | { |
| | | elmLogger = new OracleElementLogger(getOracleConnection()); |
| | | elmLogger.setDataPath(this.getDataPath()); |
| | | } |
| | | return elmLogger; |
| | | } |
| | | |
| | | public boolean isSchemaChanged() |
| | | { |
| | | return schemaChanged; |
| | | } |
| | | |
| | | public String getCurrentSchema() |
| | | { |
| | | return currentSchema; |
| | | } |
| | | |
| | | public void setCurrentSchema(String querySchema) |
| | | { |
| | | this.currentSchema = querySchema; |
| | | this.schemaChanged = true; |
| | | } |
| | | |
| | | protected Log getLogger() |
| | | { |
| | | return logger; |
| | | } |
| | | } |
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/AbstractDgnToOraSDOJobContext.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/AbstractOracleToOraSDOJobContext.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/DummyFeatureConvertOraSDOJobContext.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/FeatureDgnConvertOraSDOJobContext.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/GeneralDgnConvertOraSDOJobContext.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/IndexDgnConvertOraSDOJobContext.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/OracleConvertOraSDOJobContext.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/AbstractDgnToPostGISJobContext.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/AbstractOracleToPostGISJobContext.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/DummyFeatureConvertPostGISJobContext.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/FeatureDgnConvertPostGISJobContext.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/GeneralDgnConvertPostGISJobContext.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/IndexDgnConvertPostGISJobContext.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/OracleConvertPostGISJobContext.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/shapefile/AbstractDgnToShapefileJobContext.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/shapefile/DummyFeatureConvertShpJobContext.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/shapefile/FeatureDgnConvertShpJobContext.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/shapefile/GeneralDgnConvertShpJobContext.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/shapefile/IndexDgnConvertShpJobContext.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/shapefile/OracleConvertShapefilesJobContext.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/Base64.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/BinConverter.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/Bits.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/ByteArrayCompressor.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/ColorTableMapping.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/DefaultColorTable.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/FeatureTypeBuilderUtil.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/GeomUtil.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/LangUtil.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/PrintfFormat.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/StringUtils.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/TPCLIDConverter.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/TWD97GeometryConverterDecorator.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/TWDDatumConverter.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/postjts/JTSShape.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/postjts/JtsBinaryParser.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/postjts/JtsBinaryWriter.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/postjts/JtsGeometry.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/postjts/JtsGisWrapper.java
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/postjts/JtsWrapper.java
xdgnjobs/ximple-spatialjob/src/main/resources/com/ximple/eofms/filter/ElementDispatcherRules.xml
xdgnjobs/ximple-spatialjob/src/main/resources/com/ximple/eofms/filter/FeatureClassificationRules.xml
xdgnjobs/ximple-spatialjob/src/main/resources/conf/ConvertShpFilterForLayer.xml
xdgnjobs/ximple-spatialjob/src/main/resources/conf/DefaultConvertShpFilter.xml
xdgnjobs/ximple-spatialjob/src/main/resources/conf/DefaultMapGroups.xml
xdgnjobs/ximple-spatialjob/src/test/java/com/ximple/eofms/filter/ElementDispatcherTest.java
xdgnjobs/ximple-spatialjob/src/test/resources/com/ximple/eofms/filter/test-data/testElementFilter.xml
xdgnjobs/ximple-spatialjob/src/test/resources/com/ximple/eofms/filter/test-data/testRules.xml |