| | |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.FileNotFoundException; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.MalformedURLException; |
| | | import java.net.URL; |
| | | import java.net.URLDecoder; |
| | | import java.sql.DriverManager; |
| | | import java.sql.SQLException; |
| | | import java.util.ArrayList; |
| | |
| | | import org.apache.commons.transaction.memory.PessimisticMapWrapper; |
| | | import org.apache.commons.transaction.util.CommonsLoggingLogger; |
| | | import org.apache.commons.transaction.util.LoggerFacade; |
| | | import org.apache.commons.digester.Digester; |
| | | import org.apache.commons.digester.xmlrules.DigesterLoader; |
| | | import org.geotools.data.FeatureWriter; |
| | | import org.geotools.data.Transaction; |
| | | import org.geotools.data.shapefile.ShapefileDataStore; |
| | |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SimpleFeature; |
| | | import org.geotools.TestData; |
| | | import org.xml.sax.SAXException; |
| | | |
| | | import com.vividsolutions.jts.util.Assert; |
| | | |
| | |
| | | import com.ximple.eofms.filter.CreateLineStringStrategy; |
| | | import com.ximple.eofms.filter.ElementDispatcher; |
| | | import com.ximple.eofms.filter.TypeCompIdDispatchableFilter; |
| | | import com.ximple.eofms.filter.AbstractFLinkageDispatchableFilter; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | |
| | | public class OracleConvertJobContext |
| | | { |
| | |
| | | |
| | | protected static final long TIMEOUT = Long.MAX_VALUE; |
| | | |
| | | /** |
| | | * Encoding of URL path. |
| | | */ |
| | | private static final String ENCODING = "UTF-8"; |
| | | |
| | | static |
| | | { |
| | | try |
| | |
| | | } |
| | | |
| | | private String _oracleHost; |
| | | private String _filterConfig; |
| | | private String _oracleInstance; |
| | | private String _oraclePort; |
| | | private String _dataPath; |
| | |
| | | private HashMap featuresContext = new HashMap(); |
| | | private PessimisticMapWrapper txFeaturesContext; |
| | | |
| | | public OracleConvertJobContext() |
| | | public OracleConvertJobContext(String filterConfig) |
| | | { |
| | | properties = new Properties(); |
| | | _filterConfig = filterConfig; |
| | | elementDispatcher = createElementDispatcher(); |
| | | txFeaturesContext = new PessimisticMapWrapper(featuresContext, sLogger); |
| | | |
| | |
| | | |
| | | private ElementDispatcher createElementDispatcher() |
| | | { |
| | | ElementDispatcher dispatcher = new ElementDispatcher(); |
| | | dispatcher.addRule(new TypeCompIdDispatchableFilter("Conductor", new CreateLineStringStrategy(), 106, 0)); |
| | | return dispatcher; |
| | | URL rulesURL = getClass().getResource("ElementDispatcherRules.xml"); |
| | | |
| | | File rulesFile = null; |
| | | try |
| | | { |
| | | rulesFile = new File(URLDecoder.decode(rulesURL.getPath(), ENCODING)); |
| | | if (!rulesFile.exists()) { |
| | | throw new FileNotFoundException("Could not locate test-data: " + rulesFile); |
| | | } |
| | | Digester digester = DigesterLoader.createDigester(rulesFile.toURI().toURL()); |
| | | File config = new File(_filterConfig); |
| | | if (!config.exists()) |
| | | { |
| | | config = new File("conf\\DefaultConvertShpFilter.xml"); |
| | | } |
| | | ElementDispatcher dispatcher = (ElementDispatcher) digester.parse(config); |
| | | return dispatcher; |
| | | } 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 setLogin(String userName, String password) |
| | |
| | | { |
| | | Feature feature = elementDispatcher.execute(element); |
| | | if (feature == null) |
| | | { |
| | | FrammeAttributeData linkage = |
| | | AbstractFLinkageDispatchableFilter.getFeatureLinkage(element); |
| | | logger.debug("Unknown Element:" + element.getElementType().toString() + |
| | | ":type=" + element.getType() + ":lv=" + element.getLevelIndex() + ":id=" + |
| | | (linkage == null ? "NULL" : (linkage.getFsc() + "|" +linkage.getComponentID()))); |
| | | |
| | | return; |
| | | } |
| | | |
| | | if (!txFeaturesContext.containsKey(feature.getFeatureType())) |
| | | { |
| | |
| | | |
| | | public void commitTransaction() |
| | | { |
| | | txFeaturesContext.commitTransaction(); |
| | | if (!txFeaturesContext.isEmpty()) |
| | | { |
| | | logger.debug("Transaction size = " + txFeaturesContext.size()); |
| | | txFeaturesContext.commitTransaction(); |
| | | } else |
| | | logger.debug("Transaction is empty."); |
| | | |
| | | if (!featuresContext.isEmpty()) |
| | | { |
| | | updateDataStore(); |
| | |
| | | { |
| | | FeatureType featureType = (FeatureType) it.next(); |
| | | File sfile = new File(_dataPath + "\\" + featureType.getTypeName()); |
| | | logger.debug("Begin Save shapefile:" + sfile.toURI()); |
| | | |
| | | ShapefileDataStore shapefileDataStore = new ShapefileDataStore(sfile.toURL()); |
| | | shapefileDataStore.createSchema(featureType); |
| | | FeatureWriter writer = shapefileDataStore.getFeatureWriter(featureType.getTypeName(), Transaction.AUTO_COMMIT); |
| | |
| | | ((SimpleFeature) writer.next()).setAttributes(feature.getAttributes(null)); |
| | | } |
| | | writer.close(); |
| | | logger.debug("End Save shapefile:" + sfile.toURI()); |
| | | } |
| | | featuresContext.clear(); |
| | | } catch (MalformedURLException e) |