forked from geodmms/xdgnjobs

?? ?
2008-06-09 bd210ee7438fd203c19d3e8080ea12b79fe56159
update for EOFM-117
58 files modified
12 files added
13566 ■■■■■ changed files
.gitattributes 12 ●●●●● patch | view | raw | blame | history
xdgnjobs/pom.xml 6 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexShapeElement.java 30 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7OracleReader.java 2 ●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7fileHeader.java 6 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7fileReader.java 106 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java 36 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ElementType.java 56 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/FrammeAttributeData.java 2 ●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/LineElement.java 8 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/LineStringElement.java 8 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Lock.java 10 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/NIOUtilities.java 65 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/StreamLogging.java 4 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextElement.java 1 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextNodeElement.java 4 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/UserAttributeData.java 2 ●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/util/DgnUtility.java 32 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/util/PrintfFormat.java 1194 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7OracleReaderTest.java 12 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7TextElementReaderTest.java 2 ●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7fileReaderTest.java 3 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/test/java/com/ximple/io/dgn7/OracleTarget.java 19 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-jobcarrier/pom.xml 9 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/pom.xml 9 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/TypeCompIdDispatchableFilter.java 2 ●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/TypeCompLevelIdDispatchableFilter.java 2 ●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/TypeIdDispatchableFilter.java 2 ●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/AbstractOracleDatabaseJob.java 20 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2MySQLJob.java 1089 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2OraSDOJob.java 284 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2PostGISJob.java 58 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java 4 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/AbstractDgnFileJobContext.java 2 ●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/AbstractOracleJobContext.java 10 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/AbstractDgnToMySQLJobContext.java 47 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/AbstractOracleToMySQLJobContext.java 52 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/DummyFeatureConvertMySQlJobContext.java 304 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/FeatureDgnConvertMySQLJobContext.java 268 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/GeneralDgnConvertMySQLJobContext.java 521 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/IndexDgnConvertMySQLJobContext.java 320 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/OracleConvertMySQLJobContext.java 319 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/AbstractDgnToOraSDOJobContext.java 38 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/AbstractOracleToOraSDOJobContext.java 44 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/DummyFeatureConvertOraSDOJobContext.java 303 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/FeatureDgnConvertOraSDOJobContext.java 267 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/GeneralDgnConvertOraSDOJobContext.java 522 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/IndexDgnConvertOraSDOJobContext.java 320 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/OracleConvertOraSDOJobContext.java 294 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/AbstractDgnToPostGISJobContext.java 11 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/AbstractOracleToPostGISJobContext.java 13 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/DummyFeatureConvertPostGISJobContext.java 35 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/FeatureDgnConvertPostGISJobContext.java 53 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/GeneralDgnConvertPostGISJobContext.java 7 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/IndexDgnConvertPostGISJobContext.java 46 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/OracleConvertPostGISJobContext.java 21 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/shapefile/DummyFeatureConvertShpJobContext.java 1 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/shapefile/FeatureDgnConvertShpJobContext.java 1 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/shapefile/GeneralDgnConvertShpJobContext.java 1 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/shapefile/IndexDgnConvertShpJobContext.java 4 ●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/shapefile/OracleConvertShapefilesJobContext.java 1 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/ColorTableMapping.java 3 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/DefaultColorTable.java 71 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/FeatureTypeBuilderUtil.java 2 ●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/GeomUtil.java 2 ●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/PrintfFormat.java 1194 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/StringUtils.java 5174 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/TPCLIDConverter.java 2 ●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/TWD97GeometryConverterDecorator.java 3 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/TWDDatumConverter.java 191 ●●●● patch | view | raw | blame | history
.gitattributes
@@ -66,6 +66,7 @@
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
@@ -74,8 +75,19 @@
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/AbstractDgnFileJobContext.java -text
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/AbstractOracleJobContext.java svneol=native#text/plain
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/OracleUpgradeJobContext.java svneol=native#text/plain
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/AbstractDgnToMySQLJobContext.java svneol=native#text/plain
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/AbstractOracleToMySQLJobContext.java svneol=native#text/plain
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/DummyFeatureConvertMySQlJobContext.java svneol=native#text/plain
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/FeatureDgnConvertMySQLJobContext.java svneol=native#text/plain
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/GeneralDgnConvertMySQLJobContext.java svneol=native#text/plain
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/IndexDgnConvertMySQLJobContext.java svneol=native#text/plain
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/OracleConvertMySQLJobContext.java svneol=native#text/plain
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/AbstractDgnToOraSDOJobContext.java svneol=native#text/plain
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/AbstractOracleToOraSDOJobContext.java svneol=native#text/plain
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/DummyFeatureConvertOraSDOJobContext.java svneol=native#text/plain
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/FeatureDgnConvertOraSDOJobContext.java svneol=native#text/plain
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/GeneralDgnConvertOraSDOJobContext.java svneol=native#text/plain
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/IndexDgnConvertOraSDOJobContext.java svneol=native#text/plain
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/OracleConvertOraSDOJobContext.java svneol=native#text/plain
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/AbstractDgnToPostGISJobContext.java svneol=native#text/plain
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/AbstractOracleToPostGISJobContext.java svneol=native#text/plain
xdgnjobs/pom.xml
@@ -286,6 +286,12 @@
        <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>
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexShapeElement.java
@@ -10,10 +10,9 @@
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
@@ -152,29 +151,28 @@
    {
        ArrayList<Geometry> list = new ArrayList<Geometry>();
        for (ListIterator it = listIterator(); it.hasNext(); )
        for (ListIterator it = listIterator(); it.hasNext();)
        {
            Element element = (Element) it.next();
            if (element instanceof ShapeElement)
            {
                if( ((ShapeElement) element).getVerticeSize() == 0 || ((ShapeElement) element).getVerticeSize() > 1)
                if (((ShapeElement) element).getVerticeSize() == 0 || ((ShapeElement) element).getVerticeSize() > 1)
                {
                  list.add(((ShapeElement) element).toGeometry(factory));
                    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)
               {
                 list.add(((LineStringElement) element).toGeometry(factory));
               }
                if (((LineStringElement) element).getVerticeSize() == 0 || ((LineStringElement) element).getVerticeSize() > 1)
                {
                    list.add(((LineStringElement) element).toGeometry(factory));
                }
            } else if (element instanceof LineElement)
            {
               if( ((LineElement) element).getVertices().length == 0 || ((LineElement) element).getVertices().length > 1 )
               {
                 list.add(((LineElement) element).toGeometry(factory));
               }
                if (((LineElement) element).getVertices().length == 0 || ((LineElement) element).getVertices().length > 1)
                {
                    list.add(((LineElement) element).toGeometry(factory));
                }
            } else if (element instanceof ArcElement)
            {
            }
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7OracleReader.java
@@ -167,7 +167,7 @@
                    elementLength = (buffer.getShort() * 2) + 4;
                    if (raw.length < (offset + elementLength))
                    {
                        System.out.println("Length not match:" + offset +":"+ buffer.position() +":"+buffer.limit());
                        System.out.println("Length not match:" + offset + ":" + buffer.position() + ":" + buffer.limit());
                        break;
                    }
                    recordType = ElementType.forID(type);
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7fileHeader.java
@@ -17,7 +17,7 @@
 */
public class Dgn7fileHeader
{
    private short  elmtype;
    private short elmtype;
    private byte[] raw;
    public Dgn7fileHeader()
@@ -29,8 +29,8 @@
        file.order(ByteOrder.LITTLE_ENDIAN);
        elmtype = file.getShort();
        short wtf    = file.getShort();
        int   length = (wtf * 2);
        short wtf = file.getShort();
        int length = (wtf * 2);
        if (file.remaining() != (length))
        {
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7fileReader.java
@@ -33,27 +33,27 @@
{
    private static final Logger logger = LogManager.getLogger(Dgn7fileReader.class);
    private Dgn7fileHeader      header;
    private Dgn7fileHeader header;
    private ReadableByteChannel channel;
    ByteBuffer                  buffer;
    private ElementType         fileElementType = ElementType.UNDEFINED;
    private ByteBuffer          headerTransfer;
    private final Record        record = new Record();
    private final boolean       randomAccessEnabled;
    private Lock                lock;
    private boolean             useMemoryMappedBuffer;
    private long                currentOffset = 0L;
    private StreamLogging       streamLogger  = new StreamLogging("Shapefile Reader");
    private int                 maxElementId  = 0;
    ByteBuffer buffer;
    private ElementType fileElementType = ElementType.UNDEFINED;
    private ByteBuffer headerTransfer;
    private final Record record = new Record();
    private final boolean randomAccessEnabled;
    private Lock lock;
    private boolean useMemoryMappedBuffer;
    private long currentOffset = 0L;
    private StreamLogging streamLogger = new StreamLogging("Shapefile Reader");
    private int maxElementId = 0;
    public Dgn7fileReader(ReadableByteChannel channel, boolean strict, boolean useMemoryMapped, Lock lock)
        throws IOException, Dgn7fileException
            throws IOException, Dgn7fileException
    {
        this.channel               = channel;
        this.channel = channel;
        this.useMemoryMappedBuffer = useMemoryMapped;
        streamLogger.open();
        randomAccessEnabled = channel instanceof FileChannel;
        this.lock           = lock;
        this.lock = lock;
        lock.lockRead();
        init(strict);
    }
@@ -129,8 +129,8 @@
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        int        length = buffer.getShort(2) * 2;
        ByteBuffer old    = buffer;
        int length = buffer.getShort(2) * 2;
        ByteBuffer old = buffer;
        old.position(0);
@@ -173,7 +173,7 @@
        }
        channel = null;
        header  = null;
        header = null;
    }
    public boolean supportsRandomAccess()
@@ -190,8 +190,8 @@
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        // read shape record header
        int   recordNumber = ++maxElementId;
        short signature    = buffer.getShort();
        int recordNumber = ++maxElementId;
        short signature = buffer.getShort();
        // byte type = (byte) (buffer.get() & 0x7f);
        byte type = (byte) ((signature >>> 8) & 0x007f);
@@ -201,7 +201,7 @@
        // track the record location
        int elementLength = (buffer.getShort() * 2) + 4;
        if (!buffer.isReadOnly() &&!useMemoryMappedBuffer)
        if (!buffer.isReadOnly() && !useMemoryMappedBuffer)
        {
            // capacity is less than required for the record
            // copy the old into the newly allocated
@@ -218,16 +218,16 @@
                buffer.position(0);
            } else
            // remaining is less than record length
            // compact the remaining data and read again,
            // allowing enough room for one more record header
            if (buffer.remaining() < elementLength)
            {
                this.currentOffset += buffer.position();
                buffer.compact();
                fill(buffer, channel);
                buffer.position(0);
            }
                // remaining is less than record length
                // compact the remaining data and read again,
                // allowing enough room for one more record header
                if (buffer.remaining() < elementLength)
                {
                    this.currentOffset += buffer.position();
                    buffer.compact();
                    fill(buffer, channel);
                    buffer.position(0);
                }
        }
        // shape record is all little endian
@@ -256,32 +256,32 @@
        {
            int lowCoorX = buffer.getInt();
            lowCoorX    = DgnUtility.convertFromDGN(lowCoorX);
            lowCoorX = DgnUtility.convertFromDGN(lowCoorX);
            record.minX = DgnUtility.converUnitToCoord(lowCoorX);
            int lowCoorY = buffer.getInt();
            lowCoorY    = DgnUtility.convertFromDGN(lowCoorY);
            lowCoorY = DgnUtility.convertFromDGN(lowCoorY);
            record.minY = DgnUtility.converUnitToCoord(lowCoorY);
            int lowCoorZ = buffer.getInt();
            lowCoorZ    = DgnUtility.convertFromDGN(lowCoorZ);
            lowCoorZ = DgnUtility.convertFromDGN(lowCoorZ);
            record.minZ = DgnUtility.converUnitToCoord(lowCoorZ);
            int highCoorX = buffer.getInt();
            highCoorX   = DgnUtility.convertFromDGN(highCoorX);
            highCoorX = DgnUtility.convertFromDGN(highCoorX);
            record.maxX = DgnUtility.converUnitToCoord(highCoorX);
            int highCoorY = buffer.getInt();
            highCoorY   = DgnUtility.convertFromDGN(highCoorY);
            highCoorY = DgnUtility.convertFromDGN(highCoorY);
            record.maxY = DgnUtility.converUnitToCoord(highCoorY);
            int highCoorZ = buffer.getInt();
            highCoorZ   = DgnUtility.convertFromDGN(highCoorZ);
            highCoorZ = DgnUtility.convertFromDGN(highCoorZ);
            record.maxZ = DgnUtility.converUnitToCoord(highCoorZ);
        }
@@ -289,9 +289,9 @@
        record.offset = record.end;
        // update all the record info.
        record.length    = elementLength;
        record.length = elementLength;
        record.signature = signature;
        record.number    = recordNumber;
        record.number = recordNumber;
        // remember, we read one int already...
        record.end = this.toFileOffset(buffer.position()) + elementLength - 4;
@@ -390,7 +390,7 @@
        // looks good
        boolean hasNext = true;
        short   type    = buffer.getShort();
        short type = buffer.getShort();
        if (type == -1)
        {
@@ -553,8 +553,8 @@
    public static void main(String[] args)
    {
        JFileChooser jfc = new JFileChooser("D:/TEMP");
        File         f   = null;
        int          r   = jfc.showOpenDialog(new JFrame());
        File f = null;
        int r = jfc.showOpenDialog(new JFrame());
        if (r == JFileChooser.APPROVE_OPTION)
        {
@@ -562,16 +562,16 @@
            {
                f = jfc.getSelectedFile();
                FileChannel    channel = new FileInputStream(f).getChannel();
                Dgn7fileReader reader  = new Dgn7fileReader(channel, new Lock());
                FileChannel channel = new FileInputStream(f).getChannel();
                Dgn7fileReader reader = new Dgn7fileReader(channel, new Lock());
                System.out.println(reader.getHeader().toString());
                GeometryFactory factory = new GeometryFactory();
                int             count, size;
                int count, size;
                count = 0;
                size  = 0;
                size = 0;
                try
                {
@@ -585,8 +585,8 @@
                        if (record.element() != null)
                        {
                            Element     element = (Element) record.element();
                            ElementType type    = element.getElementType();
                            Element element = (Element) record.element();
                            ElementType type = element.getElementType();
                            if ((!type.isComplexElement()) && (!element.isComponentElement()))
                            {
@@ -647,10 +647,10 @@
    public final class Record
    {
        int   length;
        int   number = 0;
        int   offset;           // Relative to the whole file
        int   start     = 0;    // Relative to the current loaded buffer
        int length;
        int number = 0;
        int offset;           // Relative to the whole file
        int start = 0;    // Relative to the current loaded buffer
        short signature = 0;
        /**
@@ -684,8 +684,8 @@
        public double maxZ;
        // ElementType type;
        int             end     = 0;    // Relative to the whole file
        Object          element = null;
        int end = 0;    // Relative to the whole file
        Object element = null;
        IElementHandler handler;
        public Object element()
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java
@@ -21,22 +21,22 @@
 */
public class Element
{
    public static final int CONSTRUCTION_CLASS      = 0;
    public static final int CONSTRUCTION_CLASS = 0;
    public static final int CONSTRUCTION_RULE_CLASS = 0;
    public static final int DIMENSION_CLASS         = 0;
    public static final int LINEAR_PATTERNED_CLASS  = 0;
    public static final int MAX_ELEMENT_SIZE        = 0;
    public static final int MAX_VERTICES            = 100;
    public static final int PATTERN_AREA            = 0;
    public static final int DIMENSION_CLASS = 0;
    public static final int LINEAR_PATTERNED_CLASS = 0;
    public static final int MAX_ELEMENT_SIZE = 0;
    public static final int MAX_VERTICES = 100;
    public static final int PATTERN_AREA = 0;
    public static final int PATTERN_COMPONENT_CLASS = 0;
    public static final int PATTERN_CROSSHATCH      = 0;
    public static final int PATTERN_HATCH           = 0;
    public static final int PRIMARY_CLASS           = 0;
    public static final int PRIMARY_RULE_CLASS      = 0;
    public static final int PATTERN_CROSSHATCH = 0;
    public static final int PATTERN_HATCH = 0;
    public static final int PRIMARY_CLASS = 0;
    public static final int PRIMARY_RULE_CLASS = 0;
    protected short[]       raw;
    protected byte          attrOffset = 0;
    protected ByteBuffer    rawBuffer;
    protected short[] raw;
    protected byte attrOffset = 0;
    protected ByteBuffer rawBuffer;
    public Element(byte[] raw)
    {
@@ -67,7 +67,7 @@
        highCoorY = DgnUtility.convertFromDGN(highCoorY);
        return new Envelope(DgnUtility.converUnitToCoord(lowCoorX), DgnUtility.converUnitToCoord(highCoorX),
                            DgnUtility.converUnitToCoord(lowCoorY), DgnUtility.converUnitToCoord(highCoorY));
                DgnUtility.converUnitToCoord(lowCoorY), DgnUtility.converUnitToCoord(highCoorY));
    }
    public boolean isComponentElement()
@@ -143,7 +143,7 @@
    public List<UserAttributeData> getUserAttributeData()
    {
        short[] data;
        short   length, nextAttribute;
        short length, nextAttribute;
        if (raw[15] <= 0)
        {
@@ -169,7 +169,7 @@
            }
            nextAttribute = (short) (index + length + 1);
            data          = new short[length];
            data = new short[length];
            System.arraycopy(raw, index + 1, data, 0, length);
            if (data[0] == (short) 0x0020)
@@ -234,7 +234,7 @@
                buffer.get(dst, 4, dst.length - 4);
            } catch (BufferUnderflowException exception)
            {
                throw exception;
                throw exception;
            }
            ByteBuffer tmpBuffer = ByteBuffer.wrap(dst);
@@ -242,7 +242,7 @@
            tmpBuffer.position(0);
            tmpBuffer.putShort(signature);
            tmpBuffer.putShort((short) ((length / 2) - 2));
            /*
            ShortBuffer sbuffer = tmpBuffer.asShortBuffer();
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ElementType.java
@@ -169,7 +169,7 @@
     */
    protected ElementType(int id, String name)
    {
        this.id   = id;
        this.id = id;
        this.name = name;
    }
@@ -262,59 +262,59 @@
        switch (id)
        {
        case 0 :
        case 0:
            t = NULL;
            break;
        case 3 :
        case 3:
            t = LINE;
            break;
        case 4 :
        case 4:
            t = LINESTRING;
            break;
        case 6 :
        case 6:
            t = SHAPE;
            break;
        case 7 :
        case 7:
            t = TEXTNODE;
            break;
        case 8 :
        case 8:
            t = IGDSDIGITIZER;
            break;
        case 9 :
        case 9:
            t = TCB;
            break;
        case 10 :
        case 10:
            t = LEVELSYMBOLOGY;
            break;
        case 12 :
        case 12:
            t = COMPLEXCHAIN;
            break;
        case 14 :
        case 14:
            t = COMPLEXSHAPE;
            break;
        case 15 :
        case 15:
            t = ELLIPSE;
            break;
        case 16 :
        case 16:
            t = ARC;
            break;
        case 17 :
        case 17:
            t = TEXT;
            break;
        default :
        default:
            t = UNDEFINED;
            break;
        }
@@ -328,55 +328,55 @@
        switch (id)
        {
        case 3 :
        case 3:
            handler = LineElement.ElementHandler.getInstance();
            break;
        case 4 :
        case 4:
            handler = LineStringElement.ElementHandler.getInstance();
            break;
        case 6 :
        case 6:
            handler = ShapeElement.ElementHandler.getInstance();
            break;
        case 7 :
        case 7:
            handler = TextNodeElement.ElementHandler.getInstance();
            break;
        case 8 :
        case 8:
            handler = new Element.ElementHandler(this);
            break;
        case 9 :
        case 9:
            handler = new Element.ElementHandler(this);
            break;
        case 10 :
        case 10:
            handler = new Element.ElementHandler(this);
            break;
        case 12 :
        case 12:
            handler = ComplexChainElement.ElementHandler.getInstance();
            break;
        case 14 :
        case 14:
            handler = ComplexShapeElement.ElementHandler.getInstance();
            break;
        case 15 :
        case 15:
            handler = EllipseElement.ElementHandler.getInstance();
            break;
        case 16 :
        case 16:
            handler = ArcElement.ElementHandler.getInstance();
            break;
        case 17 :
        case 17:
            handler = TextElement.ElementHandler.getInstance();
            break;
        default :
        default:
            handler = null;
        }
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/FrammeAttributeData.java
@@ -66,6 +66,6 @@
    public String toString()
    {
        return "FrammeData{" + getFsc() + "," + getUfid() + "," + getComponentID() + "," + getRuleNo() + "," + getStatus() + ","
               + getOccID() + "}";
                + getOccID() + "}";
    }
}
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/LineElement.java
@@ -58,8 +58,8 @@
        int startX = ((raw[18] << 16) & 0xffff0000);
        startX = startX + (raw[19] & 0x0000ffff);
        double x      = DgnUtility.converUnitToCoord(startX);
        int    startY = ((raw[20] << 16) & 0xffff0000);
        double x = DgnUtility.converUnitToCoord(startX);
        int startY = ((raw[20] << 16) & 0xffff0000);
        startY = startY + (raw[21] & 0x0000ffff);
@@ -71,8 +71,8 @@
    public Coordinate getVertex(int index)
    {
        return (index == 0)
               ? getStartPoint()
               : getEndPoint();
                ? getStartPoint()
                : getEndPoint();
    }
    public double getLength()
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/LineStringElement.java
@@ -54,8 +54,8 @@
    public Coordinate getVertex(int index)
    {
        return (index == 0)
               ? getStartPoint()
               : getEndPoint();
                ? getStartPoint()
                : getEndPoint();
    }
    public int getVerticeSize()
@@ -65,8 +65,8 @@
    public double getLength()
    {
        double       result = 0.0;
        Coordinate[] vset   = getVertices();
        double result = 0.0;
        Coordinate[] vset = getVertices();
        for (int i = 1; i < getVerticeSize(); i++)
        {
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Lock.java
@@ -109,7 +109,7 @@
                    wait();
                } catch (InterruptedException e)
                {
                    throw(IOException) new IOException().initCause(e);
                    throw (IOException) new IOException().initCause(e);
                }
            }
        }
@@ -117,7 +117,7 @@
        assertTrue("A write lock exists that is owned by another thread", canRead());
        Thread current = Thread.currentThread();
        Owner  owner   = (Owner) owners.get(current);
        Owner owner = (Owner) owners.get(current);
        if (owner != null)
        {
@@ -183,7 +183,7 @@
                wait();
            } catch (InterruptedException e)
            {
                throw(IOException) new IOException().initCause(e);
                throw (IOException) new IOException().initCause(e);
            }
            if (writer == null)
@@ -247,11 +247,11 @@
    private class Owner
    {
        final Thread owner;
        int          timesLocked;
        int timesLocked;
        Owner(Thread owner)
        {
            this.owner  = owner;
            this.owner = owner;
            timesLocked = 1;
        }
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/NIOUtilities.java
@@ -17,6 +17,7 @@
 */
// J2SE dependencies
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.security.AccessController;
@@ -28,12 +29,13 @@
/**
 * 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.
     */
@@ -43,9 +45,10 @@
     * Do not allows instantiation of this class.
     *
     * @todo This constructor will become private when {@code NIOBufferUtils}
     *       will have been removed.
     * will have been removed.
     */
    protected NIOUtilities() {
    protected NIOUtilities()
    {
    }
    /**
@@ -54,28 +57,34 @@
     * case) will be logged as {@code SEVERE} to the logger of the package name. To
     * force logging of errors, set the System property "org.geotools.io.debugBuffer" to "true".
     *
     * @param  buffer The buffer to close.
     * @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 {
                    Method getCleanerMethod = buffer.getClass().getMethod("cleaner", (Class[])null);
                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);
                    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);
                    }
                }
@@ -89,12 +98,15 @@
    /**
     * 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) {
                            System.getProperty("os.name").indexOf("Windows") >= 0);
        } catch (SecurityException exception)
        {
            // The utilities may be running in an Applet, in which case we
            // can't read properties. Assumes we are not in debugging mode.
            return false;
@@ -104,11 +116,12 @@
    /**
     * 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")
                       + ' '         + System.getProperty("java.vendor");
                + "\n JVM : " + System.getProperty("java.version")
                + ' ' + System.getProperty("java.vendor");
        Logger.getLogger("org.geotools.io").log(Level.SEVERE, message, e);
    }
}
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/StreamLogging.java
@@ -15,8 +15,8 @@
public class StreamLogging
{
    private static final Logger LOGGER = LogManager.getLogger("com.ximple.io.dgn7");
    private String              name;
    private int                 open = 0;
    private String name;
    private int open = 0;
    /**
     * The name that will appear in the debug message
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextElement.java
@@ -2,7 +2,6 @@
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;
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextNodeElement.java
@@ -153,7 +153,7 @@
    {
        ArrayList list = new ArrayList();
        for (ListIterator it = listIterator(); it.hasNext(); )
        for (ListIterator it = listIterator(); it.hasNext();)
        {
            Element element = (Element) it.next();
@@ -256,7 +256,7 @@
        double dx = DgnUtility.converUnitToCoord(x);
        // return DgnUtility.convertFromDGN(x);
        int y  = ((raw[33] << 16) & 0xffff0000) | (raw[34] & 0x0000ffff);
        int y = ((raw[33] << 16) & 0xffff0000) | (raw[34] & 0x0000ffff);
        double dy = DgnUtility.converUnitToCoord(y);
        return new Coordinate(dx, dy);
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/UserAttributeData.java
@@ -13,7 +13,7 @@
    public UserAttributeData(short id, int attributeCount)
    {
        _src    = new short[attributeCount];
        _src = new short[attributeCount];
        _src[0] = id;
    }
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/util/DgnUtility.java
@@ -105,7 +105,7 @@
        }
        return new Envelope(converUnitToCoord((int) range.getMinX()), converUnitToCoord((int) range.getMaxX()),
                                         converUnitToCoord((int) range.getMinY()), converUnitToCoord((int) range.getMaxY()));
                converUnitToCoord((int) range.getMinY()), converUnitToCoord((int) range.getMaxY()));
    }
    public static Envelope converCoordToUnit(Envelope range)
@@ -116,7 +116,7 @@
        }
        return new Envelope(converCoordToUnit(range.getMinX()), converCoordToUnit(range.getMaxX()),
                                         converCoordToUnit(range.getMinY()), converCoordToUnit(range.getMaxY()));
                converCoordToUnit(range.getMinY()), converCoordToUnit(range.getMaxY()));
    }
    public static long convertDGNToRAWIEEEDouble(byte[] org)
@@ -136,12 +136,12 @@
        int[] tmp = new int[2];
        tmp[0]   = buf.getInt();
        tmp[1]   = buf.getInt();
        tmp[0] = buf.getInt();
        tmp[1] = buf.getInt();
        int   exponent;
        int exponent;
        int sign     = (tmp[0] & 0x80000000);
        int sign = (tmp[0] & 0x80000000);
        exponent = (tmp[0] >>> 23) & 0x000000ff;
        if (exponent != 0)
@@ -150,8 +150,8 @@
        }
        int rndbits = tmp[1] & 0x00000007;
        tmp[1]  = tmp[1] >>> 3;
        tmp[1]  = (tmp[1] & 0x1fffffff) | (tmp[0] << 29);
        tmp[1] = tmp[1] >>> 3;
        tmp[1] = (tmp[1] & 0x1fffffff) | (tmp[0] << 29);
        if (rndbits != 0)
        {
@@ -170,9 +170,9 @@
        buf.get(tmpRaw);
        buf.position(0);
        buf.order(ByteOrder.LITTLE_ENDIAN);
        for (int i = tmpRaw.length; i > 0 ; i--)
        for (int i = tmpRaw.length; i > 0; i--)
        {
            buf.put(tmpRaw[i-1]);
            buf.put(tmpRaw[i - 1]);
        }
        buf.position(0);
        long result = buf.getLong();
@@ -190,16 +190,16 @@
        // uint[]   tmp = new int[ 2 ];
        // ushort[] des = new short[ 4 ];
        int[]   tmp = new int[2];
        int[] tmp = new int[2];
        short[] des = new short[4];
        int     sign;
        int     exponent;
        int sign;
        int exponent;
        tmp[0] = (int) ((newVal >>> 32));
        tmp[1] = (int) (newVal);
        // sign = ( int ) ( ( uint ) tmp[ 0 ] & 0x80000000 );
        sign     = tmp[0] & 0x80000000;
        sign = tmp[0] & 0x80000000;
        exponent = (tmp[0] >>> 20) & 0x07ff;
        if (exponent != 0)
@@ -251,8 +251,8 @@
    public static double getLength(double x1, double y1, double x2, double y2)
    {
        double dx     = x1 - x2;
        double dy     = y1 - y2;
        double dx = x1 - x2;
        double dy = y1 - y2;
        return Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
    }
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/util/PrintfFormat.java
@@ -90,7 +90,7 @@
 * 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
@@ -98,40 +98,40 @@
 * the action.
 * <table>
 * <tr><th align=left>Sequence</th>
 *    <th align=left>Name</th>
 *    <th align=left>Description</th></tr>
 * <th align=left>Name</th>
 * <th align=left>Description</th></tr>
 * <tr><td>\\</td><td>backlash</td><td>None.
 * </td></tr>
 * <tr><td>\a</td><td>alert</td><td>Attempts to alert
 *          the user through audible or visible
 *          notification.
 * the user through audible or visible
 * notification.
 * </td></tr>
 * <tr><td>\b</td><td>backspace</td><td>Moves the
 *          printing position to one column before
 *          the current position, unless the
 *          current position is the start of a line.
 * printing position to one column before
 * the current position, unless the
 * current position is the start of a line.
 * </td></tr>
 * <tr><td>\f</td><td>form-feed</td><td>Moves the
 *          printing position to the initial
 *          printing position of the next logical
 *          page.
 * printing position to the initial
 * printing position of the next logical
 * page.
 * </td></tr>
 * <tr><td>\n</td><td>newline</td><td>Moves the
 *          printing position to the start of the
 *          next line.
 * printing position to the start of the
 * next line.
 * </td></tr>
 * <tr><td>\r</td><td>carriage-return</td><td>Moves
 *          the printing position to the start of
 *          the current line.
 * the printing position to the start of
 * the current line.
 * </td></tr>
 * <tr><td>\t</td><td>tab</td><td>Moves the printing
 *          position to the next implementation-
 *          defined horizontal tab position.
 * position to the next implementation-
 * defined horizontal tab position.
 * </td></tr>
 * <tr><td>\v</td><td>vertical-tab</td><td>Moves the
 *          printing position to the start of the
 *          next implementation-defined vertical
 *          tab position.
 * printing position to the start of the
 * next implementation-defined vertical
 * tab position.
 * </td></tr>
 * </table></p>
 * <h4>Conversion Specifications</h4>
@@ -206,55 +206,55 @@
 * 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>
 * <dl>
 * <dt>'<dd> integer portion of the result of a
 *      decimal conversion (%i, %d, %f, %g, or %G) will
 *      be formatted with thousands' grouping
 *      characters.  For other conversions the flag
 *      is ignored.  The non-monetary grouping
 *      character is used.
 * decimal conversion (%i, %d, %f, %g, or %G) will
 * be formatted with thousands' grouping
 * characters.  For other conversions the flag
 * is ignored.  The non-monetary grouping
 * character is used.
 * <dt>-<dd> result of the conversion is left-justified
 *      within the field.  (It will be right-justified
 *      if this flag is not specified).</td></tr>
 * within the field.  (It will be right-justified
 * if this flag is not specified).</td></tr>
 * <dt>+<dd> result of a signed conversion always
 *      begins with a sign (+ or -).  (It will begin
 *      with a sign only when a negative value is
 *      converted if this flag is not specified.)
 * begins with a sign (+ or -).  (It will begin
 * with a sign only when a negative value is
 * converted if this flag is not specified.)
 * <dt>&lt;space&gt;<dd> If the first character of a
 *      signed conversion is not a sign, a space
 *      character will be placed before the result.
 *      This means that if the space character and +
 *      flags both appear, the space flag will be
 *      ignored.
 * signed conversion is not a sign, a space
 * character will be placed before the result.
 * This means that if the space character and +
 * flags both appear, the space flag will be
 * ignored.
 * <dt>#<dd> value is to be converted to an alternative
 *      form.  For c, d, i, and s conversions, the flag
 *      has no effect.  For o conversion, it increases
 *      the precision to force the first digit of the
 *      result to be a zero.  For x or X conversion, a
 *      non-zero result has 0x or 0X prefixed to it,
 *      respectively.  For e, E, f, g, and G
 *      conversions, the result always contains a radix
 *      character, even if no digits follow the radix
 *      character (normally, a decimal point appears in
 *      the result of these conversions only if a digit
 *      follows it).  For g and G conversions, trailing
 *      zeros will not be removed from the result as
 *      they normally are.
 * form.  For c, d, i, and s conversions, the flag
 * has no effect.  For o conversion, it increases
 * the precision to force the first digit of the
 * result to be a zero.  For x or X conversion, a
 * non-zero result has 0x or 0X prefixed to it,
 * respectively.  For e, E, f, g, and G
 * conversions, the result always contains a radix
 * character, even if no digits follow the radix
 * character (normally, a decimal point appears in
 * the result of these conversions only if a digit
 * follows it).  For g and G conversions, trailing
 * zeros will not be removed from the result as
 * they normally are.
 * <dt>0<dd> d, i, o, x, X, e, E, f, g, and G
 *      conversions, leading zeros (following any
 *      indication of sign or base) are used to pad to
 *      the field width;  no space padding is
 *      performed.  If the 0 and - flags both appear,
 *      the 0 flag is ignored.  For d, i, o, x, and X
 *      conversions, if a precision is specified, the
 *      0 flag will be ignored. For c conversions,
 *      the flag is ignored.
 * conversions, leading zeros (following any
 * indication of sign or base) are used to pad to
 * the field width;  no space padding is
 * performed.  If the 0 and - flags both appear,
 * the 0 flag is ignored.  For d, i, o, x, and X
 * conversions, if a precision is specified, the
 * 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
@@ -263,103 +263,103 @@
 * 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>
 * <dl>
 * <dt>d,i<dd>The int argument is converted to a
 *        signed decimal in the style [-]dddd.  The
 *        precision specifies the minimum number of
 *        digits to appear;  if the value being
 *        converted can be represented in fewer
 *        digits, it will be expanded with leading
 *        zeros.  The default precision is 1.  The
 *        result of converting 0 with an explicit
 *        precision of 0 is no characters.
 * signed decimal in the style [-]dddd.  The
 * precision specifies the minimum number of
 * digits to appear;  if the value being
 * converted can be represented in fewer
 * digits, it will be expanded with leading
 * zeros.  The default precision is 1.  The
 * result of converting 0 with an explicit
 * precision of 0 is no characters.
 * <dt>o<dd> The int argument is converted to unsigned
 *        octal format in the style ddddd.  The
 *        precision specifies the minimum number of
 *        digits to appear;  if the value being
 *        converted can be represented in fewer
 *        digits, it will be expanded with leading
 *        zeros.  The default precision is 1.  The
 *        result of converting 0 with an explicit
 *        precision of 0 is no characters.
 * octal format in the style ddddd.  The
 * precision specifies the minimum number of
 * digits to appear;  if the value being
 * converted can be represented in fewer
 * digits, it will be expanded with leading
 * zeros.  The default precision is 1.  The
 * result of converting 0 with an explicit
 * precision of 0 is no characters.
 * <dt>x<dd> The int argument is converted to unsigned
 *        hexadecimal format in the style dddd;  the
 *        letters abcdef are used.  The precision
 *        specifies the minimum numberof digits to
 *        appear; if the value being converted can be
 *        represented in fewer digits, it will be
 *        expanded with leading zeros.  The default
 *        precision is 1.  The result of converting 0
 *        with an explicit precision of 0 is no
 *        characters.
 * hexadecimal format in the style dddd;  the
 * letters abcdef are used.  The precision
 * specifies the minimum numberof digits to
 * appear; if the value being converted can be
 * represented in fewer digits, it will be
 * expanded with leading zeros.  The default
 * precision is 1.  The result of converting 0
 * with an explicit precision of 0 is no
 * characters.
 * <dt>X<dd> Behaves the same as the x conversion
 *        character except that letters ABCDEF are
 *        used instead of abcdef.
 * character except that letters ABCDEF are
 * used instead of abcdef.
 * <dt>f<dd> The floating point number argument is
 *        written in decimal notation in the style
 *        [-]ddd.ddd, where the number of digits after
 *        the radix character (shown here as a decimal
 *        point) is equal to the precision
 *        specification.  A Locale is used to determine
 *        the radix character to use in this format.
 *        If the precision is omitted from the
 *        argument, six digits are written after the
 *        radix character;  if the precision is
 *        explicitly 0 and the # flag is not specified,
 *        no radix character appears.  If a radix
 *        character appears, at least 1 digit appears
 *        before it.  The value is rounded to the
 *        appropriate number of digits.
 * written in decimal notation in the style
 * [-]ddd.ddd, where the number of digits after
 * the radix character (shown here as a decimal
 * point) is equal to the precision
 * specification.  A Locale is used to determine
 * the radix character to use in this format.
 * If the precision is omitted from the
 * argument, six digits are written after the
 * radix character;  if the precision is
 * explicitly 0 and the # flag is not specified,
 * no radix character appears.  If a radix
 * character appears, at least 1 digit appears
 * before it.  The value is rounded to the
 * appropriate number of digits.
 * <dt>e,E<dd>The floating point number argument is
 *        written in the style [-]d.ddde{+-}dd
 *        (the symbols {+-} indicate either a plus or
 *        minus sign), where there is one digit before
 *        the radix character (shown here as a decimal
 *        point) and the number of digits after it is
 *        equal to the precision.  A Locale is used to
 *        determine the radix character to use in this
 *        format.  When the precision is missing, six
 *        digits are written after the radix character;
 *        if the precision is 0 and the # flag is not
 *        specified, no radix character appears.  The
 *        E conversion will produce a number with E
 *        instead of e introducing the exponent.  The
 *        exponent always contains at least two digits.
 *        However, if the value to be written requires
 *        an exponent greater than two digits,
 *        additional exponent digits are written as
 *        necessary.  The value is rounded to the
 *        appropriate number of digits.
 * written in the style [-]d.ddde{+-}dd
 * (the symbols {+-} indicate either a plus or
 * minus sign), where there is one digit before
 * the radix character (shown here as a decimal
 * point) and the number of digits after it is
 * equal to the precision.  A Locale is used to
 * determine the radix character to use in this
 * format.  When the precision is missing, six
 * digits are written after the radix character;
 * if the precision is 0 and the # flag is not
 * specified, no radix character appears.  The
 * E conversion will produce a number with E
 * instead of e introducing the exponent.  The
 * exponent always contains at least two digits.
 * However, if the value to be written requires
 * an exponent greater than two digits,
 * additional exponent digits are written as
 * necessary.  The value is rounded to the
 * appropriate number of digits.
 * <dt>g,G<dd>The floating point number argument is
 *        written in style f or e (or in sytle E in the
 *        case of a G conversion character), with the
 *        precision specifying the number of
 *        significant digits.  If the precision is
 *        zero, it is taken as one.  The style used
 *        depends on the value converted:  style e
 *        (or E) will be used only if the exponent
 *        resulting from the conversion is less than
 *        -4 or greater than or equal to the precision.
 *        Trailing zeros are removed from the result.
 *        A radix character appears only if it is
 *        followed by a digit.
 * written in style f or e (or in sytle E in the
 * case of a G conversion character), with the
 * precision specifying the number of
 * significant digits.  If the precision is
 * zero, it is taken as one.  The style used
 * depends on the value converted:  style e
 * (or E) will be used only if the exponent
 * resulting from the conversion is less than
 * -4 or greater than or equal to the precision.
 * Trailing zeros are removed from the result.
 * A radix character appears only if it is
 * followed by a digit.
 * <dt>c,C<dd>The integer argument is converted to a
 *        char and the result is written.
 *
 * 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
 *        indicated by the precision specification of
 *        the argument is reached.  If the precision
 *        is omitted from the argument, it is taken to
 *        be infinite, so all characters up to the end
 *        of the string are written.
 * bytes from the string are written until the
 * end of the string or the number of bytes
 * indicated by the precision specification of
 * the argument is reached.  If the precision
 * is omitted from the argument, it is taken to
 * be infinite, so all characters up to the end
 * of the string are written.
 * <dt>%<dd>Write a % character;  no argument is
 *        converted.
 * converted.
 * </dl>
 * <p>
 * If a conversion specification does not match one of
@@ -431,25 +431,31 @@
 *
 * @author Allan Jacobs
 * @version 1
 * Release 1: Initial release.
 * Release 2: Asterisk field widths and precisions
 *            %n$ and *m$
 *            Bug fixes
 *              g format fix (2 digits in e form corrupt)
 *              rounding in f format implemented
 *              round up when digit not printed is 5
 *              formatting of -0.0f
 *              round up/down when last digits are 50000...
 *          Release 1: Initial release.
 *          Release 2: Asterisk field widths and precisions
 *          %n$ and *m$
 *          Bug fixes
 *          g format fix (2 digits in e form corrupt)
 *          rounding in f format implemented
 *          round up when digit not printed is 5
 *          formatting of -0.0f
 *          round up/down when last digits are 50000...
 */
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;
    /**
@@ -459,10 +465,11 @@
     * 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
     * string is null, zero length, or otherwise
     * malformed.
     *
     * @param fmtArg Control string.
     * @throws IllegalArgumentException if the control
     *                                  string is null, zero length, or otherwise
     *                                  malformed.
     */
    public PrintfFormat(String fmtArg) throws IllegalArgumentException
    {
@@ -476,18 +483,19 @@
     * 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
     * string is null, zero length, or otherwise
     * malformed.
     *
     * @param fmtArg Control string.
     * @throws IllegalArgumentException if the control
     *                                  string is null, zero length, or otherwise
     *                                  malformed.
     */
    public PrintfFormat(Locale locale, String fmtArg) throws IllegalArgumentException
    {
        dfs = new DecimalFormatSymbols(locale);
        int                     ePos = 0;
        int ePos = 0;
        ConversionSpecification sFmt = null;
        String                  unCS = this.nonControl(fmtArg, 0);
        String unCS = this.nonControl(fmtArg, 0);
        if (unCS != null)
        {
@@ -590,12 +598,13 @@
     * 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 s     Control string.
     * @param start Position in the string
     *     <code>s</code> to begin looking for the start
     *     of a control string.
     *              <code>s</code> to begin looking for the start
     *              of a control string.
     * @return the substring from the start position
     *     to the beginning of the control string.
     *         to the beginning of the control string.
     */
    private String nonControl(String s, int start)
    {
@@ -616,21 +625,22 @@
     * 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.
     * @return The formatted String.
     */
    public String sprintf(Object[] o)
    {
        Enumeration             e  = vFmt.elements();
        Enumeration e = vFmt.elements();
        ConversionSpecification cs = null;
        char                    c  = 0;
        int                     i  = 0;
        StringBuffer            sb = new StringBuffer();
        char c = 0;
        int i = 0;
        StringBuffer sb = new StringBuffer();
        while (e.hasMoreElements())
        {
            cs = (ConversionSpecification) e.nextElement();
            c  = cs.getConversionCharacter();
            c = cs.getConversionCharacter();
            if (c == '\0')
            {
@@ -713,19 +723,20 @@
    /**
     * Format nothing.  Just use the control string.
     * @return  the formatted String.
     *
     * @return the formatted String.
     */
    public String sprintf()
    {
        Enumeration             e  = vFmt.elements();
        Enumeration e = vFmt.elements();
        ConversionSpecification cs = null;
        char                    c  = 0;
        StringBuffer            sb = new StringBuffer();
        char c = 0;
        StringBuffer sb = new StringBuffer();
        while (e.hasMoreElements())
        {
            cs = (ConversionSpecification) e.nextElement();
            c  = cs.getConversionCharacter();
            c = cs.getConversionCharacter();
            if (c == '\0')
            {
@@ -741,23 +752,24 @@
    /**
     * Format an int.
     *
     * @param x The int to format.
     * @return  The formatted String.
     * @exception IllegalArgumentException if the
     *     conversion character is f, e, E, g, G, s,
     *     or S.
     * @return The formatted String.
     * @throws IllegalArgumentException if the
     *                                  conversion character is f, e, E, g, G, s,
     *                                  or S.
     */
    public String sprintf(int x) throws IllegalArgumentException
    {
        Enumeration             e  = vFmt.elements();
        Enumeration e = vFmt.elements();
        ConversionSpecification cs = null;
        char                    c  = 0;
        StringBuffer            sb = new StringBuffer();
        char c = 0;
        StringBuffer sb = new StringBuffer();
        while (e.hasMoreElements())
        {
            cs = (ConversionSpecification) e.nextElement();
            c  = cs.getConversionCharacter();
            c = cs.getConversionCharacter();
            if (c == '\0')
            {
@@ -776,23 +788,24 @@
    /**
     * Format an long.
     *
     * @param x The long to format.
     * @return  The formatted String.
     * @exception IllegalArgumentException if the
     *     conversion character is f, e, E, g, G, s,
     *     or S.
     * @return The formatted String.
     * @throws IllegalArgumentException if the
     *                                  conversion character is f, e, E, g, G, s,
     *                                  or S.
     */
    public String sprintf(long x) throws IllegalArgumentException
    {
        Enumeration             e  = vFmt.elements();
        Enumeration e = vFmt.elements();
        ConversionSpecification cs = null;
        char                    c  = 0;
        StringBuffer            sb = new StringBuffer();
        char c = 0;
        StringBuffer sb = new StringBuffer();
        while (e.hasMoreElements())
        {
            cs = (ConversionSpecification) e.nextElement();
            c  = cs.getConversionCharacter();
            c = cs.getConversionCharacter();
            if (c == '\0')
            {
@@ -811,23 +824,24 @@
    /**
     * Format a double.
     *
     * @param x The double to format.
     * @return  The formatted String.
     * @exception IllegalArgumentException if the
     *     conversion character is c, C, s, S,
     *     d, d, x, X, or o.
     * @return The formatted String.
     * @throws IllegalArgumentException if the
     *                                  conversion character is c, C, s, S,
     *                                  d, d, x, X, or o.
     */
    public String sprintf(double x) throws IllegalArgumentException
    {
        Enumeration             e  = vFmt.elements();
        Enumeration e = vFmt.elements();
        ConversionSpecification cs = null;
        char                    c  = 0;
        StringBuffer            sb = new StringBuffer();
        char c = 0;
        StringBuffer sb = new StringBuffer();
        while (e.hasMoreElements())
        {
            cs = (ConversionSpecification) e.nextElement();
            c  = cs.getConversionCharacter();
            c = cs.getConversionCharacter();
            if (c == '\0')
            {
@@ -846,22 +860,23 @@
    /**
     * Format a String.
     *
     * @param x The String to format.
     * @return  The formatted String.
     * @exception IllegalArgumentException if the
     *   conversion character is neither s nor S.
     * @return The formatted String.
     * @throws IllegalArgumentException if the
     *                                  conversion character is neither s nor S.
     */
    public String sprintf(String x) throws IllegalArgumentException
    {
        Enumeration             e  = vFmt.elements();
        Enumeration e = vFmt.elements();
        ConversionSpecification cs = null;
        char                    c  = 0;
        StringBuffer            sb = new StringBuffer();
        char c = 0;
        StringBuffer sb = new StringBuffer();
        while (e.hasMoreElements())
        {
            cs = (ConversionSpecification) e.nextElement();
            c  = cs.getConversionCharacter();
            c = cs.getConversionCharacter();
            if (c == '\0')
            {
@@ -885,23 +900,24 @@
     * 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
     *    conversion character is inappropriate for
     *    formatting an unwrapped value.
     * @return the formatted String.
     * @throws IllegalArgumentException if the
     *                                  conversion character is inappropriate for
     *                                  formatting an unwrapped value.
     */
    public String sprintf(Object x) throws IllegalArgumentException
    {
        Enumeration             e  = vFmt.elements();
        Enumeration e = vFmt.elements();
        ConversionSpecification cs = null;
        char                    c  = 0;
        StringBuffer            sb = new StringBuffer();
        char c = 0;
        StringBuffer sb = new StringBuffer();
        while (e.hasMoreElements())
        {
            cs = (ConversionSpecification) e.nextElement();
            c  = cs.getConversionCharacter();
            c = cs.getConversionCharacter();
            if (c == '\0')
            {
@@ -946,30 +962,30 @@
    }
    /**
     * <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,
     * provided that this percent sign
     * <ol>
     * <li>is not escaped protected by a matching % or
     *     is not an escape % character,
     * is not an escape % character,
     * <li>is not at the end of the format string, and
     * <li>precedes a sequence of characters that parses
     *     as a valid control string.
     * 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
@@ -980,7 +996,9 @@
     */
    private class ConversionSpecification
    {
        /** Default precision. */
        /**
         * Default precision.
         */
        private final static int defaultDigits = 6;
        /**
@@ -1051,7 +1069,7 @@
         * d, i, o, u, x, or X conversions.  The number of
         * digits to appear after the radix character for
         * the e, E, and f conversions.  The maximum number
         *  of significant digits for the g and G
         * of significant digits for the g and G
         * conversions.  The maximum number of bytes to be
         * printed from a string in s and S conversions.
         */
@@ -1070,12 +1088,12 @@
        /*
         */
        private boolean positionalSpecification       = false;
        private int     argumentPosition              = 0;
        private boolean positionalFieldWidth          = false;
        private int     argumentPositionForFieldWidth = 0;
        private boolean positionalPrecision           = false;
        private int     argumentPositionForPrecision  = 0;
        private boolean positionalSpecification = false;
        private int argumentPosition = 0;
        private boolean positionalFieldWidth = false;
        private int argumentPositionForFieldWidth = 0;
        private boolean positionalPrecision = false;
        private int argumentPositionForPrecision = 0;
        /**
         * Flag specifying that a following d, i, o, u, x,
@@ -1098,7 +1116,9 @@
         */
        private boolean optionalL = false;
        /** Control string type. */
        /**
         * Control string type.
         */
        private char conversionCharacter = '\0';
        /**
@@ -1107,7 +1127,9 @@
         */
        private int pos = 0;
        /** Literal or control format string. */
        /**
         * Literal or control format string.
         */
        private String fmt;
        /**
@@ -1123,11 +1145,12 @@
         * 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
         *     input string is null, zero length, or
         *     otherwise malformed.
         *
         * @param fmtArg String specifying the
         *               conversion specification.
         * @throws IllegalArgumentException if the
         *                                  input string is null, zero length, or
         *                                  otherwise malformed.
         */
        ConversionSpecification(String fmtArg) throws IllegalArgumentException
        {
@@ -1163,7 +1186,7 @@
                        if (precisionSet && leadingZeros)
                        {
                            if ((conversionCharacter == 'd') || (conversionCharacter == 'i') || (conversionCharacter == 'o')
                                || (conversionCharacter == 'x'))
                                    || (conversionCharacter == 'x'))
                            {
                                leadingZeros = false;
                            }
@@ -1184,6 +1207,7 @@
        /**
         * Set the String for this instance.
         *
         * @param s the String to store.
         */
        void setLiteral(String s)
@@ -1200,7 +1224,7 @@
        String getLiteral()
        {
            StringBuffer sb = new StringBuffer();
            int          i  = 0;
            int i = 0;
            while (i < fmt.length())
            {
@@ -1214,42 +1238,42 @@
                        switch (c)
                        {
                        case 'a' :
                        case 'a':
                            sb.append((char) 0x07);
                            break;
                        case 'b' :
                        case 'b':
                            sb.append('\b');
                            break;
                        case 'f' :
                        case 'f':
                            sb.append('\f');
                            break;
                        case 'n' :
                        case 'n':
                            sb.append(System.getProperty("line.separator"));
                            break;
                        case 'r' :
                        case 'r':
                            sb.append('\r');
                            break;
                        case 't' :
                        case 't':
                            sb.append('\t');
                            break;
                        case 'v' :
                        case 'v':
                            sb.append((char) 0x0b);
                            break;
                        case '\\' :
                        case '\\':
                            sb.append('\\');
                            break;
@@ -1284,9 +1308,10 @@
         * 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>.
         *         uses an * field width; otherwise
         *         <code>false</code>.
         */
        boolean isVariableFieldWidth()
        {
@@ -1297,6 +1322,7 @@
         * 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)
@@ -1307,16 +1333,17 @@
            }
            fieldWidthSet = true;
            fieldWidth    = Math.abs(fw);
            fieldWidth = Math.abs(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>.
         *         uses an * precision; otherwise
         *         <code>false</code>.
         */
        boolean isVariablePrecision()
        {
@@ -1326,21 +1353,23 @@
        /**
         * Set the precision with an argument.  A
         * negative precision will be changed to zero.
         *
         * @param pr the precision.
         */
        void setPrecisionWithArg(int pr)
        {
            precisionSet = true;
            precision    = Math.max(pr, 0);
            precision = Math.max(pr, 0);
        }
        /**
         * Format an int argument using this conversion
         *  specification.
         * specification.
         *
         * @param s the int to format.
         * @return the formatted String.
         * @exception IllegalArgumentException if the
         *     conversion character is f, e, E, g, or G.
         * @throws IllegalArgumentException if the
         *                                  conversion character is f, e, E, g, or G.
         */
        String internalsprintf(int s) throws IllegalArgumentException
        {
@@ -1348,8 +1377,8 @@
            switch (conversionCharacter)
            {
            case 'd' :
            case 'i' :
            case 'd':
            case 'i':
                if (optionalh)
                {
                    s2 = printDFormat((short) s);
@@ -1363,8 +1392,8 @@
                break;
            case 'x' :
            case 'X' :
            case 'x':
            case 'X':
                if (optionalh)
                {
                    s2 = printXFormat((short) s);
@@ -1378,7 +1407,7 @@
                break;
            case 'o' :
            case 'o':
                if (optionalh)
                {
                    s2 = printOFormat((short) s);
@@ -1392,15 +1421,15 @@
                break;
            case 'c' :
            case 'C' :
            case 'c':
            case 'C':
                s2 = printCFormat((char) s);
                break;
            default :
            default:
                throw new IllegalArgumentException("Cannot format a int with a format using a " + conversionCharacter
                                                   + " conversion character.");
                        + " conversion character.");
            }
            return s2;
@@ -1409,10 +1438,11 @@
        /**
         * Format a long argument using this conversion
         * specification.
         *
         * @param s the long to format.
         * @return the formatted String.
         * @exception IllegalArgumentException if the
         *     conversion character is f, e, E, g, or G.
         * @throws IllegalArgumentException if the
         *                                  conversion character is f, e, E, g, or G.
         */
        String internalsprintf(long s) throws IllegalArgumentException
        {
@@ -1420,8 +1450,8 @@
            switch (conversionCharacter)
            {
            case 'd' :
            case 'i' :
            case 'd':
            case 'i':
                if (optionalh)
                {
                    s2 = printDFormat((short) s);
@@ -1435,8 +1465,8 @@
                break;
            case 'x' :
            case 'X' :
            case 'x':
            case 'X':
                if (optionalh)
                {
                    s2 = printXFormat((short) s);
@@ -1450,7 +1480,7 @@
                break;
            case 'o' :
            case 'o':
                if (optionalh)
                {
                    s2 = printOFormat((short) s);
@@ -1464,15 +1494,15 @@
                break;
            case 'c' :
            case 'C' :
            case 'c':
            case 'C':
                s2 = printCFormat((char) s);
                break;
            default :
            default:
                throw new IllegalArgumentException("Cannot format a long with a format using a " + conversionCharacter
                                                   + " conversion character.");
                        + " conversion character.");
            }
            return s2;
@@ -1481,11 +1511,12 @@
        /**
         * Format a double argument using this conversion
         * specification.
         *
         * @param s the double to format.
         * @return the formatted String.
         * @exception IllegalArgumentException if the
         *     conversion character is c, C, s, S, i, d,
         *     x, X, or o.
         * @throws IllegalArgumentException if the
         *                                  conversion character is c, C, s, S, i, d,
         *                                  x, X, or o.
         */
        String internalsprintf(double s) throws IllegalArgumentException
        {
@@ -1493,26 +1524,26 @@
            switch (conversionCharacter)
            {
            case 'f' :
            case 'f':
                s2 = printFFormat(s);
                break;
            case 'E' :
            case 'e' :
            case 'E':
            case 'e':
                s2 = printEFormat(s);
                break;
            case 'G' :
            case 'g' :
            case 'G':
            case 'g':
                s2 = printGFormat(s);
                break;
            default :
            default:
                throw new IllegalArgumentException("Cannot " + "format a double with a format using a " + conversionCharacter
                                                   + " conversion character.");
                        + " conversion character.");
            }
            return s2;
@@ -1521,10 +1552,11 @@
        /**
         * Format a String argument using this conversion
         * specification.
         *
         * @param s the String to format.
         * @return the formatted String.
         * @exception IllegalArgumentException if the
         *   conversion character is neither s nor S.
         * @throws IllegalArgumentException if the
         *                                  conversion character is neither s nor S.
         */
        String internalsprintf(String s) throws IllegalArgumentException
        {
@@ -1536,7 +1568,7 @@
            } else
            {
                throw new IllegalArgumentException("Cannot " + "format a String with a format using a " + conversionCharacter
                                                   + " conversion character.");
                        + " conversion character.");
            }
            return s2;
@@ -1545,10 +1577,11 @@
        /**
         * Format an Object argument using this conversion
         * specification.
         *
         * @param s the Object to format.
         * @return the formatted String.
         * @exception IllegalArgumentException if the
         *     conversion character is neither s nor S.
         * @throws IllegalArgumentException if the
         *                                  conversion character is neither s nor S.
         */
        String internalsprintf(Object s)
        {
@@ -1560,7 +1593,7 @@
            } else
            {
                throw new IllegalArgumentException("Cannot format a String with a format using" + " a " + conversionCharacter
                                                   + " conversion character.");
                        + " conversion character.");
            }
            return s2;
@@ -1578,12 +1611,12 @@
         * 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.
@@ -1591,10 +1624,10 @@
        private char[] fFormatDigits(double x)
        {
            // int defaultDigits=6;
            String  sx, sxOut;
            int     i, j, k;
            int     n1In, n2In;
            int     expon     = 0;
            String sx, sxOut;
            int i, j, k;
            int n1In, n2In;
            int expon = 0;
            boolean minusSign = false;
            if (x > 0.0)
@@ -1602,7 +1635,7 @@
                sx = Double.toString(x);
            } else if (x < 0.0)
            {
                sx        = Double.toString(-x);
                sx = Double.toString(-x);
                minusSign = true;
            } else
            {
@@ -1611,7 +1644,7 @@
                if (sx.charAt(0) == '-')
                {
                    minusSign = true;
                    sx        = sx.substring(1);
                    sx = sx.substring(1);
                }
            }
@@ -1761,7 +1794,7 @@
                    ca4[0] = '1';
                }
                if (alternateForm ||!precisionSet || (precision != 0))
                if (alternateForm || !precisionSet || (precision != 0))
                {
                    ca4[1] = '.';
@@ -1779,7 +1812,7 @@
            {
                if (!carry)
                {
                    if (alternateForm ||!precisionSet || (precision != 0))
                    if (alternateForm || !precisionSet || (precision != 0))
                    {
                        ca4 = new char[n1In + expon + p + 1];
                    } else
@@ -1790,7 +1823,7 @@
                    j = 0;
                } else
                {
                    if (alternateForm ||!precisionSet || (precision != 0))
                    if (alternateForm || !precisionSet || (precision != 0))
                    {
                        ca4 = new char[n1In + expon + p + 2];
                    } else
@@ -1799,7 +1832,7 @@
                    }
                    ca4[0] = '1';
                    j      = 1;
                    j = 1;
                }
                for (i = 0; i < Math.min(n1In + expon, ca3.length); i++, j++)
@@ -1812,7 +1845,7 @@
                    ca4[j] = '0';
                }
                if (alternateForm ||!precisionSet || (precision != 0))
                if (alternateForm || !precisionSet || (precision != 0))
                {
                    ca4[j] = '.';
                    j++;
@@ -1941,7 +1974,7 @@
            if (thousands && (nThousands > 0))
            {
                ca6    = new char[ca5.length + nThousands + lead];
                ca6 = new char[ca5.length + nThousands + lead];
                ca6[0] = ca5[0];
                for (i = lead, k = lead; i < dp; i++)
@@ -1949,9 +1982,9 @@
                    if ((i > 0) && (dp - i) % 3 == 0)
                    {
                        // ca6[k]=',';
                        ca6[k]     = dfs.getGroupingSeparator();
                        ca6[k] = dfs.getGroupingSeparator();
                        ca6[k + 1] = ca5[i];
                        k          += 2;
                        k += 2;
                    } else
                    {
                        ca6[k] = ca5[i];
@@ -1974,13 +2007,14 @@
         * 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.
         */
        private String fFormatString(double x)
        {
            boolean noDigits = false;
            char[]  ca6, ca7;
            char[] ca6, ca7;
            if (Double.isInfinite(x))
            {
@@ -2038,16 +2072,16 @@
         * 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
@@ -2061,11 +2095,11 @@
            char[] ca1, ca2, ca3;
            // int defaultDigits=6;
            String  sx, sxOut;
            int     i, j, k, p;
            int     n1In, n2In;
            int     expon = 0;
            int     ePos, rPos, eSize;
            String sx, sxOut;
            int i, j, k, p;
            int n1In, n2In;
            int expon = 0;
            int ePos, rPos, eSize;
            boolean minusSign = false;
            if (x > 0.0)
@@ -2073,7 +2107,7 @@
                sx = Double.toString(x);
            } else if (x < 0.0)
            {
                sx        = Double.toString(-x);
                sx = Double.toString(-x);
                minusSign = true;
            } else
            {
@@ -2082,7 +2116,7 @@
                if (sx.charAt(0) == '-')
                {
                    minusSign = true;
                    sx        = sx.substring(1);
                    sx = sx.substring(1);
                }
            }
@@ -2190,7 +2224,7 @@
            }
            boolean carry = false;
            int     i0    = 0;
            int i0 = 0;
            if (ca1[0] != '0')
            {
@@ -2217,7 +2251,7 @@
                if (carry)
                {
                    ca2     = new char[i0 + p + 1];
                    ca2 = new char[i0 + p + 1];
                    ca2[i0] = '1';
                    for (j = 0; j < i0; j++)
@@ -2235,7 +2269,7 @@
                }
            }
            if ((Math.abs(expon) < 100) &&!optionalL)
            if ((Math.abs(expon) < 100) && !optionalL)
            {
                eSize = 4;
            } else
@@ -2243,7 +2277,7 @@
                eSize = 5;
            }
            if (alternateForm ||!precisionSet || (precision != 0))
            if (alternateForm || !precisionSet || (precision != 0))
            {
                ca2 = new char[2 + p + eSize];
            } else
@@ -2254,12 +2288,12 @@
            if (ca1[0] != '0')
            {
                ca2[0] = ca1[0];
                j      = 1;
                j = 1;
            } else
            {
                for (j = 1; j < ((ePos == -1)
                                 ? ca1.length
                                 : ePos); j++)
                        ? ca1.length
                        : ePos); j++)
                {
                    if (ca1[j] != '0')
                    {
@@ -2270,19 +2304,19 @@
                if (((ePos != -1) && (j < ePos)) || ((ePos == -1) && (j < ca1.length)))
                {
                    ca2[0] = ca1[j];
                    expon  -= j;
                    expon -= j;
                    j++;
                } else
                {
                    ca2[0] = '0';
                    j      = 2;
                    j = 2;
                }
            }
            if (alternateForm ||!precisionSet || (precision != 0))
            if (alternateForm || !precisionSet || (precision != 0))
            {
                ca2[1] = '.';
                i      = 2;
                i = 2;
            } else
            {
                i = 1;
@@ -2314,47 +2348,47 @@
            {
                switch (expon / 100)
                {
                case 1 :
                case 1:
                    ca2[i] = '1';
                    break;
                case 2 :
                case 2:
                    ca2[i] = '2';
                    break;
                case 3 :
                case 3:
                    ca2[i] = '3';
                    break;
                case 4 :
                case 4:
                    ca2[i] = '4';
                    break;
                case 5 :
                case 5:
                    ca2[i] = '5';
                    break;
                case 6 :
                case 6:
                    ca2[i] = '6';
                    break;
                case 7 :
                case 7:
                    ca2[i] = '7';
                    break;
                case 8 :
                case 8:
                    ca2[i] = '8';
                    break;
                case 9 :
                case 9:
                    ca2[i] = '9';
                    break;
@@ -2365,52 +2399,52 @@
            switch ((expon % 100) / 10)
            {
            case 0 :
            case 0:
                ca2[i] = '0';
                break;
            case 1 :
            case 1:
                ca2[i] = '1';
                break;
            case 2 :
            case 2:
                ca2[i] = '2';
                break;
            case 3 :
            case 3:
                ca2[i] = '3';
                break;
            case 4 :
            case 4:
                ca2[i] = '4';
                break;
            case 5 :
            case 5:
                ca2[i] = '5';
                break;
            case 6 :
            case 6:
                ca2[i] = '6';
                break;
            case 7 :
            case 7:
                ca2[i] = '7';
                break;
            case 8 :
            case 8:
                ca2[i] = '8';
                break;
            case 9 :
            case 9:
                ca2[i] = '9';
                break;
@@ -2420,52 +2454,52 @@
            switch (expon % 10)
            {
            case 0 :
            case 0:
                ca2[i] = '0';
                break;
            case 1 :
            case 1:
                ca2[i] = '1';
                break;
            case 2 :
            case 2:
                ca2[i] = '2';
                break;
            case 3 :
            case 3:
                ca2[i] = '3';
                break;
            case 4 :
            case 4:
                ca2[i] = '4';
                break;
            case 5 :
            case 5:
                ca2[i] = '5';
                break;
            case 6 :
            case 6:
                ca2[i] = '6';
                break;
            case 7 :
            case 7:
                ca2[i] = '7';
                break;
            case 8 :
            case 8:
                ca2[i] = '8';
                break;
            case 9 :
            case 9:
                ca2[i] = '9';
                break;
@@ -2583,7 +2617,7 @@
            if (thousands && (nThousands > 0))
            {
                ca4    = new char[ca3.length + nThousands + lead];
                ca4 = new char[ca3.length + nThousands + lead];
                ca4[0] = ca3[0];
                for (i = lead, k = lead; i < dp; i++)
@@ -2591,9 +2625,9 @@
                    if ((i > 0) && (dp - i) % 3 == 0)
                    {
                        // ca4[k]=',';
                        ca4[k]     = dfs.getGroupingSeparator();
                        ca4[k] = dfs.getGroupingSeparator();
                        ca4[k + 1] = ca3[i];
                        k          += 2;
                        k += 2;
                    } else
                    {
                        ca4[k] = ca3[i];
@@ -2614,11 +2648,12 @@
         * 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 ca1    the array of digits
         * @param icarry the index of the first digit that
         *     is to be truncated from the print
         *               is to be truncated from the print
         * @return <code>true</code> if the truncation forces
         *     a round that will change the print
         *         a round that will change the print
         */
        private boolean checkForCarry(char[] ca1, int icarry)
        {
@@ -2646,7 +2681,7 @@
                    if (!carry && (icarry > 0))
                    {
                        carry = ((ca1[icarry - 1] == '1') || (ca1[icarry - 1] == '3') || (ca1[icarry - 1] == '5')
                                 || (ca1[icarry - 1] == '7') || (ca1[icarry - 1] == '9'));
                                || (ca1[icarry - 1] == '7') || (ca1[icarry - 1] == '9'));
                    }
                }
            }
@@ -2659,13 +2694,14 @@
         * 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 cLast  index of the last digit changed
         *               by the round
         * @param cFirst index of the first digit allowed
         *     to be changed by this phase of the round
         *               to be changed by this phase of the round
         * @return <code>true</code> if the carry forces
         *     a round that will change the print still
         *     more
         *         a round that will change the print still
         *         more
         */
        private boolean startSymbolicCarry(char[] ca, int cLast, int cFirst)
        {
@@ -2677,52 +2713,52 @@
                switch (ca[i])
                {
                case '0' :
                case '0':
                    ca[i] = '1';
                    break;
                case '1' :
                case '1':
                    ca[i] = '2';
                    break;
                case '2' :
                case '2':
                    ca[i] = '3';
                    break;
                case '3' :
                case '3':
                    ca[i] = '4';
                    break;
                case '4' :
                case '4':
                    ca[i] = '5';
                    break;
                case '5' :
                case '5':
                    ca[i] = '6';
                    break;
                case '6' :
                case '6':
                    ca[i] = '7';
                    break;
                case '7' :
                case '7':
                    ca[i] = '8';
                    break;
                case '8' :
                case '8':
                    ca[i] = '9';
                    break;
                case '9' :
                case '9':
                    ca[i] = '0';
                    carry = true;
@@ -2739,15 +2775,16 @@
         * 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 x     the double value to be formatted.
         * @param eChar an 'e' or 'E' to use in the
         *     converted double value.
         *              converted double value.
         * @return the converted double value.
         */
        private String eFormatString(double x, char eChar)
        {
            boolean noDigits = false;
            char[]  ca4, ca5;
            char[] ca4, ca5;
            if (Double.isInfinite(x))
            {
@@ -2795,8 +2832,9 @@
        /**
         * Apply zero or blank, left or right padding.
         * @param ca4 array of characters before padding is
         *     finished
         *
         * @param ca4      array of characters before padding is
         *                 finished
         * @param noDigits NaN or signed Inf
         * @return a padded array of characters
         */
@@ -2851,8 +2889,8 @@
                    if (nBlanks > 0)
                    {
                        ca5 = new char[ca4.length + nBlanks];
                        i   = 0;
                        j   = 0;
                        i = 0;
                        j = 0;
                        if (ca4[0] == '-')
                        {
@@ -2879,6 +2917,7 @@
        /**
         * Format method for the f conversion character.
         *
         * @param x the double to format.
         * @return the formatted String.
         */
@@ -2890,6 +2929,7 @@
        /**
         * Format method for the e or E conversion
         * character.
         *
         * @param x the double to format.
         * @return the formatted String.
         */
@@ -2906,9 +2946,9 @@
        /**
         * Format method for the g conversion character.
         *
         * <p/>
         * For g format, the flag character '-', means that
         *  the output should be left justified within the
         * the output should be left justified within the
         * field.  The default is to pad with blanks on the
         * left.  '+' character means that the conversion
         * will always begin with a sign (+ or -).  The
@@ -2918,24 +2958,25 @@
         * 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.
         */
        private String printGFormat(double x)
        {
            String  sx, sy, sz, ret;
            int     savePrecision = precision;
            int     i;
            char[]  ca4, ca5;
            String sx, sy, sz, ret;
            int savePrecision = precision;
            int i;
            char[] ca4, ca5;
            boolean noDigits = false;
            if (Double.isInfinite(x))
@@ -2988,11 +3029,11 @@
                if (conversionCharacter == 'g')
                {
                    sx   = eFormatString(x, 'e').trim();
                    sx = eFormatString(x, 'e').trim();
                    ePos = sx.indexOf('e');
                } else
                {
                    sx   = eFormatString(x, 'E').trim();
                    sx = eFormatString(x, 'E').trim();
                    ePos = sx.indexOf('E');
                }
@@ -3106,7 +3147,7 @@
            }
            // Pad with blanks or zeros.
            ca5       = applyFloatPadding(ca4, false);
            ca5 = applyFloatPadding(ca4, false);
            precision = savePrecision;
            return new String(ca5);
@@ -3115,7 +3156,7 @@
        /**
         * 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
@@ -3127,14 +3168,15 @@
         * 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.
         */
@@ -3146,7 +3188,7 @@
        /**
         * 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
@@ -3158,14 +3200,15 @@
         * 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.
         */
@@ -3177,7 +3220,7 @@
        /**
         * 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
@@ -3189,14 +3232,15 @@
         * 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.
         */
@@ -3208,19 +3252,20 @@
        /**
         * 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.
         *           converting a short, int, or long to a
         *           String.
         * @return the formatted String.
         */
        private String printDFormat(String sx)
        {
            int     nLeadingZeros = 0;
            int     nBlanks       = 0,
                    n             = 0;
            int     i             = 0,
                    jFirst        = 0;
            boolean neg           = sx.charAt(0) == '-';
            int nLeadingZeros = 0;
            int nBlanks = 0,
                    n = 0;
            int i = 0,
                    jFirst = 0;
            boolean neg = sx.charAt(0) == '-';
            if (sx.equals("0") && precisionSet && (precision == 0))
            {
@@ -3291,8 +3336,8 @@
                char[] csx = sx.toCharArray();
                jFirst = neg
                         ? 1
                         : 0;
                        ? 1
                        : 0;
                for (int j = 0; j < nLeadingZeros; i++, j++)
                {
@@ -3354,8 +3399,8 @@
                char[] csx = sx.toCharArray();
                jFirst = neg
                         ? 1
                         : 0;
                        ? 1
                        : 0;
                for (int j = jFirst; j < csx.length; j++, i++)
                {
@@ -3369,20 +3414,21 @@
        /**
         * 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.
         */
@@ -3412,55 +3458,55 @@
                switch (t.length())
                {
                case 1 :
                case 1:
                    sx = "800" + t;
                    break;
                case 2 :
                case 2:
                    sx = "80" + t;
                    break;
                case 3 :
                case 3:
                    sx = "8" + t;
                    break;
                case 4 :
                case 4:
                    switch (t.charAt(0))
                    {
                    case '1' :
                    case '1':
                        sx = "9" + t.substring(1, 4);
                        break;
                    case '2' :
                    case '2':
                        sx = "a" + t.substring(1, 4);
                        break;
                    case '3' :
                    case '3':
                        sx = "b" + t.substring(1, 4);
                        break;
                    case '4' :
                    case '4':
                        sx = "c" + t.substring(1, 4);
                        break;
                    case '5' :
                    case '5':
                        sx = "d" + t.substring(1, 4);
                        break;
                    case '6' :
                    case '6':
                        sx = "e" + t.substring(1, 4);
                        break;
                    case '7' :
                    case '7':
                        sx = "f" + t.substring(1, 4);
                        break;
@@ -3479,20 +3525,21 @@
        /**
         * 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.
         */
@@ -3509,115 +3556,115 @@
                switch (t.length())
                {
                case 1 :
                case 1:
                    sx = "800000000000000" + t;
                    break;
                case 2 :
                case 2:
                    sx = "80000000000000" + t;
                    break;
                case 3 :
                case 3:
                    sx = "8000000000000" + t;
                    break;
                case 4 :
                case 4:
                    sx = "800000000000" + t;
                    break;
                case 5 :
                case 5:
                    sx = "80000000000" + t;
                    break;
                case 6 :
                case 6:
                    sx = "8000000000" + t;
                    break;
                case 7 :
                case 7:
                    sx = "800000000" + t;
                    break;
                case 8 :
                case 8:
                    sx = "80000000" + t;
                    break;
                case 9 :
                case 9:
                    sx = "8000000" + t;
                    break;
                case 10 :
                case 10:
                    sx = "800000" + t;
                    break;
                case 11 :
                case 11:
                    sx = "80000" + t;
                    break;
                case 12 :
                case 12:
                    sx = "8000" + t;
                    break;
                case 13 :
                case 13:
                    sx = "800" + t;
                    break;
                case 14 :
                case 14:
                    sx = "80" + t;
                    break;
                case 15 :
                case 15:
                    sx = "8" + t;
                    break;
                case 16 :
                case 16:
                    switch (t.charAt(0))
                    {
                    case '1' :
                    case '1':
                        sx = "9" + t.substring(1, 16);
                        break;
                    case '2' :
                    case '2':
                        sx = "a" + t.substring(1, 16);
                        break;
                    case '3' :
                    case '3':
                        sx = "b" + t.substring(1, 16);
                        break;
                    case '4' :
                    case '4':
                        sx = "c" + t.substring(1, 16);
                        break;
                    case '5' :
                    case '5':
                        sx = "d" + t.substring(1, 16);
                        break;
                    case '6' :
                    case '6':
                        sx = "e" + t.substring(1, 16);
                        break;
                    case '7' :
                    case '7':
                        sx = "f" + t.substring(1, 16);
                        break;
@@ -3636,20 +3683,21 @@
        /**
         * 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.
         */
@@ -3666,75 +3714,75 @@
                switch (t.length())
                {
                case 1 :
                case 1:
                    sx = "8000000" + t;
                    break;
                case 2 :
                case 2:
                    sx = "800000" + t;
                    break;
                case 3 :
                case 3:
                    sx = "80000" + t;
                    break;
                case 4 :
                case 4:
                    sx = "8000" + t;
                    break;
                case 5 :
                case 5:
                    sx = "800" + t;
                    break;
                case 6 :
                case 6:
                    sx = "80" + t;
                    break;
                case 7 :
                case 7:
                    sx = "8" + t;
                    break;
                case 8 :
                case 8:
                    switch (t.charAt(0))
                    {
                    case '1' :
                    case '1':
                        sx = "9" + t.substring(1, 8);
                        break;
                    case '2' :
                    case '2':
                        sx = "a" + t.substring(1, 8);
                        break;
                    case '3' :
                    case '3':
                        sx = "b" + t.substring(1, 8);
                        break;
                    case '4' :
                    case '4':
                        sx = "c" + t.substring(1, 8);
                        break;
                    case '5' :
                    case '5':
                        sx = "d" + t.substring(1, 8);
                        break;
                    case '6' :
                    case '6':
                        sx = "e" + t.substring(1, 8);
                        break;
                    case '7' :
                    case '7':
                        sx = "f" + t.substring(1, 8);
                        break;
@@ -3753,15 +3801,16 @@
        /**
         * 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.
         *           converting a short, int, or long to a
         *           String.
         * @return the formatted String.
         */
        private String printXFormat(String sx)
        {
            int nLeadingZeros = 0;
            int nBlanks       = 0;
            int nBlanks = 0;
            if (sx.equals("0") && precisionSet && (precision == 0))
            {
@@ -3805,7 +3854,7 @@
            n += nBlanks;
            char[] ca = new char[n];
            int    i  = 0;
            int i = 0;
            if (leftJustify)
            {
@@ -3881,21 +3930,22 @@
        /**
         * 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.
         */
@@ -3912,27 +3962,27 @@
                switch (t.length())
                {
                case 1 :
                case 1:
                    sx = "10000" + t;
                    break;
                case 2 :
                case 2:
                    sx = "1000" + t;
                    break;
                case 3 :
                case 3:
                    sx = "100" + t;
                    break;
                case 4 :
                case 4:
                    sx = "10" + t;
                    break;
                case 5 :
                case 5:
                    sx = "1" + t;
                    break;
@@ -3948,21 +3998,22 @@
        /**
         * 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.
         */
@@ -3979,107 +4030,107 @@
                switch (t.length())
                {
                case 1 :
                case 1:
                    sx = "100000000000000000000" + t;
                    break;
                case 2 :
                case 2:
                    sx = "10000000000000000000" + t;
                    break;
                case 3 :
                case 3:
                    sx = "1000000000000000000" + t;
                    break;
                case 4 :
                case 4:
                    sx = "100000000000000000" + t;
                    break;
                case 5 :
                case 5:
                    sx = "10000000000000000" + t;
                    break;
                case 6 :
                case 6:
                    sx = "1000000000000000" + t;
                    break;
                case 7 :
                case 7:
                    sx = "100000000000000" + t;
                    break;
                case 8 :
                case 8:
                    sx = "10000000000000" + t;
                    break;
                case 9 :
                case 9:
                    sx = "1000000000000" + t;
                    break;
                case 10 :
                case 10:
                    sx = "100000000000" + t;
                    break;
                case 11 :
                case 11:
                    sx = "10000000000" + t;
                    break;
                case 12 :
                case 12:
                    sx = "1000000000" + t;
                    break;
                case 13 :
                case 13:
                    sx = "100000000" + t;
                    break;
                case 14 :
                case 14:
                    sx = "10000000" + t;
                    break;
                case 15 :
                case 15:
                    sx = "1000000" + t;
                    break;
                case 16 :
                case 16:
                    sx = "100000" + t;
                    break;
                case 17 :
                case 17:
                    sx = "10000" + t;
                    break;
                case 18 :
                case 18:
                    sx = "1000" + t;
                    break;
                case 19 :
                case 19:
                    sx = "100" + t;
                    break;
                case 20 :
                case 20:
                    sx = "10" + t;
                    break;
                case 21 :
                case 21:
                    sx = "1" + t;
                    break;
@@ -4095,21 +4146,22 @@
        /**
         * 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.
         */
@@ -4126,57 +4178,57 @@
                switch (t.length())
                {
                case 1 :
                case 1:
                    sx = "2000000000" + t;
                    break;
                case 2 :
                case 2:
                    sx = "200000000" + t;
                    break;
                case 3 :
                case 3:
                    sx = "20000000" + t;
                    break;
                case 4 :
                case 4:
                    sx = "2000000" + t;
                    break;
                case 5 :
                case 5:
                    sx = "200000" + t;
                    break;
                case 6 :
                case 6:
                    sx = "20000" + t;
                    break;
                case 7 :
                case 7:
                    sx = "2000" + t;
                    break;
                case 8 :
                case 8:
                    sx = "200" + t;
                    break;
                case 9 :
                case 9:
                    sx = "20" + t;
                    break;
                case 10 :
                case 10:
                    sx = "2" + t;
                    break;
                case 11 :
                case 11:
                    sx = "3" + t.substring(1);
                    break;
@@ -4192,15 +4244,16 @@
        /**
         * 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.
         *           converting a short, int, or long to a
         *           String.
         * @return the formatted String.
         */
        private String printOFormat(String sx)
        {
            int nLeadingZeros = 0;
            int nBlanks       = 0;
            int nBlanks = 0;
            if (sx.equals("0") && precisionSet && (precision == 0))
            {
@@ -4232,9 +4285,9 @@
                nBlanks = 0;
            }
            int    n  = nLeadingZeros + sx.length() + nBlanks;
            int n = nLeadingZeros + sx.length() + nBlanks;
            char[] ca = new char[n];
            int    i;
            int i;
            if (leftJustify)
            {
@@ -4289,24 +4342,25 @@
        /**
         * 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.
         */
        private String printCFormat(char x)
        {
            int nPrint = 1;
            int width  = fieldWidth;
            int width = fieldWidth;
            if (!fieldWidthSet)
            {
@@ -4314,7 +4368,7 @@
            }
            char[] ca = new char[width];
            int    i  = 0;
            int i = 0;
            if (leftJustify)
            {
@@ -4340,30 +4394,31 @@
        /**
         * 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.
         */
        private String printSFormat(String x)
        {
            int nPrint = x.length();
            int width  = fieldWidth;
            int width = fieldWidth;
            if (precisionSet && (nPrint > precision))
            {
@@ -4391,7 +4446,7 @@
            }
            char[] ca = new char[n];
            int    i  = 0;
            int i = 0;
            if (leftJustify)
            {
@@ -4449,9 +4504,10 @@
        /**
         * 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.
         *         character is there, and
         *         <code>false</code> otherwise.
         */
        private boolean setConversionCharacter()
        {
@@ -4465,7 +4521,7 @@
                char c = fmt.charAt(pos);
                if ((c == 'i') || (c == 'd') || (c == 'f') || (c == 'g') || (c == 'G') || (c == 'o') || (c == 'x') || (c == 'X')
                    || (c == 'e') || (c == 'E') || (c == 'c') || (c == 's') || (c == '%'))
                        || (c == 'e') || (c == 'E') || (c == 'c') || (c == 's') || (c == '%'))
                {
                    conversionCharacter = c;
                    pos++;
@@ -4531,7 +4587,7 @@
                    if (!setPrecisionArgPosition())
                    {
                        variablePrecision = true;
                        precisionSet      = true;
                        precisionSet = true;
                    }
                    return;
@@ -4554,7 +4610,7 @@
                    {
                        String sz = fmt.substring(firstPos + 1, pos);
                        precision    = Integer.parseInt(sz);
                        precision = Integer.parseInt(sz);
                        precisionSet = true;
                    }
                }
@@ -4568,7 +4624,7 @@
        {
            int firstPos = pos;
            fieldWidth    = 0;
            fieldWidth = 0;
            fieldWidthSet = false;
            if ((pos < fmt.length()) && (fmt.charAt(pos) == '*'))
@@ -4578,7 +4634,7 @@
                if (!setFieldWidthArgPosition())
                {
                    variableFieldWidth = true;
                    fieldWidthSet      = true;
                    fieldWidthSet = true;
                }
            } else
            {
@@ -4599,7 +4655,7 @@
                {
                    String sz = fmt.substring(firstPos, pos);
                    fieldWidth    = Integer.parseInt(sz);
                    fieldWidth = Integer.parseInt(sz);
                    fieldWidthSet = true;
                }
            }
@@ -4625,8 +4681,8 @@
                if (fmt.charAt(xPos) == '$')
                {
                    positionalSpecification = true;
                    argumentPosition        = Integer.parseInt(fmt.substring(pos, xPos));
                    pos                     = xPos + 1;
                    argumentPosition = Integer.parseInt(fmt.substring(pos, xPos));
                    pos = xPos + 1;
                }
            }
        }
@@ -4637,7 +4693,7 @@
        private boolean setFieldWidthArgPosition()
        {
            boolean ret = false;
            int     xPos;
            int xPos;
            for (xPos = pos; xPos < fmt.length(); xPos++)
            {
@@ -4651,10 +4707,10 @@
            {
                if (fmt.charAt(xPos) == '$')
                {
                    positionalFieldWidth          = true;
                    positionalFieldWidth = true;
                    argumentPositionForFieldWidth = Integer.parseInt(fmt.substring(pos, xPos));
                    pos                           = xPos + 1;
                    ret                           = true;
                    pos = xPos + 1;
                    ret = true;
                }
            }
@@ -4667,7 +4723,7 @@
        private boolean setPrecisionArgPosition()
        {
            boolean ret = false;
            int     xPos;
            int xPos;
            for (xPos = pos; xPos < fmt.length(); xPos++)
            {
@@ -4681,10 +4737,10 @@
            {
                if (fmt.charAt(xPos) == '$')
                {
                    positionalPrecision          = true;
                    positionalPrecision = true;
                    argumentPositionForPrecision = Integer.parseInt(fmt.substring(pos, xPos));
                    pos                          = xPos + 1;
                    ret                          = true;
                    pos = xPos + 1;
                    ret = true;
                }
            }
@@ -4727,12 +4783,12 @@
        private void setFlagCharacters()
        {
            /* '-+ #0 */
            thousands     = false;
            leftJustify   = false;
            leadingSign   = false;
            leadingSpace  = false;
            thousands = false;
            leftJustify = false;
            leadingSign = false;
            leadingSpace = false;
            alternateForm = false;
            leadingZeros  = false;
            leadingZeros = false;
            for (; pos < fmt.length(); pos++)
            {
@@ -4743,11 +4799,11 @@
                    thousands = true;
                } else if (c == '-')
                {
                    leftJustify  = true;
                    leftJustify = true;
                    leadingZeros = false;
                } else if (c == '+')
                {
                    leadingSign  = true;
                    leadingSign = true;
                    leadingSpace = false;
                } else if (c == ' ')
                {
xdgnjobs/ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7OracleReaderTest.java
@@ -8,8 +8,10 @@
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
@@ -61,8 +63,8 @@
                System.out.print("complexChain:");
                if (frammeLinkage != null)
                    System.out.print(":FSC-" + frammeLinkage.getFsc() +
                                       ":UFID-" + frammeLinkage.getUfid() +
                                       ":COMP-" + frammeLinkage.getComponentID());
                            ":UFID-" + frammeLinkage.getUfid() +
                            ":COMP-" + frammeLinkage.getComponentID());
                else
                    System.out.print("Linkage is null");
@@ -102,8 +104,8 @@
                System.out.print("TextNode:origin=" + coord.toString());
                if (frammeLinkage != null)
                    System.out.print(":FSC-" + frammeLinkage.getFsc() +
                                       ":UFID-" + frammeLinkage.getUfid() +
                                       ":COMP-" + frammeLinkage.getComponentID());
                            ":UFID-" + frammeLinkage.getUfid() +
                            ":COMP-" + frammeLinkage.getComponentID());
                else
                    System.out.print("Linkage is null");
                for (int i = 0; i < textNode.size(); i++)
xdgnjobs/ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7TextElementReaderTest.java
@@ -9,9 +9,9 @@
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
xdgnjobs/ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7fileReaderTest.java
@@ -2,14 +2,13 @@
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
xdgnjobs/ximple-dgnio/src/test/java/com/ximple/io/dgn7/OracleTarget.java
@@ -9,6 +9,7 @@
import org.apache.log4j.Logger;
import com.vividsolutions.jts.util.Assert;
import oracle.jdbc.OracleConnection;
/**
@@ -20,14 +21,14 @@
 */
public class OracleTarget
{
    private static final Logger logger          = Logger.getLogger(OracleTarget.class);
    private static OracleTarget _instance       = null;
    private static final String ORACLE_URL      = "jdbc:oracle:thin:@";
    private static final String _propUsrKey     = "user";
    private static final String _propPassKey    = "password";
    private static String       _oracleHost     = "192.168.11.200";
    private static String       _oracleInstance = "NNTPC";
    private static String       _oraclePort     = "1521";
    private static final Logger logger = Logger.getLogger(OracleTarget.class);
    private static OracleTarget _instance = null;
    private static final String ORACLE_URL = "jdbc:oracle:thin:@";
    private static final String _propUsrKey = "user";
    private static final String _propPassKey = "password";
    private static String _oracleHost = "192.168.11.200";
    private static String _oracleInstance = "NNTPC";
    private static String _oraclePort = "1521";
    static
    {
@@ -41,7 +42,7 @@
    }
    private OracleConnection oracleConnection = null;
    private Properties       properties;
    private Properties properties;
    private OracleTarget()
    {
xdgnjobs/ximple-jobcarrier/pom.xml
@@ -94,6 +94,10 @@
      <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>
@@ -149,6 +153,11 @@
      <artifactId>postgis-driver</artifactId>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <!-- Ximple Library -->
    <dependency>
      <artifactId>ximple-dgnio</artifactId>
xdgnjobs/ximple-spatialjob/pom.xml
@@ -81,6 +81,10 @@
      <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>
@@ -132,6 +136,11 @@
      <artifactId>postgis-driver</artifactId>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <!-- Ximple Library -->
    <dependency>
      <groupId>com.ximple.eofms</groupId>
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/TypeCompIdDispatchableFilter.java
@@ -100,7 +100,7 @@
    public String getFeatureTypeName(Element element)
    {
        StringBuilder sb= new StringBuilder();
        StringBuilder sb = new StringBuilder();
        sb.append(getName());
        if (useLongName)
        {
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/TypeCompLevelIdDispatchableFilter.java
@@ -109,7 +109,7 @@
    public String getFeatureTypeName(Element element)
    {
        StringBuilder sb= new StringBuilder();
        StringBuilder sb = new StringBuilder();
        sb.append(getName());
        if (useLongName)
        {
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/TypeIdDispatchableFilter.java
@@ -82,7 +82,7 @@
    public String getFeatureTypeName(Element element)
    {
        StringBuilder sb= new StringBuilder();
        StringBuilder sb = new StringBuilder();
        sb.append(getName());
        if (useLongName)
        {
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/AbstractOracleDatabaseJob.java
@@ -10,12 +10,8 @@
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;
@@ -25,13 +21,19 @@
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:@";
    private static final String PROPUsrKey = "user";
    private static final String PROPPassKey = "password";
@@ -74,9 +76,11 @@
    protected AbstractOracleDatabaseJob()
    {
        try {
        try
        {
            Class.forName(JDBC_DRIVER);
        } catch (Throwable t) {
        } catch (Throwable t)
        {
            // must be running off dummy jar!
            driverFound = false;
        }
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2MySQLJob.java
New file
@@ -0,0 +1,1089 @@
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);
        }
    }
}
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2OraSDOJob.java
@@ -13,15 +13,22 @@
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;
@@ -34,10 +41,10 @@
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;
@@ -55,10 +62,13 @@
{
    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;
@@ -76,72 +86,94 @@
        }
    }
    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
@@ -156,15 +188,25 @@
        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())
            {
@@ -172,9 +214,10 @@
                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);
@@ -212,6 +255,11 @@
            }
            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);
@@ -230,15 +278,15 @@
     * @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;
@@ -253,7 +301,7 @@
        //jobContext.startTransaction();
        jobContext.setCurrentSchema(querySchema);
        jobContext.getExecutionContext().put("ConvertDgn2ShpJobProgress", 0);
        jobContext.getExecutionContext().put("ConvertDgn2OraSDOJobProgress", 0);
        for (OrderedMapIterator it = map.orderedMapIterator(); it.hasNext();)
        {
            it.next();
@@ -285,11 +333,11 @@
            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();
@@ -387,7 +435,7 @@
        return orderedMap;
    }
    protected void queryIgsetElement(OracleConvertShapefilesJobContext jobContext,
    protected void queryIgsetElement(OracleConvertOraSDOJobContext jobContext,
                                     String srcschema, String srctable) throws SQLException
    {
        OracleConnection connection = jobContext.getOracleConnection();
@@ -429,7 +477,7 @@
        stmtSrc.close();
    }
    protected void queryRawElement(OracleConvertShapefilesJobContext jobContext,
    protected void queryRawElement(OracleConvertOraSDOJobContext jobContext,
                                   String srcschema, String srctable) throws SQLException
    {
        OracleConnection connection = jobContext.getOracleConnection();
@@ -568,7 +616,8 @@
        for (File dgnFile : dgnFiles)
        {
            IndexDgnConvertShpJobContext convertContext = new IndexDgnConvertShpJobContext(getDataPath());
            IndexDgnConvertOraSDOJobContext convertContext =
                    new IndexDgnConvertOraSDOJobContext(getDataPath(), getTargetDataStore());
            logger.debug("--- start dgnfile-" + dgnFile.toString() + " ---");
            try
            {
@@ -615,7 +664,7 @@
        }
    }
    protected void scanIndexDgnElement(IndexDgnConvertShpJobContext convertContext)
    protected void scanIndexDgnElement(IndexDgnConvertOraSDOJobContext convertContext)
            throws Dgn7fileException, IOException, IllegalAttributeException, SchemaException
    {
        Dgn7fileReader reader = convertContext.getReader();
@@ -658,7 +707,8 @@
        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)
        {
@@ -698,7 +748,8 @@
        for (File dgnFile : dgnFiles)
        {
            GeneralDgnConvertShpJobContext convertContext = new GeneralDgnConvertShpJobContext(getDataPath());
            GeneralDgnConvertOraSDOJobContext convertContext =
                    new GeneralDgnConvertOraSDOJobContext(getDataPath(), getTargetDataStore());
            logger.info("--- start dgnfile-" + dgnFile.toString() + " ---");
            try
            {
@@ -745,7 +796,7 @@
        }
    }
    public void scanOtherDgnElement(GeneralDgnConvertShpJobContext convertContext)
    public void scanOtherDgnElement(GeneralDgnConvertOraSDOJobContext convertContext)
            throws Dgn7fileException, IOException, IllegalAttributeException, SchemaException
    {
        Dgn7fileReader reader = convertContext.getReader();
@@ -788,15 +839,16 @@
        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);
@@ -811,6 +863,7 @@
        {
            deleteFilesInPath(outDataPath);
        }
        */
    }
    private void deleteFilesInPath(File outDataPath)
@@ -871,7 +924,8 @@
        for (File dgnFile : dgnFiles)
        {
            FeatureDgnConvertShpJobContext convertContext = new FeatureDgnConvertShpJobContext(getDataPath(), _filterPath);
            FeatureDgnConvertOraSDOJobContext convertContext =
                    new FeatureDgnConvertOraSDOJobContext(getDataPath(), getTargetDataStore(), _filterPath);
            logger.info("--- start dgnfile-" + dgnFile.toString() + " ---");
            try
            {
@@ -918,7 +972,7 @@
        }
    }
    public void scanFeatureDgnElement(FeatureDgnConvertShpJobContext convertContext)
    public void scanFeatureDgnElement(FeatureDgnConvertOraSDOJobContext convertContext)
            throws Dgn7fileException, IOException, IllegalAttributeException, SchemaException
    {
        Dgn7fileReader reader = convertContext.getReader();
@@ -961,7 +1015,7 @@
        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);
@@ -982,4 +1036,56 @@
        }
        */
    }
    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);
        }
    }
}
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2PostGISJob.java
@@ -18,7 +18,28 @@
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;
@@ -36,27 +57,6 @@
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
{
@@ -154,13 +154,13 @@
        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)
@@ -247,7 +247,7 @@
                    OracleConvertPostGISJobContext jobContext =
                            (OracleConvertPostGISJobContext) prepareJobContext(_filterPath);
                    jobContext.setSourceDataStore(getSourceDataStore());
                    jobContext.setConvertElementIn(_convertElementIn);
                    // jobContext.setConvertElementIn(_convertElementIn);
                    jobContext.setElementLogging(checkElementLogging());
                    jobContext.setExecutionContext(context);
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java
@@ -22,10 +22,6 @@
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;
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/AbstractDgnFileJobContext.java
@@ -2,8 +2,8 @@
import java.util.Map;
import org.quartz.JobExecutionContext;
import org.apache.commons.logging.Log;
import org.quartz.JobExecutionContext;
import com.ximple.io.dgn7.Dgn7fileReader;
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/AbstractOracleJobContext.java
@@ -1,18 +1,14 @@
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
{
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/AbstractDgnToMySQLJobContext.java
New file
@@ -0,0 +1,47 @@
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;
    }
}
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/AbstractOracleToMySQLJobContext.java
New file
@@ -0,0 +1,52 @@
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;
    }
}
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/DummyFeatureConvertMySQlJobContext.java
New file
@@ -0,0 +1,304 @@
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;
    }
}
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/FeatureDgnConvertMySQLJobContext.java
New file
@@ -0,0 +1,268 @@
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;
    }
}
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/GeneralDgnConvertMySQLJobContext.java
New file
@@ -0,0 +1,521 @@
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;
    }
}
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/IndexDgnConvertMySQLJobContext.java
New file
@@ -0,0 +1,320 @@
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;
    }
}
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/OracleConvertMySQLJobContext.java
New file
@@ -0,0 +1,319 @@
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;
    }
}
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/AbstractDgnToOraSDOJobContext.java
@@ -1,14 +1,46 @@
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;
    }
}
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/AbstractOracleToOraSDOJobContext.java
@@ -1,12 +1,52 @@
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;
    }
}
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/DummyFeatureConvertOraSDOJobContext.java
New file
@@ -0,0 +1,303 @@
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;
    }
}
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/FeatureDgnConvertOraSDOJobContext.java
New file
@@ -0,0 +1,267 @@
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;
    }
}
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/GeneralDgnConvertOraSDOJobContext.java
New file
@@ -0,0 +1,522 @@
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;
    }
}
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/IndexDgnConvertOraSDOJobContext.java
New file
@@ -0,0 +1,320 @@
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;
    }
}
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/orasdo/OracleConvertOraSDOJobContext.java
@@ -1,27 +1,315 @@
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()
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/AbstractDgnToPostGISJobContext.java
@@ -1,14 +1,13 @@
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
{
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/AbstractOracleToPostGISJobContext.java
@@ -1,13 +1,13 @@
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
{
@@ -18,7 +18,8 @@
        if ((targetDataStore != null) && (targetDataStore instanceof PostgisDataStore))
        {
            this.targetDataStore = (PostgisDataStore) targetDataStore;
        } else {
        } else
        {
            getLogger().info("targetDataStore has wrong.");
        }
        setDataPath(dataPath);
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/DummyFeatureConvertPostGISJobContext.java
@@ -5,12 +5,10 @@
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;
@@ -19,12 +17,9 @@
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;
@@ -203,8 +198,7 @@
            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()))
@@ -212,28 +206,13 @@
                    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);
                }
@@ -246,7 +225,7 @@
                    ((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)
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/FeatureDgnConvertPostGISJobContext.java
@@ -5,12 +5,10 @@
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;
@@ -19,11 +17,9 @@
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;
@@ -35,7 +31,6 @@
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;
@@ -43,10 +38,9 @@
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;
@@ -185,8 +179,7 @@
            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()))
@@ -194,27 +187,14 @@
                    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);
@@ -228,7 +208,7 @@
                    ((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)
@@ -241,23 +221,6 @@
        {
            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
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/GeneralDgnConvertPostGISJobContext.java
@@ -1,16 +1,13 @@
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;
@@ -18,11 +15,9 @@
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;
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/IndexDgnConvertPostGISJobContext.java
@@ -1,29 +1,22 @@
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;
@@ -37,10 +30,10 @@
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;
@@ -148,8 +141,7 @@
            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()))
@@ -157,17 +149,14 @@
                    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);
                    }
                    writer = targetDataStore.getFeatureWriter(featureType.getTypeName(), Transaction.AUTO_COMMIT);
                    featuresWriterContext.put(featureType.getTypeName(), writer);
                }
@@ -177,7 +166,7 @@
                    ((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)
@@ -190,23 +179,6 @@
        {
            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
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/OracleConvertPostGISJobContext.java
@@ -10,7 +10,6 @@
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;
@@ -23,7 +22,6 @@
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;
@@ -70,11 +68,9 @@
    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)
    {
@@ -239,7 +235,7 @@
                    ((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)
@@ -257,7 +253,15 @@
    private boolean isExistFeature(FeatureType featureType)
    {
        return false;
        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()
@@ -305,11 +309,6 @@
    {
        this.currentSchema = querySchema;
        this.schemaChanged = true;
    }
    public void setConvertElementIn(String convertElementIn)
    {
        _convertElementIn = convertElementIn;
    }
    protected Log getLogger()
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/shapefile/DummyFeatureConvertShpJobContext.java
@@ -37,7 +37,6 @@
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;
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/shapefile/FeatureDgnConvertShpJobContext.java
@@ -33,7 +33,6 @@
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;
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/shapefile/GeneralDgnConvertShpJobContext.java
@@ -31,7 +31,6 @@
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;
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/shapefile/IndexDgnConvertShpJobContext.java
@@ -20,7 +20,6 @@
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;
@@ -33,12 +32,11 @@
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;
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/shapefile/OracleConvertShapefilesJobContext.java
@@ -22,7 +22,6 @@
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;
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/ColorTableMapping.java
@@ -6,7 +6,10 @@
public interface ColorTableMapping
{
    boolean contain(Color color);
    List findId(Color color);
    Color getColor(int value);
    String getColorCode(int i);
}
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/DefaultColorTable.java
@@ -6,7 +6,7 @@
public class DefaultColorTable implements ColorTableMapping
{
    private static DefaultColorTable _instance  = null;
    private static DefaultColorTable _instance = null;
    public static ColorTableMapping getInstance()
    {
@@ -19,6 +19,7 @@
    }
    private ArrayList<Color> colortable = null;
    private DefaultColorTable()
    {
        initializeColorTable();
@@ -328,36 +329,40 @@
        return false;
    }
    private static String colorToString(Color c) {
        char[] buf = new char[7];
        buf[0] = '#';
        String s = Integer.toHexString(c.getRed());
        if (s.length() == 1) {
            buf[1] = '0';
            buf[2] = s.charAt(0);
        }
        else {
            buf[1] = s.charAt(0);
            buf[2] = s.charAt(1);
        }
        s = Integer.toHexString(c.getGreen());
        if (s.length() == 1) {
            buf[3] = '0';
            buf[4] = s.charAt(0);
        }
        else {
            buf[3] = s.charAt(0);
            buf[4] = s.charAt(1);
        }
        s = Integer.toHexString(c.getBlue());
        if (s.length() == 1) {
            buf[5] = '0';
            buf[6] = s.charAt(0);
        }
        else {
            buf[5] = s.charAt(0);
            buf[6] = s.charAt(1);
        }
        return String.valueOf(buf);
    }
    private static String colorToString(Color c)
    {
        char[] buf = new char[7];
        buf[0] = '#';
        String s = Integer.toHexString(c.getRed());
        if (s.length() == 1)
        {
            buf[1] = '0';
            buf[2] = s.charAt(0);
        } else
        {
            buf[1] = s.charAt(0);
            buf[2] = s.charAt(1);
        }
        s = Integer.toHexString(c.getGreen());
        if (s.length() == 1)
        {
            buf[3] = '0';
            buf[4] = s.charAt(0);
        } else
        {
            buf[3] = s.charAt(0);
            buf[4] = s.charAt(1);
        }
        s = Integer.toHexString(c.getBlue());
        if (s.length() == 1)
        {
            buf[5] = '0';
            buf[6] = s.charAt(0);
        } else
        {
            buf[5] = s.charAt(0);
            buf[6] = s.charAt(1);
        }
        return String.valueOf(buf);
    }
}
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/FeatureTypeBuilderUtil.java
@@ -1,7 +1,7 @@
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;
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/GeomUtil.java
@@ -25,6 +25,6 @@
    public static Envelope convertLogicalEnvelope(Envelope value)
    {
        return new Envelope(convertLogicalValue(value.getMinX()), convertLogicalValue(value.getMaxX()),
                            convertLogicalValue(value.getMinY()), convertLogicalValue(value.getMaxY()));
                convertLogicalValue(value.getMinY()), convertLogicalValue(value.getMaxY()));
    }
}
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/PrintfFormat.java
@@ -90,7 +90,7 @@
 * 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
@@ -98,40 +98,40 @@
 * the action.
 * <table>
 * <tr><th align=left>Sequence</th>
 *    <th align=left>Name</th>
 *    <th align=left>Description</th></tr>
 * <th align=left>Name</th>
 * <th align=left>Description</th></tr>
 * <tr><td>\\</td><td>backlash</td><td>None.
 * </td></tr>
 * <tr><td>\a</td><td>alert</td><td>Attempts to alert
 *          the user through audible or visible
 *          notification.
 * the user through audible or visible
 * notification.
 * </td></tr>
 * <tr><td>\b</td><td>backspace</td><td>Moves the
 *          printing position to one column before
 *          the current position, unless the
 *          current position is the start of a line.
 * printing position to one column before
 * the current position, unless the
 * current position is the start of a line.
 * </td></tr>
 * <tr><td>\f</td><td>form-feed</td><td>Moves the
 *          printing position to the initial
 *          printing position of the next logical
 *          page.
 * printing position to the initial
 * printing position of the next logical
 * page.
 * </td></tr>
 * <tr><td>\n</td><td>newline</td><td>Moves the
 *          printing position to the start of the
 *          next line.
 * printing position to the start of the
 * next line.
 * </td></tr>
 * <tr><td>\r</td><td>carriage-return</td><td>Moves
 *          the printing position to the start of
 *          the current line.
 * the printing position to the start of
 * the current line.
 * </td></tr>
 * <tr><td>\t</td><td>tab</td><td>Moves the printing
 *          position to the next implementation-
 *          defined horizontal tab position.
 * position to the next implementation-
 * defined horizontal tab position.
 * </td></tr>
 * <tr><td>\v</td><td>vertical-tab</td><td>Moves the
 *          printing position to the start of the
 *          next implementation-defined vertical
 *          tab position.
 * printing position to the start of the
 * next implementation-defined vertical
 * tab position.
 * </td></tr>
 * </table></p>
 * <h4>Conversion Specifications</h4>
@@ -206,55 +206,55 @@
 * 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>
 * <dl>
 * <dt>'<dd> integer portion of the result of a
 *      decimal conversion (%i, %d, %f, %g, or %G) will
 *      be formatted with thousands' grouping
 *      characters.  For other conversions the flag
 *      is ignored.  The non-monetary grouping
 *      character is used.
 * decimal conversion (%i, %d, %f, %g, or %G) will
 * be formatted with thousands' grouping
 * characters.  For other conversions the flag
 * is ignored.  The non-monetary grouping
 * character is used.
 * <dt>-<dd> result of the conversion is left-justified
 *      within the field.  (It will be right-justified
 *      if this flag is not specified).</td></tr>
 * within the field.  (It will be right-justified
 * if this flag is not specified).</td></tr>
 * <dt>+<dd> result of a signed conversion always
 *      begins with a sign (+ or -).  (It will begin
 *      with a sign only when a negative value is
 *      converted if this flag is not specified.)
 * begins with a sign (+ or -).  (It will begin
 * with a sign only when a negative value is
 * converted if this flag is not specified.)
 * <dt>&lt;space&gt;<dd> If the first character of a
 *      signed conversion is not a sign, a space
 *      character will be placed before the result.
 *      This means that if the space character and +
 *      flags both appear, the space flag will be
 *      ignored.
 * signed conversion is not a sign, a space
 * character will be placed before the result.
 * This means that if the space character and +
 * flags both appear, the space flag will be
 * ignored.
 * <dt>#<dd> value is to be converted to an alternative
 *      form.  For c, d, i, and s conversions, the flag
 *      has no effect.  For o conversion, it increases
 *      the precision to force the first digit of the
 *      result to be a zero.  For x or X conversion, a
 *      non-zero result has 0x or 0X prefixed to it,
 *      respectively.  For e, E, f, g, and G
 *      conversions, the result always contains a radix
 *      character, even if no digits follow the radix
 *      character (normally, a decimal point appears in
 *      the result of these conversions only if a digit
 *      follows it).  For g and G conversions, trailing
 *      zeros will not be removed from the result as
 *      they normally are.
 * form.  For c, d, i, and s conversions, the flag
 * has no effect.  For o conversion, it increases
 * the precision to force the first digit of the
 * result to be a zero.  For x or X conversion, a
 * non-zero result has 0x or 0X prefixed to it,
 * respectively.  For e, E, f, g, and G
 * conversions, the result always contains a radix
 * character, even if no digits follow the radix
 * character (normally, a decimal point appears in
 * the result of these conversions only if a digit
 * follows it).  For g and G conversions, trailing
 * zeros will not be removed from the result as
 * they normally are.
 * <dt>0<dd> d, i, o, x, X, e, E, f, g, and G
 *      conversions, leading zeros (following any
 *      indication of sign or base) are used to pad to
 *      the field width;  no space padding is
 *      performed.  If the 0 and - flags both appear,
 *      the 0 flag is ignored.  For d, i, o, x, and X
 *      conversions, if a precision is specified, the
 *      0 flag will be ignored. For c conversions,
 *      the flag is ignored.
 * conversions, leading zeros (following any
 * indication of sign or base) are used to pad to
 * the field width;  no space padding is
 * performed.  If the 0 and - flags both appear,
 * the 0 flag is ignored.  For d, i, o, x, and X
 * conversions, if a precision is specified, the
 * 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
@@ -263,103 +263,103 @@
 * 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>
 * <dl>
 * <dt>d,i<dd>The int argument is converted to a
 *        signed decimal in the style [-]dddd.  The
 *        precision specifies the minimum number of
 *        digits to appear;  if the value being
 *        converted can be represented in fewer
 *        digits, it will be expanded with leading
 *        zeros.  The default precision is 1.  The
 *        result of converting 0 with an explicit
 *        precision of 0 is no characters.
 * signed decimal in the style [-]dddd.  The
 * precision specifies the minimum number of
 * digits to appear;  if the value being
 * converted can be represented in fewer
 * digits, it will be expanded with leading
 * zeros.  The default precision is 1.  The
 * result of converting 0 with an explicit
 * precision of 0 is no characters.
 * <dt>o<dd> The int argument is converted to unsigned
 *        octal format in the style ddddd.  The
 *        precision specifies the minimum number of
 *        digits to appear;  if the value being
 *        converted can be represented in fewer
 *        digits, it will be expanded with leading
 *        zeros.  The default precision is 1.  The
 *        result of converting 0 with an explicit
 *        precision of 0 is no characters.
 * octal format in the style ddddd.  The
 * precision specifies the minimum number of
 * digits to appear;  if the value being
 * converted can be represented in fewer
 * digits, it will be expanded with leading
 * zeros.  The default precision is 1.  The
 * result of converting 0 with an explicit
 * precision of 0 is no characters.
 * <dt>x<dd> The int argument is converted to unsigned
 *        hexadecimal format in the style dddd;  the
 *        letters abcdef are used.  The precision
 *        specifies the minimum numberof digits to
 *        appear; if the value being converted can be
 *        represented in fewer digits, it will be
 *        expanded with leading zeros.  The default
 *        precision is 1.  The result of converting 0
 *        with an explicit precision of 0 is no
 *        characters.
 * hexadecimal format in the style dddd;  the
 * letters abcdef are used.  The precision
 * specifies the minimum numberof digits to
 * appear; if the value being converted can be
 * represented in fewer digits, it will be
 * expanded with leading zeros.  The default
 * precision is 1.  The result of converting 0
 * with an explicit precision of 0 is no
 * characters.
 * <dt>X<dd> Behaves the same as the x conversion
 *        character except that letters ABCDEF are
 *        used instead of abcdef.
 * character except that letters ABCDEF are
 * used instead of abcdef.
 * <dt>f<dd> The floating point number argument is
 *        written in decimal notation in the style
 *        [-]ddd.ddd, where the number of digits after
 *        the radix character (shown here as a decimal
 *        point) is equal to the precision
 *        specification.  A Locale is used to determine
 *        the radix character to use in this format.
 *        If the precision is omitted from the
 *        argument, six digits are written after the
 *        radix character;  if the precision is
 *        explicitly 0 and the # flag is not specified,
 *        no radix character appears.  If a radix
 *        character appears, at least 1 digit appears
 *        before it.  The value is rounded to the
 *        appropriate number of digits.
 * written in decimal notation in the style
 * [-]ddd.ddd, where the number of digits after
 * the radix character (shown here as a decimal
 * point) is equal to the precision
 * specification.  A Locale is used to determine
 * the radix character to use in this format.
 * If the precision is omitted from the
 * argument, six digits are written after the
 * radix character;  if the precision is
 * explicitly 0 and the # flag is not specified,
 * no radix character appears.  If a radix
 * character appears, at least 1 digit appears
 * before it.  The value is rounded to the
 * appropriate number of digits.
 * <dt>e,E<dd>The floating point number argument is
 *        written in the style [-]d.ddde{+-}dd
 *        (the symbols {+-} indicate either a plus or
 *        minus sign), where there is one digit before
 *        the radix character (shown here as a decimal
 *        point) and the number of digits after it is
 *        equal to the precision.  A Locale is used to
 *        determine the radix character to use in this
 *        format.  When the precision is missing, six
 *        digits are written after the radix character;
 *        if the precision is 0 and the # flag is not
 *        specified, no radix character appears.  The
 *        E conversion will produce a number with E
 *        instead of e introducing the exponent.  The
 *        exponent always contains at least two digits.
 *        However, if the value to be written requires
 *        an exponent greater than two digits,
 *        additional exponent digits are written as
 *        necessary.  The value is rounded to the
 *        appropriate number of digits.
 * written in the style [-]d.ddde{+-}dd
 * (the symbols {+-} indicate either a plus or
 * minus sign), where there is one digit before
 * the radix character (shown here as a decimal
 * point) and the number of digits after it is
 * equal to the precision.  A Locale is used to
 * determine the radix character to use in this
 * format.  When the precision is missing, six
 * digits are written after the radix character;
 * if the precision is 0 and the # flag is not
 * specified, no radix character appears.  The
 * E conversion will produce a number with E
 * instead of e introducing the exponent.  The
 * exponent always contains at least two digits.
 * However, if the value to be written requires
 * an exponent greater than two digits,
 * additional exponent digits are written as
 * necessary.  The value is rounded to the
 * appropriate number of digits.
 * <dt>g,G<dd>The floating point number argument is
 *        written in style f or e (or in sytle E in the
 *        case of a G conversion character), with the
 *        precision specifying the number of
 *        significant digits.  If the precision is
 *        zero, it is taken as one.  The style used
 *        depends on the value converted:  style e
 *        (or E) will be used only if the exponent
 *        resulting from the conversion is less than
 *        -4 or greater than or equal to the precision.
 *        Trailing zeros are removed from the result.
 *        A radix character appears only if it is
 *        followed by a digit.
 * written in style f or e (or in sytle E in the
 * case of a G conversion character), with the
 * precision specifying the number of
 * significant digits.  If the precision is
 * zero, it is taken as one.  The style used
 * depends on the value converted:  style e
 * (or E) will be used only if the exponent
 * resulting from the conversion is less than
 * -4 or greater than or equal to the precision.
 * Trailing zeros are removed from the result.
 * A radix character appears only if it is
 * followed by a digit.
 * <dt>c,C<dd>The integer argument is converted to a
 *        char and the result is written.
 *
 * 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
 *        indicated by the precision specification of
 *        the argument is reached.  If the precision
 *        is omitted from the argument, it is taken to
 *        be infinite, so all characters up to the end
 *        of the string are written.
 * bytes from the string are written until the
 * end of the string or the number of bytes
 * indicated by the precision specification of
 * the argument is reached.  If the precision
 * is omitted from the argument, it is taken to
 * be infinite, so all characters up to the end
 * of the string are written.
 * <dt>%<dd>Write a % character;  no argument is
 *        converted.
 * converted.
 * </dl>
 * <p>
 * If a conversion specification does not match one of
@@ -431,25 +431,31 @@
 *
 * @author Allan Jacobs
 * @version 1
 * Release 1: Initial release.
 * Release 2: Asterisk field widths and precisions
 *            %n$ and *m$
 *            Bug fixes
 *              g format fix (2 digits in e form corrupt)
 *              rounding in f format implemented
 *              round up when digit not printed is 5
 *              formatting of -0.0f
 *              round up/down when last digits are 50000...
 *          Release 1: Initial release.
 *          Release 2: Asterisk field widths and precisions
 *          %n$ and *m$
 *          Bug fixes
 *          g format fix (2 digits in e form corrupt)
 *          rounding in f format implemented
 *          round up when digit not printed is 5
 *          formatting of -0.0f
 *          round up/down when last digits are 50000...
 */
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;
    /**
@@ -459,10 +465,11 @@
     * 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
     * string is null, zero length, or otherwise
     * malformed.
     *
     * @param fmtArg Control string.
     * @throws IllegalArgumentException if the control
     *                                  string is null, zero length, or otherwise
     *                                  malformed.
     */
    public PrintfFormat(String fmtArg) throws IllegalArgumentException
    {
@@ -476,18 +483,19 @@
     * 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
     * string is null, zero length, or otherwise
     * malformed.
     *
     * @param fmtArg Control string.
     * @throws IllegalArgumentException if the control
     *                                  string is null, zero length, or otherwise
     *                                  malformed.
     */
    public PrintfFormat(Locale locale, String fmtArg) throws IllegalArgumentException
    {
        dfs = new DecimalFormatSymbols(locale);
        int                     ePos = 0;
        int ePos = 0;
        ConversionSpecification sFmt = null;
        String                  unCS = this.nonControl(fmtArg, 0);
        String unCS = this.nonControl(fmtArg, 0);
        if (unCS != null)
        {
@@ -590,12 +598,13 @@
     * 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 s     Control string.
     * @param start Position in the string
     *     <code>s</code> to begin looking for the start
     *     of a control string.
     *              <code>s</code> to begin looking for the start
     *              of a control string.
     * @return the substring from the start position
     *     to the beginning of the control string.
     *         to the beginning of the control string.
     */
    private String nonControl(String s, int start)
    {
@@ -616,21 +625,22 @@
     * 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.
     * @return The formatted String.
     */
    public String sprintf(Object[] o)
    {
        Enumeration             e  = vFmt.elements();
        Enumeration e = vFmt.elements();
        ConversionSpecification cs = null;
        char                    c  = 0;
        int                     i  = 0;
        StringBuffer            sb = new StringBuffer();
        char c = 0;
        int i = 0;
        StringBuffer sb = new StringBuffer();
        while (e.hasMoreElements())
        {
            cs = (ConversionSpecification) e.nextElement();
            c  = cs.getConversionCharacter();
            c = cs.getConversionCharacter();
            if (c == '\0')
            {
@@ -713,19 +723,20 @@
    /**
     * Format nothing.  Just use the control string.
     * @return  the formatted String.
     *
     * @return the formatted String.
     */
    public String sprintf()
    {
        Enumeration             e  = vFmt.elements();
        Enumeration e = vFmt.elements();
        ConversionSpecification cs = null;
        char                    c  = 0;
        StringBuffer            sb = new StringBuffer();
        char c = 0;
        StringBuffer sb = new StringBuffer();
        while (e.hasMoreElements())
        {
            cs = (ConversionSpecification) e.nextElement();
            c  = cs.getConversionCharacter();
            c = cs.getConversionCharacter();
            if (c == '\0')
            {
@@ -741,23 +752,24 @@
    /**
     * Format an int.
     *
     * @param x The int to format.
     * @return  The formatted String.
     * @exception IllegalArgumentException if the
     *     conversion character is f, e, E, g, G, s,
     *     or S.
     * @return The formatted String.
     * @throws IllegalArgumentException if the
     *                                  conversion character is f, e, E, g, G, s,
     *                                  or S.
     */
    public String sprintf(int x) throws IllegalArgumentException
    {
        Enumeration             e  = vFmt.elements();
        Enumeration e = vFmt.elements();
        ConversionSpecification cs = null;
        char                    c  = 0;
        StringBuffer            sb = new StringBuffer();
        char c = 0;
        StringBuffer sb = new StringBuffer();
        while (e.hasMoreElements())
        {
            cs = (ConversionSpecification) e.nextElement();
            c  = cs.getConversionCharacter();
            c = cs.getConversionCharacter();
            if (c == '\0')
            {
@@ -776,23 +788,24 @@
    /**
     * Format an long.
     *
     * @param x The long to format.
     * @return  The formatted String.
     * @exception IllegalArgumentException if the
     *     conversion character is f, e, E, g, G, s,
     *     or S.
     * @return The formatted String.
     * @throws IllegalArgumentException if the
     *                                  conversion character is f, e, E, g, G, s,
     *                                  or S.
     */
    public String sprintf(long x) throws IllegalArgumentException
    {
        Enumeration             e  = vFmt.elements();
        Enumeration e = vFmt.elements();
        ConversionSpecification cs = null;
        char                    c  = 0;
        StringBuffer            sb = new StringBuffer();
        char c = 0;
        StringBuffer sb = new StringBuffer();
        while (e.hasMoreElements())
        {
            cs = (ConversionSpecification) e.nextElement();
            c  = cs.getConversionCharacter();
            c = cs.getConversionCharacter();
            if (c == '\0')
            {
@@ -811,23 +824,24 @@
    /**
     * Format a double.
     *
     * @param x The double to format.
     * @return  The formatted String.
     * @exception IllegalArgumentException if the
     *     conversion character is c, C, s, S,
     *     d, d, x, X, or o.
     * @return The formatted String.
     * @throws IllegalArgumentException if the
     *                                  conversion character is c, C, s, S,
     *                                  d, d, x, X, or o.
     */
    public String sprintf(double x) throws IllegalArgumentException
    {
        Enumeration             e  = vFmt.elements();
        Enumeration e = vFmt.elements();
        ConversionSpecification cs = null;
        char                    c  = 0;
        StringBuffer            sb = new StringBuffer();
        char c = 0;
        StringBuffer sb = new StringBuffer();
        while (e.hasMoreElements())
        {
            cs = (ConversionSpecification) e.nextElement();
            c  = cs.getConversionCharacter();
            c = cs.getConversionCharacter();
            if (c == '\0')
            {
@@ -846,22 +860,23 @@
    /**
     * Format a String.
     *
     * @param x The String to format.
     * @return  The formatted String.
     * @exception IllegalArgumentException if the
     *   conversion character is neither s nor S.
     * @return The formatted String.
     * @throws IllegalArgumentException if the
     *                                  conversion character is neither s nor S.
     */
    public String sprintf(String x) throws IllegalArgumentException
    {
        Enumeration             e  = vFmt.elements();
        Enumeration e = vFmt.elements();
        ConversionSpecification cs = null;
        char                    c  = 0;
        StringBuffer            sb = new StringBuffer();
        char c = 0;
        StringBuffer sb = new StringBuffer();
        while (e.hasMoreElements())
        {
            cs = (ConversionSpecification) e.nextElement();
            c  = cs.getConversionCharacter();
            c = cs.getConversionCharacter();
            if (c == '\0')
            {
@@ -885,23 +900,24 @@
     * 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
     *    conversion character is inappropriate for
     *    formatting an unwrapped value.
     * @return the formatted String.
     * @throws IllegalArgumentException if the
     *                                  conversion character is inappropriate for
     *                                  formatting an unwrapped value.
     */
    public String sprintf(Object x) throws IllegalArgumentException
    {
        Enumeration             e  = vFmt.elements();
        Enumeration e = vFmt.elements();
        ConversionSpecification cs = null;
        char                    c  = 0;
        StringBuffer            sb = new StringBuffer();
        char c = 0;
        StringBuffer sb = new StringBuffer();
        while (e.hasMoreElements())
        {
            cs = (ConversionSpecification) e.nextElement();
            c  = cs.getConversionCharacter();
            c = cs.getConversionCharacter();
            if (c == '\0')
            {
@@ -946,30 +962,30 @@
    }
    /**
     * <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,
     * provided that this percent sign
     * <ol>
     * <li>is not escaped protected by a matching % or
     *     is not an escape % character,
     * is not an escape % character,
     * <li>is not at the end of the format string, and
     * <li>precedes a sequence of characters that parses
     *     as a valid control string.
     * 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
@@ -980,7 +996,9 @@
     */
    private class ConversionSpecification
    {
        /** Default precision. */
        /**
         * Default precision.
         */
        private final static int defaultDigits = 6;
        /**
@@ -1051,7 +1069,7 @@
         * d, i, o, u, x, or X conversions.  The number of
         * digits to appear after the radix character for
         * the e, E, and f conversions.  The maximum number
         *  of significant digits for the g and G
         * of significant digits for the g and G
         * conversions.  The maximum number of bytes to be
         * printed from a string in s and S conversions.
         */
@@ -1070,12 +1088,12 @@
        /*
         */
        private boolean positionalSpecification       = false;
        private int     argumentPosition              = 0;
        private boolean positionalFieldWidth          = false;
        private int     argumentPositionForFieldWidth = 0;
        private boolean positionalPrecision           = false;
        private int     argumentPositionForPrecision  = 0;
        private boolean positionalSpecification = false;
        private int argumentPosition = 0;
        private boolean positionalFieldWidth = false;
        private int argumentPositionForFieldWidth = 0;
        private boolean positionalPrecision = false;
        private int argumentPositionForPrecision = 0;
        /**
         * Flag specifying that a following d, i, o, u, x,
@@ -1098,7 +1116,9 @@
         */
        private boolean optionalL = false;
        /** Control string type. */
        /**
         * Control string type.
         */
        private char conversionCharacter = '\0';
        /**
@@ -1107,7 +1127,9 @@
         */
        private int pos = 0;
        /** Literal or control format string. */
        /**
         * Literal or control format string.
         */
        private String fmt;
        /**
@@ -1123,11 +1145,12 @@
         * 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
         *     input string is null, zero length, or
         *     otherwise malformed.
         *
         * @param fmtArg String specifying the
         *               conversion specification.
         * @throws IllegalArgumentException if the
         *                                  input string is null, zero length, or
         *                                  otherwise malformed.
         */
        ConversionSpecification(String fmtArg) throws IllegalArgumentException
        {
@@ -1163,7 +1186,7 @@
                        if (precisionSet && leadingZeros)
                        {
                            if ((conversionCharacter == 'd') || (conversionCharacter == 'i') || (conversionCharacter == 'o')
                                || (conversionCharacter == 'x'))
                                    || (conversionCharacter == 'x'))
                            {
                                leadingZeros = false;
                            }
@@ -1184,6 +1207,7 @@
        /**
         * Set the String for this instance.
         *
         * @param s the String to store.
         */
        void setLiteral(String s)
@@ -1200,7 +1224,7 @@
        String getLiteral()
        {
            StringBuffer sb = new StringBuffer();
            int          i  = 0;
            int i = 0;
            while (i < fmt.length())
            {
@@ -1214,42 +1238,42 @@
                        switch (c)
                        {
                        case 'a' :
                        case 'a':
                            sb.append((char) 0x07);
                            break;
                        case 'b' :
                        case 'b':
                            sb.append('\b');
                            break;
                        case 'f' :
                        case 'f':
                            sb.append('\f');
                            break;
                        case 'n' :
                        case 'n':
                            sb.append(System.getProperty("line.separator"));
                            break;
                        case 'r' :
                        case 'r':
                            sb.append('\r');
                            break;
                        case 't' :
                        case 't':
                            sb.append('\t');
                            break;
                        case 'v' :
                        case 'v':
                            sb.append((char) 0x0b);
                            break;
                        case '\\' :
                        case '\\':
                            sb.append('\\');
                            break;
@@ -1284,9 +1308,10 @@
         * 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>.
         *         uses an * field width; otherwise
         *         <code>false</code>.
         */
        boolean isVariableFieldWidth()
        {
@@ -1297,6 +1322,7 @@
         * 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)
@@ -1307,16 +1333,17 @@
            }
            fieldWidthSet = true;
            fieldWidth    = Math.abs(fw);
            fieldWidth = Math.abs(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>.
         *         uses an * precision; otherwise
         *         <code>false</code>.
         */
        boolean isVariablePrecision()
        {
@@ -1326,21 +1353,23 @@
        /**
         * Set the precision with an argument.  A
         * negative precision will be changed to zero.
         *
         * @param pr the precision.
         */
        void setPrecisionWithArg(int pr)
        {
            precisionSet = true;
            precision    = Math.max(pr, 0);
            precision = Math.max(pr, 0);
        }
        /**
         * Format an int argument using this conversion
         *  specification.
         * specification.
         *
         * @param s the int to format.
         * @return the formatted String.
         * @exception IllegalArgumentException if the
         *     conversion character is f, e, E, g, or G.
         * @throws IllegalArgumentException if the
         *                                  conversion character is f, e, E, g, or G.
         */
        String internalsprintf(int s) throws IllegalArgumentException
        {
@@ -1348,8 +1377,8 @@
            switch (conversionCharacter)
            {
            case 'd' :
            case 'i' :
            case 'd':
            case 'i':
                if (optionalh)
                {
                    s2 = printDFormat((short) s);
@@ -1363,8 +1392,8 @@
                break;
            case 'x' :
            case 'X' :
            case 'x':
            case 'X':
                if (optionalh)
                {
                    s2 = printXFormat((short) s);
@@ -1378,7 +1407,7 @@
                break;
            case 'o' :
            case 'o':
                if (optionalh)
                {
                    s2 = printOFormat((short) s);
@@ -1392,15 +1421,15 @@
                break;
            case 'c' :
            case 'C' :
            case 'c':
            case 'C':
                s2 = printCFormat((char) s);
                break;
            default :
            default:
                throw new IllegalArgumentException("Cannot format a int with a format using a " + conversionCharacter
                                                   + " conversion character.");
                        + " conversion character.");
            }
            return s2;
@@ -1409,10 +1438,11 @@
        /**
         * Format a long argument using this conversion
         * specification.
         *
         * @param s the long to format.
         * @return the formatted String.
         * @exception IllegalArgumentException if the
         *     conversion character is f, e, E, g, or G.
         * @throws IllegalArgumentException if the
         *                                  conversion character is f, e, E, g, or G.
         */
        String internalsprintf(long s) throws IllegalArgumentException
        {
@@ -1420,8 +1450,8 @@
            switch (conversionCharacter)
            {
            case 'd' :
            case 'i' :
            case 'd':
            case 'i':
                if (optionalh)
                {
                    s2 = printDFormat((short) s);
@@ -1435,8 +1465,8 @@
                break;
            case 'x' :
            case 'X' :
            case 'x':
            case 'X':
                if (optionalh)
                {
                    s2 = printXFormat((short) s);
@@ -1450,7 +1480,7 @@
                break;
            case 'o' :
            case 'o':
                if (optionalh)
                {
                    s2 = printOFormat((short) s);
@@ -1464,15 +1494,15 @@
                break;
            case 'c' :
            case 'C' :
            case 'c':
            case 'C':
                s2 = printCFormat((char) s);
                break;
            default :
            default:
                throw new IllegalArgumentException("Cannot format a long with a format using a " + conversionCharacter
                                                   + " conversion character.");
                        + " conversion character.");
            }
            return s2;
@@ -1481,11 +1511,12 @@
        /**
         * Format a double argument using this conversion
         * specification.
         *
         * @param s the double to format.
         * @return the formatted String.
         * @exception IllegalArgumentException if the
         *     conversion character is c, C, s, S, i, d,
         *     x, X, or o.
         * @throws IllegalArgumentException if the
         *                                  conversion character is c, C, s, S, i, d,
         *                                  x, X, or o.
         */
        String internalsprintf(double s) throws IllegalArgumentException
        {
@@ -1493,26 +1524,26 @@
            switch (conversionCharacter)
            {
            case 'f' :
            case 'f':
                s2 = printFFormat(s);
                break;
            case 'E' :
            case 'e' :
            case 'E':
            case 'e':
                s2 = printEFormat(s);
                break;
            case 'G' :
            case 'g' :
            case 'G':
            case 'g':
                s2 = printGFormat(s);
                break;
            default :
            default:
                throw new IllegalArgumentException("Cannot " + "format a double with a format using a " + conversionCharacter
                                                   + " conversion character.");
                        + " conversion character.");
            }
            return s2;
@@ -1521,10 +1552,11 @@
        /**
         * Format a String argument using this conversion
         * specification.
         *
         * @param s the String to format.
         * @return the formatted String.
         * @exception IllegalArgumentException if the
         *   conversion character is neither s nor S.
         * @throws IllegalArgumentException if the
         *                                  conversion character is neither s nor S.
         */
        String internalsprintf(String s) throws IllegalArgumentException
        {
@@ -1536,7 +1568,7 @@
            } else
            {
                throw new IllegalArgumentException("Cannot " + "format a String with a format using a " + conversionCharacter
                                                   + " conversion character.");
                        + " conversion character.");
            }
            return s2;
@@ -1545,10 +1577,11 @@
        /**
         * Format an Object argument using this conversion
         * specification.
         *
         * @param s the Object to format.
         * @return the formatted String.
         * @exception IllegalArgumentException if the
         *     conversion character is neither s nor S.
         * @throws IllegalArgumentException if the
         *                                  conversion character is neither s nor S.
         */
        String internalsprintf(Object s)
        {
@@ -1560,7 +1593,7 @@
            } else
            {
                throw new IllegalArgumentException("Cannot format a String with a format using" + " a " + conversionCharacter
                                                   + " conversion character.");
                        + " conversion character.");
            }
            return s2;
@@ -1578,12 +1611,12 @@
         * 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.
@@ -1591,10 +1624,10 @@
        private char[] fFormatDigits(double x)
        {
            // int defaultDigits=6;
            String  sx, sxOut;
            int     i, j, k;
            int     n1In, n2In;
            int     expon     = 0;
            String sx, sxOut;
            int i, j, k;
            int n1In, n2In;
            int expon = 0;
            boolean minusSign = false;
            if (x > 0.0)
@@ -1602,7 +1635,7 @@
                sx = Double.toString(x);
            } else if (x < 0.0)
            {
                sx        = Double.toString(-x);
                sx = Double.toString(-x);
                minusSign = true;
            } else
            {
@@ -1611,7 +1644,7 @@
                if (sx.charAt(0) == '-')
                {
                    minusSign = true;
                    sx        = sx.substring(1);
                    sx = sx.substring(1);
                }
            }
@@ -1761,7 +1794,7 @@
                    ca4[0] = '1';
                }
                if (alternateForm ||!precisionSet || (precision != 0))
                if (alternateForm || !precisionSet || (precision != 0))
                {
                    ca4[1] = '.';
@@ -1779,7 +1812,7 @@
            {
                if (!carry)
                {
                    if (alternateForm ||!precisionSet || (precision != 0))
                    if (alternateForm || !precisionSet || (precision != 0))
                    {
                        ca4 = new char[n1In + expon + p + 1];
                    } else
@@ -1790,7 +1823,7 @@
                    j = 0;
                } else
                {
                    if (alternateForm ||!precisionSet || (precision != 0))
                    if (alternateForm || !precisionSet || (precision != 0))
                    {
                        ca4 = new char[n1In + expon + p + 2];
                    } else
@@ -1799,7 +1832,7 @@
                    }
                    ca4[0] = '1';
                    j      = 1;
                    j = 1;
                }
                for (i = 0; i < Math.min(n1In + expon, ca3.length); i++, j++)
@@ -1812,7 +1845,7 @@
                    ca4[j] = '0';
                }
                if (alternateForm ||!precisionSet || (precision != 0))
                if (alternateForm || !precisionSet || (precision != 0))
                {
                    ca4[j] = '.';
                    j++;
@@ -1941,7 +1974,7 @@
            if (thousands && (nThousands > 0))
            {
                ca6    = new char[ca5.length + nThousands + lead];
                ca6 = new char[ca5.length + nThousands + lead];
                ca6[0] = ca5[0];
                for (i = lead, k = lead; i < dp; i++)
@@ -1949,9 +1982,9 @@
                    if ((i > 0) && (dp - i) % 3 == 0)
                    {
                        // ca6[k]=',';
                        ca6[k]     = dfs.getGroupingSeparator();
                        ca6[k] = dfs.getGroupingSeparator();
                        ca6[k + 1] = ca5[i];
                        k          += 2;
                        k += 2;
                    } else
                    {
                        ca6[k] = ca5[i];
@@ -1974,13 +2007,14 @@
         * 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.
         */
        private String fFormatString(double x)
        {
            boolean noDigits = false;
            char[]  ca6, ca7;
            char[] ca6, ca7;
            if (Double.isInfinite(x))
            {
@@ -2038,16 +2072,16 @@
         * 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
@@ -2061,11 +2095,11 @@
            char[] ca1, ca2, ca3;
            // int defaultDigits=6;
            String  sx, sxOut;
            int     i, j, k, p;
            int     n1In, n2In;
            int     expon = 0;
            int     ePos, rPos, eSize;
            String sx, sxOut;
            int i, j, k, p;
            int n1In, n2In;
            int expon = 0;
            int ePos, rPos, eSize;
            boolean minusSign = false;
            if (x > 0.0)
@@ -2073,7 +2107,7 @@
                sx = Double.toString(x);
            } else if (x < 0.0)
            {
                sx        = Double.toString(-x);
                sx = Double.toString(-x);
                minusSign = true;
            } else
            {
@@ -2082,7 +2116,7 @@
                if (sx.charAt(0) == '-')
                {
                    minusSign = true;
                    sx        = sx.substring(1);
                    sx = sx.substring(1);
                }
            }
@@ -2190,7 +2224,7 @@
            }
            boolean carry = false;
            int     i0    = 0;
            int i0 = 0;
            if (ca1[0] != '0')
            {
@@ -2217,7 +2251,7 @@
                if (carry)
                {
                    ca2     = new char[i0 + p + 1];
                    ca2 = new char[i0 + p + 1];
                    ca2[i0] = '1';
                    for (j = 0; j < i0; j++)
@@ -2235,7 +2269,7 @@
                }
            }
            if ((Math.abs(expon) < 100) &&!optionalL)
            if ((Math.abs(expon) < 100) && !optionalL)
            {
                eSize = 4;
            } else
@@ -2243,7 +2277,7 @@
                eSize = 5;
            }
            if (alternateForm ||!precisionSet || (precision != 0))
            if (alternateForm || !precisionSet || (precision != 0))
            {
                ca2 = new char[2 + p + eSize];
            } else
@@ -2254,12 +2288,12 @@
            if (ca1[0] != '0')
            {
                ca2[0] = ca1[0];
                j      = 1;
                j = 1;
            } else
            {
                for (j = 1; j < ((ePos == -1)
                                 ? ca1.length
                                 : ePos); j++)
                        ? ca1.length
                        : ePos); j++)
                {
                    if (ca1[j] != '0')
                    {
@@ -2270,19 +2304,19 @@
                if (((ePos != -1) && (j < ePos)) || ((ePos == -1) && (j < ca1.length)))
                {
                    ca2[0] = ca1[j];
                    expon  -= j;
                    expon -= j;
                    j++;
                } else
                {
                    ca2[0] = '0';
                    j      = 2;
                    j = 2;
                }
            }
            if (alternateForm ||!precisionSet || (precision != 0))
            if (alternateForm || !precisionSet || (precision != 0))
            {
                ca2[1] = '.';
                i      = 2;
                i = 2;
            } else
            {
                i = 1;
@@ -2314,47 +2348,47 @@
            {
                switch (expon / 100)
                {
                case 1 :
                case 1:
                    ca2[i] = '1';
                    break;
                case 2 :
                case 2:
                    ca2[i] = '2';
                    break;
                case 3 :
                case 3:
                    ca2[i] = '3';
                    break;
                case 4 :
                case 4:
                    ca2[i] = '4';
                    break;
                case 5 :
                case 5:
                    ca2[i] = '5';
                    break;
                case 6 :
                case 6:
                    ca2[i] = '6';
                    break;
                case 7 :
                case 7:
                    ca2[i] = '7';
                    break;
                case 8 :
                case 8:
                    ca2[i] = '8';
                    break;
                case 9 :
                case 9:
                    ca2[i] = '9';
                    break;
@@ -2365,52 +2399,52 @@
            switch ((expon % 100) / 10)
            {
            case 0 :
            case 0:
                ca2[i] = '0';
                break;
            case 1 :
            case 1:
                ca2[i] = '1';
                break;
            case 2 :
            case 2:
                ca2[i] = '2';
                break;
            case 3 :
            case 3:
                ca2[i] = '3';
                break;
            case 4 :
            case 4:
                ca2[i] = '4';
                break;
            case 5 :
            case 5:
                ca2[i] = '5';
                break;
            case 6 :
            case 6:
                ca2[i] = '6';
                break;
            case 7 :
            case 7:
                ca2[i] = '7';
                break;
            case 8 :
            case 8:
                ca2[i] = '8';
                break;
            case 9 :
            case 9:
                ca2[i] = '9';
                break;
@@ -2420,52 +2454,52 @@
            switch (expon % 10)
            {
            case 0 :
            case 0:
                ca2[i] = '0';
                break;
            case 1 :
            case 1:
                ca2[i] = '1';
                break;
            case 2 :
            case 2:
                ca2[i] = '2';
                break;
            case 3 :
            case 3:
                ca2[i] = '3';
                break;
            case 4 :
            case 4:
                ca2[i] = '4';
                break;
            case 5 :
            case 5:
                ca2[i] = '5';
                break;
            case 6 :
            case 6:
                ca2[i] = '6';
                break;
            case 7 :
            case 7:
                ca2[i] = '7';
                break;
            case 8 :
            case 8:
                ca2[i] = '8';
                break;
            case 9 :
            case 9:
                ca2[i] = '9';
                break;
@@ -2583,7 +2617,7 @@
            if (thousands && (nThousands > 0))
            {
                ca4    = new char[ca3.length + nThousands + lead];
                ca4 = new char[ca3.length + nThousands + lead];
                ca4[0] = ca3[0];
                for (i = lead, k = lead; i < dp; i++)
@@ -2591,9 +2625,9 @@
                    if ((i > 0) && (dp - i) % 3 == 0)
                    {
                        // ca4[k]=',';
                        ca4[k]     = dfs.getGroupingSeparator();
                        ca4[k] = dfs.getGroupingSeparator();
                        ca4[k + 1] = ca3[i];
                        k          += 2;
                        k += 2;
                    } else
                    {
                        ca4[k] = ca3[i];
@@ -2614,11 +2648,12 @@
         * 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 ca1    the array of digits
         * @param icarry the index of the first digit that
         *     is to be truncated from the print
         *               is to be truncated from the print
         * @return <code>true</code> if the truncation forces
         *     a round that will change the print
         *         a round that will change the print
         */
        private boolean checkForCarry(char[] ca1, int icarry)
        {
@@ -2646,7 +2681,7 @@
                    if (!carry && (icarry > 0))
                    {
                        carry = ((ca1[icarry - 1] == '1') || (ca1[icarry - 1] == '3') || (ca1[icarry - 1] == '5')
                                 || (ca1[icarry - 1] == '7') || (ca1[icarry - 1] == '9'));
                                || (ca1[icarry - 1] == '7') || (ca1[icarry - 1] == '9'));
                    }
                }
            }
@@ -2659,13 +2694,14 @@
         * 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 cLast  index of the last digit changed
         *               by the round
         * @param cFirst index of the first digit allowed
         *     to be changed by this phase of the round
         *               to be changed by this phase of the round
         * @return <code>true</code> if the carry forces
         *     a round that will change the print still
         *     more
         *         a round that will change the print still
         *         more
         */
        private boolean startSymbolicCarry(char[] ca, int cLast, int cFirst)
        {
@@ -2677,52 +2713,52 @@
                switch (ca[i])
                {
                case '0' :
                case '0':
                    ca[i] = '1';
                    break;
                case '1' :
                case '1':
                    ca[i] = '2';
                    break;
                case '2' :
                case '2':
                    ca[i] = '3';
                    break;
                case '3' :
                case '3':
                    ca[i] = '4';
                    break;
                case '4' :
                case '4':
                    ca[i] = '5';
                    break;
                case '5' :
                case '5':
                    ca[i] = '6';
                    break;
                case '6' :
                case '6':
                    ca[i] = '7';
                    break;
                case '7' :
                case '7':
                    ca[i] = '8';
                    break;
                case '8' :
                case '8':
                    ca[i] = '9';
                    break;
                case '9' :
                case '9':
                    ca[i] = '0';
                    carry = true;
@@ -2739,15 +2775,16 @@
         * 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 x     the double value to be formatted.
         * @param eChar an 'e' or 'E' to use in the
         *     converted double value.
         *              converted double value.
         * @return the converted double value.
         */
        private String eFormatString(double x, char eChar)
        {
            boolean noDigits = false;
            char[]  ca4, ca5;
            char[] ca4, ca5;
            if (Double.isInfinite(x))
            {
@@ -2795,8 +2832,9 @@
        /**
         * Apply zero or blank, left or right padding.
         * @param ca4 array of characters before padding is
         *     finished
         *
         * @param ca4      array of characters before padding is
         *                 finished
         * @param noDigits NaN or signed Inf
         * @return a padded array of characters
         */
@@ -2851,8 +2889,8 @@
                    if (nBlanks > 0)
                    {
                        ca5 = new char[ca4.length + nBlanks];
                        i   = 0;
                        j   = 0;
                        i = 0;
                        j = 0;
                        if (ca4[0] == '-')
                        {
@@ -2879,6 +2917,7 @@
        /**
         * Format method for the f conversion character.
         *
         * @param x the double to format.
         * @return the formatted String.
         */
@@ -2890,6 +2929,7 @@
        /**
         * Format method for the e or E conversion
         * character.
         *
         * @param x the double to format.
         * @return the formatted String.
         */
@@ -2906,9 +2946,9 @@
        /**
         * Format method for the g conversion character.
         *
         * <p/>
         * For g format, the flag character '-', means that
         *  the output should be left justified within the
         * the output should be left justified within the
         * field.  The default is to pad with blanks on the
         * left.  '+' character means that the conversion
         * will always begin with a sign (+ or -).  The
@@ -2918,24 +2958,25 @@
         * 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.
         */
        private String printGFormat(double x)
        {
            String  sx, sy, sz, ret;
            int     savePrecision = precision;
            int     i;
            char[]  ca4, ca5;
            String sx, sy, sz, ret;
            int savePrecision = precision;
            int i;
            char[] ca4, ca5;
            boolean noDigits = false;
            if (Double.isInfinite(x))
@@ -2988,11 +3029,11 @@
                if (conversionCharacter == 'g')
                {
                    sx   = eFormatString(x, 'e').trim();
                    sx = eFormatString(x, 'e').trim();
                    ePos = sx.indexOf('e');
                } else
                {
                    sx   = eFormatString(x, 'E').trim();
                    sx = eFormatString(x, 'E').trim();
                    ePos = sx.indexOf('E');
                }
@@ -3106,7 +3147,7 @@
            }
            // Pad with blanks or zeros.
            ca5       = applyFloatPadding(ca4, false);
            ca5 = applyFloatPadding(ca4, false);
            precision = savePrecision;
            return new String(ca5);
@@ -3115,7 +3156,7 @@
        /**
         * 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
@@ -3127,14 +3168,15 @@
         * 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.
         */
@@ -3146,7 +3188,7 @@
        /**
         * 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
@@ -3158,14 +3200,15 @@
         * 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.
         */
@@ -3177,7 +3220,7 @@
        /**
         * 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
@@ -3189,14 +3232,15 @@
         * 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.
         */
@@ -3208,19 +3252,20 @@
        /**
         * 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.
         *           converting a short, int, or long to a
         *           String.
         * @return the formatted String.
         */
        private String printDFormat(String sx)
        {
            int     nLeadingZeros = 0;
            int     nBlanks       = 0,
                    n             = 0;
            int     i             = 0,
                    jFirst        = 0;
            boolean neg           = sx.charAt(0) == '-';
            int nLeadingZeros = 0;
            int nBlanks = 0,
                    n = 0;
            int i = 0,
                    jFirst = 0;
            boolean neg = sx.charAt(0) == '-';
            if (sx.equals("0") && precisionSet && (precision == 0))
            {
@@ -3291,8 +3336,8 @@
                char[] csx = sx.toCharArray();
                jFirst = neg
                         ? 1
                         : 0;
                        ? 1
                        : 0;
                for (int j = 0; j < nLeadingZeros; i++, j++)
                {
@@ -3354,8 +3399,8 @@
                char[] csx = sx.toCharArray();
                jFirst = neg
                         ? 1
                         : 0;
                        ? 1
                        : 0;
                for (int j = jFirst; j < csx.length; j++, i++)
                {
@@ -3369,20 +3414,21 @@
        /**
         * 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.
         */
@@ -3412,55 +3458,55 @@
                switch (t.length())
                {
                case 1 :
                case 1:
                    sx = "800" + t;
                    break;
                case 2 :
                case 2:
                    sx = "80" + t;
                    break;
                case 3 :
                case 3:
                    sx = "8" + t;
                    break;
                case 4 :
                case 4:
                    switch (t.charAt(0))
                    {
                    case '1' :
                    case '1':
                        sx = "9" + t.substring(1, 4);
                        break;
                    case '2' :
                    case '2':
                        sx = "a" + t.substring(1, 4);
                        break;
                    case '3' :
                    case '3':
                        sx = "b" + t.substring(1, 4);
                        break;
                    case '4' :
                    case '4':
                        sx = "c" + t.substring(1, 4);
                        break;
                    case '5' :
                    case '5':
                        sx = "d" + t.substring(1, 4);
                        break;
                    case '6' :
                    case '6':
                        sx = "e" + t.substring(1, 4);
                        break;
                    case '7' :
                    case '7':
                        sx = "f" + t.substring(1, 4);
                        break;
@@ -3479,20 +3525,21 @@
        /**
         * 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.
         */
@@ -3509,115 +3556,115 @@
                switch (t.length())
                {
                case 1 :
                case 1:
                    sx = "800000000000000" + t;
                    break;
                case 2 :
                case 2:
                    sx = "80000000000000" + t;
                    break;
                case 3 :
                case 3:
                    sx = "8000000000000" + t;
                    break;
                case 4 :
                case 4:
                    sx = "800000000000" + t;
                    break;
                case 5 :
                case 5:
                    sx = "80000000000" + t;
                    break;
                case 6 :
                case 6:
                    sx = "8000000000" + t;
                    break;
                case 7 :
                case 7:
                    sx = "800000000" + t;
                    break;
                case 8 :
                case 8:
                    sx = "80000000" + t;
                    break;
                case 9 :
                case 9:
                    sx = "8000000" + t;
                    break;
                case 10 :
                case 10:
                    sx = "800000" + t;
                    break;
                case 11 :
                case 11:
                    sx = "80000" + t;
                    break;
                case 12 :
                case 12:
                    sx = "8000" + t;
                    break;
                case 13 :
                case 13:
                    sx = "800" + t;
                    break;
                case 14 :
                case 14:
                    sx = "80" + t;
                    break;
                case 15 :
                case 15:
                    sx = "8" + t;
                    break;
                case 16 :
                case 16:
                    switch (t.charAt(0))
                    {
                    case '1' :
                    case '1':
                        sx = "9" + t.substring(1, 16);
                        break;
                    case '2' :
                    case '2':
                        sx = "a" + t.substring(1, 16);
                        break;
                    case '3' :
                    case '3':
                        sx = "b" + t.substring(1, 16);
                        break;
                    case '4' :
                    case '4':
                        sx = "c" + t.substring(1, 16);
                        break;
                    case '5' :
                    case '5':
                        sx = "d" + t.substring(1, 16);
                        break;
                    case '6' :
                    case '6':
                        sx = "e" + t.substring(1, 16);
                        break;
                    case '7' :
                    case '7':
                        sx = "f" + t.substring(1, 16);
                        break;
@@ -3636,20 +3683,21 @@
        /**
         * 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.
         */
@@ -3666,75 +3714,75 @@
                switch (t.length())
                {
                case 1 :
                case 1:
                    sx = "8000000" + t;
                    break;
                case 2 :
                case 2:
                    sx = "800000" + t;
                    break;
                case 3 :
                case 3:
                    sx = "80000" + t;
                    break;
                case 4 :
                case 4:
                    sx = "8000" + t;
                    break;
                case 5 :
                case 5:
                    sx = "800" + t;
                    break;
                case 6 :
                case 6:
                    sx = "80" + t;
                    break;
                case 7 :
                case 7:
                    sx = "8" + t;
                    break;
                case 8 :
                case 8:
                    switch (t.charAt(0))
                    {
                    case '1' :
                    case '1':
                        sx = "9" + t.substring(1, 8);
                        break;
                    case '2' :
                    case '2':
                        sx = "a" + t.substring(1, 8);
                        break;
                    case '3' :
                    case '3':
                        sx = "b" + t.substring(1, 8);
                        break;
                    case '4' :
                    case '4':
                        sx = "c" + t.substring(1, 8);
                        break;
                    case '5' :
                    case '5':
                        sx = "d" + t.substring(1, 8);
                        break;
                    case '6' :
                    case '6':
                        sx = "e" + t.substring(1, 8);
                        break;
                    case '7' :
                    case '7':
                        sx = "f" + t.substring(1, 8);
                        break;
@@ -3753,15 +3801,16 @@
        /**
         * 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.
         *           converting a short, int, or long to a
         *           String.
         * @return the formatted String.
         */
        private String printXFormat(String sx)
        {
            int nLeadingZeros = 0;
            int nBlanks       = 0;
            int nBlanks = 0;
            if (sx.equals("0") && precisionSet && (precision == 0))
            {
@@ -3805,7 +3854,7 @@
            n += nBlanks;
            char[] ca = new char[n];
            int    i  = 0;
            int i = 0;
            if (leftJustify)
            {
@@ -3881,21 +3930,22 @@
        /**
         * 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.
         */
@@ -3912,27 +3962,27 @@
                switch (t.length())
                {
                case 1 :
                case 1:
                    sx = "10000" + t;
                    break;
                case 2 :
                case 2:
                    sx = "1000" + t;
                    break;
                case 3 :
                case 3:
                    sx = "100" + t;
                    break;
                case 4 :
                case 4:
                    sx = "10" + t;
                    break;
                case 5 :
                case 5:
                    sx = "1" + t;
                    break;
@@ -3948,21 +3998,22 @@
        /**
         * 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.
         */
@@ -3979,107 +4030,107 @@
                switch (t.length())
                {
                case 1 :
                case 1:
                    sx = "100000000000000000000" + t;
                    break;
                case 2 :
                case 2:
                    sx = "10000000000000000000" + t;
                    break;
                case 3 :
                case 3:
                    sx = "1000000000000000000" + t;
                    break;
                case 4 :
                case 4:
                    sx = "100000000000000000" + t;
                    break;
                case 5 :
                case 5:
                    sx = "10000000000000000" + t;
                    break;
                case 6 :
                case 6:
                    sx = "1000000000000000" + t;
                    break;
                case 7 :
                case 7:
                    sx = "100000000000000" + t;
                    break;
                case 8 :
                case 8:
                    sx = "10000000000000" + t;
                    break;
                case 9 :
                case 9:
                    sx = "1000000000000" + t;
                    break;
                case 10 :
                case 10:
                    sx = "100000000000" + t;
                    break;
                case 11 :
                case 11:
                    sx = "10000000000" + t;
                    break;
                case 12 :
                case 12:
                    sx = "1000000000" + t;
                    break;
                case 13 :
                case 13:
                    sx = "100000000" + t;
                    break;
                case 14 :
                case 14:
                    sx = "10000000" + t;
                    break;
                case 15 :
                case 15:
                    sx = "1000000" + t;
                    break;
                case 16 :
                case 16:
                    sx = "100000" + t;
                    break;
                case 17 :
                case 17:
                    sx = "10000" + t;
                    break;
                case 18 :
                case 18:
                    sx = "1000" + t;
                    break;
                case 19 :
                case 19:
                    sx = "100" + t;
                    break;
                case 20 :
                case 20:
                    sx = "10" + t;
                    break;
                case 21 :
                case 21:
                    sx = "1" + t;
                    break;
@@ -4095,21 +4146,22 @@
        /**
         * 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.
         */
@@ -4126,57 +4178,57 @@
                switch (t.length())
                {
                case 1 :
                case 1:
                    sx = "2000000000" + t;
                    break;
                case 2 :
                case 2:
                    sx = "200000000" + t;
                    break;
                case 3 :
                case 3:
                    sx = "20000000" + t;
                    break;
                case 4 :
                case 4:
                    sx = "2000000" + t;
                    break;
                case 5 :
                case 5:
                    sx = "200000" + t;
                    break;
                case 6 :
                case 6:
                    sx = "20000" + t;
                    break;
                case 7 :
                case 7:
                    sx = "2000" + t;
                    break;
                case 8 :
                case 8:
                    sx = "200" + t;
                    break;
                case 9 :
                case 9:
                    sx = "20" + t;
                    break;
                case 10 :
                case 10:
                    sx = "2" + t;
                    break;
                case 11 :
                case 11:
                    sx = "3" + t.substring(1);
                    break;
@@ -4192,15 +4244,16 @@
        /**
         * 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.
         *           converting a short, int, or long to a
         *           String.
         * @return the formatted String.
         */
        private String printOFormat(String sx)
        {
            int nLeadingZeros = 0;
            int nBlanks       = 0;
            int nBlanks = 0;
            if (sx.equals("0") && precisionSet && (precision == 0))
            {
@@ -4232,9 +4285,9 @@
                nBlanks = 0;
            }
            int    n  = nLeadingZeros + sx.length() + nBlanks;
            int n = nLeadingZeros + sx.length() + nBlanks;
            char[] ca = new char[n];
            int    i;
            int i;
            if (leftJustify)
            {
@@ -4289,24 +4342,25 @@
        /**
         * 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.
         */
        private String printCFormat(char x)
        {
            int nPrint = 1;
            int width  = fieldWidth;
            int width = fieldWidth;
            if (!fieldWidthSet)
            {
@@ -4314,7 +4368,7 @@
            }
            char[] ca = new char[width];
            int    i  = 0;
            int i = 0;
            if (leftJustify)
            {
@@ -4340,30 +4394,31 @@
        /**
         * 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.
         */
        private String printSFormat(String x)
        {
            int nPrint = x.length();
            int width  = fieldWidth;
            int width = fieldWidth;
            if (precisionSet && (nPrint > precision))
            {
@@ -4391,7 +4446,7 @@
            }
            char[] ca = new char[n];
            int    i  = 0;
            int i = 0;
            if (leftJustify)
            {
@@ -4449,9 +4504,10 @@
        /**
         * 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.
         *         character is there, and
         *         <code>false</code> otherwise.
         */
        private boolean setConversionCharacter()
        {
@@ -4465,7 +4521,7 @@
                char c = fmt.charAt(pos);
                if ((c == 'i') || (c == 'd') || (c == 'f') || (c == 'g') || (c == 'G') || (c == 'o') || (c == 'x') || (c == 'X')
                    || (c == 'e') || (c == 'E') || (c == 'c') || (c == 's') || (c == '%'))
                        || (c == 'e') || (c == 'E') || (c == 'c') || (c == 's') || (c == '%'))
                {
                    conversionCharacter = c;
                    pos++;
@@ -4531,7 +4587,7 @@
                    if (!setPrecisionArgPosition())
                    {
                        variablePrecision = true;
                        precisionSet      = true;
                        precisionSet = true;
                    }
                    return;
@@ -4554,7 +4610,7 @@
                    {
                        String sz = fmt.substring(firstPos + 1, pos);
                        precision    = Integer.parseInt(sz);
                        precision = Integer.parseInt(sz);
                        precisionSet = true;
                    }
                }
@@ -4568,7 +4624,7 @@
        {
            int firstPos = pos;
            fieldWidth    = 0;
            fieldWidth = 0;
            fieldWidthSet = false;
            if ((pos < fmt.length()) && (fmt.charAt(pos) == '*'))
@@ -4578,7 +4634,7 @@
                if (!setFieldWidthArgPosition())
                {
                    variableFieldWidth = true;
                    fieldWidthSet      = true;
                    fieldWidthSet = true;
                }
            } else
            {
@@ -4599,7 +4655,7 @@
                {
                    String sz = fmt.substring(firstPos, pos);
                    fieldWidth    = Integer.parseInt(sz);
                    fieldWidth = Integer.parseInt(sz);
                    fieldWidthSet = true;
                }
            }
@@ -4625,8 +4681,8 @@
                if (fmt.charAt(xPos) == '$')
                {
                    positionalSpecification = true;
                    argumentPosition        = Integer.parseInt(fmt.substring(pos, xPos));
                    pos                     = xPos + 1;
                    argumentPosition = Integer.parseInt(fmt.substring(pos, xPos));
                    pos = xPos + 1;
                }
            }
        }
@@ -4637,7 +4693,7 @@
        private boolean setFieldWidthArgPosition()
        {
            boolean ret = false;
            int     xPos;
            int xPos;
            for (xPos = pos; xPos < fmt.length(); xPos++)
            {
@@ -4651,10 +4707,10 @@
            {
                if (fmt.charAt(xPos) == '$')
                {
                    positionalFieldWidth          = true;
                    positionalFieldWidth = true;
                    argumentPositionForFieldWidth = Integer.parseInt(fmt.substring(pos, xPos));
                    pos                           = xPos + 1;
                    ret                           = true;
                    pos = xPos + 1;
                    ret = true;
                }
            }
@@ -4667,7 +4723,7 @@
        private boolean setPrecisionArgPosition()
        {
            boolean ret = false;
            int     xPos;
            int xPos;
            for (xPos = pos; xPos < fmt.length(); xPos++)
            {
@@ -4681,10 +4737,10 @@
            {
                if (fmt.charAt(xPos) == '$')
                {
                    positionalPrecision          = true;
                    positionalPrecision = true;
                    argumentPositionForPrecision = Integer.parseInt(fmt.substring(pos, xPos));
                    pos                          = xPos + 1;
                    ret                          = true;
                    pos = xPos + 1;
                    ret = true;
                }
            }
@@ -4727,12 +4783,12 @@
        private void setFlagCharacters()
        {
            /* '-+ #0 */
            thousands     = false;
            leftJustify   = false;
            leadingSign   = false;
            leadingSpace  = false;
            thousands = false;
            leftJustify = false;
            leadingSign = false;
            leadingSpace = false;
            alternateForm = false;
            leadingZeros  = false;
            leadingZeros = false;
            for (; pos < fmt.length(); pos++)
            {
@@ -4743,11 +4799,11 @@
                    thousands = true;
                } else if (c == '-')
                {
                    leftJustify  = true;
                    leftJustify = true;
                    leadingZeros = false;
                } else if (c == '+')
                {
                    leadingSign  = true;
                    leadingSign = true;
                    leadingSpace = false;
                } else if (c == ' ')
                {
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/StringUtils.java
Diff too large
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/TPCLIDConverter.java
@@ -368,7 +368,7 @@
        Coordinate pt2 = new Coordinate(point);
        pt2.x += width;
        pt2.y += height;
        return  new Envelope(point, pt2);
        return new Envelope(point, pt2);
    }
    public static Coordinate convertTpclIdToCoordinate(String tpclid)
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/TWD97GeometryConverterDecorator.java
@@ -7,7 +7,6 @@
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
@@ -45,7 +44,7 @@
    {
        public void filter(CoordinateSequence coordinateSequence, int i)
        {
            Coordinate pt =coordinateSequence.getCoordinate(i);
            Coordinate pt = coordinateSequence.getCoordinate(i);
            Coordinate pt97 = TWDDatumConverter.fromTM2ToTWD97(pt);
            pt.x = pt97.x;
            pt.y = pt97.y;
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/TWDDatumConverter.java
@@ -15,7 +15,7 @@
     *   Definition of math related value
     */
    private static final double COS67_5 = 0.3826834323650897717284599840304e0;
    private static final double PI      = 3.14159265358979323e0;
    private static final double PI = 3.14159265358979323e0;
    private static final double HALF_PI = 1.570796326794896615e0;
    private static final double DEG_RAD = 0.01745329251994329572e0;
    private static final double RAD_DEG = 57.295779513082321031e0;
@@ -23,10 +23,10 @@
    /*
     * Definition of datum related value
     */
    private static final double AD_C       = 1.0026000e0;
    private static final double TWD67_A    = 6378160.0e0;
    private static final double TWD67_B    = 6356774.7192e0;
    private static final double TWD67_ECC  = 0.00669454185458e0;
    private static final double AD_C = 1.0026000e0;
    private static final double TWD67_A = 6378160.0e0;
    private static final double TWD67_B = 6356774.7192e0;
    private static final double TWD67_ECC = 0.00669454185458e0;
    private static final double TWD67_ECC2 = 0.00673966079586e0;
    // different from garmin and already knowned value, but those all value only
@@ -36,17 +36,17 @@
    private static final double TWD67_DY = -361.32e0;
    // release to public. if can got more enough twd67/twd97 control point coordinare,
    private static final double TWD67_DZ   = -180.51e0;
    private static final double TWD67_RX   = -0.00000117e0;    // then we can calculate a better value than now.
    private static final double TWD67_RY   = 0.00000184e0;     //
    private static final double TWD67_RZ   = 0.00000098e0;     // and, also lack twd67/twd97 altitude convertion value...
    private static final double TWD67_S    = 0.00002329e0;     //
    private static final double TWD97_A    = 6378137.0e0;
    private static final double TWD97_B    = 6356752.3141e0;
    private static final double TWD97_ECC  = 0.00669438002290e0;
    private static final double TWD67_DZ = -180.51e0;
    private static final double TWD67_RX = -0.00000117e0;    // then we can calculate a better value than now.
    private static final double TWD67_RY = 0.00000184e0;     //
    private static final double TWD67_RZ = 0.00000098e0;     // and, also lack twd67/twd97 altitude convertion value...
    private static final double TWD67_S = 0.00002329e0;     //
    private static final double TWD97_A = 6378137.0e0;
    private static final double TWD97_B = 6356752.3141e0;
    private static final double TWD97_ECC = 0.00669438002290e0;
    private static final double TWD97_ECC2 = 0.00673949677556e0;
    private static final double TWD67_TM2  = 0.9999e0;         // TWD67->TM2 scale
    private static final double TWD97_TM2  = 0.9999e0;         // TWD97->TM2 scale
    private static final double TWD67_TM2 = 0.9999e0;         // TWD67->TM2 scale
    private static final double TWD97_TM2 = 0.9999e0;         // TWD97->TM2 scale
    /*
     * datum convert function
@@ -59,8 +59,8 @@
        double x1, y1, z1, x2, y2, z2;
        double q, q2, t, t1, s, s1, sum, sin_b, cos_b, sin_p, cos_p;
        lon    = pt.x * DEG_RAD;
        lat    = pt.y * DEG_RAD;
        lon = pt.x * DEG_RAD;
        lat = pt.y * DEG_RAD;
        height = pt.z * DEG_RAD;
        if ((lat < -HALF_PI) && (lat > -1.001 * HALF_PI))
@@ -81,14 +81,14 @@
        sin_lat = Math.sin(lat);
        cos_lat = Math.cos(lat);
        r       = TWD67_A / (Math.sqrt(1.0 - TWD67_ECC * sin_lat * sin_lat));
        x1      = (r + height) * cos_lat * Math.cos(lon);
        y1      = (r + height) * cos_lat * Math.sin(lon);
        z1      = ((r * (1 - TWD67_ECC)) + height) * sin_lat;
        x2      = x1 + TWD67_DX + TWD67_S * (lon + TWD67_RZ * lat - TWD67_RY * height);
        y2      = y1 + TWD67_DY + TWD67_S * (-TWD67_RZ * lon + lat + TWD67_RX * height);
        z2      = z1 + TWD67_DZ + TWD67_S * (TWD67_RY * lon - TWD67_RX * lat + height);
        pole    = 0.0;
        r = TWD67_A / (Math.sqrt(1.0 - TWD67_ECC * sin_lat * sin_lat));
        x1 = (r + height) * cos_lat * Math.cos(lon);
        y1 = (r + height) * cos_lat * Math.sin(lon);
        z1 = ((r * (1 - TWD67_ECC)) + height) * sin_lat;
        x2 = x1 + TWD67_DX + TWD67_S * (lon + TWD67_RZ * lat - TWD67_RY * height);
        y2 = y1 + TWD67_DY + TWD67_S * (-TWD67_RZ * lon + lat + TWD67_RX * height);
        z2 = z1 + TWD67_DZ + TWD67_S * (TWD67_RY * lon - TWD67_RX * lat + height);
        pole = 0.0;
        if (x2 != 0.0)
        {
@@ -104,7 +104,7 @@
            } else
            {
                pole = 1;
                lon  = 0;
                lon = 0;
                if (z2 > 0)
                {
@@ -114,7 +114,7 @@
                    lat = -HALF_PI;
                } else
                {
                    lat  = HALF_PI;
                    lat = HALF_PI;
                    newX = lon * RAD_DEG;
                    newY = lat * RAD_DEG;
                    newZ = -TWD97_B;
@@ -124,18 +124,18 @@
            }
        }
        q2    = x2 * x2 + y2 * y2;
        q     = Math.sqrt(q2);
        t     = z2 * AD_C;
        s     = Math.sqrt(t * t + q2);
        q2 = x2 * x2 + y2 * y2;
        q = Math.sqrt(q2);
        t = z2 * AD_C;
        s = Math.sqrt(t * t + q2);
        sin_b = t / s;
        cos_b = q / s;
        t1    = z2 + TWD97_B * TWD97_ECC2 * sin_b * sin_b * sin_b;
        sum   = q - TWD97_A * TWD97_ECC * cos_b * cos_b * cos_b;
        s1    = Math.sqrt(t1 * t1 + sum * sum);
        t1 = z2 + TWD97_B * TWD97_ECC2 * sin_b * sin_b * sin_b;
        sum = q - TWD97_A * TWD97_ECC * cos_b * cos_b * cos_b;
        s1 = Math.sqrt(t1 * t1 + sum * sum);
        sin_p = t1 / s1;
        cos_p = sum / s1;
        r     = TWD97_A / Math.sqrt(1.0 - TWD97_ECC * sin_p * sin_p);
        r = TWD97_A / Math.sqrt(1.0 - TWD97_ECC * sin_p * sin_p);
        if (cos_p >= COS67_5)
        {
@@ -148,7 +148,7 @@
            height = z2 / sin_p + r * (TWD97_ECC - 1.0);
        }
        if (pole !=0.0)
        if (pole != 0.0)
        {
            lat = Math.atan(sin_p / cos_p);
        }
@@ -167,8 +167,8 @@
        double x1, y1, z1, x2, y2, z2;
        double q, q2, t, t1, s, s1, sum, sin_b, cos_b, sin_p, cos_p;
        lon    = pt.x * DEG_RAD;
        lat    = pt.y * DEG_RAD;
        lon = pt.x * DEG_RAD;
        lat = pt.y * DEG_RAD;
        height = pt.z * DEG_RAD;
        if ((lat < -HALF_PI) && (lat > -1.001 * HALF_PI))
@@ -189,14 +189,14 @@
        sin_lat = Math.sin(lat);
        cos_lat = Math.cos(lat);
        r       = TWD97_A / (Math.sqrt(1.0 - TWD97_ECC * sin_lat * sin_lat));
        x1      = (r + height) * cos_lat * Math.cos(lon);
        y1      = (r + height) * cos_lat * Math.sin(lon);
        z1      = ((r * (1 - TWD97_ECC)) + height) * sin_lat;
        x2      = x1 - TWD67_DX - TWD67_S * (lon + TWD67_RZ * lat - TWD67_RY * height);
        y2      = y1 - TWD67_DY - TWD67_S * (-TWD67_RZ * lon + lat + TWD67_RX * height);
        z2      = z1 - TWD67_DZ - TWD67_S * (TWD67_RY * lon - TWD67_RX * lat + height);
        pole    = 0;
        r = TWD97_A / (Math.sqrt(1.0 - TWD97_ECC * sin_lat * sin_lat));
        x1 = (r + height) * cos_lat * Math.cos(lon);
        y1 = (r + height) * cos_lat * Math.sin(lon);
        z1 = ((r * (1 - TWD97_ECC)) + height) * sin_lat;
        x2 = x1 - TWD67_DX - TWD67_S * (lon + TWD67_RZ * lat - TWD67_RY * height);
        y2 = y1 - TWD67_DY - TWD67_S * (-TWD67_RZ * lon + lat + TWD67_RX * height);
        z2 = z1 - TWD67_DZ - TWD67_S * (TWD67_RY * lon - TWD67_RX * lat + height);
        pole = 0;
        if (x2 != 0.0)
        {
@@ -212,7 +212,7 @@
            } else
            {
                pole = 1;
                lon  = 0;
                lon = 0;
                if (z2 > 0)
                {
@@ -222,7 +222,7 @@
                    lat = -HALF_PI;
                } else
                {
                    lat  = HALF_PI;
                    lat = HALF_PI;
                    newX = lon * RAD_DEG;
                    newY = lat * RAD_DEG;
                    newZ = -TWD67_B;
@@ -232,18 +232,18 @@
            }
        }
        q2    = x2 * x2 + y2 * y2;
        q     = Math.sqrt(q2);
        t     = z2 * AD_C;
        s     = Math.sqrt(t * t + q2);
        q2 = x2 * x2 + y2 * y2;
        q = Math.sqrt(q2);
        t = z2 * AD_C;
        s = Math.sqrt(t * t + q2);
        sin_b = t / s;
        cos_b = q / s;
        t1    = z2 + TWD67_B * TWD67_ECC2 * sin_b * sin_b * sin_b;
        sum   = q - TWD67_A * TWD67_ECC * cos_b * cos_b * cos_b;
        s1    = Math.sqrt(t1 * t1 + sum * sum);
        t1 = z2 + TWD67_B * TWD67_ECC2 * sin_b * sin_b * sin_b;
        sum = q - TWD67_A * TWD67_ECC * cos_b * cos_b * cos_b;
        s1 = Math.sqrt(t1 * t1 + sum * sum);
        sin_p = t1 / s1;
        cos_p = sum / s1;
        r     = TWD67_A / Math.sqrt(1.0 - TWD67_ECC * sin_p * sin_p);
        r = TWD67_A / Math.sqrt(1.0 - TWD67_ECC * sin_p * sin_p);
        if (cos_p >= COS67_5)
        {
@@ -273,24 +273,24 @@
        double n, t, c, A;
        double newX, newY;
        x0   = x * DEG_RAD;
        y0   = y * DEG_RAD;
        x1   = lon * DEG_RAD;
        y1   = lat * DEG_RAD;
        m0   = mercator(y1, a, ecc);
        m1   = mercator(y0, a, ecc);
        n    = a / Math.sqrt(1 - ecc * Math.pow(Math.sin(y0), 2.0));
        t    = Math.pow(Math.tan(y0), 2.0);
        c    = ecc2 * Math.pow(Math.cos(y0), 2.0);
        A    = (x0 - x1) * Math.cos(y0);
        x0 = x * DEG_RAD;
        y0 = y * DEG_RAD;
        x1 = lon * DEG_RAD;
        y1 = lat * DEG_RAD;
        m0 = mercator(y1, a, ecc);
        m1 = mercator(y0, a, ecc);
        n = a / Math.sqrt(1 - ecc * Math.pow(Math.sin(y0), 2.0));
        t = Math.pow(Math.tan(y0), 2.0);
        c = ecc2 * Math.pow(Math.cos(y0), 2.0);
        A = (x0 - x1) * Math.cos(y0);
        newX = scale * n
               * (A + (1.0 - t + c) * A * A * A / 6.0
                  + (5.0 - 18.0 * t + t * t + 72.0 * c - 58.0 * ecc2) * Math.pow(A, 5.0) / 120.0);
                * (A + (1.0 - t + c) * A * A * A / 6.0
                + (5.0 - 18.0 * t + t * t + 72.0 * c - 58.0 * ecc2) * Math.pow(A, 5.0) / 120.0);
        newY = scale
               * (m1 - m0
                  + n * Math.tan(y0)
                    * (A * A / 2.0 + (5.0 - t + 9.0 * c + 4 * c * c) * Math.pow(A, 4.0) / 24.0
                       + (61.0 - 58.0 * t + t * t + 600.0 * c - 330.0 * ecc2) * Math.pow(A, 6.0) / 720.0));
                * (m1 - m0
                + n * Math.tan(y0)
                * (A * A / 2.0 + (5.0 - t + 9.0 * c + 4 * c * c) * Math.pow(A, 4.0) / 24.0
                + (61.0 - 58.0 * t + t * t + 600.0 * c - 330.0 * ecc2) * Math.pow(A, 6.0) / 720.0));
        return new Coordinate(newX, newY);
    }
@@ -300,30 +300,30 @@
        double x0, y0, x1, y1, phi, m, m0, mu, e1;
        double c1, t1, n1, r1, d;
        x0  = x;
        y0  = y;
        x1  = lon * DEG_RAD;
        y1  = lat * DEG_RAD;
        m0  = mercator(y1, a, ecc);
        m   = m0 + y0 / scale;
        e1  = (1.0 - Math.sqrt(1.0 - ecc)) / (1.0 + Math.sqrt(1.0 - ecc));
        mu  = m / (a * (1.0 - ecc / 4.0 - 3.0 * ecc * ecc / 64.0 - 5.0 * ecc * ecc * ecc / 256.0));
        x0 = x;
        y0 = y;
        x1 = lon * DEG_RAD;
        y1 = lat * DEG_RAD;
        m0 = mercator(y1, a, ecc);
        m = m0 + y0 / scale;
        e1 = (1.0 - Math.sqrt(1.0 - ecc)) / (1.0 + Math.sqrt(1.0 - ecc));
        mu = m / (a * (1.0 - ecc / 4.0 - 3.0 * ecc * ecc / 64.0 - 5.0 * ecc * ecc * ecc / 256.0));
        phi = mu + (3.0 * e1 / 2.0 - 27.0 * Math.pow(e1, 3.0) / 32.0) * Math.sin(2.0 * mu)
              + (21.0 * e1 * e1 / 16.0 - 55.0 * Math.pow(e1, 4.0) / 32.0) * Math.sin(4.0 * mu)
              + 151.0 * Math.pow(e1, 3.0) / 96.0 * Math.sin(6.0 * mu) + 1097.0 * Math.pow(e1, 4.0) / 512.0 * Math.sin(8.0 * mu);
        c1   = ecc2 * Math.pow(Math.cos(phi), 2.0);
        t1   = Math.pow(Math.tan(phi), 2.0);
        n1   = a / Math.sqrt(1 - ecc * Math.pow(Math.sin(phi), 2.0));
        r1   = a * (1.0 - ecc) / Math.pow(1.0 - ecc * Math.pow(Math.sin(phi), 2.0), 1.5);
        d    = x0 / (n1 * scale);
                + (21.0 * e1 * e1 / 16.0 - 55.0 * Math.pow(e1, 4.0) / 32.0) * Math.sin(4.0 * mu)
                + 151.0 * Math.pow(e1, 3.0) / 96.0 * Math.sin(6.0 * mu) + 1097.0 * Math.pow(e1, 4.0) / 512.0 * Math.sin(8.0 * mu);
        c1 = ecc2 * Math.pow(Math.cos(phi), 2.0);
        t1 = Math.pow(Math.tan(phi), 2.0);
        n1 = a / Math.sqrt(1 - ecc * Math.pow(Math.sin(phi), 2.0));
        r1 = a * (1.0 - ecc) / Math.pow(1.0 - ecc * Math.pow(Math.sin(phi), 2.0), 1.5);
        d = x0 / (n1 * scale);
        newX = (x1 + (d - (1.0 + 2.0 * t1 + c1) * Math.pow(d, 3.0) / 6.0
                      + (5.0 - 2.0 * c1 + 28.0 * t1 - 3.0 * c1 * c1 + 8.0 * ecc2 + 24.0 * t1 * t1) * Math.pow(d, 5.0)
                        / 120.0) / Math.cos(phi)) * RAD_DEG;
                + (5.0 - 2.0 * c1 + 28.0 * t1 - 3.0 * c1 * c1 + 8.0 * ecc2 + 24.0 * t1 * t1) * Math.pow(d, 5.0)
                / 120.0) / Math.cos(phi)) * RAD_DEG;
        newY = (phi
                - n1 * Math.tan(phi) / r1
                  * (d * d / 2.0 - (5.0 + 3.0 * t1 + 10.0 * c1 - 4.0 * c1 * c1 - 9.0 * ecc2) * Math.pow(d, 4.0) / 24.0
                     + (61.0 + 90.0 * t1 + 298.0 * c1 + 45.0 * t1 * t1 - 252.0 * ecc2 - 3.0 * c1 * c1) * Math.pow(d, 6.0)
                       / 72.0)) * RAD_DEG;
                * (d * d / 2.0 - (5.0 + 3.0 * t1 + 10.0 * c1 - 4.0 * c1 * c1 - 9.0 * ecc2) * Math.pow(d, 4.0) / 24.0
                + (61.0 + 90.0 * t1 + 298.0 * c1 + 45.0 * t1 * t1 - 252.0 * ecc2 - 3.0 * c1 * c1) * Math.pow(d, 6.0)
                / 72.0)) * RAD_DEG;
        return new Coordinate(newX, newY);
    }
@@ -335,9 +335,9 @@
        } else
        {
            return a * ((1.0 - ecc / 4.0 - 3.0 * ecc * ecc / 64.0 - 5.0 * ecc * ecc * ecc / 256.0) * y
                        - (3.0 * ecc / 8.0 + 3.0 * ecc * ecc / 32.0 + 45.0 * ecc * ecc * ecc / 1024.0) * Math.sin(2.0 * y)
                        + (15.0 * ecc * ecc / 256.0 + 45.0 * ecc * ecc * ecc / 1024.0) * Math.sin(4.0 * y)
                        - (35.0 * ecc * ecc * ecc / 3072.0) * Math.sin(6.0 * y));
                    - (3.0 * ecc / 8.0 + 3.0 * ecc * ecc / 32.0 + 45.0 * ecc * ecc * ecc / 1024.0) * Math.sin(2.0 * y)
                    + (15.0 * ecc * ecc / 256.0 + 45.0 * ecc * ecc * ecc / 1024.0) * Math.sin(4.0 * y)
                    - (35.0 * ecc * ecc * ecc / 3072.0) * Math.sin(6.0 * y));
        }
    }
@@ -492,6 +492,7 @@
    /**
     * ¥ÑTM2®y¼ÐÂà´«¦ÜTWD97®y¼Ð
     *
     * @param pt TM2¦ì¸m
     * @return ·sªºTWD97®y¼Ð
     */