commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r695567 [1/3] - in /commons/sandbox/flatfile/trunk: ./ src/ src/main/ src/main/antlr/ src/main/java/ src/main/java/com/ src/main/java/com/pgac/ src/main/java/com/pgac/flatfile/ src/main/java/com/pgac/flatfile/dsl/ src/main/java/com/pgac/fla...
Date Mon, 15 Sep 2008 18:14:29 GMT
Author: mbenson
Date: Mon Sep 15 11:14:26 2008
New Revision: 695567

URL: http://svn.apache.org/viewvc?rev=695567&view=rev
Log:
add commons-flatfile to sandbox

Added:
    commons/sandbox/flatfile/trunk/LICENSE.txt   (with props)
    commons/sandbox/flatfile/trunk/NOTICE.txt   (with props)
    commons/sandbox/flatfile/trunk/pom.xml   (with props)
    commons/sandbox/flatfile/trunk/src/
    commons/sandbox/flatfile/trunk/src/main/
    commons/sandbox/flatfile/trunk/src/main/antlr/
    commons/sandbox/flatfile/trunk/src/main/antlr/EntityParser.g
    commons/sandbox/flatfile/trunk/src/main/antlr/EntityTreeParser.g
    commons/sandbox/flatfile/trunk/src/main/java/
    commons/sandbox/flatfile/trunk/src/main/java/com/
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/DynamicField.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/Entity.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityArray.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityCollection.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityCollectionSupport.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityFactory.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityMap.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntitySupport.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/Field.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/FieldOption.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/FieldSupport.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/ImmutableEntity.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/IndexedEntityCollection.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/InputFilteringDynamicField.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/NamedEntityCollection.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/PadJustifyFieldSupport.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/dsl/
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/dsl/ConstantEntityNameStrategy.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/dsl/DefaultEntityNameStrategy.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/dsl/EntityDefinition.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/dsl/EntityNameStrategy.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/dsl/ParserEntityFactory.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/entityfactory/
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/entityfactory/CloningEntityFactory.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/entityfactory/CompositeEntityFactory.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/morph/
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/morph/BaseEntityCollectionReflector.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/morph/ByteArrayToEntityCopier.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/morph/ContainerToIndexedEntityCollectionCopier.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/morph/EntityCollectionReflector.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/morph/EntityInstantiatingReflector.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/morph/EntityToByteArrayConverter.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/morph/FieldOptionConstantConverter.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/morph/IndexedEntityCollectionInstantiatingReflector.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/morph/IndexedEntityCollectionReflector.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/morph/NamedEntityCollectionReflector.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/morph/TextToByteConverter.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/morph/TextToEntityCopier.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/util/
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/util/ApplyOptions.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/util/BasicFilterFactory.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/util/ConcatenatedInputStream.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/util/EmptyArray.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/util/FilterFactory.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/util/RepeatingInputStream.java   (with props)
    commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/util/ThresholdingInputStream.java   (with props)
    commons/sandbox/flatfile/trunk/src/test/
    commons/sandbox/flatfile/trunk/src/test/java/
    commons/sandbox/flatfile/trunk/src/test/java/com/
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/BasicFunctionalityTest.java   (with props)
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/DefaultOptionsTest.java   (with props)
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/DelimiterTest.java   (with props)
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/DynamicFieldTest.java   (with props)
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/EntityArrayLifecycleTest.java   (with props)
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/EntityParserTestBase.java   (with props)
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/FieldOptionsTest.java   (with props)
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/FillerTest.java   (with props)
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/ImmutableTest.java   (with props)
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/LengthCheckTest.java   (with props)
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/RunParser.java   (with props)
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/TypesTest.java   (with props)
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/ValuesTest.java   (with props)
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/basic.test
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/conversion/
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/conversion/Bar.java   (with props)
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/conversion/BasicConversionTest.java   (with props)
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/conversion/ConversionTestBase.java   (with props)
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/conversion/Foo.java   (with props)
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/conversion/NestedConversionTest.java   (with props)
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/conversion/basic.test
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/conversion/nested.test
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/defaultOptions.test
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/delimiter.test
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/dynamicField.test
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/entityarraylifecycle.test
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/fieldOptions.test
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/filler.test
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/immutable.test
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/lengthcheck1.test
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/lengthcheck2.test
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/morph/
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/morph/TextToByteConverterTest.java   (with props)
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/types.test
    commons/sandbox/flatfile/trunk/src/test/java/com/pgac/flatfile/values.test

Added: commons/sandbox/flatfile/trunk/LICENSE.txt
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/LICENSE.txt?rev=695567&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/LICENSE.txt (added)
+++ commons/sandbox/flatfile/trunk/LICENSE.txt Mon Sep 15 11:14:26 2008
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.

