58 files modified
12 files added
| | |
| | | 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/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/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 |
| | |
| | | <version>1.3.2</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>mysql</groupId> |
| | | <artifactId>mysql-connector-java</artifactId> |
| | | <version>5.1.6</version> |
| | | </dependency> |
| | | |
| | | <!-- opensymphony --> |
| | | <dependency> |
| | | <groupId>opensymphony</groupId> |
| | |
| | | |
| | | import org.apache.log4j.Logger; |
| | | |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryCollection; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | import com.vividsolutions.jts.geom.CoordinateList; |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | /** |
| | | * ComplexShapeElement |
| | |
| | | { |
| | | list.add(((ShapeElement) element).toGeometry(factory)); |
| | | } |
| | | } |
| | | else if (element instanceof LineStringElement) |
| | | } else if (element instanceof LineStringElement) |
| | | { |
| | | if( ((LineStringElement) element).getVerticeSize() == 0 || ((LineStringElement) element).getVerticeSize() > 1) |
| | | { |
| | |
| | | */ |
| | | |
| | | // J2SE dependencies |
| | | |
| | | import java.lang.reflect.Method; |
| | | import java.nio.ByteBuffer; |
| | | import java.security.AccessController; |
| | |
| | | /** |
| | | * Utility class for managing memory mapped buffers. |
| | | * |
| | | * @since 2.0 |
| | | * @source $URL$ |
| | | * @version $Id$ |
| | | * @author Andres Aimes |
| | | * @version $Id$ |
| | | * @source $URL$ |
| | | * @since 2.0 |
| | | */ |
| | | public class NIOUtilities { |
| | | public class NIOUtilities |
| | | { |
| | | /** |
| | | * {@code true} if a warning has already been logged. |
| | | */ |
| | |
| | | * @todo This constructor will become private when {@code NIOBufferUtils} |
| | | * will have been removed. |
| | | */ |
| | | protected NIOUtilities() { |
| | | protected NIOUtilities() |
| | | { |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @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() ) { |
| | | 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 b = (Boolean) AccessController.doPrivileged(new PrivilegedAction() |
| | | { |
| | | public Object run() |
| | | { |
| | | Boolean success = Boolean.FALSE; |
| | | try { |
| | | 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) { |
| | | } catch (Exception e) |
| | | { |
| | | // This really is a show stopper on windows |
| | | if (isLoggable()) { |
| | | if (isLoggable()) |
| | | { |
| | | log(e, buffer); |
| | | } |
| | | } |
| | |
| | | /** |
| | | * Check if a warning message should be logged. |
| | | */ |
| | | private static synchronized boolean isLoggable() { |
| | | try { |
| | | 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) { |
| | | } 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) { |
| | | 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") |
| | |
| | | |
| | | import java.awt.geom.AffineTransform; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.ByteOrder; |
| | | import java.nio.CharBuffer; |
| | | import java.nio.charset.CharacterCodingException; |
| | | import java.nio.charset.Charset; |
| | |
| | | * In format strings containing the %<code>n</code>$ |
| | | * form of conversion specifications, each argument |
| | | * in the argument list is used exactly once.</p> |
| | | * |
| | | * <p/> |
| | | * <h4>Escape Sequences</h4> |
| | | * <p> |
| | | * The following table lists escape sequences and |
| | |
| | | * be mixed with the %<code>n</code>$ form. The |
| | | * results of mixing numbered and unnumbered argument |
| | | * specifications in a format string are undefined.</p> |
| | | * |
| | | * <p/> |
| | | * <h4>Flag Characters</h4> |
| | | * <p> |
| | | * The flags and their meanings are:</p> |
| | |
| | | * 0 flag will be ignored. For c conversions, |
| | | * the flag is ignored. |
| | | * </dl> |
| | | * |
| | | * <p/> |
| | | * <h4>Conversion Characters</h4> |
| | | * <p> |
| | | * Each conversion character results in fetching zero |
| | |
| | | * Usually, an unchecked exception will be thrown. |
| | | * If the format is exhausted while arguments remain, |
| | | * the excess arguments are ignored.</p> |
| | | * |
| | | * <p/> |
| | | * <p> |
| | | * The conversion characters and their meanings are: |
| | | * </p> |
| | |
| | | * followed by a digit. |
| | | * <dt>c,C<dd>The integer argument is converted to a |
| | | * char and the result is written. |
| | | * |
| | | * <p/> |
| | | * <dt>s,S<dd>The argument is taken to be a string and |
| | | * bytes from the string are written until the |
| | | * end of the string or the number of bytes |
| | |
| | | */ |
| | | public final class PrintfFormat |
| | | { |
| | | /** Vector of control strings and format literals. */ |
| | | /** |
| | | * Vector of control strings and format literals. |
| | | */ |
| | | private Vector vFmt = new Vector(); |
| | | |
| | | /** Character position. Used by the constructor. */ |
| | | /** |
| | | * Character position. Used by the constructor. |
| | | */ |
| | | private int cPos = 0; |
| | | |
| | | /** Character position. Used by the constructor. */ |
| | | /** |
| | | * Character position. Used by the constructor. |
| | | */ |
| | | private DecimalFormatSymbols dfs = null; |
| | | |
| | | /** |
| | |
| | | * unpaired percent signs. A pair of successive |
| | | * percent signs designates a single percent sign in |
| | | * the format. |
| | | * |
| | | * @param fmtArg Control string. |
| | | * @exception IllegalArgumentException if the control |
| | | * @throws IllegalArgumentException if the control |
| | | * string is null, zero length, or otherwise |
| | | * malformed. |
| | | */ |
| | |
| | | * unpaired percent signs. A pair of successive |
| | | * percent signs designates a single percent sign in |
| | | * the format. |
| | | * |
| | | * @param fmtArg Control string. |
| | | * @exception IllegalArgumentException if the control |
| | | * @throws IllegalArgumentException if the control |
| | | * string is null, zero length, or otherwise |
| | | * malformed. |
| | | */ |
| | |
| | | * of the String <code>s</code>, the next unpaired |
| | | * percent sign, or at the end of the String if the |
| | | * last character is a percent sign. |
| | | * |
| | | * @param s Control string. |
| | | * @param start Position in the string |
| | | * <code>s</code> to begin looking for the start |
| | |
| | | * Integer, Long, Float, Double, and Character |
| | | * arguments are treated as wrappers for primitive |
| | | * types. |
| | | * |
| | | * @param o The array of objects to format. |
| | | * @return The formatted String. |
| | | */ |
| | |
| | | |
| | | /** |
| | | * Format nothing. Just use the control string. |
| | | * |
| | | * @return the formatted String. |
| | | */ |
| | | public String sprintf() |
| | |
| | | |
| | | /** |
| | | * Format an int. |
| | | * |
| | | * @param x The int to format. |
| | | * @return The formatted String. |
| | | * @exception IllegalArgumentException if the |
| | | * @throws IllegalArgumentException if the |
| | | * conversion character is f, e, E, g, G, s, |
| | | * or S. |
| | | */ |
| | |
| | | |
| | | /** |
| | | * Format an long. |
| | | * |
| | | * @param x The long to format. |
| | | * @return The formatted String. |
| | | * @exception IllegalArgumentException if the |
| | | * @throws IllegalArgumentException if the |
| | | * conversion character is f, e, E, g, G, s, |
| | | * or S. |
| | | */ |
| | |
| | | |
| | | /** |
| | | * Format a double. |
| | | * |
| | | * @param x The double to format. |
| | | * @return The formatted String. |
| | | * @exception IllegalArgumentException if the |
| | | * @throws IllegalArgumentException if the |
| | | * conversion character is c, C, s, S, |
| | | * d, d, x, X, or o. |
| | | */ |
| | |
| | | |
| | | /** |
| | | * Format a String. |
| | | * |
| | | * @param x The String to format. |
| | | * @return The formatted String. |
| | | * @exception IllegalArgumentException if the |
| | | * @throws IllegalArgumentException if the |
| | | * conversion character is neither s nor S. |
| | | */ |
| | | public String sprintf(String x) throws IllegalArgumentException |
| | |
| | | * Strings using an internal formatting method for |
| | | * Strings. Otherwise use the default formatter |
| | | * (use toString). |
| | | * |
| | | * @param x the Object to format. |
| | | * @return the formatted String. |
| | | * @exception IllegalArgumentException if the |
| | | * @throws IllegalArgumentException if the |
| | | * conversion character is inappropriate for |
| | | * formatting an unwrapped value. |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * <p> |
| | | * <p/> |
| | | * ConversionSpecification allows the formatting of |
| | | * a single primitive or object embedded within a |
| | | * string. The formatting is controlled by a |
| | | * format string. Only one Java primitive or |
| | | * object can be formatted at a time. |
| | | * <p> |
| | | * <p/> |
| | | * A format string is a Java string that contains |
| | | * a control string. The control string starts at |
| | | * the first percent sign (%) in the string, |
| | |
| | | * <li>precedes a sequence of characters that parses |
| | | * as a valid control string. |
| | | * </ol> |
| | | * <p> |
| | | * <p/> |
| | | * A control string takes the form: |
| | | * <pre> % ['-+ #0]* [0..9]* { . [0..9]* }+ |
| | | * { [hlL] }+ [idfgGoxXeEcs] |
| | | * </pre> |
| | | * <p> |
| | | * <p/> |
| | | * The behavior is like printf. One (hopefully the |
| | | * only) exception is that the minimum number of |
| | | * exponent digits is 3 instead of 2 for e and E |
| | |
| | | */ |
| | | private class ConversionSpecification |
| | | { |
| | | /** Default precision. */ |
| | | /** |
| | | * Default precision. |
| | | */ |
| | | private final static int defaultDigits = 6; |
| | | |
| | | /** |
| | |
| | | */ |
| | | private boolean optionalL = false; |
| | | |
| | | /** Control string type. */ |
| | | /** |
| | | * Control string type. |
| | | */ |
| | | private char conversionCharacter = '\0'; |
| | | |
| | | /** |
| | |
| | | */ |
| | | private int pos = 0; |
| | | |
| | | /** Literal or control format string. */ |
| | | /** |
| | | * Literal or control format string. |
| | | */ |
| | | private String fmt; |
| | | |
| | | /** |
| | |
| | | * The argument must begin with a % and end |
| | | * with the conversion character for the |
| | | * conversion specification. |
| | | * |
| | | * @param fmtArg String specifying the |
| | | * conversion specification. |
| | | * @exception IllegalArgumentException if the |
| | | * @throws IllegalArgumentException if the |
| | | * input string is null, zero length, or |
| | | * otherwise malformed. |
| | | */ |
| | |
| | | |
| | | /** |
| | | * Set the String for this instance. |
| | | * |
| | | * @param s the String to store. |
| | | */ |
| | | void setLiteral(String s) |
| | |
| | | * Check whether the specifier has a variable |
| | | * field width that is going to be set by an |
| | | * argument. |
| | | * |
| | | * @return <code>true</code> if the conversion |
| | | * uses an * field width; otherwise |
| | | * <code>false</code>. |
| | |
| | | * Set the field width with an argument. A |
| | | * negative field width is taken as a - flag |
| | | * followed by a positive field width. |
| | | * |
| | | * @param fw the field width. |
| | | */ |
| | | void setFieldWidthWithArg(int fw) |
| | |
| | | * Check whether the specifier has a variable |
| | | * precision that is going to be set by an |
| | | * argument. |
| | | * |
| | | * @return <code>true</code> if the conversion |
| | | * uses an * precision; otherwise |
| | | * <code>false</code>. |
| | |
| | | /** |
| | | * Set the precision with an argument. A |
| | | * negative precision will be changed to zero. |
| | | * |
| | | * @param pr the precision. |
| | | */ |
| | | void setPrecisionWithArg(int pr) |
| | |
| | | /** |
| | | * Format an int argument using this conversion |
| | | * specification. |
| | | * |
| | | * @param s the int to format. |
| | | * @return the formatted String. |
| | | * @exception IllegalArgumentException if the |
| | | * @throws IllegalArgumentException if the |
| | | * conversion character is f, e, E, g, or G. |
| | | */ |
| | | String internalsprintf(int s) throws IllegalArgumentException |
| | |
| | | /** |
| | | * Format a long argument using this conversion |
| | | * specification. |
| | | * |
| | | * @param s the long to format. |
| | | * @return the formatted String. |
| | | * @exception IllegalArgumentException if the |
| | | * @throws IllegalArgumentException if the |
| | | * conversion character is f, e, E, g, or G. |
| | | */ |
| | | String internalsprintf(long s) throws IllegalArgumentException |
| | |
| | | /** |
| | | * Format a double argument using this conversion |
| | | * specification. |
| | | * |
| | | * @param s the double to format. |
| | | * @return the formatted String. |
| | | * @exception IllegalArgumentException if the |
| | | * @throws IllegalArgumentException if the |
| | | * conversion character is c, C, s, S, i, d, |
| | | * x, X, or o. |
| | | */ |
| | |
| | | /** |
| | | * Format a String argument using this conversion |
| | | * specification. |
| | | * |
| | | * @param s the String to format. |
| | | * @return the formatted String. |
| | | * @exception IllegalArgumentException if the |
| | | * @throws IllegalArgumentException if the |
| | | * conversion character is neither s nor S. |
| | | */ |
| | | String internalsprintf(String s) throws IllegalArgumentException |
| | |
| | | /** |
| | | * Format an Object argument using this conversion |
| | | * specification. |
| | | * |
| | | * @param s the Object to format. |
| | | * @return the formatted String. |
| | | * @exception IllegalArgumentException if the |
| | | * @throws IllegalArgumentException if the |
| | | * conversion character is neither s nor S. |
| | | */ |
| | | String internalsprintf(Object s) |
| | |
| | | * is ignored. The '0' flag character implies that |
| | | * padding to the field width will be done with |
| | | * zeros instead of blanks. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the number of digits |
| | | * to appear after the radix character. Padding is |
| | | * with trailing 0s. |
| | |
| | | * the input double value is an infinity, |
| | | * not-a-number, or a finite double and formats |
| | | * each type of input appropriately. |
| | | * |
| | | * @param x the double value to be formatted. |
| | | * @return the converted double value. |
| | | */ |
| | |
| | | * ignored. The '0' flag character implies that |
| | | * padding to the field width will be done with |
| | | * zeros instead of blanks. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the minimum number of |
| | | * digits to appear after the radix character. |
| | | * Padding is with trailing 0s. |
| | | * |
| | | * <p/> |
| | | * The behavior is like printf. One (hopefully the |
| | | * only) exception is that the minimum number of |
| | | * exponent digits is 3 instead of 2 for e and E |
| | |
| | | * Check to see if the digits that are going to |
| | | * be truncated because of the precision should |
| | | * force a round in the preceding digits. |
| | | * |
| | | * @param ca1 the array of digits |
| | | * @param icarry the index of the first digit that |
| | | * is to be truncated from the print |
| | |
| | | * is not quite finished because the symbolic |
| | | * carry may change the length of the string and |
| | | * change the exponent (in e format). |
| | | * |
| | | * @param cLast index of the last digit changed |
| | | * by the round |
| | | * @param cFirst index of the first digit allowed |
| | |
| | | * the input double value is an infinity, |
| | | * not-a-number, or a finite double and formats |
| | | * each type of input appropriately. |
| | | * |
| | | * @param x the double value to be formatted. |
| | | * @param eChar an 'e' or 'E' to use in the |
| | | * converted double value. |
| | |
| | | |
| | | /** |
| | | * Apply zero or blank, left or right padding. |
| | | * |
| | | * @param ca4 array of characters before padding is |
| | | * finished |
| | | * @param noDigits NaN or signed Inf |
| | |
| | | |
| | | /** |
| | | * Format method for the f conversion character. |
| | | * |
| | | * @param x the double to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Format method for the e or E conversion |
| | | * character. |
| | | * |
| | | * @param x the double to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | |
| | | /** |
| | | * Format method for the g conversion character. |
| | | * |
| | | * <p/> |
| | | * For g format, the flag character '-', means that |
| | | * the output should be left justified within the |
| | | * field. The default is to pad with blanks on the |
| | |
| | | * ignored. The '0' flag character implies that |
| | | * padding to the field width will be done with |
| | | * zeros instead of blanks. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the minimum number of |
| | | * digits to appear after the radix character. |
| | | * Padding is with trailing 0s. |
| | | * |
| | | * @param x the double to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Format method for the d conversion specifer and |
| | | * short argument. |
| | | * |
| | | * <p/> |
| | | * For d format, the flag character '-', means that |
| | | * the output should be left justified within the |
| | | * field. The default is to pad with blanks on the |
| | |
| | | * ignored. The '0' flag character implies that |
| | | * padding to the field width will be done with |
| | | * zeros instead of blanks. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the minimum number of |
| | | * digits to appear. Padding is with leading 0s. |
| | | * |
| | | * @param x the short to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Format method for the d conversion character and |
| | | * long argument. |
| | | * |
| | | * <p/> |
| | | * For d format, the flag character '-', means that |
| | | * the output should be left justified within the |
| | | * field. The default is to pad with blanks on the |
| | |
| | | * ignored. The '0' flag character implies that |
| | | * padding to the field width will be done with |
| | | * zeros instead of blanks. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the minimum number of |
| | | * digits to appear. Padding is with leading 0s. |
| | | * |
| | | * @param x the long to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Format method for the d conversion character and |
| | | * int argument. |
| | | * |
| | | * <p/> |
| | | * For d format, the flag character '-', means that |
| | | * the output should be left justified within the |
| | | * field. The default is to pad with blanks on the |
| | |
| | | * ignored. The '0' flag character implies that |
| | | * padding to the field width will be done with |
| | | * zeros instead of blanks. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the minimum number of |
| | | * digits to appear. Padding is with leading 0s. |
| | | * |
| | | * @param x the int to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Utility method for formatting using the d |
| | | * conversion character. |
| | | * |
| | | * @param sx the String to format, the result of |
| | | * converting a short, int, or long to a |
| | | * String. |
| | |
| | | /** |
| | | * Format method for the x conversion character and |
| | | * short argument. |
| | | * |
| | | * <p/> |
| | | * For x format, the flag character '-', means that |
| | | * the output should be left justified within the |
| | | * field. The default is to pad with blanks on the |
| | | * left. The '#' flag character means to lead with |
| | | * '0x'. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the minimum number of |
| | | * digits to appear. Padding is with leading 0s. |
| | | * |
| | | * @param x the short to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Format method for the x conversion character and |
| | | * long argument. |
| | | * |
| | | * <p/> |
| | | * For x format, the flag character '-', means that |
| | | * the output should be left justified within the |
| | | * field. The default is to pad with blanks on the |
| | | * left. The '#' flag character means to lead with |
| | | * '0x'. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the minimum number of |
| | | * digits to appear. Padding is with leading 0s. |
| | | * |
| | | * @param x the long to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Format method for the x conversion character and |
| | | * int argument. |
| | | * |
| | | * <p/> |
| | | * For x format, the flag character '-', means that |
| | | * the output should be left justified within the |
| | | * field. The default is to pad with blanks on the |
| | | * left. The '#' flag character means to lead with |
| | | * '0x'. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the minimum number of |
| | | * digits to appear. Padding is with leading 0s. |
| | | * |
| | | * @param x the int to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Utility method for formatting using the x |
| | | * conversion character. |
| | | * |
| | | * @param sx the String to format, the result of |
| | | * converting a short, int, or long to a |
| | | * String. |
| | |
| | | /** |
| | | * Format method for the o conversion character and |
| | | * short argument. |
| | | * |
| | | * <p/> |
| | | * For o format, the flag character '-', means that |
| | | * the output should be left justified within the |
| | | * field. The default is to pad with blanks on the |
| | | * left. The '#' flag character means that the |
| | | * output begins with a leading 0 and the precision |
| | | * is increased by 1. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the minimum number of |
| | | * digits to appear. Padding is with leading 0s. |
| | | * |
| | | * @param x the short to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Format method for the o conversion character and |
| | | * long argument. |
| | | * |
| | | * <p/> |
| | | * For o format, the flag character '-', means that |
| | | * the output should be left justified within the |
| | | * field. The default is to pad with blanks on the |
| | | * left. The '#' flag character means that the |
| | | * output begins with a leading 0 and the precision |
| | | * is increased by 1. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the minimum number of |
| | | * digits to appear. Padding is with leading 0s. |
| | | * |
| | | * @param x the long to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Format method for the o conversion character and |
| | | * int argument. |
| | | * |
| | | * <p/> |
| | | * For o format, the flag character '-', means that |
| | | * the output should be left justified within the |
| | | * field. The default is to pad with blanks on the |
| | | * left. The '#' flag character means that the |
| | | * output begins with a leading 0 and the precision |
| | | * is increased by 1. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the minimum number of |
| | | * digits to appear. Padding is with leading 0s. |
| | | * |
| | | * @param x the int to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Utility method for formatting using the o |
| | | * conversion character. |
| | | * |
| | | * @param sx the String to format, the result of |
| | | * converting a short, int, or long to a |
| | | * String. |
| | |
| | | /** |
| | | * Format method for the c conversion character and |
| | | * char argument. |
| | | * |
| | | * <p/> |
| | | * The only flag character that affects c format is |
| | | * the '-', meaning that the output should be left |
| | | * justified within the field. The default is to |
| | | * pad with blanks on the left. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. Padding is with |
| | | * blanks by default. The default width is 1. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is ignored. |
| | | * |
| | | * @param x the char to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Format method for the s conversion character and |
| | | * String argument. |
| | | * |
| | | * <p/> |
| | | * The only flag character that affects s format is |
| | | * the '-', meaning that the output should be left |
| | | * justified within the field. The default is to |
| | | * pad with blanks on the left. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is the |
| | | * smaller of the number of characters in the the |
| | | * input and the precision. Padding is with blanks |
| | | * by default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, specifies the maximum |
| | | * number of characters to be printed from the |
| | | * string. A null digit string is treated |
| | | * as a 0. The default is not to set a maximum |
| | | * number of characters to be printed. |
| | | * |
| | | * @param x the String to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Check for a conversion character. If it is |
| | | * there, store it. |
| | | * |
| | | * @return <code>true</code> if the conversion |
| | | * character is there, and |
| | | * <code>false</code> otherwise. |
| | |
| | | import org.testng.annotations.Test; |
| | | |
| | | import com.vividsolutions.jts.geom.Coordinate; |
| | | import com.ximple.util.PrintfFormat; |
| | | |
| | | import oracle.jdbc.OracleConnection; |
| | | |
| | | import com.ximple.util.PrintfFormat; |
| | | |
| | | /** |
| | | * Dgn7OracleReaderTest |
| | | * User: Ulysses |
| | |
| | | import java.util.List; |
| | | |
| | | import org.apache.log4j.Logger; |
| | | import org.geotools.TestData; |
| | | import org.testng.annotations.BeforeTest; |
| | | import org.testng.annotations.Test; |
| | | import org.geotools.TestData; |
| | | |
| | | /** |
| | | * Dgn7TextElementReaderTest |
| | |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileNotFoundException; |
| | | 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; |
| | | import org.geotools.TestData; |
| | | |
| | | /** |
| | | * Dgn7fileReaderTest |
| | |
| | | import org.apache.log4j.Logger; |
| | | |
| | | import com.vividsolutions.jts.util.Assert; |
| | | |
| | | import oracle.jdbc.OracleConnection; |
| | | |
| | | /** |
| | |
| | | <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> |
| | |
| | | <artifactId>postgis-driver</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>mysql</groupId> |
| | | <artifactId>mysql-connector-java</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- Ximple Library --> |
| | | <dependency> |
| | | <artifactId>ximple-dgnio</artifactId> |
| | |
| | | <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> |
| | |
| | | <artifactId>postgis-driver</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>mysql</groupId> |
| | | <artifactId>mysql-connector-java</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- Ximple Library --> |
| | | <dependency> |
| | | <groupId>com.ximple.eofms</groupId> |
| | |
| | | import java.util.StringTokenizer; |
| | | import java.util.TreeMap; |
| | | |
| | | import com.vividsolutions.jts.util.Assert; |
| | | import com.ximple.eofms.jobs.context.AbstractOracleJobContext; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | | import org.geotools.data.DataStore; |
| | | import org.geotools.data.postgis.PostgisDataStoreFactory; |
| | | import org.geotools.data.jdbc.ConnectionPoolManager; |
| | | import org.geotools.data.oracle.OracleDataStore; |
| | | import org.geotools.data.oracle.OracleDataStoreFactory; |
| | |
| | | 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 */ |
| | | /** |
| | | * The Oracle driver class name |
| | | */ |
| | | private static final String JDBC_DRIVER = "oracle.jdbc.driver.OracleDriver"; |
| | | |
| | | private static final String ORACLE_URL = "jdbc:oracle:thin:@"; |
| | |
| | | |
| | | protected AbstractOracleDatabaseJob() |
| | | { |
| | | try { |
| | | try |
| | | { |
| | | Class.forName(JDBC_DRIVER); |
| | | } catch (Throwable t) { |
| | | } catch (Throwable t) |
| | | { |
| | | // must be running off dummy jar! |
| | | driverFound = false; |
| | | } |
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.util.Calendar; |
| | | 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 BATCHSIZE = 25; |
| | | 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 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(); |
| | | |
| | | // 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."); |
| | | } |
| | | |
| | | Calendar cal = Calendar.getInstance(); |
| | | Date startTime = cal.getTime(); |
| | | try |
| | | { |
| | | logger.info("-- step:clearOutputDatabase --"); |
| | | clearOutputDatabase(); |
| | | boolean bFirst = true; |
| | | if (checkConvertDB()) |
| | | { |
| | | logger.info("-- step:convertOracleDB --"); |
| | | |
| | | for (String orgSchema : _orgSchema) |
| | | { |
| | | OracleConvertMySQLJobContext jobContext = |
| | | (OracleConvertMySQLJobContext) prepareJobContext(_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(); |
| | | Date endTime = cal.getTime(); |
| | | Date time = new Date(endTime.getTime() - startTime.getTime()); |
| | | // public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss"; |
| | | // SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW); |
| | | logger.warn("use time = " + time); |
| | | } 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.info(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 |
| | | { |
| | | OracleConnection 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(); |
| | | } |
| | | |
| | | 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(); |
| | | } |
| | | |
| | | protected OrderedMap getBlobStorageList(OracleConnection 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); |
| | | |
| | | while (rs.next()) |
| | | { |
| | | int size = rs.getMetaData().getColumnCount(); |
| | | 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); |
| | | |
| | | while (rs.next()) |
| | | { |
| | | int size = rs.getMetaData().getColumnCount(); |
| | | 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 |
| | | { |
| | | OracleConnection 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); |
| | | |
| | | while (rsSrc.next()) |
| | | { |
| | | byte[] raw = null; |
| | | |
| | | if (rsSrc.getMetaData().getColumnType(1) == 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 |
| | | { |
| | | OracleConnection 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]); |
| | | |
| | | 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(); |
| | | } 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())) |
| | | { |
| | | lastComplex = null; |
| | | |
| | | processIndexElement(element, convertContext); |
| | | } else if (element.isComponentElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | ((ComplexElement) lastComplex).add(element); |
| | | } |
| | | } else if (type.isComplexElement()) |
| | | { |
| | | if (lastComplex == null) |
| | | { |
| | | lastComplex = element; |
| | | } else |
| | | { |
| | | processIndexElement(element, convertContext); |
| | | lastComplex = element; |
| | | } |
| | | } |
| | | } |
| | | count++; |
| | | } |
| | | |
| | | 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]); |
| | | |
| | | 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(); |
| | | } 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())) |
| | | { |
| | | lastComplex = null; |
| | | |
| | | processOtherElement(element, convertContext); |
| | | } else if (element.isComponentElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | ((ComplexElement) lastComplex).add(element); |
| | | } |
| | | } else if (type.isComplexElement()) |
| | | { |
| | | if (lastComplex == null) |
| | | { |
| | | lastComplex = element; |
| | | } else |
| | | { |
| | | processOtherElement(element, convertContext); |
| | | lastComplex = element; |
| | | } |
| | | } |
| | | } |
| | | count++; |
| | | } |
| | | |
| | | 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]); |
| | | |
| | | FileInputStream fs = new FileInputStream(dgnFile); |
| | | FileChannel fc = fs.getChannel(); |
| | | Dgn7fileReader reader = new Dgn7fileReader(fc, new Lock()); |
| | | convertContext.setReader(reader); |
| | | |
| | | scanFeatureDgnElement(convertContext); |
| | | |
| | | convertContext.commitTransaction(); |
| | | convertContext.closeFeatureWriter(); |
| | | System.gc(); |
| | | } catch (FileNotFoundException e) |
| | | { |
| | | convertContext.rollbackTransaction(); |
| | | logger.warn(e.getMessage(), e); |
| | | throw new JobExecutionException(e.getMessage(), e); |
| | | } catch (Dgn7fileException e) |
| | | { |
| | | convertContext.rollbackTransaction(); |
| | | logger.warn(e.getMessage(), e); |
| | | throw new JobExecutionException(e.getMessage(), e); |
| | | } catch (IOException e) |
| | | { |
| | | convertContext.rollbackTransaction(); |
| | | logger.warn(e.getMessage(), e); |
| | | throw new JobExecutionException(e.getMessage(), e); |
| | | } catch (IllegalAttributeException e) |
| | | { |
| | | convertContext.rollbackTransaction(); |
| | | logger.warn(e.getMessage(), e); |
| | | throw new JobExecutionException(e.getMessage(), e); |
| | | } catch (SchemaException e) |
| | | { |
| | | convertContext.rollbackTransaction(); |
| | | logger.warn(e.getMessage(), e); |
| | | throw new JobExecutionException(e.getMessage(), e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void scanFeatureDgnElement(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())) |
| | | { |
| | | lastComplex = null; |
| | | |
| | | processFeatureElement(element, convertContext); |
| | | } else if (element.isComponentElement()) |
| | | { |
| | | if (lastComplex != null) |
| | | { |
| | | ((ComplexElement) lastComplex).add(element); |
| | | } |
| | | } else if (type.isComplexElement()) |
| | | { |
| | | if (lastComplex == null) |
| | | { |
| | | lastComplex = element; |
| | | } else |
| | | { |
| | | processFeatureElement(element, convertContext); |
| | | lastComplex = element; |
| | | } |
| | | } |
| | | } |
| | | count++; |
| | | } |
| | | |
| | | logger.debug("ElementRecord Count=" + count); |
| | | } |
| | | |
| | | private void processFeatureElement(Element element, 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); |
| | | } |
| | | } |
| | | } |
| | |
| | | import java.sql.SQLException; |
| | | import java.sql.Statement; |
| | | import java.sql.Types; |
| | | import java.util.Calendar; |
| | | 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 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.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; |
| | |
| | | { |
| | | final static Log logger = LogFactory.getLog(OracleConvertDgn2OraSDOJob.class); |
| | | |
| | | /** |
| | | * The Oracle driver class name |
| | | */ |
| | | private static final String JDBC_DRIVER = "oracle.jdbc.driver.OracleDriver"; |
| | | 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 BATCHSIZE = 25; |
| | |
| | | } |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | |
| | | // OracleDataStoreFactory factory = new OracleDataStoreFactory(); |
| | | /* |
| | | Map map = new HashMap(); |
| | | map.put("host", fixture.getProperty("host")); |
| | | map.put("port", fixture.getProperty("port")); |
| | | map.put("instance", fixture.getProperty("instance")); |
| | | map.put("user", fixture.getProperty("user")); |
| | | map.put("passwd", fixture.getProperty("passwd")); |
| | | map.put("dbtype", "oracle"); |
| | | map.put("alias", fixture.getProperty("instance")); |
| | | map.put("namespace", null); |
| | | |
| | | assertTrue(factory.canProcess(map)); |
| | | |
| | | OracleDataStore store = (OracleDataStore) factory.createDataStore(map); |
| | | assertNull(store.getNameSpace()); |
| | | |
| | | map.put("schema", fixture.getProperty("user").toUpperCase()); |
| | | store = (OracleDataStore) factory.createDataStore(map); |
| | | assertNull(store.getNameSpace()); |
| | | |
| | | map.put("namespace", "topp"); |
| | | store = (OracleDataStore) factory.createDataStore(map); |
| | | assertEquals(new URI("topp"), store.getNameSpace()); |
| | | */ |
| | | |
| | | /* |
| | | FeatureWriter writer = dstore.getFeatureWriter("ORA_TEST_POINTS", Filter.INCLUDE, |
| | | Transaction.AUTO_COMMIT); |
| | | assertNotNull(writer); |
| | | |
| | | Feature feature = writer.next(); |
| | | System.out.println(feature); |
| | | feature.setAttribute(0, "Changed Feature"); |
| | | System.out.println(feature); |
| | | writer.write(); |
| | | writer.close(); |
| | | */ |
| | | |
| | | /* |
| | | Map fidGen = new HashMap(); |
| | | fidGen.put("ORA_TEST_POINTS", JDBCDataStoreConfig.FID_GEN_MANUAL_INC); |
| | | |
| | | JDBCDataStoreConfig config = JDBCDataStoreConfig.createWithSchemaNameAndFIDGenMap(schemaName, |
| | | fidGen); |
| | | |
| | | String name = "add_name"; |
| | | BigDecimal intval = new BigDecimal(70); |
| | | Point point = jtsFactory.createPoint(new Coordinate(-15.0, -25)); |
| | | Feature feature = dstore.getSchema("ORA_TEST_POINTS") |
| | | .create(new Object[] { name, intval, point }); |
| | | |
| | | FeatureStore fs = (FeatureStore) dstore.getFeatureSource("ORA_TEST_POINTS"); |
| | | fs.addFeatures(DataUtilities.collection(feature)); |
| | | */ |
| | | |
| | | protected AbstractOracleJobContext prepareJobContext(String filterPath) |
| | | { |
| | | return new OracleConvertShapefilesJobContext(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 |
| | |
| | | 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."); |
| | | } |
| | | |
| | | Calendar cal = Calendar.getInstance(); |
| | | Date startTime = cal.getTime(); |
| | | try |
| | | { |
| | | logger.info("-- step:clearOutputDirectory --"); |
| | | clearOutputDirectory(); |
| | | logger.info("-- step:clearOutputDatabase --"); |
| | | clearOutputDatabase(); |
| | | boolean bFirst = true; |
| | | if (checkConvertDB()) |
| | | { |
| | |
| | | |
| | | for (String orgSchema : _orgSchema) |
| | | { |
| | | OracleConvertShapefilesJobContext jobContext = (OracleConvertShapefilesJobContext) prepareJobContext(_filterPath); |
| | | OracleConvertOraSDOJobContext jobContext = |
| | | (OracleConvertOraSDOJobContext) prepareJobContext(_filterPath); |
| | | jobContext.setSourceDataStore(getSourceDataStore()); |
| | | jobContext.setConvertElementIn(_convertElementIn); |
| | | // jobContext.setConvertElementIn(_convertElementIn); |
| | | jobContext.setElementLogging(checkElementLogging()); |
| | | jobContext.setExecutionContext(context); |
| | | |
| | |
| | | } |
| | | |
| | | disconnect(); |
| | | Date endTime = cal.getTime(); |
| | | Date time = new Date(endTime.getTime() - startTime.getTime()); |
| | | // public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss"; |
| | | // SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW); |
| | | logger.warn("use time = " + time); |
| | | } catch (SQLException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | |
| | | * @param jobContext job context |
| | | * @throws SQLException sql exception |
| | | */ |
| | | private void copyConnectivity(OracleConvertShapefilesJobContext jobContext) throws SQLException |
| | | private void copyConnectivity(OracleConvertOraSDOJobContext jobContext) throws SQLException |
| | | { |
| | | OracleConnection connection = jobContext.getOracleConnection(); |
| | | Statement stmt = connection.createStatement(); |
| | | stmt.execute(OracleConvertShapefilesJobContext.TRUNCATE_CONNECTIVITY_WEBCHECK); |
| | | stmt.execute(OracleConvertShapefilesJobContext.COPY_CONNECTIVITY_TO_WEBCHECK); |
| | | stmt.execute(AbstractOracleJobContext.TRUNCATE_CONNECTIVITY_WEBCHECK); |
| | | stmt.execute(AbstractOracleJobContext.COPY_CONNECTIVITY_TO_WEBCHECK); |
| | | } |
| | | |
| | | private void exetcuteConvert(OracleConvertShapefilesJobContext jobContext, |
| | | private void exetcuteConvert(OracleConvertOraSDOJobContext jobContext, |
| | | String querySchema, String dataPath) throws SQLException |
| | | { |
| | | int order = 0; |
| | |
| | | |
| | | //jobContext.startTransaction(); |
| | | jobContext.setCurrentSchema(querySchema); |
| | | jobContext.getExecutionContext().put("ConvertDgn2ShpJobProgress", 0); |
| | | jobContext.getExecutionContext().put("ConvertDgn2OraSDOJobProgress", 0); |
| | | for (OrderedMapIterator it = map.orderedMapIterator(); it.hasNext();) |
| | | { |
| | | it.next(); |
| | |
| | | if (now != current) |
| | | { |
| | | current = now; |
| | | jobContext.getExecutionContext().put("ConvertDgn2ShpJobProgress", current); |
| | | jobContext.getExecutionContext().put("ConvertDgn2OraSDOJobProgress", current); |
| | | |
| | | } |
| | | } |
| | | jobContext.getExecutionContext().put("ConvertDgn2ShpJobProgress", 100); |
| | | jobContext.getExecutionContext().put("ConvertDgn2OraSDOJobProgress", 100); |
| | | |
| | | jobContext.commitTransaction(); |
| | | |
| | |
| | | return orderedMap; |
| | | } |
| | | |
| | | protected void queryIgsetElement(OracleConvertShapefilesJobContext jobContext, |
| | | protected void queryIgsetElement(OracleConvertOraSDOJobContext jobContext, |
| | | String srcschema, String srctable) throws SQLException |
| | | { |
| | | OracleConnection connection = jobContext.getOracleConnection(); |
| | |
| | | stmtSrc.close(); |
| | | } |
| | | |
| | | protected void queryRawElement(OracleConvertShapefilesJobContext jobContext, |
| | | protected void queryRawElement(OracleConvertOraSDOJobContext jobContext, |
| | | String srcschema, String srctable) throws SQLException |
| | | { |
| | | OracleConnection connection = jobContext.getOracleConnection(); |
| | |
| | | |
| | | for (File dgnFile : dgnFiles) |
| | | { |
| | | IndexDgnConvertShpJobContext convertContext = new IndexDgnConvertShpJobContext(getDataPath()); |
| | | IndexDgnConvertOraSDOJobContext convertContext = |
| | | new IndexDgnConvertOraSDOJobContext(getDataPath(), getTargetDataStore()); |
| | | logger.debug("--- start dgnfile-" + dgnFile.toString() + " ---"); |
| | | try |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | protected void scanIndexDgnElement(IndexDgnConvertShpJobContext convertContext) |
| | | protected void scanIndexDgnElement(IndexDgnConvertOraSDOJobContext convertContext) |
| | | throws Dgn7fileException, IOException, IllegalAttributeException, SchemaException |
| | | { |
| | | Dgn7fileReader reader = convertContext.getReader(); |
| | |
| | | logger.debug("ElementRecord Count=" + count); |
| | | } |
| | | |
| | | private void processIndexElement(Element element, IndexDgnConvertShpJobContext convertContext) throws IllegalAttributeException, SchemaException |
| | | private void processIndexElement(Element element, IndexDgnConvertOraSDOJobContext convertContext) |
| | | throws IllegalAttributeException, SchemaException |
| | | { |
| | | if (element instanceof TextElement) |
| | | { |
| | |
| | | |
| | | for (File dgnFile : dgnFiles) |
| | | { |
| | | GeneralDgnConvertShpJobContext convertContext = new GeneralDgnConvertShpJobContext(getDataPath()); |
| | | GeneralDgnConvertOraSDOJobContext convertContext = |
| | | new GeneralDgnConvertOraSDOJobContext(getDataPath(), getTargetDataStore()); |
| | | logger.info("--- start dgnfile-" + dgnFile.toString() + " ---"); |
| | | try |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | public void scanOtherDgnElement(GeneralDgnConvertShpJobContext convertContext) |
| | | public void scanOtherDgnElement(GeneralDgnConvertOraSDOJobContext convertContext) |
| | | throws Dgn7fileException, IOException, IllegalAttributeException, SchemaException |
| | | { |
| | | Dgn7fileReader reader = convertContext.getReader(); |
| | |
| | | logger.debug("ElementRecord Count=" + count); |
| | | } |
| | | |
| | | private void processOtherElement(Element element, GeneralDgnConvertShpJobContext convertContext) |
| | | private void processOtherElement(Element element, GeneralDgnConvertOraSDOJobContext convertContext) |
| | | throws IllegalAttributeException, SchemaException |
| | | { |
| | | convertContext.putFeatureCollection(element); |
| | | } |
| | | |
| | | private void clearOutputDirectory() |
| | | private void clearOutputDatabase() |
| | | { |
| | | File outDataPath = new File(getDataPath(), OracleConvertShapefilesJobContext.SHPOUTPATH); |
| | | /* |
| | | File outDataPath = new File(getDataPath(), OracleConvertOraSDOJobContext.SHPOUTPATH); |
| | | if (outDataPath.exists() && outDataPath.isDirectory()) |
| | | { |
| | | deleteFilesInPath(outDataPath); |
| | |
| | | { |
| | | deleteFilesInPath(outDataPath); |
| | | } |
| | | */ |
| | | } |
| | | |
| | | private void deleteFilesInPath(File outDataPath) |
| | |
| | | |
| | | for (File dgnFile : dgnFiles) |
| | | { |
| | | FeatureDgnConvertShpJobContext convertContext = new FeatureDgnConvertShpJobContext(getDataPath(), _filterPath); |
| | | FeatureDgnConvertOraSDOJobContext convertContext = |
| | | new FeatureDgnConvertOraSDOJobContext(getDataPath(), getTargetDataStore(), _filterPath); |
| | | logger.info("--- start dgnfile-" + dgnFile.toString() + " ---"); |
| | | try |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | public void scanFeatureDgnElement(FeatureDgnConvertShpJobContext convertContext) |
| | | public void scanFeatureDgnElement(FeatureDgnConvertOraSDOJobContext convertContext) |
| | | throws Dgn7fileException, IOException, IllegalAttributeException, SchemaException |
| | | { |
| | | Dgn7fileReader reader = convertContext.getReader(); |
| | |
| | | logger.debug("ElementRecord Count=" + count); |
| | | } |
| | | |
| | | private void processFeatureElement(Element element, FeatureDgnConvertShpJobContext convertContext) |
| | | private void processFeatureElement(Element element, FeatureDgnConvertOraSDOJobContext convertContext) |
| | | throws IllegalAttributeException, SchemaException |
| | | { |
| | | convertContext.putFeatureCollection(element); |
| | |
| | | } |
| | | */ |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | |
| | | 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.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.io.dgn7.Lock; |
| | | import com.ximple.io.dgn7.TextElement; |
| | | import com.ximple.util.PrintfFormat; |
| | | |
| | | 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.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 oracle.jdbc.OracleConnection; |
| | | import oracle.jdbc.OracleResultSet; |
| | | import oracle.sql.ARRAY; |
| | | import oracle.sql.BLOB; |
| | | |
| | | public class OracleConvertDgn2PostGISJob extends AbstractOracleDatabaseJob |
| | | { |
| | |
| | | |
| | | Log logger = getLogger(); |
| | | /* |
| | | logger.info("PGHOST=" + _pgHost); |
| | | logger.info("PGDDATBASE=" + _pgDatabase); |
| | | logger.info("PGPORT=" + _pgPort); |
| | | logger.info("PGSCHEMA=" + _pgSchema); |
| | | logger.info("PGUSER=" + _pgUsername); |
| | | logger.info("PGPASS=" + _pgPassword); |
| | | logger.info("USEWKB=" + _pgUseWKB); |
| | | 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) |
| | |
| | | OracleConvertPostGISJobContext jobContext = |
| | | (OracleConvertPostGISJobContext) prepareJobContext(_filterPath); |
| | | jobContext.setSourceDataStore(getSourceDataStore()); |
| | | jobContext.setConvertElementIn(_convertElementIn); |
| | | // jobContext.setConvertElementIn(_convertElementIn); |
| | | jobContext.setElementLogging(checkElementLogging()); |
| | | jobContext.setExecutionContext(context); |
| | | |
| | |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | import org.geotools.data.oracle.OracleDataStore; |
| | | import org.geotools.data.jdbc.ConnectionPoolManager; |
| | | import org.geotools.data.jdbc.datasource.DataSourceUtil; |
| | | import org.geotools.data.jdbc.datasource.DataSourceFinder; |
| | | import org.quartz.JobDetail; |
| | | import org.quartz.JobExecutionContext; |
| | | import org.quartz.JobExecutionException; |
| | |
| | |
|
| | | import java.util.Map;
|
| | |
|
| | | import org.quartz.JobExecutionContext;
|
| | | import org.apache.commons.logging.Log;
|
| | | import org.quartz.JobExecutionContext;
|
| | |
|
| | | import com.ximple.io.dgn7.Dgn7fileReader;
|
| | |
|
| | |
| | | package com.ximple.eofms.jobs.context; |
| | | |
| | | import java.sql.DriverManager; |
| | | import java.sql.SQLException; |
| | | import java.util.Properties; |
| | | import java.io.IOException; |
| | | import java.util.Properties; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | | import org.geotools.data.oracle.OracleDataStore; |
| | | import org.geotools.data.Transaction; |
| | | import org.geotools.data.DataStore; |
| | | import org.geotools.data.Transaction; |
| | | import org.geotools.data.oracle.OracleDataStore; |
| | | |
| | | import oracle.jdbc.OracleConnection; |
| | | |
| | | import com.ximple.eofms.jobs.context.shapefile.OracleConvertShapefilesJobContext; |
| | | |
| | | public abstract class AbstractOracleJobContext |
| | | { |
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.mysql.MySQLDataStore; |
| | | |
| | | 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; |
| | | } |
| | | } |
| | | |
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.mysql.MySQLDataStore; |
| | | |
| | | 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; |
| | | } |
| | | } |
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.jobs.context.orasdo.AbstractDgnToOraSDOJobContext; |
| | | 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); |
| | | 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 (targetDataStore.getSchema(featureType.getTypeName()) == null) |
| | | { |
| | | 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); |
| | | 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 (targetDataStore.getSchema(featureType.getTypeName()) == null) |
| | | { |
| | | 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 (targetDataStore.getSchema(featureType.getTypeName()) != null) |
| | | { |
| | | 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(); |
| | | StringBuffer sb = new StringBuffer(); |
| | | 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() + "L"; |
| | | 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; |
| | | |
| | | 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 (targetDataStore.getSchema(featureType.getTypeName()) == null) |
| | | { |
| | | 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) |
| | | { |
| | | typeBuilderRect = 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; |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | |
| | | 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.sql.DriverManager; |
| | | import java.sql.SQLException; |
| | | import java.util.HashMap; |
| | | import java.util.ArrayList; |
| | | import java.util.Iterator; |
| | | 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.data.FeatureWriter; |
| | | import org.geotools.data.DataStore; |
| | | 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.SimpleFeature; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.quartz.JobExecutionContext; |
| | | import org.xml.sax.SAXException; |
| | | |
| | | import com.vividsolutions.jts.util.Assert; |
| | | |
| | | import com.ximple.eofms.jobs.OracleElementLogger; |
| | | 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; |
| | | |
| | | 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 pgCurrentSchema = 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); |
| | | 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); |
| | | } |
| | | |
| | | } |
| | | |
| | | private boolean isExistFeature(FeatureType featureType) |
| | | { |
| | | try |
| | | { |
| | | FeatureType existFeatureType = targetDataStore.getSchema(featureType.getTypeName()); |
| | | return existFeatureType != null && existFeatureType.equals(featureType); |
| | | } catch (IOException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | 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 String getCurrentSchema() |
| | | { |
| | | return currentSchema; |
| | | } |
| | | |
| | | public void setCurrentSchema(String querySchema) |
| | | { |
| | | this.currentSchema = querySchema; |
| | | this.schemaChanged = true; |
| | | } |
| | | |
| | | protected Log getLogger() |
| | | { |
| | | return logger; |
| | | } |
| | | } |
| | |
| | | package com.ximple.eofms.jobs.context.orasdo; |
| | | |
| | | import java.util.Properties; |
| | | import java.io.IOException; |
| | | import java.sql.Connection; |
| | | |
| | | import org.geotools.data.DataStore; |
| | | import org.geotools.data.Transaction; |
| | | import org.geotools.data.oracle.OracleDataStore; |
| | | |
| | | import com.ximple.eofms.jobs.context.AbstractDgnFileJobContext; |
| | | |
| | | public abstract class AbstractDgnToOraSDOJobContext extends AbstractDgnFileJobContext |
| | | { |
| | | public AbstractDgnToOraSDOJobContext(String dataPath, Properties properties) |
| | | protected OracleDataStore targetDataStore; |
| | | |
| | | public AbstractDgnToOraSDOJobContext(String dataPath, DataStore targetDataStore) |
| | | { |
| | | super(dataPath); |
| | | this.properties = properties; |
| | | this.targetDataStore = (OracleDataStore) targetDataStore; |
| | | } |
| | | |
| | | public OracleDataStore getTargetDataStore() |
| | | { |
| | | return targetDataStore; |
| | | } |
| | | |
| | | public void setTargetDataStore(OracleDataStore 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; |
| | | } |
| | | } |
| | |
| | | package com.ximple.eofms.jobs.context.orasdo; |
| | | |
| | | import java.util.Properties; |
| | | import java.io.IOException; |
| | | import java.sql.Connection; |
| | | |
| | | import org.geotools.data.DataStore; |
| | | import org.geotools.data.Transaction; |
| | | import org.geotools.data.oracle.OracleDataStore; |
| | | |
| | | import com.ximple.eofms.jobs.context.AbstractOracleJobContext; |
| | | |
| | | public abstract class AbstractOracleToOraSDOJobContext extends AbstractOracleJobContext |
| | | { |
| | | public AbstractOracleToOraSDOJobContext(String dataPath, Properties properties) |
| | | protected OracleDataStore targetDataStore; |
| | | |
| | | public AbstractOracleToOraSDOJobContext(String dataPath, DataStore targetDataStore) |
| | | { |
| | | if ((targetDataStore != null) && (targetDataStore instanceof OracleDataStore)) |
| | | { |
| | | this.targetDataStore = (OracleDataStore) targetDataStore; |
| | | } else |
| | | { |
| | | getLogger().info("targetDataStore has wrong."); |
| | | } |
| | | setDataPath(dataPath); |
| | | } |
| | | |
| | | public OracleDataStore getTargetDataStore() |
| | | { |
| | | return targetDataStore; |
| | | } |
| | | |
| | | public void setTargetDataStore(OracleDataStore 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; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ximple.eofms.jobs.context.orasdo; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.MalformedURLException; |
| | | import java.net.URL; |
| | | 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.DataStore; |
| | | import org.geotools.data.FeatureWriter; |
| | | import org.geotools.data.Transaction; |
| | | 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.io.dgn7.ComplexElement; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.io.dgn7.UserAttributeData; |
| | | |
| | | public class DummyFeatureConvertOraSDOJobContext extends AbstractDgnToOraSDOJobContext |
| | | { |
| | | static final Log logger = LogFactory.getLog(DummyFeatureConvertOraSDOJobContext.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 DummyFeatureConvertOraSDOJobContext(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); |
| | | 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 (targetDataStore.getSchema(featureType.getTypeName()) == null) |
| | | { |
| | | 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.orasdo; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.MalformedURLException; |
| | | import java.net.URL; |
| | | 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.DataStore; |
| | | import org.geotools.data.FeatureWriter; |
| | | import org.geotools.data.Transaction; |
| | | 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.ElementDispatcher; |
| | | 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 FeatureDgnConvertOraSDOJobContext extends AbstractDgnToOraSDOJobContext |
| | | { |
| | | static final Log logger = LogFactory.getLog(FeatureDgnConvertOraSDOJobContext.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 FeatureDgnConvertOraSDOJobContext(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); |
| | | 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 (targetDataStore.getSchema(featureType.getTypeName()) == null) |
| | | { |
| | | 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.orasdo; |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.net.MalformedURLException; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.TreeMap; |
| | | |
| | | 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.feature.Feature; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.FeatureTypeBuilder; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | import org.geotools.feature.SimpleFeature; |
| | | |
| | | 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.ArcElement; |
| | | import com.ximple.io.dgn7.ComplexChainElement; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.EllipseElement; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | 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.UserAttributeData; |
| | | |
| | | public class GeneralDgnConvertOraSDOJobContext extends AbstractDgnToOraSDOJobContext |
| | | { |
| | | static final Log logger = LogFactory.getLog(GeneralDgnConvertOraSDOJobContext.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 GeneralDgnConvertOraSDOJobContext(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 (targetDataStore.getSchema(featureType.getTypeName()) != null) |
| | | { |
| | | 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(); |
| | | StringBuffer sb = new StringBuffer(); |
| | | 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() + "L"; |
| | | 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.orasdo; |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.net.MalformedURLException; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | |
| | | 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.feature.Feature; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.FeatureTypeBuilder; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.SchemaException; |
| | | import org.geotools.feature.SimpleFeature; |
| | | |
| | | import com.vividsolutions.jts.geom.Coordinate; |
| | | import com.vividsolutions.jts.geom.Envelope; |
| | | 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.TPCLIDConverter; |
| | | import com.ximple.eofms.util.TWD97GeometryConverterDecorator; |
| | | import com.ximple.eofms.util.TWDDatumConverter; |
| | | 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 IndexDgnConvertOraSDOJobContext extends AbstractDgnToOraSDOJobContext |
| | | { |
| | | static final Log logger = LogFactory.getLog(IndexDgnConvertOraSDOJobContext.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; |
| | | |
| | | public IndexDgnConvertOraSDOJobContext(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 (targetDataStore.getSchema(featureType.getTypeName()) == null) |
| | | { |
| | | 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) |
| | | { |
| | | typeBuilderRect = 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; |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | } |
| | | |
| | |
| | | package com.ximple.eofms.jobs.context.orasdo; |
| | | |
| | | 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.util.LoggerFacade; |
| | | 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.oracle.OracleDataStoreFactory; |
| | | 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.ximple.eofms.jobs.context.AbstractOracleJobContext; |
| | | import com.vividsolutions.jts.util.Assert; |
| | | |
| | | public class OracleConvertOraSDOJobContext extends AbstractOracleJobContext |
| | | 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 OracleConvertOraSDOJobContext extends AbstractOracleToOraSDOJobContext |
| | | { |
| | | static Log logger = LogFactory.getLog(OracleConvertOraSDOJobContext.class); |
| | | static final LoggerFacade sLogger = new CommonsLoggingLogger(logger); |
| | | |
| | | static OracleDataStoreFactory dataStoreFactory = new OracleDataStoreFactory(); |
| | | |
| | | 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 pgCurrentSchema = null; |
| | | private boolean schemaChanged = false; |
| | | // private String _convertElementIn = null; |
| | | |
| | | public OracleConvertOraSDOJobContext(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); |
| | | 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); |
| | | } |
| | | |
| | | } |
| | | |
| | | private boolean isExistFeature(FeatureType featureType) |
| | | { |
| | | try |
| | | { |
| | | FeatureType existFeatureType = targetDataStore.getSchema(featureType.getTypeName()); |
| | | return existFeatureType != null && existFeatureType.equals(featureType); |
| | | } catch (IOException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | 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 String getCurrentSchema() |
| | | { |
| | | return currentSchema; |
| | | } |
| | | |
| | | public void setCurrentSchema(String querySchema) |
| | | { |
| | | this.currentSchema = querySchema; |
| | | this.schemaChanged = true; |
| | | } |
| | | |
| | | protected Log getLogger() |
| | |
| | | package com.ximple.eofms.jobs.context.postgis; |
| | | |
| | | import java.util.Map; |
| | | import java.sql.Connection; |
| | | import java.io.IOException; |
| | | import java.sql.Connection; |
| | | |
| | | import org.geotools.data.DataStore; |
| | | import org.geotools.data.Transaction; |
| | | import org.geotools.data.postgis.PostgisDataStore; |
| | | |
| | | import com.ximple.eofms.jobs.context.AbstractDgnFileJobContext; |
| | | |
| | | import org.geotools.data.postgis.PostgisDataStore; |
| | | import org.geotools.data.Transaction; |
| | | import org.geotools.data.DataStore; |
| | | |
| | | public abstract class AbstractDgnToPostGISJobContext extends AbstractDgnFileJobContext |
| | | { |
| | |
| | | package com.ximple.eofms.jobs.context.postgis; |
| | | |
| | | import java.sql.Connection; |
| | | import java.io.IOException; |
| | | import java.sql.Connection; |
| | | |
| | | import org.geotools.data.DataStore; |
| | | import org.geotools.data.Transaction; |
| | | import org.geotools.data.postgis.PostgisDataStore; |
| | | |
| | | import com.ximple.eofms.jobs.context.AbstractOracleJobContext; |
| | | |
| | | import org.geotools.data.postgis.PostgisDataStore; |
| | | import org.geotools.data.Transaction; |
| | | import org.geotools.data.DataStore; |
| | | |
| | | public abstract class AbstractOracleToPostGISJobContext extends AbstractOracleJobContext |
| | | { |
| | |
| | | if ((targetDataStore != null) && (targetDataStore instanceof PostgisDataStore)) |
| | | { |
| | | this.targetDataStore = (PostgisDataStore) targetDataStore; |
| | | } else { |
| | | } else |
| | | { |
| | | getLogger().info("targetDataStore has wrong."); |
| | | } |
| | | setDataPath(dataPath); |
| | |
| | | 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 java.util.Map; |
| | | |
| | | import org.apache.commons.digester.Digester; |
| | | import org.apache.commons.digester.xmlrules.DigesterLoader; |
| | |
| | | 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.DataStore; |
| | | import org.geotools.data.postgis.PostgisDataStore; |
| | | 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; |
| | |
| | | while (it.hasNext()) |
| | | { |
| | | FeatureType featureType = (FeatureType) it.next(); |
| | | File sfile = new File(getDataOutPath() + File.separator + featureType.getTypeName()); |
| | | logger.debug("Begin Save shapefile:" + sfile.toURI()); |
| | | logger.debug("Begin Save PostGIS:" + featureType.getTypeName()); |
| | | |
| | | FeatureWriter writer; |
| | | if (featuresWriterContext.containsKey(featureType.getTypeName())) |
| | |
| | | writer = featuresWriterContext.get(featureType.getTypeName()); |
| | | } else |
| | | { |
| | | ShapefileDataStore shapefileDataStore = null; |
| | | boolean existFile = sfile.exists(); |
| | | |
| | | if (!withIndex) |
| | | if (targetDataStore.getSchema(featureType.getTypeName()) == null) |
| | | { |
| | | shapefileDataStore = new ShapefileDataStore(sfile.toURI().toURL(), |
| | | true, Charset.forName("UTF-8")); |
| | | targetDataStore.createSchema(featureType); |
| | | writer = targetDataStore.getFeatureWriter(featureType.getTypeName(), Transaction.AUTO_COMMIT); |
| | | } else |
| | | { |
| | | shapefileDataStore = new IndexedShapefileDataStore(sfile.toURI().toURL(), |
| | | null, true, true, IndexedShapefileDataStore.TREE_QIX, Charset.forName("UTF-8")); |
| | | } |
| | | |
| | | if (!existFile) |
| | | { |
| | | shapefileDataStore.createSchema(featureType); |
| | | writer = shapefileDataStore.getFeatureWriter(featureType.getTypeName(), |
| | | Transaction.AUTO_COMMIT); |
| | | } else |
| | | { |
| | | writer = shapefileDataStore.getFeatureWriterAppend(featureType.getTypeName(), |
| | | Transaction.AUTO_COMMIT); |
| | | writer = targetDataStore.getFeatureWriterAppend(featureType.getTypeName(), Transaction.AUTO_COMMIT); |
| | | } |
| | | featuresWriterContext.put(featureType.getTypeName(), writer); |
| | | } |
| | |
| | | ((SimpleFeature) writer.next()).setAttributes(feature.getAttributes(null)); |
| | | } |
| | | //writer.close(); |
| | | logger.debug("End Save shapefile:" + sfile.toURI()); |
| | | logger.debug("End Save PostGIS:" + featureType.getTypeName()); |
| | | } |
| | | featuresContext.clear(); |
| | | } catch (MalformedURLException e) |
| | |
| | | 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 java.util.Map; |
| | | |
| | | import org.apache.commons.digester.Digester; |
| | | import org.apache.commons.digester.xmlrules.DigesterLoader; |
| | |
| | | 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.DataStore; |
| | | 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 com.ximple.eofms.filter.AbstractFLinkageDispatchableFilter; |
| | | import com.ximple.eofms.filter.ElementDispatcher; |
| | | import com.ximple.eofms.jobs.context.shapefile.FeatureDgnConvertShpJobContext; |
| | | import com.ximple.io.dgn7.ComplexElement; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | |
| | | |
| | | public class FeatureDgnConvertPostGISJobContext extends AbstractDgnToPostGISJobContext |
| | | { |
| | | static final Log logger = LogFactory.getLog(FeatureDgnConvertShpJobContext.class); |
| | | static final Log logger = LogFactory.getLog(FeatureDgnConvertPostGISJobContext.class); |
| | | static final LoggerFacade sLogger = new CommonsLoggingLogger(logger); |
| | | static final GeometryFactory geometryFactory = new GeometryFactory(); |
| | | static final String SHPOUTPATH = "shpout"; |
| | | |
| | | private String dataOut = null; |
| | | |
| | |
| | | while (it.hasNext()) |
| | | { |
| | | FeatureType featureType = (FeatureType) it.next(); |
| | | File sfile = new File(getDataOutPath() + File.separator + featureType.getTypeName()); |
| | | logger.debug("Begin Save shapefile:" + sfile.toURI()); |
| | | logger.debug("Begin Save PostGIS:" + featureType.getTypeName()); |
| | | |
| | | FeatureWriter writer; |
| | | if (featuresWriterContext.containsKey(featureType.getTypeName())) |
| | |
| | | writer = featuresWriterContext.get(featureType.getTypeName()); |
| | | } else |
| | | { |
| | | ShapefileDataStore shapefileDataStore = null; |
| | | boolean existFile = sfile.exists(); |
| | | |
| | | if (!withIndex) |
| | | if (targetDataStore.getSchema(featureType.getTypeName()) == null) |
| | | { |
| | | shapefileDataStore = new ShapefileDataStore(sfile.toURI().toURL(), |
| | | true, Charset.forName("UTF-8")); |
| | | } else |
| | | { |
| | | shapefileDataStore = new IndexedShapefileDataStore(sfile.toURI().toURL(), |
| | | null, true, true, IndexedShapefileDataStore.TREE_QIX, Charset.forName("UTF-8")); |
| | | } |
| | | |
| | | if (!existFile) |
| | | { |
| | | shapefileDataStore.createSchema(featureType); |
| | | writer = shapefileDataStore.getFeatureWriter(featureType.getTypeName(), |
| | | targetDataStore.createSchema(featureType); |
| | | writer = targetDataStore.getFeatureWriter(featureType.getTypeName(), |
| | | Transaction.AUTO_COMMIT); |
| | | } else |
| | | { |
| | | writer = shapefileDataStore.getFeatureWriterAppend(featureType.getTypeName(), |
| | | writer = targetDataStore.getFeatureWriterAppend(featureType.getTypeName(), |
| | | Transaction.AUTO_COMMIT); |
| | | } |
| | | featuresWriterContext.put(featureType.getTypeName(), writer); |
| | |
| | | ((SimpleFeature) writer.next()).setAttributes(feature.getAttributes(null)); |
| | | } |
| | | //writer.close(); |
| | | logger.debug("End Save shapefile:" + sfile.toURI()); |
| | | logger.debug("End Save PostGIS:" + featureType.getTypeName()); |
| | | } |
| | | featuresContext.clear(); |
| | | } catch (MalformedURLException 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 |
| | |
| | | package com.ximple.eofms.jobs.context.postgis; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.net.MalformedURLException; |
| | | import java.nio.charset.Charset; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.TreeMap; |
| | | |
| | | import org.apache.commons.logging.Log; |
| | |
| | | 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.DataStore; |
| | | 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.FeatureTypeBuilder; |
| | |
| | | package com.ximple.eofms.jobs.context.postgis; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.net.MalformedURLException; |
| | | import java.nio.charset.Charset; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | 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.DataStore; |
| | | import org.geotools.data.postgis.PostgisDataStore; |
| | | import org.geotools.data.shapefile.ShapefileDataStore; |
| | | import org.geotools.data.shapefile.indexed.IndexedShapefileDataStore; |
| | | import org.geotools.feature.AttributeTypeFactory; |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.FeatureTypeBuilder; |
| | |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | import com.ximple.eofms.util.DefaultColorTable; |
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil; |
| | | import com.ximple.eofms.util.TPCLIDConverter; |
| | | import com.ximple.eofms.util.TWD97GeometryConverterDecorator; |
| | | import com.ximple.eofms.util.TWDDatumConverter; |
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.io.dgn7.TextElement; |
| | |
| | | while (it.hasNext()) |
| | | { |
| | | FeatureType featureType = (FeatureType) it.next(); |
| | | File sfile = new File(getDataOutPath() + File.separator + featureType.getTypeName()); |
| | | logger.debug("Begin Save shapefile:" + sfile.toURI()); |
| | | logger.debug("Begin Save PostGIS:" + featureType.getTypeName()); |
| | | |
| | | FeatureWriter writer; |
| | | if (featuresWriterContext.containsKey(featureType.getTypeName())) |
| | |
| | | writer = featuresWriterContext.get(featureType.getTypeName()); |
| | | } else |
| | | { |
| | | /* |
| | | ShapefileDataStore shapefileDataStore = new ShapefileDataStore(sfile.toURI().toURL(), |
| | | true, Charset.forName("UTF-8")); |
| | | PostgisDataStore shapefileDataStore = new IndexedShapefileDataStore(sfile.toURI().toURL(), |
| | | null, true, true, IndexedShapefileDataStore.TREE_QIX, Charset.forName("UTF-8")); |
| | | */ |
| | | if (targetDataStore.getSchema(featureType.getTypeName()) != null) |
| | | if (targetDataStore.getSchema(featureType.getTypeName()) == null) |
| | | { |
| | | 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); |
| | | } |
| | | |
| | |
| | | ((SimpleFeature) writer.next()).setAttributes(feature1.getAttributes(null)); |
| | | } |
| | | //writer.close(); |
| | | logger.debug("End Save shapefile:" + sfile.toURI()); |
| | | logger.debug("End Save PostGIS:" + featureType.getTypeName()); |
| | | } |
| | | featuresContext.clear(); |
| | | } catch (MalformedURLException 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 |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.Map; |
| | | |
| | | 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.postgis.PostgisDataStoreFactory; |
| | | import org.geotools.data.postgis.PostgisDataStore; |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | |
| | | |
| | | private JobExecutionContext executionContext; |
| | | |
| | | private String dataOut = null; |
| | | private String currentSchema = null; |
| | | private String pgCurrentSchema = null; |
| | | private boolean schemaChanged = false; |
| | | private String _convertElementIn = null; |
| | | |
| | | public OracleConvertPostGISJobContext(String dataPath, DataStore pgDS, String filterConfig) |
| | | { |
| | |
| | | ((SimpleFeature) writer.next()).setAttributes(feature.getAttributes(null)); |
| | | } |
| | | //writer.close(); |
| | | logger.debug("End Save posgis:"); |
| | | logger.debug("End Save PostGIS:" + featureType.getTypeName()); |
| | | } |
| | | featuresContext.clear(); |
| | | } catch (MalformedURLException e) |
| | |
| | | |
| | | private boolean isExistFeature(FeatureType featureType) |
| | | { |
| | | try |
| | | { |
| | | FeatureType existFeatureType = targetDataStore.getSchema(featureType.getTypeName()); |
| | | return existFeatureType != null && existFeatureType.equals(featureType); |
| | | } catch (IOException e) |
| | | { |
| | | logger.info(e.getMessage(), e); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | public JobExecutionContext getExecutionContext() |
| | |
| | | { |
| | | this.currentSchema = querySchema; |
| | | this.schemaChanged = true; |
| | | } |
| | | |
| | | public void setConvertElementIn(String convertElementIn) |
| | | { |
| | | _convertElementIn = convertElementIn; |
| | | } |
| | | |
| | | protected Log getLogger() |
| | |
| | | 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.eofms.filter.AbstractFLinkageDispatchableFilter; |
| | | import com.ximple.eofms.filter.ElementDispatcher; |
| | | 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.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | import com.ximple.eofms.jobs.context.AbstractDgnFileJobContext; |
| | | import com.ximple.eofms.util.DefaultColorTable; |
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil; |
| | | import com.ximple.eofms.util.TWD97GeometryConverterDecorator; |
| | |
| | | import org.geotools.data.Transaction; |
| | | import org.geotools.data.shapefile.ShapefileDataStore; |
| | | import org.geotools.data.shapefile.indexed.IndexedShapefileDataStore; |
| | | import org.geotools.feature.AttributeTypeFactory; |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.FeatureTypeBuilder; |
| | |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | import com.ximple.eofms.jobs.context.AbstractDgnFileJobContext; |
| | | import com.ximple.eofms.util.DefaultColorTable; |
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil; |
| | | import com.ximple.eofms.util.TPCLIDConverter; |
| | | import com.ximple.eofms.util.TWD97GeometryConverterDecorator; |
| | | import com.ximple.eofms.util.TWDDatumConverter; |
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.io.dgn7.TextElement; |
| | |
| | | import org.apache.commons.transaction.util.LoggerFacade; |
| | | import org.geotools.data.FeatureWriter; |
| | | import org.geotools.data.Transaction; |
| | | import org.geotools.data.oracle.OracleDataStore; |
| | | import org.geotools.data.shapefile.ShapefileDataStore; |
| | | import org.geotools.data.shapefile.indexed.IndexedShapefileDataStore; |
| | | import org.geotools.feature.Feature; |
| | |
| | | public interface ColorTableMapping |
| | | { |
| | | boolean contain(Color color); |
| | | |
| | | List findId(Color color); |
| | | |
| | | Color getColor(int value); |
| | | |
| | | String getColorCode(int i); |
| | | } |
| | |
| | | } |
| | | |
| | | private ArrayList<Color> colortable = null; |
| | | |
| | | private DefaultColorTable() |
| | | { |
| | | initializeColorTable(); |
| | |
| | | return false; |
| | | } |
| | | |
| | | private static String colorToString(Color c) { |
| | | private static String colorToString(Color c) |
| | | { |
| | | char[] buf = new char[7]; |
| | | buf[0] = '#'; |
| | | String s = Integer.toHexString(c.getRed()); |
| | | if (s.length() == 1) { |
| | | if (s.length() == 1) |
| | | { |
| | | buf[1] = '0'; |
| | | buf[2] = s.charAt(0); |
| | | } |
| | | else { |
| | | } else |
| | | { |
| | | buf[1] = s.charAt(0); |
| | | buf[2] = s.charAt(1); |
| | | } |
| | | s = Integer.toHexString(c.getGreen()); |
| | | if (s.length() == 1) { |
| | | if (s.length() == 1) |
| | | { |
| | | buf[3] = '0'; |
| | | buf[4] = s.charAt(0); |
| | | } |
| | | else { |
| | | } else |
| | | { |
| | | buf[3] = s.charAt(0); |
| | | buf[4] = s.charAt(1); |
| | | } |
| | | s = Integer.toHexString(c.getBlue()); |
| | | if (s.length() == 1) { |
| | | if (s.length() == 1) |
| | | { |
| | | buf[5] = '0'; |
| | | buf[6] = s.charAt(0); |
| | | } |
| | | else { |
| | | } else |
| | | { |
| | | buf[5] = s.charAt(0); |
| | | buf[6] = s.charAt(1); |
| | | } |
| | |
| | | package com.ximple.eofms.util; |
| | | |
| | | import org.geotools.feature.FeatureTypeBuilder; |
| | | import org.geotools.feature.AttributeTypeFactory; |
| | | import org.geotools.feature.FeatureTypeBuilder; |
| | | |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | |
| | |
| | | * In format strings containing the %<code>n</code>$ |
| | | * form of conversion specifications, each argument |
| | | * in the argument list is used exactly once.</p> |
| | | * |
| | | * <p/> |
| | | * <h4>Escape Sequences</h4> |
| | | * <p> |
| | | * The following table lists escape sequences and |
| | |
| | | * be mixed with the %<code>n</code>$ form. The |
| | | * results of mixing numbered and unnumbered argument |
| | | * specifications in a format string are undefined.</p> |
| | | * |
| | | * <p/> |
| | | * <h4>Flag Characters</h4> |
| | | * <p> |
| | | * The flags and their meanings are:</p> |
| | |
| | | * 0 flag will be ignored. For c conversions, |
| | | * the flag is ignored. |
| | | * </dl> |
| | | * |
| | | * <p/> |
| | | * <h4>Conversion Characters</h4> |
| | | * <p> |
| | | * Each conversion character results in fetching zero |
| | |
| | | * Usually, an unchecked exception will be thrown. |
| | | * If the format is exhausted while arguments remain, |
| | | * the excess arguments are ignored.</p> |
| | | * |
| | | * <p/> |
| | | * <p> |
| | | * The conversion characters and their meanings are: |
| | | * </p> |
| | |
| | | * followed by a digit. |
| | | * <dt>c,C<dd>The integer argument is converted to a |
| | | * char and the result is written. |
| | | * |
| | | * <p/> |
| | | * <dt>s,S<dd>The argument is taken to be a string and |
| | | * bytes from the string are written until the |
| | | * end of the string or the number of bytes |
| | |
| | | */ |
| | | public final class PrintfFormat |
| | | { |
| | | /** Vector of control strings and format literals. */ |
| | | /** |
| | | * Vector of control strings and format literals. |
| | | */ |
| | | private Vector vFmt = new Vector(); |
| | | |
| | | /** Character position. Used by the constructor. */ |
| | | /** |
| | | * Character position. Used by the constructor. |
| | | */ |
| | | private int cPos = 0; |
| | | |
| | | /** Character position. Used by the constructor. */ |
| | | /** |
| | | * Character position. Used by the constructor. |
| | | */ |
| | | private DecimalFormatSymbols dfs = null; |
| | | |
| | | /** |
| | |
| | | * unpaired percent signs. A pair of successive |
| | | * percent signs designates a single percent sign in |
| | | * the format. |
| | | * |
| | | * @param fmtArg Control string. |
| | | * @exception IllegalArgumentException if the control |
| | | * @throws IllegalArgumentException if the control |
| | | * string is null, zero length, or otherwise |
| | | * malformed. |
| | | */ |
| | |
| | | * unpaired percent signs. A pair of successive |
| | | * percent signs designates a single percent sign in |
| | | * the format. |
| | | * |
| | | * @param fmtArg Control string. |
| | | * @exception IllegalArgumentException if the control |
| | | * @throws IllegalArgumentException if the control |
| | | * string is null, zero length, or otherwise |
| | | * malformed. |
| | | */ |
| | |
| | | * of the String <code>s</code>, the next unpaired |
| | | * percent sign, or at the end of the String if the |
| | | * last character is a percent sign. |
| | | * |
| | | * @param s Control string. |
| | | * @param start Position in the string |
| | | * <code>s</code> to begin looking for the start |
| | |
| | | * Integer, Long, Float, Double, and Character |
| | | * arguments are treated as wrappers for primitive |
| | | * types. |
| | | * |
| | | * @param o The array of objects to format. |
| | | * @return The formatted String. |
| | | */ |
| | |
| | | |
| | | /** |
| | | * Format nothing. Just use the control string. |
| | | * |
| | | * @return the formatted String. |
| | | */ |
| | | public String sprintf() |
| | |
| | | |
| | | /** |
| | | * Format an int. |
| | | * |
| | | * @param x The int to format. |
| | | * @return The formatted String. |
| | | * @exception IllegalArgumentException if the |
| | | * @throws IllegalArgumentException if the |
| | | * conversion character is f, e, E, g, G, s, |
| | | * or S. |
| | | */ |
| | |
| | | |
| | | /** |
| | | * Format an long. |
| | | * |
| | | * @param x The long to format. |
| | | * @return The formatted String. |
| | | * @exception IllegalArgumentException if the |
| | | * @throws IllegalArgumentException if the |
| | | * conversion character is f, e, E, g, G, s, |
| | | * or S. |
| | | */ |
| | |
| | | |
| | | /** |
| | | * Format a double. |
| | | * |
| | | * @param x The double to format. |
| | | * @return The formatted String. |
| | | * @exception IllegalArgumentException if the |
| | | * @throws IllegalArgumentException if the |
| | | * conversion character is c, C, s, S, |
| | | * d, d, x, X, or o. |
| | | */ |
| | |
| | | |
| | | /** |
| | | * Format a String. |
| | | * |
| | | * @param x The String to format. |
| | | * @return The formatted String. |
| | | * @exception IllegalArgumentException if the |
| | | * @throws IllegalArgumentException if the |
| | | * conversion character is neither s nor S. |
| | | */ |
| | | public String sprintf(String x) throws IllegalArgumentException |
| | |
| | | * Strings using an internal formatting method for |
| | | * Strings. Otherwise use the default formatter |
| | | * (use toString). |
| | | * |
| | | * @param x the Object to format. |
| | | * @return the formatted String. |
| | | * @exception IllegalArgumentException if the |
| | | * @throws IllegalArgumentException if the |
| | | * conversion character is inappropriate for |
| | | * formatting an unwrapped value. |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * <p> |
| | | * <p/> |
| | | * ConversionSpecification allows the formatting of |
| | | * a single primitive or object embedded within a |
| | | * string. The formatting is controlled by a |
| | | * format string. Only one Java primitive or |
| | | * object can be formatted at a time. |
| | | * <p> |
| | | * <p/> |
| | | * A format string is a Java string that contains |
| | | * a control string. The control string starts at |
| | | * the first percent sign (%) in the string, |
| | |
| | | * <li>precedes a sequence of characters that parses |
| | | * as a valid control string. |
| | | * </ol> |
| | | * <p> |
| | | * <p/> |
| | | * A control string takes the form: |
| | | * <pre> % ['-+ #0]* [0..9]* { . [0..9]* }+ |
| | | * { [hlL] }+ [idfgGoxXeEcs] |
| | | * </pre> |
| | | * <p> |
| | | * <p/> |
| | | * The behavior is like printf. One (hopefully the |
| | | * only) exception is that the minimum number of |
| | | * exponent digits is 3 instead of 2 for e and E |
| | |
| | | */ |
| | | private class ConversionSpecification |
| | | { |
| | | /** Default precision. */ |
| | | /** |
| | | * Default precision. |
| | | */ |
| | | private final static int defaultDigits = 6; |
| | | |
| | | /** |
| | |
| | | */ |
| | | private boolean optionalL = false; |
| | | |
| | | /** Control string type. */ |
| | | /** |
| | | * Control string type. |
| | | */ |
| | | private char conversionCharacter = '\0'; |
| | | |
| | | /** |
| | |
| | | */ |
| | | private int pos = 0; |
| | | |
| | | /** Literal or control format string. */ |
| | | /** |
| | | * Literal or control format string. |
| | | */ |
| | | private String fmt; |
| | | |
| | | /** |
| | |
| | | * The argument must begin with a % and end |
| | | * with the conversion character for the |
| | | * conversion specification. |
| | | * |
| | | * @param fmtArg String specifying the |
| | | * conversion specification. |
| | | * @exception IllegalArgumentException if the |
| | | * @throws IllegalArgumentException if the |
| | | * input string is null, zero length, or |
| | | * otherwise malformed. |
| | | */ |
| | |
| | | |
| | | /** |
| | | * Set the String for this instance. |
| | | * |
| | | * @param s the String to store. |
| | | */ |
| | | void setLiteral(String s) |
| | |
| | | * Check whether the specifier has a variable |
| | | * field width that is going to be set by an |
| | | * argument. |
| | | * |
| | | * @return <code>true</code> if the conversion |
| | | * uses an * field width; otherwise |
| | | * <code>false</code>. |
| | |
| | | * Set the field width with an argument. A |
| | | * negative field width is taken as a - flag |
| | | * followed by a positive field width. |
| | | * |
| | | * @param fw the field width. |
| | | */ |
| | | void setFieldWidthWithArg(int fw) |
| | |
| | | * Check whether the specifier has a variable |
| | | * precision that is going to be set by an |
| | | * argument. |
| | | * |
| | | * @return <code>true</code> if the conversion |
| | | * uses an * precision; otherwise |
| | | * <code>false</code>. |
| | |
| | | /** |
| | | * Set the precision with an argument. A |
| | | * negative precision will be changed to zero. |
| | | * |
| | | * @param pr the precision. |
| | | */ |
| | | void setPrecisionWithArg(int pr) |
| | |
| | | /** |
| | | * Format an int argument using this conversion |
| | | * specification. |
| | | * |
| | | * @param s the int to format. |
| | | * @return the formatted String. |
| | | * @exception IllegalArgumentException if the |
| | | * @throws IllegalArgumentException if the |
| | | * conversion character is f, e, E, g, or G. |
| | | */ |
| | | String internalsprintf(int s) throws IllegalArgumentException |
| | |
| | | /** |
| | | * Format a long argument using this conversion |
| | | * specification. |
| | | * |
| | | * @param s the long to format. |
| | | * @return the formatted String. |
| | | * @exception IllegalArgumentException if the |
| | | * @throws IllegalArgumentException if the |
| | | * conversion character is f, e, E, g, or G. |
| | | */ |
| | | String internalsprintf(long s) throws IllegalArgumentException |
| | |
| | | /** |
| | | * Format a double argument using this conversion |
| | | * specification. |
| | | * |
| | | * @param s the double to format. |
| | | * @return the formatted String. |
| | | * @exception IllegalArgumentException if the |
| | | * @throws IllegalArgumentException if the |
| | | * conversion character is c, C, s, S, i, d, |
| | | * x, X, or o. |
| | | */ |
| | |
| | | /** |
| | | * Format a String argument using this conversion |
| | | * specification. |
| | | * |
| | | * @param s the String to format. |
| | | * @return the formatted String. |
| | | * @exception IllegalArgumentException if the |
| | | * @throws IllegalArgumentException if the |
| | | * conversion character is neither s nor S. |
| | | */ |
| | | String internalsprintf(String s) throws IllegalArgumentException |
| | |
| | | /** |
| | | * Format an Object argument using this conversion |
| | | * specification. |
| | | * |
| | | * @param s the Object to format. |
| | | * @return the formatted String. |
| | | * @exception IllegalArgumentException if the |
| | | * @throws IllegalArgumentException if the |
| | | * conversion character is neither s nor S. |
| | | */ |
| | | String internalsprintf(Object s) |
| | |
| | | * is ignored. The '0' flag character implies that |
| | | * padding to the field width will be done with |
| | | * zeros instead of blanks. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the number of digits |
| | | * to appear after the radix character. Padding is |
| | | * with trailing 0s. |
| | |
| | | * the input double value is an infinity, |
| | | * not-a-number, or a finite double and formats |
| | | * each type of input appropriately. |
| | | * |
| | | * @param x the double value to be formatted. |
| | | * @return the converted double value. |
| | | */ |
| | |
| | | * ignored. The '0' flag character implies that |
| | | * padding to the field width will be done with |
| | | * zeros instead of blanks. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the minimum number of |
| | | * digits to appear after the radix character. |
| | | * Padding is with trailing 0s. |
| | | * |
| | | * <p/> |
| | | * The behavior is like printf. One (hopefully the |
| | | * only) exception is that the minimum number of |
| | | * exponent digits is 3 instead of 2 for e and E |
| | |
| | | * Check to see if the digits that are going to |
| | | * be truncated because of the precision should |
| | | * force a round in the preceding digits. |
| | | * |
| | | * @param ca1 the array of digits |
| | | * @param icarry the index of the first digit that |
| | | * is to be truncated from the print |
| | |
| | | * is not quite finished because the symbolic |
| | | * carry may change the length of the string and |
| | | * change the exponent (in e format). |
| | | * |
| | | * @param cLast index of the last digit changed |
| | | * by the round |
| | | * @param cFirst index of the first digit allowed |
| | |
| | | * the input double value is an infinity, |
| | | * not-a-number, or a finite double and formats |
| | | * each type of input appropriately. |
| | | * |
| | | * @param x the double value to be formatted. |
| | | * @param eChar an 'e' or 'E' to use in the |
| | | * converted double value. |
| | |
| | | |
| | | /** |
| | | * Apply zero or blank, left or right padding. |
| | | * |
| | | * @param ca4 array of characters before padding is |
| | | * finished |
| | | * @param noDigits NaN or signed Inf |
| | |
| | | |
| | | /** |
| | | * Format method for the f conversion character. |
| | | * |
| | | * @param x the double to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Format method for the e or E conversion |
| | | * character. |
| | | * |
| | | * @param x the double to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | |
| | | /** |
| | | * Format method for the g conversion character. |
| | | * |
| | | * <p/> |
| | | * For g format, the flag character '-', means that |
| | | * the output should be left justified within the |
| | | * field. The default is to pad with blanks on the |
| | |
| | | * ignored. The '0' flag character implies that |
| | | * padding to the field width will be done with |
| | | * zeros instead of blanks. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the minimum number of |
| | | * digits to appear after the radix character. |
| | | * Padding is with trailing 0s. |
| | | * |
| | | * @param x the double to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Format method for the d conversion specifer and |
| | | * short argument. |
| | | * |
| | | * <p/> |
| | | * For d format, the flag character '-', means that |
| | | * the output should be left justified within the |
| | | * field. The default is to pad with blanks on the |
| | |
| | | * ignored. The '0' flag character implies that |
| | | * padding to the field width will be done with |
| | | * zeros instead of blanks. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the minimum number of |
| | | * digits to appear. Padding is with leading 0s. |
| | | * |
| | | * @param x the short to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Format method for the d conversion character and |
| | | * long argument. |
| | | * |
| | | * <p/> |
| | | * For d format, the flag character '-', means that |
| | | * the output should be left justified within the |
| | | * field. The default is to pad with blanks on the |
| | |
| | | * ignored. The '0' flag character implies that |
| | | * padding to the field width will be done with |
| | | * zeros instead of blanks. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the minimum number of |
| | | * digits to appear. Padding is with leading 0s. |
| | | * |
| | | * @param x the long to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Format method for the d conversion character and |
| | | * int argument. |
| | | * |
| | | * <p/> |
| | | * For d format, the flag character '-', means that |
| | | * the output should be left justified within the |
| | | * field. The default is to pad with blanks on the |
| | |
| | | * ignored. The '0' flag character implies that |
| | | * padding to the field width will be done with |
| | | * zeros instead of blanks. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the minimum number of |
| | | * digits to appear. Padding is with leading 0s. |
| | | * |
| | | * @param x the int to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Utility method for formatting using the d |
| | | * conversion character. |
| | | * |
| | | * @param sx the String to format, the result of |
| | | * converting a short, int, or long to a |
| | | * String. |
| | |
| | | /** |
| | | * Format method for the x conversion character and |
| | | * short argument. |
| | | * |
| | | * <p/> |
| | | * For x format, the flag character '-', means that |
| | | * the output should be left justified within the |
| | | * field. The default is to pad with blanks on the |
| | | * left. The '#' flag character means to lead with |
| | | * '0x'. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the minimum number of |
| | | * digits to appear. Padding is with leading 0s. |
| | | * |
| | | * @param x the short to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Format method for the x conversion character and |
| | | * long argument. |
| | | * |
| | | * <p/> |
| | | * For x format, the flag character '-', means that |
| | | * the output should be left justified within the |
| | | * field. The default is to pad with blanks on the |
| | | * left. The '#' flag character means to lead with |
| | | * '0x'. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the minimum number of |
| | | * digits to appear. Padding is with leading 0s. |
| | | * |
| | | * @param x the long to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Format method for the x conversion character and |
| | | * int argument. |
| | | * |
| | | * <p/> |
| | | * For x format, the flag character '-', means that |
| | | * the output should be left justified within the |
| | | * field. The default is to pad with blanks on the |
| | | * left. The '#' flag character means to lead with |
| | | * '0x'. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the minimum number of |
| | | * digits to appear. Padding is with leading 0s. |
| | | * |
| | | * @param x the int to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Utility method for formatting using the x |
| | | * conversion character. |
| | | * |
| | | * @param sx the String to format, the result of |
| | | * converting a short, int, or long to a |
| | | * String. |
| | |
| | | /** |
| | | * Format method for the o conversion character and |
| | | * short argument. |
| | | * |
| | | * <p/> |
| | | * For o format, the flag character '-', means that |
| | | * the output should be left justified within the |
| | | * field. The default is to pad with blanks on the |
| | | * left. The '#' flag character means that the |
| | | * output begins with a leading 0 and the precision |
| | | * is increased by 1. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the minimum number of |
| | | * digits to appear. Padding is with leading 0s. |
| | | * |
| | | * @param x the short to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Format method for the o conversion character and |
| | | * long argument. |
| | | * |
| | | * <p/> |
| | | * For o format, the flag character '-', means that |
| | | * the output should be left justified within the |
| | | * field. The default is to pad with blanks on the |
| | | * left. The '#' flag character means that the |
| | | * output begins with a leading 0 and the precision |
| | | * is increased by 1. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the minimum number of |
| | | * digits to appear. Padding is with leading 0s. |
| | | * |
| | | * @param x the long to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Format method for the o conversion character and |
| | | * int argument. |
| | | * |
| | | * <p/> |
| | | * For o format, the flag character '-', means that |
| | | * the output should be left justified within the |
| | | * field. The default is to pad with blanks on the |
| | | * left. The '#' flag character means that the |
| | | * output begins with a leading 0 and the precision |
| | | * is increased by 1. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is to |
| | | * add no padding. Padding is with blanks by |
| | | * default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is the minimum number of |
| | | * digits to appear. Padding is with leading 0s. |
| | | * |
| | | * @param x the int to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Utility method for formatting using the o |
| | | * conversion character. |
| | | * |
| | | * @param sx the String to format, the result of |
| | | * converting a short, int, or long to a |
| | | * String. |
| | |
| | | /** |
| | | * Format method for the c conversion character and |
| | | * char argument. |
| | | * |
| | | * <p/> |
| | | * The only flag character that affects c format is |
| | | * the '-', meaning that the output should be left |
| | | * justified within the field. The default is to |
| | | * pad with blanks on the left. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. Padding is with |
| | | * blanks by default. The default width is 1. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, is ignored. |
| | | * |
| | | * @param x the char to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Format method for the s conversion character and |
| | | * String argument. |
| | | * |
| | | * <p/> |
| | | * The only flag character that affects s format is |
| | | * the '-', meaning that the output should be left |
| | | * justified within the field. The default is to |
| | | * pad with blanks on the left. |
| | | * |
| | | * <p/> |
| | | * The field width is treated as the minimum number |
| | | * of characters to be printed. The default is the |
| | | * smaller of the number of characters in the the |
| | | * input and the precision. Padding is with blanks |
| | | * by default. |
| | | * |
| | | * <p/> |
| | | * The precision, if set, specifies the maximum |
| | | * number of characters to be printed from the |
| | | * string. A null digit string is treated |
| | | * as a 0. The default is not to set a maximum |
| | | * number of characters to be printed. |
| | | * |
| | | * @param x the String to format. |
| | | * @return the formatted String. |
| | | */ |
| | |
| | | /** |
| | | * Check for a conversion character. If it is |
| | | * there, store it. |
| | | * |
| | | * @return <code>true</code> if the conversion |
| | | * character is there, and |
| | | * <code>false</code> otherwise. |
| | |
| | | package com.ximple.eofms.util; |
| | | |
| | | import java.util.Map; |
| | | import java.util.HashMap; |
| | | import java.util.Set; |
| | | import java.util.ArrayList; |
| | | import java.util.Iterator; |
| | | import java.util.Collection; |
| | | import java.util.Locale; |
| | | import java.util.regex.Pattern; |
| | | import java.util.regex.Matcher; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.lang.reflect.Array; |
| | | import java.net.URLEncoder; |
| | | import java.nio.CharBuffer; |
| | | import java.nio.charset.CharacterCodingException; |
| | | import java.nio.charset.Charset; |
| | | import java.nio.charset.CharsetEncoder; |
| | | import java.nio.charset.CharacterCodingException; |
| | | import java.nio.CharBuffer; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLEncoder; |
| | | import java.lang.reflect.Array; |
| | | import java.text.BreakIterator; |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.Locale; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | public abstract class StringUtils |
| | | { |
| | |
| | | if (null == decoded) |
| | | { |
| | | return null; |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | return new String(decoded, StringUtils.ENCODING_UTF_8); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @since 1.6 |
| | | */ |
| | | public static String decodeHtml(String source) |
| | |
| | | { |
| | | result.append(entity); |
| | | } |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | // try to decode the entity as a literal |
| | | Character decoded = HTML_DECODE_MAP.get(entity); |
| | |
| | | result.append(entity); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | break; |
| | | } |
| | |
| | | if (null == result) |
| | | { |
| | | return source; |
| | | } |
| | | else if (current_index < source.length()) |
| | | } else if (current_index < source.length()) |
| | | { |
| | | result.append(source.substring(current_index)); |
| | | } |
| | |
| | | if (null == encoded_string) |
| | | { |
| | | return source; |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | int difference = string_to_encode_array.length-(last_match+1); |
| | | if (difference > 0) |
| | |
| | | private static interface EncoderFallbackHandler |
| | | { |
| | | abstract boolean hasFallback(char character); |
| | | |
| | | abstract void appendFallback(StringBuilder encodedBuffer, char character); |
| | | } |
| | | |
| | |
| | | if (-1 == substring_index) |
| | | { |
| | | break; |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | current_index = substring_index + substring.length(); |
| | | count++; |
| | |
| | | { |
| | | source_lookup_reference = source.toLowerCase(); |
| | | seperator = seperator.toLowerCase(); |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | source_lookup_reference = source; |
| | | } |
| | |
| | | element = new String(source.substring(current_index, source.length())); |
| | | substrings.add(element); |
| | | current_index = source.length() + 1; |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | element = new String(source.substring(current_index, delimiter_index)); |
| | | substrings.add(element); |
| | |
| | | { |
| | | source_lookup_reference = source.toLowerCase(); |
| | | stringToStrip = stringToStrip.toLowerCase(); |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | source_lookup_reference = source; |
| | | } |
| | |
| | | new_index == last_index+strip_length); |
| | | |
| | | return source.substring(last_index+strip_length); |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | return source; |
| | | } |
| | |
| | | { |
| | | source_lookup_reference = source.toLowerCase(); |
| | | stringToStrip = stringToStrip.toLowerCase(); |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | source_lookup_reference = source; |
| | | } |
| | |
| | | new_index == last_index-strip_length); |
| | | |
| | | return source.substring(0, last_index); |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | return source; |
| | | } |
| | |
| | | if (0 == collection.size()) |
| | | { |
| | | return ""; |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | StringBuilder result = new StringBuilder(); |
| | | for (Object element : collection) |
| | |
| | | if (0 == array.length) |
| | | { |
| | | return ""; |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | int current_index = 0; |
| | | String array_value = null; |
| | |
| | | if (null == array[current_index]) |
| | | { |
| | | result.append("null"); |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | array_value = String.valueOf(array[current_index]); |
| | | if (encodeStrings) |
| | |
| | | if (null == array[current_index]) |
| | | { |
| | | result.append("null"); |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | array_value = String.valueOf(array[current_index]); |
| | | if (encodeStrings) |
| | |
| | | if (0 == array.length) |
| | | { |
| | | return ""; |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | int current_index = 0; |
| | | String result = ""; |
| | |
| | | if (0 == array.length) |
| | | { |
| | | return ""; |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | int current_index = 0; |
| | | String result = ""; |
| | |
| | | if (0 == array.length) |
| | | { |
| | | return ""; |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | int current_index = 0; |
| | | String result = ""; |
| | |
| | | if (0 == array.length) |
| | | { |
| | | return ""; |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | int current_index = 0; |
| | | String result = ""; |
| | |
| | | if (0 == array.length) |
| | | { |
| | | return ""; |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | int current_index = 0; |
| | | String result = ""; |
| | |
| | | if (0 == array.length) |
| | | { |
| | | return ""; |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | int current_index = 0; |
| | | String result = ""; |
| | |
| | | if (0 == array.length) |
| | | { |
| | | return ""; |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | int current_index = 0; |
| | | String result = ""; |
| | |
| | | if (0 == array.length) |
| | | { |
| | | return ""; |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | int current_index = 0; |
| | | StringBuilder result = new StringBuilder(); |
| | |
| | | { |
| | | source_lookup_reference = source.toLowerCase(); |
| | | substring = substring.toLowerCase(); |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | source_lookup_reference = source; |
| | | } |
| | |
| | | if (-1 == substring_index) |
| | | { |
| | | break; |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | current_index = substring_index + substring.length(); |
| | | indices[counter] = substring_index; |
| | |
| | | if (null == included) |
| | | { |
| | | accepted = true; |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | for (Pattern pattern : included) |
| | | { |
| | |
| | | if (url_matcher.groupCount() > 1) |
| | | { |
| | | visual_url = url_matcher.group(2); |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | visual_url = actual_url; |
| | | } |
| | |
| | | if (pattern.equals(BBCODE_BAREURL)) |
| | | { |
| | | sb.append(source.substring(last, url_matcher.start(1))); |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | sb.append(source.substring(last, url_matcher.start(0))); |
| | | } |
| | |
| | | if (visual_url.length() <= max_length || !shorten) |
| | | { |
| | | sb.append(visual_url); |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | String ellipsis = "..."; |
| | | int query_index = visual_url.indexOf("?"); |
| | |
| | | if (pattern.equals(BBCODE_BAREURL)) |
| | | { |
| | | last = url_matcher.end(1); |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | last = url_matcher.end(0); |
| | | } |
| | |
| | | if (next < begin && next < end) |
| | | { |
| | | endIndex = next; |
| | | } |
| | | else if (begin < next && begin < end) |
| | | } else if (begin < next && begin < end) |
| | | { |
| | | endIndex = begin; |
| | | } |
| | | else if (end < next && end < begin) |
| | | } else if (end < next && end < begin) |
| | | { |
| | | endIndex = end; |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | endIndex = resultLowerCopy.length(); |
| | | } |
| | |
| | | if (0 == last_tab_index) |
| | | { |
| | | return line; |
| | | } |
| | | else |
| | | } else |
| | | { |
| | | result.append(line.substring(last_tab_index)); |
| | | } |
| | |
| | | * are split apart at the earliest wordbreak or at maxLength, whichever is |
| | | * sooner. If the width specified is less than 5 or greater than the input |
| | | * Strings length the string will be returned as is. |
| | | * <p> |
| | | * <p/> |
| | | * Please note that this method can be lossy - trailing spaces on wrapped |
| | | * lines may be trimmed. |
| | | * |
| | |
| | | if (input == null) |
| | | { |
| | | return ""; |
| | | } |
| | | else if (width < 5) |
| | | } else if (width < 5) |
| | | { |
| | | return input; |
| | | } |
| | | else if (width >= input.length()) |
| | | } else if (width >= input.length()) |
| | | { |
| | | return input; |
| | | } |
| | |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | import com.vividsolutions.jts.util.Assert; |
| | | |
| | | import com.ximple.eofms.util.TWDDatumConverter; |
| | | import com.ximple.io.dgn7.GeometryConverter; |
| | | |
| | | public class TWD97GeometryConverterDecorator implements GeometryConverter |
| | |
| | | |
| | | /** |
| | | * ¥ÑTM2®y¼ÐÂà´«¦ÜTWD97®y¼Ð |
| | | * |
| | | * @param pt TM2¦ì¸m |
| | | * @return ·sªºTWD97®y¼Ð |
| | | */ |