Propchange: commons/sandbox/flatfile/trunk/LICENSE.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/flatfile/trunk/NOTICE.txt
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/NOTICE.txt?rev=695567&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/NOTICE.txt (added)
+++ commons/sandbox/flatfile/trunk/NOTICE.txt Mon Sep 15 11:14:26 2008
@@ -0,0 +1,8 @@
+Apache Commons Flatfile
+Copyright 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
+This product includes software developed by
+Permanent General Assurance Corporation (http://www.pgac.com/) Copyright 2006-2008.

Propchange: commons/sandbox/flatfile/trunk/NOTICE.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/flatfile/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/pom.xml?rev=695567&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/pom.xml (added)
+++ commons/sandbox/flatfile/trunk/pom.xml Mon Sep 15 11:14:26 2008
@@ -0,0 +1,148 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+                    http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.commons</groupId>
+    <artifactId>commons-sandbox-parent</artifactId>
+    <version>7</version>
+  </parent>
+  <artifactId>commons-flatfile</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+  <name>Commons Flatfile (Sandbox)</name>
+  <url>http://commons.apache.org/sandbox/flatfile/</url>
+  <inceptionYear>2008</inceptionYear>
+  <description>
+    Commons Flatfile provides multiple complementary mechanisms for working with
+    &quot;flat file&quot; structures in Java.
+  </description>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <version>1.4</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+      <version>2.4</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-collections</groupId>
+      <artifactId>commons-collections</artifactId>
+      <version>3.2.1</version>
+    </dependency>
+    <dependency>
+      <groupId>net.sf.morph</groupId>
+      <artifactId>morph</artifactId>
+      <version>1.1.1</version>
+      <optional>true</optional>
+    </dependency>
+    <dependency>
+      <groupId>antlr</groupId>
+      <artifactId>antlr</artifactId>
+      <version>2.7.7</version>
+      <optional>true</optional>
+    </dependency>
+  </dependencies>
+  <developers>
+    <developer>
+      <id>mbenson</id>
+      <name>Matt Benson</name>
+      <email>mbenson AT apache DOT org</email>
+      <organization>Apache</organization>
+    </developer>
+  </developers>
+  <scm>
+
+  <connection>scm:svn:http://svn.apache.org/repos/asf/commons/sandbox/flatfile/trunk/</connection>
+
+  <developerConnection>scm:svn:https://svn.apache.org/repos/asf/commons/sandbox/flatfile/trunk/</developerConnection>
+
+  <url>http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/</url>
+  </scm>
+  <build>
+    <testResources>
+      <testResource> 
+        <directory>src/test/java/</directory>
+        <filtering>false</filtering>
+        <excludes>
+          <exclude>**/*.java</exclude>
+        </excludes>
+      </testResource>
+    </testResources>
+    <plugins>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>antlr-maven-plugin</artifactId>
+        <configuration>
+          <!--
+            Comma separated list of grammar files or pattern grammar files
+            By default, grammar file(s) is in ${basedir}/src/main/antlr
+          -->
+          <grammars>EntityParser.g,EntityTreeParser.g</grammars>
+        </configuration>
+        <executions>
+          <execution>
+            <goals>
+              <goal>generate</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  <distributionManagement>
+    <site>
+      <id>website</id>
+      <name>Apache Website</name>
+      <url>scp://people.apache.org/www/commons.apache.org/sandbox/flatfile/</url>
+    </site>
+  </distributionManagement>
+
+  <!-- Compiler source and target JVM (see parent pom) -->
+  <properties>
+    <maven.compile.source>1.5</maven.compile.source>
+    <maven.compile.target>1.5</maven.compile.target>
+    <commons.componentid>flatfile</commons.componentid>
+  </properties>
+  <reporting>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-pmd-plugin</artifactId>
+        <version>2.3</version>
+        <configuration>
+          <targetJdk>1.5</targetJdk>
+        </configuration>
+      </plugin>
+    </plugins>
+  </reporting>
+
+</project>

Propchange: commons/sandbox/flatfile/trunk/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/flatfile/trunk/src/main/antlr/EntityParser.g
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/antlr/EntityParser.g?rev=695567&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/antlr/EntityParser.g (added)
+++ commons/sandbox/flatfile/trunk/src/main/antlr/EntityParser.g Mon Sep 15 11:14:26 2008
@@ -0,0 +1,322 @@
+header {
+package com.pgac.flatfile.dsl;
+
+import java.io.IOException;
+import java.util.Map;
+
+import com.pgac.flatfile.*;
+}
+
+class EntityParser extends Parser;
+options {
+	k = 2;
+	defaultErrorHandler = false;
+	buildAST = true;
+	exportVocab = Entity;
+//	codeGenBitsetTestThreshold=999;
+}
+
+tokens {
+	ROOT; CHECK; VALUE; ALL; FIELD; LENGTH; ARRAY; IMMUTABLE; MAP; PROTOTYPE; OPTIONS; MIN; MAX;
+}
+
+/* public */ parse
+	:	( optionBlock )*
+		(	explicitAssign
+			( lengthcheck )?
+		)+ EOF!
+		{ ## = #([ROOT, "root"], ##); }
+	;
+
+protected optionBlock
+	:	o:OPTION_BLOCK^ { #o.setType(OPTIONS); }
+		( entityOption )+
+		SEMI!
+	;
+
+protected explicitAssign
+	:	IDENT entity { ## = #([ASSIGN, "="], ##); }
+	;
+
+protected anonymousAssign
+	:	ANON entity { ## = #([ASSIGN, "="], ##); }
+	;
+
+protected lengthcheck
+	:	c:COLON { #c.setType(CHECK); } length
+	;
+
+protected entity
+{ String junk = null; }
+	:	valueOnlyEntity
+	|	junk=typeRefEntity
+	|	fieldOrMapEntity
+	;
+
+protected valueOnlyEntity
+{ AST ast = null; }
+	:	explicitValue { ## = #([FIELD, "field"], ##); ast = ##; }
+		( immutable )? ( a:array[ast]! { ## = #a; } )?
+	;
+
+protected typeRefEntity returns [String name]
+{ AST ast = null; }
+	:	(	t:TYPEREF^ { name = t.getText(); }
+			( entityOptions )?
+			( value )?
+		) { ast = ##; }
+		( a:array[ast]! { ## = #a; } )?
+	;
+
+protected fieldOrMapEntity
+{ AST ast = null; }
+	:	( field | map ) { ast = ##; }
+		( a:array[ast]! { ## = #a; } )?
+	;
+
+protected array[AST p]
+	:	a:LBRACK^ { #a.setType(ARRAY); }
+		( arrayLength )?
+		RBRACK!
+		{ ##.addChild(#([PROTOTYPE, "prototype"], p)); }
+		( o:entityOptions! { ##.addChild(#o); } )?
+		( v:value! { ##.addChild(#v); } )?
+	;
+
+protected value
+	:	( fillValue | explicitValue )
+		( immutable )?
+	;
+
+protected fillValue
+	:	c:CHAR_LITERAL STAR! { #c.setType(ALL); }
+	;
+
+protected explicitValue
+	:	c:CHAR_LITERAL { #c.setType(VALUE); }
+	|	s:STRING_LITERAL { #s.setType(VALUE); }
+	;
+
+protected immutable
+	:	b:BANG { #b.setType(IMMUTABLE); }
+	;
+
+protected field
+	:	LPAREN! ( arrayLength | unboundedDynamicField ) RPAREN!
+		( entityOptions )?
+		( value )?
+		{ ## = #([FIELD, "field"], ##); }
+	;
+
+protected map
+	:	m:LCURLY^ { #m.setType(MAP); }
+		mapChild ( ( COMMA! )? mapChild )* RCURLY!
+		( entityOptions )?
+		( value )?
+	;
+
+protected mapChild
+	:	explicitAssign
+	|	anonymousAssign
+	|	implicitTypeAssign
+	;
+
+protected implicitTypeAssign
+{ String name = null; }
+	:	name=typeRefEntity
+		{ ## = #([ASSIGN], [IDENT, name], ##); }
+	;
+
+protected arrayLength
+	:	n:NUMBER { #n.setType(MIN); }
+		RANGE^
+		( n2:NUMBER { #n2.setType(MAX); } )?
+	|	RANGE^ n3:NUMBER { #n3.setType(MAX); }
+	|	length
+	;
+
+protected unboundedDynamicField
+	:	s:STAR^ { #s.setType(RANGE); }
+	;
+
+protected length
+	:	n:NUMBER { #n.setType(LENGTH); }
+	;
+
+protected entityOptions
+	:	( entityOption )+
+		{ ## = #([OPTIONS, "options"], ##); }
+	;
+
+protected entityOption
+	:	( IDENT | STRING_LITERAL | CHAR_LITERAL | NUMBER )
+		ASSIGN ^
+		( IDENT | STRING_LITERAL | CHAR_LITERAL | NUMBER )
+	;
+
+//-------------------------------------------------------
+class EntityLexer extends Lexer;
+
+options {
+	k = 2;
+    charVocabulary='\u0003'..'\uFFFF'; // allow ascii
+}
+
+SEMI : ';' ;
+COMMA : ',';
+LPAREN : '(' ;
+RPAREN : ')' ;
+LCURLY : '{' ;
+RCURLY : '}' ;
+LBRACK : '[' ;
+RBRACK : ']' ;
+STAR : '*' ;
+ANON : '?' ;
+COLON : ':' ;
+BANG : '!' ;
+ASSIGN : '=';
+RANGE : "..";
+WS:	( ' '
+	| '\t'
+	| '\f'
+	| NL
+	) {$setType(Token.SKIP);}
+	;
+
+// Single-line comments
+SL_COMMENT
+	:	"//"
+		(~('\n'|'\r'))* (NL)?
+		{$setType(Token.SKIP);}
+	;
+
+// multiple-line comments
+ML_COMMENT
+	:	"/*"
+		(	/*	'\r' '\n' can be matched in one alternative or by matching
+				'\r' in one iteration and '\n' in another.  I am trying to
+				handle any flavor of newline that comes in, but the language
+				that allows both "\r\n" and "\r" and "\n" to all be valid
+				newline is ambiguous.  Consequently, the resulting grammar
+				must be ambiguous.  I'm shutting this warning off.
+			 */
+			options {
+				generateAmbigWarnings=false;
+			}
+		:
+			{ LA(2)!='/' }? '*'
+		|	NL
+		|	~('*'|'\n'|'\r')
+		)*
+		"*/"
+		{$setType(Token.SKIP);}
+	;
+
+protected
+NL : ( {LA(2) == '\n'}? '\r' '\n'
+       | '\r'
+       | '\n'
+     )
+     { newline(); }
+   ;
+
+// an identifier.  Note that testLiterals is set to true!  This means
+// that after we match the rule, we look in the literals table to see
+// if it's a literal or really an identifer
+IDENT : PTIDENT ;
+
+protected
+PTIDENT
+options { testLiterals = true; }
+	:	('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'_'|'0'..'9'|'$'|'/'|'*')*
+	;
+
+TYPEREF : '$' i:PTIDENT { $setText(i.getText()); } ;
+
+OPTION_BLOCK : '@' i:PTIDENT { $setText(i.getText()); } ;
+
+NUMBER : ('0'..'9')+ ;
+
+// character literals
+CHAR_LITERAL : '\'' c:CHAR_BODY '\'' { $setText(c.getText()); } ;
+
+protected
+CHAR_BODY : ESC | ~('\''|'\n'|'\r'|'\\') ;
+
+// string literals
+STRING_LITERAL
+	:	'"' s:STRING_BODY '"' { $setText(s.getText()); }
+	;
+
+protected
+STRING_BODY
+{ StringBuffer sb = new StringBuffer(); }
+	:	(e:ESC { sb.append(e.getText()); }
+		|	o:~('"'|'\\'|'\n'|'\r') { sb.append(o); } )*
+		{ $setText(sb.toString()); }
+	;
+
+// escape sequence -- note that this is protected; it can only be called
+//   from another lexer rule -- it will not ever directly return a token to
+//   the parser
+// There are various ambiguities hushed in this rule.  The optional
+// '0'...'9' digit matches should be matched here rather than letting
+// them go back to STRING_LITERAL to be matched.  ANTLR does the
+// right thing by matching immediately; hence, it's ok to shut off
+// the FOLLOW ambig warnings.
+protected
+ESC
+{ char c = 0; }
+	:	'\\'
+		(	'n' { $setText("\n"); }
+		|	'r' { $setText("\r"); }
+		|	't' { $setText("\t"); }
+		|	'b' { $setText("\b"); }
+		|	'f' { $setText("\f"); }
+		|	'"' { $setText("\""); }
+		|	'\'' { $setText("\'"); }
+		|	'\\' { $setText("\\"); }
+		|	c=UNICODE { $setText(Character.toString(c)); }
+		|	c=OCTAL { $setText(Character.toString(c)); }
+		)
+	;
+
+protected
+UNICODE returns [char c = 0;]
+	:	('u')+
+		HEX_DIGIT { c <<= 4; c |= Character.digit(LA(0), 16); }
+		HEX_DIGIT { c <<= 4; c |= Character.digit(LA(0), 16); }
+		HEX_DIGIT { c <<= 4; c |= Character.digit(LA(0), 16); }
+		HEX_DIGIT { c <<= 4; c |= Character.digit(LA(0), 16); }
+	;
+
+protected
+OCTAL returns [char c = 0;]
+	:	'0'..'3' { c <<= 3; c |= Character.digit(LA(0), 8); }
+		(
+			options {
+				warnWhenFollowAmbig = false;
+			}
+		:	'0'..'7' { c <<= 3; c |= Character.digit(LA(0), 8); }
+			(
+				options {
+					warnWhenFollowAmbig = false;
+				}
+			:	'0'..'7' { c <<= 3; c |= Character.digit(LA(0), 8); }
+			)?
+		)?
+	|	'4'..'7' { c <<= 3; c |= Character.digit(LA(0), 8); }
+		(
+			options {
+				warnWhenFollowAmbig = false;
+			}
+		:	'0'..'7' { c <<= 3; c |= Character.digit(LA(0), 8); }
+		)?
+	;
+
+// hexadecimal digit (again, note it's protected!)
+protected
+HEX_DIGIT returns [int i = 0;]
+	:	('0'..'9'|'A'..'F'|'a'..'f')
+		{ i = Character.digit(LA(0), 16); }
+	;

Added: commons/sandbox/flatfile/trunk/src/main/antlr/EntityTreeParser.g
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/antlr/EntityTreeParser.g?rev=695567&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/antlr/EntityTreeParser.g (added)
+++ commons/sandbox/flatfile/trunk/src/main/antlr/EntityTreeParser.g Mon Sep 15 11:14:26 2008
@@ -0,0 +1,212 @@
+header {
+package com.pgac.flatfile.dsl;
+
+import java.io.IOException;
+
+import java.util.List;
+import java.util.Stack;
+import java.util.Iterator;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import com.pgac.flatfile.*;
+import com.pgac.flatfile.util.ApplyOptions;
+}
+
+class EntityTreeParser extends TreeParser;
+options {
+	importVocab = Entity;
+	defaultErrorHandler = false;
+	codeGenBitsetTestThreshold=999;
+}
+
+{
+	private ParserEntityFactory entityFactory;
+	private Stack stk = new Stack();
+
+	public synchronized Entity createEntity(EntityDefinition def) {
+		String name = def.getName();
+		if (stk.contains(def.getName())) {
+			throw new IllegalStateException("Circular reference detected for entity type " + name);
+		}
+		stk.push(def.getName());
+		try {
+			Entity result = entity(def.getAst());
+			runChecks(def, result);
+			return result;
+		} catch (ANTLRException e) {
+			throw new RuntimeException(e);
+		} finally {
+			Object x = stk.pop();
+			if (!x.equals(def.getName())) {
+				throw new IllegalStateException("Stack out of balance; encountered " + x);
+			}
+		}
+	}
+
+	public void setEntityFactory(ParserEntityFactory entityFactory) {
+		this.entityFactory = entityFactory;
+	}
+
+	private void runChecks(EntityDefinition def, Entity e) {
+		for (Iterator it = def.getChecks().iterator(); it.hasNext();) {
+			AST check = (AST) it.next();
+			switch (check.getType()) {
+				case LENGTH :
+					int expected = Integer.parseInt(check.getText());
+					int actual = e.length();
+					if (expected != actual) {
+						throw new IllegalStateException(
+								"expected entity " + def.getName() + " length=" + expected + "; actually " + actual);
+					}
+					break;
+				default :
+					throw new IllegalArgumentException("Unknown check: " + check);
+			}
+		}
+	}
+
+	private byte[] getBytes(String s) {
+		try {
+			return s.getBytes("UTF-8");
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
+	}
+
+}
+
+/* public */ load
+{ List checks = new ArrayList(); String name = null; }
+	:	#(	ROOT
+			( defaultOptions )*
+			(	#(	ASSIGN name=name e:. )
+				(
+					CHECK c:. {
+						checks.add(c);
+					} 
+				)*
+				{
+					EntityDefinition ed = new EntityDefinition(name, e);
+					if (!checks.isEmpty()) {
+						ed.setChecks(checks);
+						checks = new ArrayList();
+					}
+					entityFactory.add(name, ed);
+				}
+			)+
+		)
+	;
+
+protected defaultOptions
+{ HashMap m = new HashMap(); String key = null, value = null; }
+	:	#(	o:OPTIONS
+			( #( ASSIGN key=optionKV value=optionKV { m.put(key, value); } ) )+
+		) { entityFactory.setDefaultOptions(o.getText(), m); }
+	;
+
+protected entity returns [Entity e = null]
+	:	e=array | e=field | e=map | e=typeRef
+	;
+
+protected name returns [String s = null]
+	:	i:IDENT { s = i.getText(); }
+	|	ANON //let remain null
+	;
+
+protected typeRef returns [Entity e = null]
+{
+	if (entityFactory == null) {
+		throw new IllegalStateException("entityFactory is null");
+	}
+}
+	:	#(t:TYPEREF { e = entityFactory.getEntity(t.getText()); }
+			( entityOptions[e] )?
+			( e=value[e] )?
+		)
+	;
+
+protected array returns [IndexedEntityCollection a = null]
+{ Entity prototype = null, e = null; Integer len = null, min = null, max = null; }
+	:	#( ARRAY
+			(	l:LENGTH { len = Integer.valueOf(l.getText()); }
+			|	#(RANGE
+					( m:MIN { min = Integer.valueOf(m.getText()); } )?
+					( n:MAX { max = Integer.valueOf(n.getText()); } )?
+				)
+			)?
+			#(PROTOTYPE prototype=entity)
+			{	a = new EntityArray(prototype);
+				if (len != null) {
+					((EntityArray) a).setSize(len.intValue());
+				} else {
+					if (min != null) {
+						((EntityArray) a).setMinimumSize(min.intValue());
+					}
+					if (max != null) {
+						((EntityArray) a).setMaximumSize(max.intValue());
+					}
+				}
+			}
+			( entityOptions[a] )?
+			( e=value[a] { a = (IndexedEntityCollection) e; } )?
+		)
+	;
+
+protected value[Entity e] returns [Entity result = e]
+	:	(	a:ALL { e.fill(getBytes(a.getText())[0]); }
+		|	v:VALUE { e.setValue(getBytes(v.getText())); }
+		)
+		( result=immutable[e] )?
+	;
+exception
+	catch [IOException exc] {
+		throw new RuntimeException(exc);
+	}
+
+protected field returns [Entity e = null]
+	:	#( FIELD e=fieldDef )
+	;
+
+protected fieldDef returns [Entity e = null]
+	:	(	l:LENGTH { e = entityFactory.createField(Integer.parseInt(l.getText())); }
+			( entityOptions[e] )?
+			( e=value[e] )?
+		|	v:VALUE { e = entityFactory.createField(getBytes(v.getText())); }
+			( e=immutable[e] )?
+		|	#(	RANGE { e = entityFactory.createDynamicField(); }
+				( n:MIN { ((DynamicField) e).getBounds().setMinimum(Integer.parseInt(n.getText())); } )?
+				( x:MAX { ((DynamicField) e).getBounds().setMaximum(Integer.parseInt(x.getText())); } )?
+			)
+			( v2:VALUE { e.setValue(getBytes(v2.getText())); } )?
+		)
+	;
+
+protected map returns [NamedEntityCollection m = new EntityMap()]
+{ String name = null; Entity temp = null; }
+	:	#(	MAP
+			( #(ASSIGN name=name temp=entity { ((EntityMap) m).add(name, temp); } ) )+
+			( entityOptions[m] )?
+			( temp=value[m] { m = (NamedEntityCollection) temp; } )?
+		)
+	;
+
+protected immutable[Entity e] returns [Entity result = null]
+	:	IMMUTABLE { result = ImmutableEntity.getInstance(e); }
+	;
+
+protected entityOptions[Entity e]
+	:	#( OPTIONS ( entityOption[e] )+ )
+	;
+
+protected entityOption[Entity e]
+{ String key = null, value = null; }
+	:	#( ASSIGN key=optionKV value=optionKV { ApplyOptions.apply(e, key, value); } )
+	;
+
+protected optionKV returns [String result = null]
+	:	c:CHAR_LITERAL { result = c.getText(); }
+	|	s:STRING_LITERAL { result = s.getText(); }
+	|	n:NUMBER { result = n.getText(); }
+	|	i:IDENT { result = i.getText(); }
+	;
\ No newline at end of file

Added: commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/DynamicField.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/DynamicField.java?rev=695567&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/DynamicField.java (added)
+++ commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/DynamicField.java Mon Sep 15 11:14:26 2008
@@ -0,0 +1,367 @@
+package com.pgac.flatfile;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.util.Arrays;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.ObjectUtils;
+import org.apache.commons.lang.Validate;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+
+import com.pgac.flatfile.util.ThresholdingInputStream;
+
+/**
+ * Dynamically-resizable field. Supports pad/justify, but only relevant when an assigned value is too small for the
+ * field AND underflow == IGNORE.
+ */
+public class DynamicField extends PadJustifyFieldSupport {
+    /**
+     * Bounds
+     */
+    public static class Bounds implements Serializable {
+        /**
+         * Immutable range of all valid lengths.
+         */
+        public static final Bounds ALL_VALID = new Bounds() {
+            private static final long serialVersionUID = -2039931927562380883L;
+
+            {
+                this.minimum = 0;
+                this.maximum = Integer.MAX_VALUE;
+            }
+
+            /**
+             * {@inheritDoc}
+             */
+            public void setMinimum(int minimum) {
+            }
+
+            /**
+             * {@inheritDoc}
+             */
+            public void setMaximum(int maximum) {
+            }
+        };
+
+        /**
+         * Default bounds.
+         */
+        public static final Bounds DEFAULT = ALL_VALID;
+
+        private static final long serialVersionUID = 1L;
+
+        /** Minimum */
+        protected int minimum;
+
+        /** Maximum */
+        protected int maximum;
+
+        /**
+         * Create a new Bounds.
+         * @param minimum
+         * @param maximum
+         */
+        public Bounds(int minimum, int maximum) {
+            setMinimum(minimum);
+            setMaximum(maximum);
+        }
+
+        private Bounds(Bounds example) {
+            this(example.getMinimum(), example.getMaximum());
+        }
+
+        private Bounds() {
+        }
+
+        /**
+         * Get the maximum.
+         * @return int
+         */
+        public int getMaximum() {
+            return maximum;
+        }
+
+        /**
+         * Set the maximum.
+         * @param maximum int
+         */
+        public void setMaximum(int maximum) {
+            Validate.isTrue(maximum <= ALL_VALID.getMaximum(),
+                    "maximum value > " + ALL_VALID.getMaximum(), maximum);
+            this.maximum = maximum;
+        }
+
+        /**
+         * Get the minimum.
+         * @return int
+         */
+        public int getMinimum() {
+            return minimum;
+        }
+
+        /**
+         * Set the minimum.
+         * @param minimum int
+         */
+        public void setMinimum(int minimum) {
+            Validate.isTrue(minimum >= ALL_VALID.getMinimum(),
+                    "minimum value < " + ALL_VALID.getMinimum(), minimum);
+            this.minimum = minimum;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public boolean equals(Object o) {
+            if (o == this) {
+                return true;
+            }
+            if (!(o instanceof Bounds)) {
+                return false;
+            }
+            Bounds ob = (Bounds) o;
+            return ob.getMaximum() == getMaximum()
+                    && ob.getMinimum() == getMinimum();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public int hashCode() {
+            return new HashCodeBuilder().append(minimum).append(maximum)
+                    .toHashCode();
+        }
+
+        /**
+         * Validate a field and value against these Bounds.
+         * @param value to validate
+         * @param df field to validate
+         */
+        public void validate(byte[] value, DynamicField df) {
+            df.getUnderflow().check(value, getMinimum());
+            df.getOverflow().check(value, getMaximum());
+        }
+    }
+
+    private static final long serialVersionUID = -319053179741813727L;
+
+    private Bounds bounds;
+    private Overflow overflow;
+    private Underflow underflow;
+    private transient ByteArrayOutputStream buffer;
+
+    /**
+     * Create a new DynamicField.
+     */
+    public DynamicField() {
+        this(new Bounds(Bounds.DEFAULT));
+    }
+
+    /**
+     * Create a new DynamicField.
+     * @param bounds bounds
+     */
+    public DynamicField(Bounds bounds) {
+        setBounds(bounds);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.pgac.fixedlength.Entity#getValue()
+     */
+    public synchronized byte[] getValue() {
+        initialize(ArrayUtils.EMPTY_BYTE_ARRAY);
+        return buffer.toByteArray();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.pgac.fixedlength.Entity#length()
+     */
+    public int length() {
+        initialize(ArrayUtils.EMPTY_BYTE_ARRAY);
+        return buffer.size();
+    }
+
+    /**
+     * Read up to <code>maximumLength</code> bytes from the specified InputStream or stop at EOF. This will rarely be
+     * what you want. Instead, consider using InputFilteringDynamicField. In the case that &lt;
+     * <code>minimumLength</code> bytes are available from <code>is</code> the <code>justify</code> and
+     * <code>pad</code> options come into play.
+     * @param is the InputStream from which to read data.
+     * @throws IOException on problems with I/O, duh...
+     */
+    public synchronized void readFrom(InputStream is) throws IOException {
+        initialize();
+        buffer.reset();
+        IOUtils.copy(new ThresholdingInputStream(is, getBounds().getMaximum()),
+                buffer);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.pgac.fixedlength.Entity#setValue(byte[])
+     */
+    public synchronized void setValue(byte[] b) {
+        getBounds().validate(b, this);
+        initialize();
+        iSetValue(b);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.pgac.fixedlength.Entity#writeTo(java.io.OutputStream)
+     */
+    public synchronized void writeTo(OutputStream os) throws IOException {
+        initialize(ArrayUtils.EMPTY_BYTE_ARRAY);
+        buffer.writeTo(os);
+    }
+
+    /**
+     * Get the overflow.
+     * @return Overflow
+     */
+    public Overflow getOverflow() {
+        return overflow == null ? Overflow.ERROR : overflow;
+    }
+
+    /**
+     * Set the overflow.
+     * @param overflow Overflow
+     */
+    public void setOverflow(Overflow overflow) {
+        this.overflow = overflow;
+    }
+
+    /**
+     * Get the underflow.
+     * @return Underflow
+     */
+    public Underflow getUnderflow() {
+        return underflow == null ? Underflow.ERROR : underflow;
+    }
+
+    /**
+     * Set the underflow.
+     * @param underflow Underflow
+     */
+    public void setUnderflow(Underflow underflow) {
+        this.underflow = underflow;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.lang.Object#hashCode()
+     */
+    public int hashCode() {
+        return new HashCodeBuilder().append(getBounds()).append(getValue())
+                .toHashCode();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    public boolean equals(Object other) {
+        if (other == this) {
+            return true;
+        }
+        if (!(other instanceof DynamicField)) {
+            return false;
+        }
+        DynamicField odf = (DynamicField) other;
+        return ObjectUtils.equals(odf.getBounds(), getBounds())
+                && Arrays.equals(odf.getValue(), getValue());
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.pgac.fixedlength.PadJustifyFieldSupport#getPadJustifyLength()
+     */
+    protected int getPadJustifyLength() {
+        return getBounds().getMinimum();
+    }
+
+    /**
+     * Protected inner setValue
+     * @param value byte[]
+     */
+    protected synchronized void iSetValue(byte[] value) {
+        super.setValue(value);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.pgac.fixedlength.EntitySupport#clone()
+     */
+    public Object clone() {
+        DynamicField result = (DynamicField) super.clone();
+        result.setBounds(new Bounds(getBounds()));
+        result.buffer = null;
+        result.setValue(getValue());
+        return result;
+    }
+
+    private synchronized void writeObject(ObjectOutputStream out)
+            throws IOException {
+        out.writeObject(getBounds());
+        initialize(ArrayUtils.EMPTY_BYTE_ARRAY);
+        out.write(buffer.size());
+        buffer.writeTo(out);
+    }
+
+    private void readObject(ObjectInputStream in) throws IOException,
+            ClassNotFoundException {
+        setBounds((Bounds) in.readObject());
+        int n = in.read();
+        initialize();
+        if (n > 0) {
+            IOUtils.copy(new ThresholdingInputStream(in, n), buffer);
+        }
+    }
+
+    private void initialize() {
+        initialize(null);
+    }
+
+    private synchronized void initialize(byte[] value) {
+        if (buffer == null) {
+            buffer = new ByteArrayOutputStream();
+            if (value != null) {
+                iSetValue(value);
+            }
+        }
+    }
+
+    /**
+     * Get the bounds.
+     * @return Bounds
+     */
+    public Bounds getBounds() {
+        return bounds;
+    }
+
+    /**
+     * Set the bounds.
+     * @param bounds Bounds
+     */
+    public void setBounds(Bounds bounds) {
+        Validate.notNull(bounds, "bounds cannot be null");
+        this.bounds = bounds;
+    }
+}

Propchange: commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/DynamicField.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/Entity.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/Entity.java?rev=695567&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/Entity.java (added)
+++ commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/Entity.java Mon Sep 15 11:14:26 2008
@@ -0,0 +1,72 @@
+package com.pgac.flatfile;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+
+/**
+ * Represents a record or field.
+ */
+public interface Entity extends Cloneable, Serializable {
+    /**
+     * Get the length of this Entity.
+     * @return int
+     */
+    int length();
+
+    /**
+     * Read value from an InputStream.
+     * @param is
+     * @throws IOException
+     */
+    void readFrom(InputStream is) throws IOException;
+
+    /**
+     * Write value to an OutputStream.
+     * @param os
+     * @throws IOException
+     */
+    void writeTo(OutputStream os) throws IOException;
+
+    /**
+     * Clone oneself.
+     * @return a deep (or otherwise "safe") copy of this Entity.
+     */
+    Object clone();
+
+    /**
+     * Fill this entity's value with all <code>b</code>.
+     * @param b
+     * @throws IOException
+     */
+    void fill(byte b) throws IOException;
+
+    /**
+     * Get the value of this Entity.
+     * @return byte[]
+     */
+    byte[] getValue();
+
+    /**
+     * Get a subset of this Entity's value.
+     * @param offset
+     * @param length
+     * @return byte[]
+     */
+    byte[] getValue(int offset, int length);
+
+    /**
+     * Set this Entity's value.
+     * @param b byte[]
+     */
+    void setValue(byte[] b);
+
+    /**
+     * Set this Entity's value to a subset of the specified byte[].
+     * @param b byte[]
+     * @param offset int
+     * @param length int
+     */
+    void setValue(byte[] b, int offset, int length);
+}

Propchange: commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/Entity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityArray.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityArray.java?rev=695567&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityArray.java (added)
+++ commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityArray.java Mon Sep 15 11:14:26 2008
@@ -0,0 +1,228 @@
+package com.pgac.flatfile;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Entity collection with the following approach:  a size (number of children)
+ * and a prototypical child are assigned.  The prototype child is cloned
+ * <code>size</code> times, and these clones become the indexed child entities.
+ */
+public class EntityArray extends EntityCollectionSupport implements
+        IndexedEntityCollection {
+    private static final long serialVersionUID = 8716199462287161060L;
+    private int size = -1;
+    private int minimumSize = 0;
+    private int maximumSize = Integer.MAX_VALUE;
+    private boolean resizable = false;
+    private List children;
+    private Entity prototype;
+
+    /**
+     * Create a new EntityArray.
+     */
+    public EntityArray() {
+        // default constructor
+    }
+
+    /**
+     * Create a new IndexedEntityCollection.
+     * @param size
+     */
+    public EntityArray(int size) {
+        setSize(size);
+    }
+
+    /**
+     * Create a new EntityArray with the specified prototype.
+     * @param prototype
+     */
+    public EntityArray(Entity prototype) {
+        setPrototype(prototype);
+    }
+
+    /**
+     * Create a new IndexedEntityCollection.
+     * @param prototype
+     * @param size
+     */
+    public EntityArray(Entity prototype, int size) {
+        this(prototype);
+        setSize(size);
+    }
+
+    /**
+     * Get the child at the specified index.
+     * @param index int
+     * @return Entity
+     */
+    public Entity getChild(int index) {
+        initialize();
+        return (Entity) children.get(index);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.pgac.fixedlength.EntityCollection#getChildren()
+     */
+    public synchronized Collection getChildren() {
+        initialize();
+        return Collections.unmodifiableCollection(children);
+    }
+
+    /**
+     * Get the prototype.
+     * @return Entity.
+     */
+    public synchronized Entity getPrototype() {
+        return prototype;
+    }
+
+    /**
+     * Set the prototype.
+     * @param prototype The Entity prototype to set.
+     */
+    public synchronized void setPrototype(Entity prototype) {
+        if (prototype == null) {
+            throw new IllegalArgumentException("prototype Entity was null");
+        }
+        this.prototype = prototype;
+    }
+
+    /**
+     * Set the size.
+     * @param size the size to set.
+     */
+    public synchronized void setSize(int size) {
+        if (this.size >= 0 && !isResizable()) {
+            if (size == this.size()) {
+                return;
+            }
+            throw new IllegalStateException("size already set");
+        }
+        if (size < minimumSize || size > maximumSize) {
+            throw new IllegalArgumentException("illegal collection size: "
+                    + size + "; should be <= " + maximumSize + " and >= "
+                    + minimumSize);
+        }
+        this.size = size;
+    }
+
+    /**
+     * Get the size (# of child elements) of this IndexedEntityCollection.
+     * @return int
+     */
+    public synchronized int size() {
+        return size;
+    }
+
+    /**
+     * Learn whether this EntityArray's size can be set.
+     * @return
+     */
+    public synchronized boolean isSizable() {
+        return size == -1 || isResizable();
+    }
+
+    /**
+     * Clone this EntityArray.
+     * @return new EntityArray
+     */
+    public synchronized Object clone() {
+        EntityArray result = (EntityArray) super.clone();
+        if (children != null) {
+            result.children = new ArrayList();
+            for (Iterator iter = children.iterator(); iter.hasNext();) {
+                result.children.add(((Entity) iter.next()).clone());
+            }
+        }
+        return result;
+    }
+
+    private synchronized void initialize() {
+        if (children != null) {
+            return;
+        }
+        if (size < 0) {
+            throw new IllegalStateException("EntityArray size not set");
+        }
+        if (size == 0) {
+            children = Collections.EMPTY_LIST;
+            return;
+        }
+        if (prototype == null) {
+            throw new IllegalStateException("Prototype child entity not set");
+        }
+        children = new ArrayList(size);
+        adjustSize();
+    }
+
+    private synchronized void adjustSize() {
+        if (children.size() > size) {
+            children.subList(size, children.size()).clear();
+            return;
+        }
+        for (int i = children.size(); i < size; i++) {
+            children.add(prototype.clone());
+        }
+    }
+
+    /**
+     * Get the int maximumSize.
+     * @return int
+     */
+    public synchronized int getMaximumSize() {
+        return maximumSize;
+    }
+
+    /**
+     * Set the int maximumSize.
+     * @param maximumSize int
+     */
+    public synchronized void setMaximumSize(int maximumSize) {
+        if (maximumSize > Integer.MAX_VALUE || maximumSize < getMinimumSize()) {
+            throw new IllegalArgumentException(Integer.toString(maximumSize));
+        }
+        this.maximumSize = maximumSize;
+    }
+
+    /**
+     * Get the int minimumSize.
+     * @return int
+     */
+    public synchronized int getMinimumSize() {
+        return minimumSize;
+    }
+
+    /**
+     * Set the int minimumSize.
+     * @param minimumSize int
+     */
+    public synchronized void setMinimumSize(int minimumSize) {
+        if (minimumSize < 0 || minimumSize > getMaximumSize()) {
+            throw new IllegalArgumentException(Integer.toString(minimumSize));
+        }
+        this.minimumSize = minimumSize;
+    }
+
+    /**
+     * Get the boolean resizable.
+     * @return boolean
+     */
+    public boolean isResizable() {
+        return resizable;
+    }
+
+    /**
+     * Set the boolean resizable.
+     * @param resizable boolean
+     */
+    public void setResizable(boolean resizable) {
+        this.resizable = resizable;
+    }
+
+}

Propchange: commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityArray.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityCollection.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityCollection.java?rev=695567&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityCollection.java (added)
+++ commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityCollection.java Mon Sep 15 11:14:26 2008
@@ -0,0 +1,15 @@
+package com.pgac.flatfile;
+
+import java.util.Collection;
+
+/**
+ * An entity that is a collection of child entities.
+ */
+public interface EntityCollection extends Entity {
+
+    /**
+     * Get the children.
+     * @return Collection<Entity>.
+     */
+    Collection getChildren();
+}

Propchange: commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityCollection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityCollectionSupport.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityCollectionSupport.java?rev=695567&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityCollectionSupport.java (added)
+++ commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityCollectionSupport.java Mon Sep 15 11:14:26 2008
@@ -0,0 +1,177 @@
+package com.pgac.flatfile;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Iterator;
+
+import org.apache.commons.lang.ArrayUtils;
+
+/**
+ * Implementation of common operations for an EntityCollection.
+ */
+public abstract class EntityCollectionSupport extends EntitySupport implements
+        EntityCollection {
+    private static final byte[] DEFAULT_DELIMITER = ArrayUtils.EMPTY_BYTE_ARRAY;
+    private byte[] delim = DEFAULT_DELIMITER;
+    private boolean delimAfter = true;
+    private boolean suppressEmptyChildren = true;
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.pgac.fixedlength.Entity#length()
+     */
+    public final synchronized int length() {
+        int result = 0;
+        for (Iterator it = getChildren().iterator(); it.hasNext();) {
+            Entity e = (Entity) it.next();
+            if (shouldSuppress(e)) {
+                continue;
+            }
+            result += e.length();
+            if (it.hasNext() || isDelimAfter()) {
+                result += getDelim().length;
+            }
+        }
+        return result;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.pgac.fixedlength.Entity#readFrom(java.io.InputStream)
+     */
+    public final synchronized void readFrom(InputStream is) throws IOException {
+        for (Iterator it = getChildren().iterator(); it.hasNext();) {
+            Entity e = (Entity) it.next();
+            if (shouldSuppress(e)) {
+                continue;
+            }
+            e.readFrom(is);
+            if (it.hasNext() || isDelimAfter()) {
+                for (int i = 0; i < getDelim().length; i++) {
+                    is.read();
+                }
+            }
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.pgac.fixedlength.Entity#writeTo(java.io.OutputStream)
+     */
+    public final synchronized void writeTo(OutputStream os) throws IOException {
+        for (Iterator it = getChildren().iterator(); it.hasNext();) {
+            Entity e = (Entity) it.next();
+            if (shouldSuppress(e)) {
+                continue;
+            }
+            e.writeTo(os);
+            if (it.hasNext() || isDelimAfter()) {
+                os.write(getDelim());
+            }
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.pgac.fixedlength.Entity#getValue()
+     */
+    public final synchronized byte[] getValue() {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        try {
+            writeTo(baos);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        return baos.toByteArray();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.pgac.fixedlength.Entity#setValue(byte[])
+     */
+    public final synchronized void setValue(byte[] b) {
+        try {
+            readFrom(new ByteArrayInputStream(b));
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     * @see com.pgac.flatfile.EntitySupport#setValue(byte[], int, int)
+     */
+    public final void setValue(byte[] b, int offset, int length) {
+        try {
+            readFrom(new ByteArrayInputStream(b, offset, length));
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * Learn whether a trailing delimiter will be added when a delimiter is being used.
+     * @return boolean.
+     */
+    public boolean isDelimAfter() {
+        return delimAfter;
+    }
+
+    /**
+     * Set whether to add a trailing delimiter when a delimiter is being used.
+     * Default is <code>true</code>.
+     * @param delimAfter The boolean delimAfter to set.
+     */
+    public void setDelimAfter(boolean delimAfter) {
+        this.delimAfter = delimAfter;
+    }
+
+    /**
+     * Get the delimiter to use between children.
+     * @return byte[].
+     */
+    public byte[] getDelim() {
+        return delim;
+    }
+
+    /**
+     * Set the delimiter to use between children.
+     * @param delim The byte[] delimiter to set.
+     */
+    public synchronized void setDelim(byte[] delim) {
+        this.delim = delim == null ? DEFAULT_DELIMITER : delim;
+    }
+
+    /**
+     * Get the boolean suppressEmptyChildren.
+     * @return boolean
+     */
+    public boolean isSuppressEmptyChildren() {
+        return suppressEmptyChildren;
+    }
+
+    /**
+     * Set the boolean suppressEmptyChildren.
+     * @param suppressEmptyChildren boolean
+     */
+    public void setSuppressEmptyChildren(boolean suppressEmptyChildren) {
+        this.suppressEmptyChildren = suppressEmptyChildren;
+    }
+
+    /**
+     * Learn whether the specified child should be suppressed.
+     * @param child
+     * @return boolean
+     */
+    protected boolean shouldSuppress(Entity child) {
+        return isSuppressEmptyChildren() && child.length() == 0;
+    }
+}

Propchange: commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityCollectionSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityFactory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityFactory.java?rev=695567&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityFactory.java (added)
+++ commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityFactory.java Mon Sep 15 11:14:26 2008
@@ -0,0 +1,15 @@
+package com.pgac.flatfile;
+
+/**
+ * Entity factory interface.
+ */
+public interface EntityFactory {
+
+    /**
+     * Get an Entity.
+     * @param cue an Object that <u>may</u> provide a cue as to what type of Entity is required.
+     * @return Entity.
+     */
+    Entity getEntity(Object cue);
+
+}
\ No newline at end of file

Propchange: commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityMap.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityMap.java?rev=695567&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityMap.java (added)
+++ commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityMap.java Mon Sep 15 11:14:26 2008
@@ -0,0 +1,145 @@
+package com.pgac.flatfile;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.apache.commons.collections.Transformer;
+import org.apache.commons.collections.list.AbstractSerializableListDecorator;
+
+import com.pgac.flatfile.util.EmptyArray;
+
+/**
+ * Basic implementation of NamedEntityCollection.
+ */
+public class EntityMap extends EntityCollectionSupport implements
+        NamedEntityCollection {
+
+    private static final long serialVersionUID = 3162898927743996952L;
+
+    private class ChildrenList extends AbstractSerializableListDecorator {
+        private static final long serialVersionUID = 3241482030276238909L;
+
+        private Transformer t = new Transformer() {
+            public Object transform(Object o) {
+                return o instanceof Entity ? o : getChildMap().get(o);
+            }
+        };
+
+        private ChildrenList() {
+            super(children);
+        }
+
+        public Object get(int index) {
+            return t.transform(super.get(index));
+        }
+
+        public Iterator iterator() {
+            return IteratorUtils.transformedIterator(super.iterator(), t);
+        }
+    }
+
+    /** contains names of mapped children OR the children themselves for unmapped children */
+    private List children;
+
+    /** contains mapped children only */
+    private Map childMap;
+
+    private List exposeChildrenList;
+
+    /**
+     * Add a child.
+     * @param name if null filler element
+     * @param child non-null child Entity
+     */
+    public synchronized void add(String name, Entity child) {
+        if (child == null) {
+            throw new IllegalArgumentException("child entity is null");
+        }
+        if (children == null) {
+            children = new ArrayList();
+            childMap = new HashMap();
+        }
+        if (childMap.containsKey(name)) {
+            throw new IllegalArgumentException("cannot add > 1 child entity '"
+                    + name + "'");
+        }
+        if (name != null) {
+            childMap.put(name, child);
+        }
+        children.add(name == null ? (Object) child : name);
+    }
+
+    /**
+     * Get a map of the children.
+     * @return
+     */
+    public synchronized Map getChildMap() {
+        return childMap == null ? Collections.EMPTY_MAP : Collections
+                .unmodifiableMap(childMap);
+    }
+
+    /**
+     * {@inheritDoc}
+     * @see com.pgac.flatfile.NamedEntityCollection#getChildNames()
+     */
+    public synchronized String[] getChildNames() {
+        return childMap == null ? EmptyArray.STRING : (String[]) childMap
+                .keySet().toArray(new String[childMap.size()]);
+    }
+
+    /**
+     * {@inheritDoc}
+     * @see com.pgac.flatfile.NamedEntityCollection#getChild(java.lang.String)
+     */
+    public Entity getChild(String name) {
+        return (Entity) getChildMap().get(name);
+    }
+
+    /**
+     * {@inheritDoc}
+     * @see com.pgac.flatfile.NamedEntityCollection#hasChild(java.lang.String)
+     */
+    public boolean hasChild(String name) {
+        return getChildMap().containsKey(name);
+    }
+
+    /**
+     * {@inheritDoc}
+     * @see com.pgac.flatfile.EntityCollection#getChildren()
+     */
+    public synchronized Collection getChildren() {
+        if (children == null) {
+            return Collections.EMPTY_LIST;
+        }
+        if (exposeChildrenList == null) {
+            exposeChildrenList = new ChildrenList();
+        }
+        return exposeChildrenList;
+    }
+
+    /**
+     * {@inheritDoc}
+     * @see com.pgac.flatfile.EntitySupport#clone()
+     */
+    public synchronized Object clone() {
+        EntityMap result = (EntityMap) super.clone();
+        result.children = null;
+        result.childMap = null;
+        result.exposeChildrenList = null;
+        if (children != null) {
+            for (Iterator iter = children.iterator(); iter.hasNext();) {
+                Object o = iter.next();
+                String name = o instanceof String ? (String) o : null;
+                Entity e = (Entity) (o instanceof Entity ? o : childMap.get(o));
+                result.add(name, (Entity) e.clone());
+            }
+        }
+        return result;
+    }
+}

Propchange: commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntityMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntitySupport.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntitySupport.java?rev=695567&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntitySupport.java (added)
+++ commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntitySupport.java Mon Sep 15 11:14:26 2008
@@ -0,0 +1,61 @@
+package com.pgac.flatfile;
+
+import java.io.IOException;
+
+import com.pgac.flatfile.util.RepeatingInputStream;
+
+/**
+ * Generic entity support stuff.
+ */
+public abstract class EntitySupport implements Entity {
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.pgac.fixedlength.Entity#fill(byte)
+     */
+    public void fill(byte b) throws IOException {
+        readFrom(RepeatingInputStream.getInstance(b));
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.pgac.fixedlength.Entity#clone()
+     */
+    public Object clone() {
+        try {
+            return super.clone();
+        } catch (CloneNotSupportedException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     * @see com.pgac.flatfile.Entity#getValue(int, int)
+     */
+    public byte[] getValue(int offset, int length) {
+        if (offset + length > length()) {
+            throw new IndexOutOfBoundsException();
+        }
+        byte[] value = getValue();
+        byte[] result = new byte[length];
+        System.arraycopy(value, offset, result, 0, length);
+        return result;
+    }
+
+    /**
+     * {@inheritDoc}
+     * @see com.pgac.flatfile.Entity#setValue(byte[], int, int)
+     */
+    public void setValue(byte[] b, int offset, int length) {
+        if (offset + length > b.length) {
+            throw new IndexOutOfBoundsException();
+        }
+        byte[] subset = new byte[length];
+        System.arraycopy(b, offset, subset, 0, length);
+        setValue(subset);
+    }
+
+}
\ No newline at end of file

Propchange: commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/EntitySupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/Field.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/Field.java?rev=695567&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/Field.java (added)
+++ commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/Field.java Mon Sep 15 11:14:26 2008
@@ -0,0 +1,115 @@
+package com.pgac.flatfile;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * Stores string representations of objects in a (fixed-length) byte array.
+ */
+public class Field extends PadJustifyFieldSupport {
+
+    private static final long serialVersionUID = 3939293448043882440L;
+
+    private Overflow overflow;
+    private byte[] buffer;
+
+    /**
+     * Create a new Field.
+     * @param size
+     */
+    public Field(int size) {
+        this(new byte[size]);
+    }
+
+    /**
+     * Create and initialize a new Field.
+     * @param buffer byte[] which is not copied, but used directly.
+     */
+    public Field(byte[] buffer) {
+        this.buffer = buffer;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.pgac.fixedlength.Entity#length()
+     */
+    public int length() {
+        return buffer.length;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.pgac.fixedlength.Entity#readFrom(java.io.InputStream)
+     */
+    public synchronized void readFrom(InputStream is) throws IOException {
+        is.read(buffer);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.pgac.fixedlength.Entity#writeTo(java.io.OutputStream)
+     */
+    public synchronized void writeTo(OutputStream os) throws IOException {
+        os.write(buffer);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.pgac.fixedlength.Entity#setValue(byte[])
+     */
+    public void setValue(byte[] b) {
+        getOverflow().check(b, buffer.length);
+        super.setValue(b);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.pgac.fixedlength.Entity#getValue()
+     */
+    public byte[] getValue() {
+        return buffer;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.pgac.fixedlength.Entity#clone()
+     */
+    public Object clone() {
+        Field result = (Field) super.clone();
+        result.buffer = new byte[buffer.length];
+        System.arraycopy(buffer, 0, result.buffer, 0, buffer.length);
+        return result;
+    }
+
+    /**
+     * Get the overflow.
+     * @return Overflow
+     */
+    public Overflow getOverflow() {
+        return overflow == null ? Overflow.ERROR : overflow;
+    }
+
+    /**
+     * Set the overflow.
+     * @param overflow Overflow
+     */
+    public void setOverflow(Overflow overflow) {
+        this.overflow = overflow;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.pgac.fixedlength.PadJustifyFieldSupport#getPadJustifyLength()
+     */
+    protected int getPadJustifyLength() {
+        return length();
+    }
+}

Propchange: commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/Field.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/FieldOption.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/FieldOption.java?rev=695567&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/FieldOption.java (added)
+++ commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/FieldOption.java Mon Sep 15 11:14:26 2008
@@ -0,0 +1,10 @@
+package com.pgac.flatfile;
+
+import java.io.Serializable;
+
+/**
+ * Field option interface
+ */
+public interface FieldOption extends Serializable {
+
+}

Propchange: commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/FieldOption.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/FieldSupport.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/FieldSupport.java?rev=695567&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/FieldSupport.java (added)
+++ commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/FieldSupport.java Mon Sep 15 11:14:26 2008
@@ -0,0 +1,89 @@
+package com.pgac.flatfile;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Support and basic field options. 
+ */
+public abstract class FieldSupport extends EntitySupport {
+
+    /**
+     * Overflow enumerated type.
+     */
+    public static abstract class Overflow implements FieldOption {
+        /** Error on overflow */
+        public static final Overflow ERROR = new Overflow() {
+            private static final long serialVersionUID = -7441509026880178410L;
+
+            protected void check(byte[] b, int len) {
+                if (b.length > len) {
+                    throw new IllegalArgumentException(new String(b)
+                            + " too large for field (" + len + ")");
+                }
+            }
+        };
+
+        /** Ignore on overflow */
+        public static final Overflow IGNORE = new Overflow() {
+            private static final long serialVersionUID = -904459454393715111L;
+
+            protected void check(byte[] b, int len) {
+                // ignore
+            }
+        };
+
+        /** Field-specific backwards compatible IGNORE alias */
+        public static final Overflow TRUNCATE = IGNORE;
+
+        private Overflow() {
+        }
+
+        /** Check the given aspect of the field */
+        protected abstract void check(byte[] b, int len);
+    }
+
+    /**
+     * Underflow enumerated type.
+     */
+    public static abstract class Underflow implements FieldOption {
+        /** Error on Underflow */
+        public static final Underflow ERROR = new Underflow() {
+            private static final long serialVersionUID = 6868582529171417983L;
+
+            protected void check(byte[] b, int len) {
+                if (b.length < len) {
+                    throw new IllegalArgumentException(new String(b)
+                            + " too small for field (" + len + ")");
+                }
+            }
+        };
+
+        /** Ignore on Underflow */
+        public static final Underflow IGNORE = new Underflow() {
+            private static final long serialVersionUID = -8423193000820647264L;
+
+            protected void check(byte[] b, int len) {
+                // ignore
+            }
+        };
+
+        private Underflow() {
+        }
+
+        /** Check the given aspect of the field */
+        protected abstract void check(byte[] b, int len);
+    }
+
+    /**
+     * Convenience #readFrom alias.
+     * @param is InputStream for <code>readFrom</code>.
+     */
+    protected void dieOnExceptionRead(InputStream is) {
+        try {
+            readFrom(is);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+}

Propchange: commons/sandbox/flatfile/trunk/src/main/java/com/pgac/flatfile/FieldSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message