diff --git a/.classpath b/.classpath deleted file mode 100644 index 7b47d45..0000000 --- a/.classpath +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..85b8f0a --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,28 @@ +name: Java CI + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4.2.2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v4.5.0 + with: + distribution: 'adopt' + java-version: 8.0.432+6 + - name: Cache Maven packages + uses: actions/cache@v4.1.2 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 + - name: Build with Maven + run: mvn -V javadoc:javadoc -DadditionalJOption=-Xdoclint:none install --file pom.xml + # - name: Publish to personal mave repository + # env: + # GITHUB_TOKEN: ${{ github.token }} + # run: mvn -V javadoc:javadoc -DadditionalJOption=-Xdoclint:none deploy --file pom.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9873cc9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +/bin +/target +.classpath +.DS_Store +.project +.settings + + diff --git a/.project b/.project deleted file mode 100644 index 301bc13..0000000 --- a/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - Texgit - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 31685be..0000000 --- a/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,4 +0,0 @@ -#Fri Oct 17 16:07:30 GMT-03:00 2008 -eclipse.preferences.version=1 -encoding//src/resource/TexgitSchema.xsd=UTF-8 -encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 7d1ffc5..0000000 --- a/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,12 +0,0 @@ -#Sun Aug 03 00:38:14 GMT-03:00 2008 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.6 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..d8d89f5 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,13 @@ +Texgit Changelog +============================= + +0.2.3 (2014/02/01) suport bopepo-0.2.3 +--------------------------------------- + +**Improvement** + + * #1: Implementação de testes para funcionalidade LineOfFields + + +0.2.0-SNAPSHOT (2010/12/07) incubation +--------------------------------------- \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..37ec93a --- /dev/null +++ b/LICENSE @@ -0,0 +1,191 @@ +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: + +You must give any other recipients of the Work or Derivative Works a copy of +this License; and +You must cause any modified files to carry prominent notices stating that You +changed the files; and +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 +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..fd183fc --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +Texgit +====== + +[![Build Status](https://ci-jrimum.rhcloud.com/buildStatus/icon?job=Texgit)](https://ci-jrimum.rhcloud.com) + +O projeto Texgit é um componente e framework em Java que facilita a manipulação de arquivos Flat Files (arquivo-texto) através de objetos. + +Diversas empresas já usam o Texgit em produção e estão colaborando no Design do componente e da API. + diff --git a/commons-lang-2.4.jar b/commons-lang-2.4.jar deleted file mode 100644 index 532939e..0000000 Binary files a/commons-lang-2.4.jar and /dev/null differ diff --git a/log4j-1.2.15.jar b/log4j-1.2.15.jar deleted file mode 100644 index c930a6a..0000000 Binary files a/log4j-1.2.15.jar and /dev/null differ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..9b39959 --- /dev/null +++ b/pom.xml @@ -0,0 +1,249 @@ + + + 4.0.0 + org.jrimum + jrimum-texgit + Projeto Texgit + 0.2.3 + Projeto open source de componentes de software para o domínio de negócios do Brasil. + http://www.jrimum.org/texgit + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + Projeto JRimum + http://www.jrimum.org + + + + GitHub + http://github.com/jrimum/texgit/issues + + + + http://github.com/jrimum/texgit + + + + + Gilmar P. S. L. + gilmatryx@gmail.com + + + Misael Barreto + misaelbarreto@gmail.com + + + Rômulo Augusto + romulomail@gmail.com + + + + + UTF-8 + UTF-8 + + gilbertoca + mvn-artifact + main + github + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + 1.8 + 1.8 + + + + org.codehaus.mojo + animal-sniffer-maven-plugin + 1.20 + + + org.codehaus.mojo.signature + java15 + 1.0 + + + + + animal-sniffer + compile + + check + + + + + + maven-assembly-plugin + 2.4 + + + src/main/assembly/jrimum-texgit-with-dependencies.xml + + + + + make-assembly + package + + single + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.16 + + false + + org/jrimum/texgit/**/* + + + org/jrimum/texgit/excludes/**/* + org/jrimum/texgit/**/*$* + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + package + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.3.0 + + + attach-javadoc + package + + jar + + + + + UTF-8 + UTF-8 + true + private + + + + com.github.github + site-maven-plugin + 0.12 + + Maven artifacts for ${project.version} + true + ${project.build.directory}/mvn-artifact + refs/heads/${branch-name} + + **/* + + true + ${repository-name} + ${repository-owner} + ${github.global.server} + + + + + site + + deploy + + + + + maven-deploy-plugin + 2.8.2 + + + internal.repo::default::file://${project.build.directory}/mvn-artifact + + + + + + + + + + org.jrimum + jrimum-utilix + 0.2.3 + + + javax.xml.bind + jaxb-api + 2.3.0 + + + com.sun.xml.bind + jaxb-core + 2.3.0 + + + com.sun.xml.bind + jaxb-impl + 2.3.0 + + + + junit + junit + 4.11 + test + + + + + + mvn-artifact-publish + https://github.com/${repository-owner}/${repository-name}/${branch-name} + + true + always + + + + mvn-artifact + https://raw.github.com/${repository-owner}/${repository-name}/${branch-name} + + + + + + internal.repo + Temporary Staging Repository + file://${project.build.directory}/mvn-artifact + + + diff --git a/src/br/com/nordestefomento/jrimum/texgit/FlatFile.java b/src/br/com/nordestefomento/jrimum/texgit/FlatFile.java deleted file mode 100644 index bad1fcd..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/FlatFile.java +++ /dev/null @@ -1,33 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit; - -import java.util.Collection; - -public interface FlatFile extends TextFileStream { - - // Registros individuais - - public G createRecord(String idType); - - public void addRecord(G record); - - public G getRecord(String idName); - - public G removeRecord(String idName); - - // Grupos de Registros (Registros que se repetem) - - public void addRecords(String idName, Collection records); - - public void setRecords(String idName, Collection records); - - public Collection getRecords(String idName); - - // Todos os Registros - - public void addAllRecords(Collection records); - - public void setAllRecords(Collection records); - - public Collection getAllRecords(); - -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/Record.java b/src/br/com/nordestefomento/jrimum/texgit/Record.java deleted file mode 100644 index 1c6a30a..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/Record.java +++ /dev/null @@ -1,16 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit; - -import java.util.List; - - - -public interface Record{ - - public void setValue(String fieldName, G value); - - public G getValue(String fieldName); - - public void addInnerRecord(Record record); - - public List getInnerRecords(); -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/Texgit.java b/src/br/com/nordestefomento/jrimum/texgit/Texgit.java deleted file mode 100644 index 597e6ec..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/Texgit.java +++ /dev/null @@ -1,39 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit; - -import static br.com.nordestefomento.jrimum.utilix.ObjectUtil.isNotNull; -import static org.apache.commons.lang.StringUtils.isNotBlank; - -import java.io.File; - -import br.com.nordestefomento.jrimum.texgit.engine.TGManager; - - - -public final class Texgit { - - public static final FlatFile createFlatFile(File xmlDef)throws TexgitException{ - - FlatFile iFlatFile = null; - - if (isNotNull(xmlDef)) - iFlatFile = TGManager.buildFlatFile(xmlDef); - - return iFlatFile; - } - - public static final FlatFile createFlatFile(String xmlDef)throws TexgitException{ - - FlatFile iFlatFile = null; - - try{ - - if(isNotBlank(xmlDef)) - iFlatFile = createFlatFile(new File(xmlDef)); - - }catch (Exception e) { - throw new TexgitException(e); - } - - return iFlatFile; - } -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/TexgitException.java b/src/br/com/nordestefomento/jrimum/texgit/TexgitException.java deleted file mode 100644 index adf49e2..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/TexgitException.java +++ /dev/null @@ -1,50 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit; - - -/** - * - *

- * Invólucro para exceções ocorridas no componente. - *

- * - * @author Gilmar P.S.L. - * - * */ - -@SuppressWarnings("serial") -public class TexgitException extends RuntimeException { - - /** - * - */ - public TexgitException() { - super(); - - } - - /** - * @param arg0 - * @param arg1 - */ - public TexgitException(String arg0, Throwable arg1) { - super(arg0, arg1); - - } - - /** - * @param arg0 - */ - public TexgitException(String arg0) { - super(arg0); - - } - - /** - * @param arg0 - */ - public TexgitException(Throwable arg0) { - super(arg0); - - } - -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/TextFileStream.java b/src/br/com/nordestefomento/jrimum/texgit/TextFileStream.java deleted file mode 100644 index 8202e0d..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/TextFileStream.java +++ /dev/null @@ -1,9 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit; - -import java.util.List; - -import br.com.nordestefomento.jrimum.utilix.ReadWriteStream; - -public interface TextFileStream extends ReadWriteStream> { - -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/engine/Builder4FlatFile.java b/src/br/com/nordestefomento/jrimum/texgit/engine/Builder4FlatFile.java deleted file mode 100644 index 9d83b87..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/engine/Builder4FlatFile.java +++ /dev/null @@ -1,49 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit.engine; - -import static br.com.nordestefomento.jrimum.utilix.ObjectUtil.isNotNull; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import br.com.nordestefomento.jrimum.texgit.language.MetaFlatFile; -import br.com.nordestefomento.jrimum.texgit.language.MetaRecord; -import br.com.nordestefomento.jrimum.texgit.type.component.FlatFile; - - -public class Builder4FlatFile { - - static FlatFile build(MetaFlatFile mFlatFile) { - - FlatFile ff = null; - - List metaRecords = mFlatFile.getGroupOfRecords().getRecords(); - - ff = new FlatFile(new Factory4Record(metaRecords)); - - Set repitables = new HashSet(); - - List recordsOrder = new ArrayList(); - - if (isNotNull(metaRecords)) { - - if (!metaRecords.isEmpty()) { - - for (MetaRecord mRec : metaRecords) { - - recordsOrder.add(mRec.getName()); - - if (mRec.isRepeatable()) - repitables.add(mRec.getName()); - } - } - } - - ff.setRecordsOrder(recordsOrder); - ff.setRepitablesRecords(repitables); - - return ff; - } - -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/engine/Builder4Record.java b/src/br/com/nordestefomento/jrimum/texgit/engine/Builder4Record.java deleted file mode 100644 index 2c0197d..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/engine/Builder4Record.java +++ /dev/null @@ -1,104 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit.engine; - -import static br.com.nordestefomento.jrimum.utilix.ObjectUtil.isNotNull; -import static br.com.nordestefomento.jrimum.utilix.ObjectUtil.isNull; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; - -import br.com.nordestefomento.jrimum.texgit.language.MetaField; -import br.com.nordestefomento.jrimum.texgit.language.MetaOrderedField; -import br.com.nordestefomento.jrimum.texgit.language.MetaRecord; -import br.com.nordestefomento.jrimum.texgit.type.component.FixedField; -import br.com.nordestefomento.jrimum.texgit.type.component.Record; - - -class Builder4Record { - - @SuppressWarnings("unchecked") - static Record build(MetaRecord metaRecord) { - - int strLength = getStringLength(metaRecord.getGroupOfFields().getFields()); - int fldSize = metaRecord.getGroupOfFields().getFields().size(); - - MetaOrderedField id = metaRecord.getGroupOfFields().getIdType(); - MetaOrderedField sequencialNumber = metaRecord.getGroupOfFields().getSequencialNumber(); - - if(isNotNull(id)){ - fldSize += 1; - strLength += id.getLength(); - } - - if(isNotNull(sequencialNumber)){ - fldSize += 1; - strLength += sequencialNumber.getLength(); - } - - Record record = new Record(strLength,fldSize); - - record.setName(metaRecord.getName()); - record.setDescription(metaRecord.getDescription()); - - /* - * getPossition eh de 1 a X - * e nao de 0 a X. - */ - if(isNotNull(id)){ - record.setIdType((FixedField) Builder4FixedField.build(id)); - record.set(id.getPosition()-1, record.getIdType()); - } - - if(isNotNull(sequencialNumber)){ - record.setSequencialNumber((FixedField) Builder4FixedField.build(sequencialNumber)); - record.set(sequencialNumber.getPosition()-1,record.getSequencialNumber()); - } - - List fields = metaRecord.getGroupOfFields().getFields(); - - /* - * As somas sao para caso id ou sequencia jah - * estejam na devida posicao. - */ - for(MetaField mField : fields){ - - if(isNull(record.get(fields.indexOf(mField)))) - record.set(fields.indexOf(mField), Builder4FixedField.build(mField)); - else - if(isNull(record.get(fields.indexOf(mField)+1))) - record.set(fields.indexOf(mField) + 1, Builder4FixedField.build(mField)); - else - record.set(fields.indexOf(mField) + 2, Builder4FixedField.build(mField)); - } - - // innerRecords - if (isNotNull(metaRecord.getGroupOfInnerRecords())){ - - record.setHeadOfGroup(true); - record.setDeclaredInnerRecords(new ArrayList(metaRecord.getGroupOfInnerRecords().getRecords().size())); - record.setRepitablesRecords(new HashSet()); - - List metaInnerRecords = metaRecord.getGroupOfInnerRecords().getRecords(); - - for(MetaRecord mRecord : metaInnerRecords){ - record.getDeclaredInnerRecords().add(mRecord.getName()); - if(mRecord.isRepeatable()) - record.getRepitablesRecords().add(mRecord.getName()); - } - - }else - record.setHeadOfGroup(false); - - return record; - } - - private static int getStringLength(List fields){ - int length = 0; - - for(MetaField mField : fields) - length += mField.getLength(); - - return length; - } - -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/engine/Factory4Record.java b/src/br/com/nordestefomento/jrimum/texgit/engine/Factory4Record.java deleted file mode 100644 index 0243246..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/engine/Factory4Record.java +++ /dev/null @@ -1,69 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit.engine; - -import static br.com.nordestefomento.jrimum.utilix.ObjectUtil.isNotNull; -import static org.apache.commons.lang.StringUtils.isNotBlank; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import br.com.nordestefomento.jrimum.texgit.language.MetaRecord; -import br.com.nordestefomento.jrimum.texgit.type.component.RecordFactory; -import br.com.nordestefomento.jrimum.texgit.type.component.Record; - - -public class Factory4Record implements RecordFactory { - - private Map name_record; - - Factory4Record(List metaRecords) { - - if (isNotNull(metaRecords)) { - if (!metaRecords.isEmpty()) { - - name_record = new HashMap(metaRecords - .size()); - - for (MetaRecord mRecord : metaRecords) { - - name_record.put(mRecord.getName(), mRecord); - - if (isNotNull(mRecord.getGroupOfInnerRecords())) - loadInnerRecords(name_record, mRecord - .getGroupOfInnerRecords().getRecords()); - } - } - } - } - - private void loadInnerRecords(Map name_record, - List innerMetaRecords) { - - if (isNotNull(innerMetaRecords)) { - if (!innerMetaRecords.isEmpty()) { - - for (MetaRecord iMetaRecord : innerMetaRecords) { - - name_record.put(iMetaRecord.getName(), iMetaRecord); - - if (isNotNull(iMetaRecord.getGroupOfInnerRecords())) - loadInnerRecords(name_record, iMetaRecord - .getGroupOfInnerRecords().getRecords()); - } - } - } - - } - - @Override - public Record create(String name) { - - Record record = null; - - if (isNotBlank(name)) - if (name_record.containsKey(name)) - record = Builder4Record.build(name_record.get(name)); - - return record; - } -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/engine/TGLanguageException.java b/src/br/com/nordestefomento/jrimum/texgit/engine/TGLanguageException.java deleted file mode 100644 index 90b092d..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/engine/TGLanguageException.java +++ /dev/null @@ -1,41 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit.engine; - -import br.com.nordestefomento.jrimum.texgit.TexgitException; - -@SuppressWarnings("serial") -public class TGLanguageException extends TexgitException { - - /** - * - */ - public TGLanguageException() { - super(); - - } - - /** - * @param arg0 - * @param arg1 - */ - public TGLanguageException(String arg0, Throwable arg1) { - super(arg0, arg1); - - } - - /** - * @param arg0 - */ - public TGLanguageException(String arg0) { - super(arg0); - - } - - /** - * @param arg0 - */ - public TGLanguageException(Throwable arg0) { - super(arg0); - - } - -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/engine/TGManager.java b/src/br/com/nordestefomento/jrimum/texgit/engine/TGManager.java deleted file mode 100644 index 7f4716e..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/engine/TGManager.java +++ /dev/null @@ -1,32 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit.engine; - -import java.io.File; - -import br.com.nordestefomento.jrimum.texgit.FlatFile; -import br.com.nordestefomento.jrimum.texgit.TexgitException; -import br.com.nordestefomento.jrimum.texgit.language.MetaTexgit; - - -public class TGManager { - - @SuppressWarnings("unchecked") - public static br.com.nordestefomento.jrimum.texgit.FlatFile buildFlatFile(File xmlDef) { - - br.com.nordestefomento.jrimum.texgit.FlatFile iFlatFile = null; - - try { - - MetaTexgit tgMeta = TGXMLReader.parse(xmlDef); - - FlatFile ff = Builder4FlatFile.build(tgMeta.getFlatFile()); - - iFlatFile = ff; - - } catch (Exception e) { - throw new TexgitException(e); - } - - return iFlatFile; - } - -} \ No newline at end of file diff --git a/src/br/com/nordestefomento/jrimum/texgit/engine/TGSchemaValidator.java b/src/br/com/nordestefomento/jrimum/texgit/engine/TGSchemaValidator.java deleted file mode 100644 index d3ee6d2..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/engine/TGSchemaValidator.java +++ /dev/null @@ -1,37 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit.engine; - -import javax.xml.bind.ValidationEvent; -import javax.xml.bind.ValidationEventHandler; -import javax.xml.bind.ValidationEventLocator; - -class TGSchemaValidator implements ValidationEventHandler { - - @Override - public boolean handleEvent(ValidationEvent event) { - - boolean handled = false; - - if (event.getSeverity() == ValidationEvent.WARNING) { - - System.err.println(getMensagem("ATENÇÃO LAYOUT INCONSISTENTE!\n", - event)); - - handled = true; - - } else - // ERROR - System.err.println(getMensagem("ERRO NO LAYOUT!\n", event)); - - return handled; - } - - private String getMensagem(String msg, ValidationEvent event) { - - ValidationEventLocator local = event.getLocator(); - - return msg + - - "Linha { " + local.getLineNumber() + " } " + "Conluna [ " - + local.getColumnNumber() + " ] " + event.getMessage(); - } -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/engine/TGXMLReader.java b/src/br/com/nordestefomento/jrimum/texgit/engine/TGXMLReader.java deleted file mode 100644 index 3183240..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/engine/TGXMLReader.java +++ /dev/null @@ -1,68 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit.engine; - -import static br.com.nordestefomento.jrimum.utilix.ObjectUtil.isNotNull; -import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; -import javax.xml.validation.Schema; -import javax.xml.validation.SchemaFactory; - -import org.xml.sax.SAXException; - -import br.com.nordestefomento.jrimum.texgit.Texgit; -import br.com.nordestefomento.jrimum.texgit.TexgitException; -import br.com.nordestefomento.jrimum.texgit.language.MetaTexgit; - - -class TGXMLReader { - - public static MetaTexgit parse(File xmlDef) throws TexgitException { - - MetaTexgit txg = null; - - if (isNotNull(xmlDef)) { - - try { - - JAXBContext aJaxbContext = JAXBContext - .newInstance(MetaTexgit.class); - - Unmarshaller aUnmarshaller = aJaxbContext.createUnmarshaller(); - - SchemaFactory aSchemaFactory = SchemaFactory - .newInstance(W3C_XML_SCHEMA_NS_URI); - - Schema schema = aSchemaFactory.newSchema(Texgit.class - .getResource("/resource/TexgitSchema.xsd")); - - aUnmarshaller.setSchema(schema); - - aUnmarshaller.setEventHandler(new TGSchemaValidator()); - - txg = (MetaTexgit) aUnmarshaller.unmarshal(new FileInputStream( - xmlDef)); - - } catch (SAXException e) { - - throw new TGLanguageException(e); - - } catch (JAXBException e) { - - throw new TGLanguageException(e); - - } catch (FileNotFoundException e) { - - throw new TGLanguageException(e); - } - } - - return txg; - } - -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/language/EnumFormatsTypes.java b/src/br/com/nordestefomento/jrimum/texgit/language/EnumFormatsTypes.java deleted file mode 100644 index 0550df7..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/language/EnumFormatsTypes.java +++ /dev/null @@ -1,53 +0,0 @@ -// -// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6 -// See http://java.sun.com/xml/jaxb -// Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2008.08.03 at 12:27:56 AM GMT-03:00 -// - -package br.com.nordestefomento.jrimum.texgit.language; - -import javax.xml.bind.annotation.XmlEnum; - -/** - * - * - *

- * Tipo de formatadores suportados. Usados junto a defini��o de novos - * formatadores. - *

- * - * - * - *

- * Java class for enumFormatsTypes. - * - *

- * The following schema fragment specifies the expected content contained within - * this class. - *

- * - *

- * <simpleType name="enumFormatsTypes">
- *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
- *     <enumeration value="DATE"/>
- *     <enumeration value="DECIMAL"/>
- *   </restriction>
- * </simpleType>
- * 
- * - */ -@XmlEnum -public enum EnumFormatsTypes { - - DATE, DECIMAL; - - public String value() { - return name(); - } - - public static EnumFormatsTypes fromValue(String v) { - return valueOf(v); - } - -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/language/EnumPaddings.java b/src/br/com/nordestefomento/jrimum/texgit/language/EnumPaddings.java deleted file mode 100644 index 7e8ee89..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/language/EnumPaddings.java +++ /dev/null @@ -1,54 +0,0 @@ -// -// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6 -// See http://java.sun.com/xml/jaxb -// Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2008.08.03 at 12:27:56 AM GMT-03:00 -// - -package br.com.nordestefomento.jrimum.texgit.language; - -import javax.xml.bind.annotation.XmlEnum; - -/** - * - * - *

- * Preenchimentos suportados por padr�o pelo componente. - *

- * - * - * - *

- * Java class for enumPaddings. - * - *

- * The following schema fragment specifies the expected content contained within - * this class. - *

- * - *

- * <simpleType name="enumPaddings">
- *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
- *     <enumeration value="ZERO_RIGHT"/>
- *     <enumeration value="ZERO_LEFT"/>
- *     <enumeration value="WHITE_SPACE_RIGHT"/>
- *     <enumeration value="WHITE_SPACE_LEFT"/>
- *   </restriction>
- * </simpleType>
- * 
- * - */ -@XmlEnum -public enum EnumPaddings { - - ZERO_RIGHT, ZERO_LEFT, WHITE_SPACE_RIGHT, WHITE_SPACE_LEFT; - - public String value() { - return name(); - } - - public static EnumPaddings fromValue(String v) { - return valueOf(v); - } - -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/language/EnumSide.java b/src/br/com/nordestefomento/jrimum/texgit/language/EnumSide.java deleted file mode 100644 index d55ba67..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/language/EnumSide.java +++ /dev/null @@ -1,52 +0,0 @@ -// -// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6 -// See http://java.sun.com/xml/jaxb -// Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2008.08.03 at 12:27:56 AM GMT-03:00 -// - -package br.com.nordestefomento.jrimum.texgit.language; - -import javax.xml.bind.annotation.XmlEnum; - -/** - * - * - *

- * Basicamente s�o defini��es de dire��es de escrita e leitura. - *

- * - * - * - *

- * Java class for enumSide. - * - *

- * The following schema fragment specifies the expected content contained within - * this class. - *

- * - *

- * <simpleType name="enumSide">
- *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
- *     <enumeration value="LEFT"/>
- *     <enumeration value="RIGHT"/>
- *   </restriction>
- * </simpleType>
- * 
- * - */ -@XmlEnum -public enum EnumSide { - - LEFT, RIGHT; - - public String value() { - return name(); - } - - public static EnumSide fromValue(String v) { - return valueOf(v); - } - -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/language/MetaOrderedField.java b/src/br/com/nordestefomento/jrimum/texgit/language/MetaOrderedField.java deleted file mode 100644 index 09a6290..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/language/MetaOrderedField.java +++ /dev/null @@ -1,50 +0,0 @@ -// -// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6 -// See http://java.sun.com/xml/jaxb -// Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2008.08.03 at 12:27:56 AM GMT-03:00 -// - -package br.com.nordestefomento.jrimum.texgit.language; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlType; - -/** - * - * - *

- * Para defini��o da posi��o. - *

- * - * - * - * - * - */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "MetaOrderedField") -public class MetaOrderedField extends MetaField { - - @XmlAttribute(required = true) - protected int position; - - /** - * Gets the value of the position property. - * - */ - public int getPosition() { - return position; - } - - /** - * Sets the value of the position property. - * - */ - public void setPosition(int value) { - this.position = value; - } - -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/language/package-info.java b/src/br/com/nordestefomento/jrimum/texgit/language/package-info.java deleted file mode 100644 index c425a8b..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/language/package-info.java +++ /dev/null @@ -1,12 +0,0 @@ -// -// This file was generated by the JavaTM Architecture for XML Binding(JAXB) -// Reference Implementation, vJAXB 2.0 in JDK 1.6 -// See http://java.sun.com/xml/jaxb -// Any modifications to this file will be lost upon recompilation of the source -// schema. -// Generated on: 2008.08.03 at 12:27:56 AM GMT-03:00 -// - -@javax.xml.bind.annotation.XmlSchema(namespace = "http://gilmatryx.googlepages.com/Texgit") -package br.com.nordestefomento.jrimum.texgit.language; - diff --git a/src/br/com/nordestefomento/jrimum/texgit/type/Field.java b/src/br/com/nordestefomento/jrimum/texgit/type/Field.java deleted file mode 100644 index 80d9e48..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/type/Field.java +++ /dev/null @@ -1,26 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit.type; - -import java.text.Format; - -import br.com.nordestefomento.jrimum.utilix.TextStream; - -public interface Field extends TextStream, Cloneable{ - - public abstract String getName(); - - public abstract void setName(String name); - - public abstract G getValue(); - - public abstract void setValue(G value); - - public abstract Format getFormatter(); - - public abstract void setFormatter(Format formatter); - - public abstract boolean isBlankAccepted(); - - public abstract void setBlankAccepted(boolean blankAccepted); - - public abstract Field clone() throws CloneNotSupportedException; -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/type/Fixed.java b/src/br/com/nordestefomento/jrimum/texgit/type/Fixed.java deleted file mode 100644 index ffd0834..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/type/Fixed.java +++ /dev/null @@ -1,24 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit.type; - -public interface Fixed { - - - /** - *

- * Informa a validade para a fixação de uma ou mais medidas. Exemplo: - *
- *

-	 * {
-	 * isLenghtAsDefine();
-	 * isSizeAsDefine();
-	 * }
-	 * 
- *

- * - * @return - * - * @throws IllegalStateException - */ - - public abstract boolean isFixedAsDefined() throws IllegalStateException; -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/type/FixedField.java b/src/br/com/nordestefomento/jrimum/texgit/type/FixedField.java deleted file mode 100644 index 6b3af6b..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/type/FixedField.java +++ /dev/null @@ -1,17 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit.type; - -import br.com.nordestefomento.jrimum.texgit.type.component.Filler; - - -public interface FixedField extends Field, FixedLength{ - - /** - * @return the filler - */ - public abstract Filler getFiller(); - - /** - * @param filler the filler to set - */ - public abstract void setFiller(Filler filler); -} \ No newline at end of file diff --git a/src/br/com/nordestefomento/jrimum/texgit/type/FixedLength.java b/src/br/com/nordestefomento/jrimum/texgit/type/FixedLength.java deleted file mode 100644 index ae9e3ab..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/type/FixedLength.java +++ /dev/null @@ -1,6 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit.type; - -public interface FixedLength extends Fixed{ - - public Integer getFixedLength(); -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/type/FixedSize.java b/src/br/com/nordestefomento/jrimum/texgit/type/FixedSize.java deleted file mode 100644 index c48be95..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/type/FixedSize.java +++ /dev/null @@ -1,6 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit.type; - -public interface FixedSize extends Fixed{ - - public Integer getFixedSize(); -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/type/component/BlockOfFields.java b/src/br/com/nordestefomento/jrimum/texgit/type/component/BlockOfFields.java deleted file mode 100644 index 1245217..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/type/component/BlockOfFields.java +++ /dev/null @@ -1,163 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit.type.component; - -import static br.com.nordestefomento.jrimum.utilix.ObjectUtil.isNotNull; -import br.com.nordestefomento.jrimum.texgit.type.AbstractStringOfFields; -import br.com.nordestefomento.jrimum.texgit.type.FixedLength; -import br.com.nordestefomento.jrimum.texgit.type.FixedSize; -import br.com.nordestefomento.jrimum.utilix.ObjectUtil; - -@SuppressWarnings("serial") -public class BlockOfFields extends AbstractStringOfFields> implements FixedSize, FixedLength{ - - /** - * Definição - */ - private Integer length; - - /** - * Definição - */ - private Integer size; - - /** - *

- * Tamanho da string de escrita do bloco. - *

- */ - private Integer instantLength; - - /** - * - */ - public BlockOfFields() { - super(); - } - - /** - * @param length - * @param size - */ - public BlockOfFields(Integer length, Integer size) { - - super(size); - - ObjectUtil.checkNotNull(length, "length"); - - if (length > 0) { - - setLength(length); - setSize(size); - - } else - throw new IllegalArgumentException("O comprimento do bloco [ " - + length + " ] deve ser um número natural > 0!"); - } - - @Override - public BlockOfFields clone() throws CloneNotSupportedException { - - return(BlockOfFields) super.clone(); - } - - @Override - public void read(String lineOfFields) { - - ObjectUtil.checkNotNull(lineOfFields, "lineOfFields"); - - ObjectUtil.checkNotNull(getFields(), "fields"); - - if (isSizeAsDefinaed() && isLengthWithDefinaed(lineOfFields.length())) { - - StringBuilder builder = new StringBuilder(lineOfFields); - - for (FixedField field : getFields()) { - - field.read(builder.substring(0, field.getFixedLength())); - builder.delete(0, field.getFixedLength()); - } - - builder = null; - } - } - - @Override - public String write() { - - ObjectUtil.checkNotNull(getFields(), "fields"); - - String str = null; - - isSizeAsDefinaed(); - - str = super.write(); - - instantLength = str.length(); - - isFixedAsDefined(); - - return str; - } - - @Override - public boolean isFixedAsDefined() throws IllegalStateException { - - return (isSizeAsDefinaed() && isLengthWithDefinaed()); - } - - private boolean isLengthWithDefinaed(){ - - return isLengthWithDefinaed(instantLength); - } - - private boolean isLengthWithDefinaed(int length){ - - if(length == getFixedLength()) - return true; - else - throw new IllegalStateException("O comprimento da string [ " + instantLength + " ] é incompátivel com o definido ["+getFixedLength()+"]!"); - } - - private boolean isSizeAsDefinaed(){ - - if(size() == getFixedSize()) - return true; - else - throw new IllegalStateException("O número de fields [ " + size() + " ] é incompátivel com o definido ["+getFixedSize()+"]!"); - } - - /** - * @return the length - */ - public Integer getFixedLength() { - return length; - } - - /** - * @param length the length to set - */ - private void setLength(Integer length) { - - if (isNotNull(length)) - this.length = length; - else - throw new IllegalArgumentException("Comprimento inválido [" + length + "]!"); - } - - /** - * @return the size - */ - public Integer getFixedSize() { - return size; - } - - /** - * @param size the size to set - */ - private void setSize(Integer size) { - - if (isNotNull(size)) - this.size = size; - else - throw new IllegalArgumentException("Tamanho inválido [" + size + "]!"); - } -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/type/component/CommonFiller.java b/src/br/com/nordestefomento/jrimum/texgit/type/component/CommonFiller.java deleted file mode 100644 index 981ca88..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/type/component/CommonFiller.java +++ /dev/null @@ -1,38 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit.type.component; - -import br.com.nordestefomento.jrimum.utilix.StringUtil; - - -public enum CommonFiller { - - /** - * Filler padrão para preenchimento com zeros a esquerda. - */ - ZERO_LEFT(new Filler(0, Side.LEFT)), - - /** - * Filler padrão para preenchimento com zeros a direita. - */ - ZERO_RIGHT(new Filler(0, Side.RIGHT)), - - /** - * Filler padrão para preenchimento com espaços em branco a esquerda. - */ - WHITE_SPACE_LEFT(new Filler(StringUtil.WHITE_SPACE, Side.LEFT)), - - /** - * Filler padrão para preenchimento com espaços em branco a direita. - */ - WHITE_SPACE_RIGHT(new Filler(StringUtil.WHITE_SPACE, Side.RIGHT)); - - private Filler instanceEnumFiller; - - CommonFiller(Filler filler){ - - this.instanceEnumFiller = filler; - } - - public Filler getOne(){ - return this.instanceEnumFiller; - } -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/type/component/Field.java b/src/br/com/nordestefomento/jrimum/texgit/type/component/Field.java deleted file mode 100644 index c0235ec..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/type/component/Field.java +++ /dev/null @@ -1,336 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit.type.component; - -import static br.com.nordestefomento.jrimum.utilix.ObjectUtil.isNotNull; -import static org.apache.commons.lang.StringUtils.isBlank; -import static org.apache.commons.lang.StringUtils.isNumeric; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.math.BigDecimal; -import java.text.DecimalFormat; -import java.text.Format; -import java.text.ParseException; -import java.util.Date; - -import org.apache.commons.lang.StringUtils; - -import br.com.nordestefomento.jrimum.utilix.DateUtil; -import br.com.nordestefomento.jrimum.utilix.ObjectUtil; -import br.com.nordestefomento.jrimum.utilix.TextStream; - -@SuppressWarnings("serial") -public class Field implements br.com.nordestefomento.jrimum.texgit.type.Field{ - - /** - *

- *Nome do campo, também pode ser usado como id. - *

- */ - private String name; - - /** - *

- * Valor do campo. - *

- */ - private G value; - - /** - *

- * Formatador utilizado na leitura e escrita do valor do campo. - *

- */ - private Format formatter; - - /** - *

- * Necessário para ler campos númericos em branco. - *

- */ - private boolean blankAccepted; - - /** - * - */ - public Field() { - super(); - } - - /** - * @param name - * @param value - */ - public Field(String name, G value) { - super(); - setName(name); - setValue(value); - } - - /** - *

- * Cria um Field com um valor e um formatador para o valor. Isto significa que a leitura e escrita do valor informado - * será de acordo com o formatador. - *

- * - * @param value - * @param formatter - */ - public Field(G value, Format formatter){ - - setValue(value); - setFormatter(formatter); - } - - /** - *

- * Cria um Field com nome para identificação, valor e um formatador. - *

- * - * @param name - * @param value - * @param formatter - * - * @see #Field(Object, Format) - */ - public Field(String name, G value, Format formatter){ - - setName(name); - setValue(value); - setFormatter(formatter); - } - - @SuppressWarnings("unchecked") - @Override - public Field clone() throws CloneNotSupportedException { - - return (Field) super.clone(); - } - - @Override - public void read(String str) { - - ObjectUtil.checkNotNull(str, "String Inválida"); - - if (this.value instanceof TextStream) { - - TextStream reader = (TextStream) this.value; - reader.read(str); - - } else if (this.value instanceof BigDecimal) { - - readDecimalField(str); - - } else if (this.value instanceof Date) { - - readDateField(str); - - } else if (this.value instanceof Character) { - - readCharacter(str); - - } else { - - readStringOrNumericField(str); - } - } - - @SuppressWarnings("unchecked") - private void readCharacter(String str) { - - if(str.length() == 1){ - - value = (G) new Character(str.charAt(0)); - - }else - throw new IllegalArgumentException("String com mais de 1 character!"); - } - - @SuppressWarnings("unchecked") - private void readDecimalField(String str) { - - DecimalFormat decimalFormat = (DecimalFormat) formatter; - - try { - - String number = parseNumber(str); - - Long parsedValue = (Long) formatter.parseObject(number); - - BigDecimal decimalValue = new BigDecimal(parsedValue.longValue()); - - decimalValue = decimalValue.movePointLeft(decimalFormat.getMaximumFractionDigits()); - - value = (G) decimalValue; - - } - catch (ParseException e) { - - errorG(e, str); - } - } - - @SuppressWarnings("unchecked") - private void readDateField(String str) { - - try { - - if(isBlank(str)){ - - if(isBlankAccepted()) - value = (G) DateUtil.DATE_NULL; - else - new IllegalArgumentException("Campo data vazio não permitido: ["+str+"]"); - } - - value = (G) formatter.parseObject(str); - - } catch (ParseException e) { - - errorG(e, str); - } - } - - @SuppressWarnings("unchecked") - private void readStringOrNumericField(String str) { - - str = parseNumber(str); - - Class c = value.getClass(); - - for (Constructor cons : c.getConstructors()) { - - if (cons.getParameterTypes().length == 1){ - if (cons.getParameterTypes()[0].equals(String.class)){ - try { - - value = (G) cons.newInstance(str); - - } catch (IllegalArgumentException e) { - errorG(e, str).printStackTrace(); - } catch (InstantiationException e) { - errorG(e, str).printStackTrace(); - } catch (IllegalAccessException e) { - errorG(e, str).printStackTrace(); - } catch (InvocationTargetException e) { - errorG(e, str).printStackTrace(); - } - } - } - } - } - - @Override - public String write() { - - String str = null; - - if (value instanceof TextStream) { - - TextStream its = (TextStream) value; - - str = its.write(); - - } else if (value instanceof Date) { - - str = writeDateField(); - } - - else if (value instanceof BigDecimal) - str = writeDecimalField(); - - else - str = value.toString(); - - return str; - } - - private String writeDecimalField(){ - - BigDecimal decimalValue = (BigDecimal) value; - - decimalValue = decimalValue.movePointRight(((DecimalFormat)formatter).getMaximumFractionDigits()); - - return decimalValue.toString(); - } - - private String writeDateField(){ - - String str = StringUtils.EMPTY; - - Date dateValue = (Date) value; - - if (dateValue.compareTo(DateUtil.DATE_NULL) != 0) - str = formatter.format(dateValue); - - return str; - } - - protected static Exception errorG(Exception e, String value){ - - StackTraceElement[] stackTrace = e.getStackTrace(); - e = new RuntimeException("Problems entre a instância e o valor: [ " + value + " ]!\nCausado por: "+e.getCause()); - e.setStackTrace(stackTrace); - - return e; - } - - private String parseNumber(String str){ - - if(isBlank(str)){ - - if(isBlankAccepted()) - str = "0"; - else - new IllegalArgumentException("Campo numérico vazio não permitido: ["+str+"]"); - }else - if(!isNumeric(str)) - new IllegalArgumentException("O campo deve ser numérico e não: ["+str+"]"); - - return str; - } - - - public String getName() { - return name; - } - - public void setName(String name) { - - if (isNotNull(name)) - this.name = name; - else - throw new IllegalArgumentException("Nome Inválido [" + name + "]!"); - } - - public boolean isBlankAccepted() { - return this.blankAccepted; - } - - public void setBlankAccepted(boolean blankAccepted) { - this.blankAccepted = blankAccepted; - } - - public G getValue() { - return value; - } - - public void setValue(G value) { - - if (isNotNull(value)) - this.value = value; - else - throw new IllegalArgumentException("Valor Inválido [" + value + "]!"); - } - - public Format getFormatter() { - return formatter; - } - - public void setFormatter(Format formatter) { - - if (isNotNull(formatter)) - this.formatter = formatter; - else - throw new IllegalArgumentException("Formato inválido [ " + formatter + " ]!"); - } -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/type/component/FixedField.java b/src/br/com/nordestefomento/jrimum/texgit/type/component/FixedField.java deleted file mode 100644 index 2e607e7..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/type/component/FixedField.java +++ /dev/null @@ -1,161 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit.type.component; - -import static br.com.nordestefomento.jrimum.utilix.ObjectUtil.isNotNull; - -import java.text.Format; - -import br.com.nordestefomento.jrimum.utilix.ObjectUtil; - - - - -@SuppressWarnings("serial") -public class FixedField extends Field implements br.com.nordestefomento.jrimum.texgit.type.FixedField{ - - /** - *

- * Tamanho de especificação e parâmetro da string de leitura ou escrita do campo. - *

- */ - private Integer length; - - /** - *

- * Preenchedor do valor utilizado na hora da escrita. - *

- */ - private Filler filler; - - - /** - *

- * Tamanho da string de escrita do campo. - *

- */ - private Integer instantLength; - - - /** - * - */ - public FixedField() { - super(); - } - - /** - * @param ordem - * @param length - * @param filler - */ - public FixedField(String name, G value, Integer length, Filler filler) { - super(name,value); - setFixedLength(length); - setFiller(filler); - } - - /** - * @param ordem - * @param length - * @param filler - */ - public FixedField(G value, Format formatter, Integer length, Filler filler) { - super(value,formatter); - setFixedLength(length); - setFiller(filler); - } - - /** - * @param ordem - * @param length - * @param filler - */ - public FixedField(String name, G value, Format formatter, Integer length, Filler filler) { - super(name,value,formatter); - setFixedLength(length); - setFiller(filler); - } - - @Override - public FixedField clone() throws CloneNotSupportedException { - - return (FixedField) super.clone(); - } - - /** - * @see br.com.nordestefomento.jrimum.texgit.type.component.Field#read(java.lang.String) - */ - @Override - public void read(String str) { - - ObjectUtil.checkNotNull(str, "String Inválida"); - - if (str.length() == getFixedLength()) { - super.read(str); - } else - throw new IllegalArgumentException("Tamanho da string [ " - + str.length() + " ] diferente do especificado [ " - + getFixedLength() + " ]!"); - } - - /** - * @see br.com.nordestefomento.jrimum.texgit.type.component.Field#write() - */ - @Override - public String write() { - - String str = fill(super.write()); - - instantLength = str.length(); - - isFixedAsDefined(); - - return str; - } - - private String fill(String str) { - - if(isNotNull(filler)) - str = filler.fill(str, length); - - return str; - } - - @Override - public boolean isFixedAsDefined() throws IllegalStateException { - - if(instantLength.equals(getFixedLength())) - return true; - else - throw new IllegalStateException("Tamanho da string [ " + instantLength - + " ] diferente do especificado [" + getFixedLength() + "]!"); - } - - @Override - public Integer getFixedLength() { - - return this.length; - } - - public void setFixedLength(Integer length) { - - if (isNotNull(length)) - this.length = length; - else - throw new IllegalArgumentException("Comprimento inválido [" + length + "]!"); - - } - - @Override - public Filler getFiller() { - return filler; - } - - @Override - public void setFiller(Filler filler) { - - if(isNotNull(filler)) - this.filler = filler; - else - throw new IllegalArgumentException("Preenchedor inválido [ " + filler + " ]!"); - } -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/type/component/FlatFile.java b/src/br/com/nordestefomento/jrimum/texgit/type/component/FlatFile.java deleted file mode 100644 index b8558b9..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/type/component/FlatFile.java +++ /dev/null @@ -1,262 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit.type.component; - -import static br.com.nordestefomento.jrimum.utilix.ObjectUtil.isNotNull; -import static br.com.nordestefomento.jrimum.utilix.ObjectUtil.isNull; -import static org.apache.commons.lang.StringUtils.isNotBlank; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Set; - - -@SuppressWarnings("serial") -public class FlatFile implements br.com.nordestefomento.jrimum.texgit.FlatFile{ - - private List records; - - private Set repitablesRecords; - - private List recordsOrder; - - private RecordFactory recordFactory; - - public FlatFile(RecordFactory iFac4Rec) { - - this.recordFactory = iFac4Rec; - this.records = new ArrayList(); - } - - public Record getRecord(String idName){ - - Record record = null; - - if (isNotBlank(idName)) { - if (!isRepitable(idName)){ - if (!records.isEmpty()) { - for (Record rec : records) { - if (idName.equals(rec.getName())) - record = rec; - } - } - } - } - - return record; - } - - public boolean isRepitable(String idName){ - - return (isNotNull(repitablesRecords) && !repitablesRecords.isEmpty() && repitablesRecords.contains(idName)); - } - - public br.com.nordestefomento.jrimum.texgit.Record createRecord(String idName){ - - return recordFactory.create(idName); - } - - public void addRecord(Record record){ - - if(isNotNull(record)) - if(isMyRecord(record.getName())) - records.add(record); - else - throw new IllegalArgumentException("Record fora de scopo!"); - } - - public boolean isMyRecord(String idName){ - boolean is = false; - - if (isNotBlank(idName)) { - if(!recordsOrder.isEmpty()) - if(recordsOrder.contains(idName)) - is = true; - } - return is; - } - - @Override - public void read(List str) { - - if(isNotNull(str)){ - if(!str.isEmpty()){ - - boolean read = true; - - String line = null; - int lineIndex = 0; - - FixedField typeRecord = null; - Record record = null; - - for(String id : recordsOrder){ - - record = recordFactory.create(id); - - if(isRepitable(id)){ - - while(read){ - - if(isNull(record)) - record = recordFactory.create(id); - - if(lineIndex < str.size()) - line = str.get(lineIndex); - - typeRecord = record.readID(line); - - read = record.getIdType().getValue().equals(typeRecord.getValue()) && (lineIndex < str.size()); - - if(read){ - - record.read(line); - lineIndex++; - addRecord(record); - - if(record.isHeadOfGroup()) - lineIndex = record.readInnerRecords(str,lineIndex,recordFactory); - - record = null; - } - } - - }else{ - if((lineIndex < str.size())){ - - line = str.get(lineIndex); - typeRecord = record.readID(line); - - if(record.getIdType().getValue().equals(typeRecord.getValue())){ - - record.read(line); - lineIndex++; - addRecord(record); - - if(record.isHeadOfGroup()) - lineIndex = record.readInnerRecords(str,lineIndex,recordFactory); - - record = null; - } - } - } - } - } - } - } - - @Override - public List write() { - - ArrayList out = new ArrayList(records.size()); - - for(String id : recordsOrder){ - - if(isRepitable(id)){ - - Record rec = null; - - for(br.com.nordestefomento.jrimum.texgit.Record record : getRecords(id)){ - - rec = Record.class.cast(record); - - out.add(rec.write()+"\r\n"); - - if(rec.isHeadOfGroup()) - out.addAll(rec.writeInnerRecords()); - } - - }else{ - - Record rec = getRecord(id); - - out.add(rec.write()+"\r\n"); - - if(rec.isHeadOfGroup()) - out.addAll(rec.writeInnerRecords()); - } - } - - return out; - } - - @Override - public void addRecord(br.com.nordestefomento.jrimum.texgit.Record record) { - - if(isNotNull(record)){ - Record rec = Record.class.cast(record); - addRecord(rec); - } - } - - @Override - public Collection getRecords(String idName) { - - List secRecords = new ArrayList(); - - if (isNotBlank(idName)) { - if (isRepitable(idName)) { - if (!records.isEmpty()) { - for (Record rec : records) { - if (idName.equals(rec.getName())) - secRecords.add(rec); - } - } - } - } - - return secRecords; - } - - @Override - public void addAllRecords(Collection records) { - // TODO Auto-generated method stub - - } - - @Override - public void addRecords(String idName, Collection records) { - // TODO Auto-generated method stub - - } - - @Override - public Collection getAllRecords() { - // TODO Auto-generated method stub - return null; - } - - @Override - public br.com.nordestefomento.jrimum.texgit.Record removeRecord(String idName) { - // TODO Auto-generated method stub - return null; - } - - @Override - public void setAllRecords(Collection records) { - // TODO Auto-generated method stub - - } - - @Override - public void setRecords(String idName, Collection records) { - // TODO Auto-generated method stub - - } - - public Set getRepitablesRecords() { - return repitablesRecords; - } - - public void setRepitablesRecords(Set repitablesRecords) { - this.repitablesRecords = repitablesRecords; - } - - public List getRecordsOrder() { - return recordsOrder; - } - - public void setRecordsOrder(List recordsOrder) { - this.recordsOrder = recordsOrder; - } - -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/type/component/RecordFactory.java b/src/br/com/nordestefomento/jrimum/texgit/type/component/RecordFactory.java deleted file mode 100644 index 87363f0..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/type/component/RecordFactory.java +++ /dev/null @@ -1,8 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit.type.component; - -import br.com.nordestefomento.jrimum.texgit.Record; - -public interface RecordFactory { - - public abstract G create(String name); -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/type/component/Side.java b/src/br/com/nordestefomento/jrimum/texgit/type/component/Side.java deleted file mode 100644 index eec625d..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/type/component/Side.java +++ /dev/null @@ -1,14 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit.type.component; - - -/** - *

- * Lados para alinhar campos, preenchimento ou orientações em geral. - *

- */ -public enum Side { - - LEFT, - - RIGHT; -} diff --git a/src/br/com/nordestefomento/jrimum/texgit/util/FileUtil.java b/src/br/com/nordestefomento/jrimum/texgit/util/FileUtil.java deleted file mode 100644 index d740a77..0000000 --- a/src/br/com/nordestefomento/jrimum/texgit/util/FileUtil.java +++ /dev/null @@ -1,355 +0,0 @@ -package br.com.nordestefomento.jrimum.texgit.util; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.lang.StringUtils; - - -/** - * - *

- * DEFINIÇÃO DA CLASSE - *

- * - *

- * OBJETIVO/PROPÓSITO - *

- * - *

- * EXEMPLO: - *

- * - * @author Gilmar P.S.L. - * - * @since - * - * @version - */ - -public class FileUtil { - - public static final String ENTER = "\r\n"; - - - - /** - *

- * Método responsável pela leitura de qualqer arquivo. Cada linha do arquivo - * corresponde a um item da lista retornada. Caso tenha lido algum arquivo - * ou não houve poblema na leitura, retorna List senão null - *

- * - * @param pathName - * @return sucess - * - * @since - */ - - public static List read(String pathName) { - - if (pathName != null) { - - try { - - return readFree(new File(pathName)); - - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - return null; - } - - /** - *

- * Método responável pela leitura de qualqer arquivo. Cada linha do arquivo - * corresponde a um item da lista retornada. Caso tenha lido algum arquivo - * ou não houve poblema na leitura, retorna List senão null. - *

- * - * @param file - * @return - * - * @since - */ - - public static List read(File file) { - - if (file != null) { - - try { - - return readFree(file); - - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - return null; - } - - private static List readFree(File file) throws IOException { - - List archive = new ArrayList(); - - BufferedReader reader = new BufferedReader(new FileReader(file)); - - String s; - - do { - s = reader.readLine(); - if (s != null) { - archive.add(s); - } - } while (s != null); - - reader.close(); - - return archive; - } - - public static void createOthers(File file, String tagName, int lineBuffer) - throws IOException { - - List archive = new ArrayList(lineBuffer); - - BufferedReader reader = new BufferedReader(new FileReader(file)); - - String s; - - int count = 0; - int countFile = 1; - - String path = StringUtils.substringBefore(file.getAbsolutePath(), "\\" - + file.getName()) - + "\\"; - - do { - - s = reader.readLine(); - - if (s != null) { - archive.add(s + "\r\n"); - count++; - } - - if ((count % lineBuffer == 0) && count > 1) { // multiplos - - createFile(path + tagName + countFile + ".txt", archive); - archive = new ArrayList(lineBuffer); - countFile++; - } - - } while (s != null); - - if (!archive.isEmpty()) { - createFile(path + tagName + countFile + ".txt", archive); - } - - reader.close(); - } - - - - /** - *

- * Método responsável pela marcação de qualqer arquivo. - *

- * - * @param pathName - * @param tag - * @return sucess - * - * @since - */ - - public static boolean mark(String pathName, String tag) { - - if (pathName != null & tag != null) { - - File arch = new File(pathName); - File newArch = new File(pathName + tag); - - arch.renameTo(newArch); - - return true; - } - return false; - } - - - - /** - *

- * Método responsável pela renomeação de qualqer arquivo - *

- * - * @param pathDir - * @param name - * @param wishName - * @return sucess - * - * @since - */ - - public static boolean renameAs(String pathDir, String name, - String wishName) { - - if (pathDir != null & name != null & wishName != null) { - - File arch = new File(pathDir + "/" + name); - File newArch = new File(pathDir + "/" + wishName); - - arch.renameTo(newArch); - - return true; - } - - return false; - } - - - - /** - *

- * Cria um arquivo a partir de uma única string com o layout da mesma. Ou - * seja, se a string tem quebra de linha o arquivo também terá. - *

- * - * @param path - * @param content - * @return sucess - * - * @since - */ - - public static boolean createFile(String path, String content) { - - try { - - File arch = null; - - arch = new File(path); - - BufferedWriter wtr = new BufferedWriter(new FileWriter(arch)); - wtr.write(content); - wtr.flush(); - wtr.close(); - - arch.setWritable(true); - arch.setReadable(true); - arch.setExecutable(true); - - return true; - - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - - return false; - - } - - - /** - *

- * Cria um arquivo com várias linhas a partir de uma lista de strings. Para - * cada item da lista uma linha será criada no arquivo. - *

- * - * @param path - * @param content - * - * @since - */ - - public static void createFile(String path, List content) { - - File arq = null; - - arq = new File(path); - - write(arq, content); - - } - - - - /** - *

- * Cria um arquivo com vária linhas a partir de uma lista de strings. Para - * cada item da lista uma linha será criada no arquivo. - *

- * - * @param file - * @param content - * - * @since - */ - - public static void write(File file, List content) { - - try { - - BufferedWriter wtr = new BufferedWriter(new FileWriter(file)); - for (String c : content) { - wtr.write(c); - } - - wtr.flush(); - wtr.close(); - - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - - /** - *

- * Cria um arquivo a partir de uma única string. - *

- * - * @param file - * @param content - * - * @since - */ - - public static void write(File file, String content) { - - try { - - BufferedWriter wtr = new BufferedWriter(new FileWriter(file)); - - wtr.write(content); - - wtr.flush(); - wtr.close(); - - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } - -} diff --git a/src/br/com/nordestefomento/jrimum/utilix/DateUtil.java b/src/br/com/nordestefomento/jrimum/utilix/DateUtil.java deleted file mode 100644 index 322bc1c..0000000 --- a/src/br/com/nordestefomento/jrimum/utilix/DateUtil.java +++ /dev/null @@ -1,271 +0,0 @@ -/* - * Copyright 2008 JRimum Project - * - * 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. - * - * Created at: 30/03/2008 - 18:17:40 - * - * ================================================================================ - * - * Direitos autorais 2008 JRimum Project - * - * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar - * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma - * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que - * haja exigência legal ou acordo por escrito, a distribuição de software sob - * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER - * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a - * reger permissões e limitações sob esta LICENÇA. - * - * Criado em: 30/03/2008 - 18:17:40 - * - */ - -package br.com.nordestefomento.jrimum.utilix; - -import static br.com.nordestefomento.jrimum.utilix.ObjectUtil.isNotNull; - -import java.io.Serializable; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; - -import org.apache.commons.lang.time.DateUtils; - -/** - * - *

- * Serviços utilitários relacionados a manipulação de Objetos - * Date, Calendar, GregorianCalendar. - *

- * - * - * - * @author Gilmar P.S.L - * @author Misael Barreto - * @author Rômulo Augusto - * @author Nordeste Fomento - * Mercantil - * - * @since 0.2 - * - * @version 0.2 - */ -public class DateUtil implements Serializable { - - /** - * - */ - private static final long serialVersionUID = 4339951860440604914L; - - /** - *

- * Formatador de datas no padrão dd/MM/yyyy. - *

- */ - public static final DateFormat FORMAT_DD_MM_YYYY = new SimpleDateFormat( - "dd/MM/yyyy"); - - /** - *

- * Formatador de datas no padrão ddMMyy. - *

- */ - public static final DateFormat FORMAT_DDMMYY = new SimpleDateFormat( - "ddMMyy"); - - /** - *

- * Formatador de datas no padrão yyMMdd. - *

- */ - public static final DateFormat FORMAT_YYMMDD = new SimpleDateFormat( - "yyMMdd"); - - /** - *

- * Representa uma data inexistente, pode ser usada em casos que não se pode - * usar null [ é obtida da seguinte forma: - * new GregorianCalendar(1, 0, 1).getTime() ] - *

- */ - public static final Date DATE_NULL; - - static { - - Calendar calendar = Calendar.getInstance(); - calendar.set(1, 0, 1); - calendar.setLenient(false); - DATE_NULL = DateUtils.truncate(calendar.getTime(), Calendar.YEAR); - } - - /** - *

- * Converte um objeto String em um objeto - * java.util.Date no formato de data padrão brasileiro: - * dd/MM/yyyy. - *

- *

- * Utiliza a sobrecarca - * parse(String dateAsString, DateFormat dateFormat) para - * realizar a conversão. - *

- * - * @param dateAsString - * - um valor de data em forma de String. - * @return Objeto java.util.Date convertido a partir do objeto - * String - * - * @throws IllegalArgumentException - * caso o objeto String não seja um valor válido de - * data suportado pelo formato. - * @since 0.2 - */ - public static Date parse(String dateAsString) { - - return parse(dateAsString, FORMAT_DD_MM_YYYY); - } - - /** - *

- * Converte um objeto String em um objeto - * java.util.Date a partir do formato de data especificado. - *

- *

- * Utiliza a sobrecarca - * parse(String dateAsString, DateFormat dateFormat) para - * realizar a conversão. - *

- * - * @param dateAsString - * - um valor de data em forma de String. - * @param dateFormat - * - formato de data - * @return Objeto java.util.Date convertido a partir do objeto - * String - * - * @throws IllegalArgumentException - * caso o objeto String não seja um valor válido de - * data suportado pelo formato. - * @since 0.2 - */ - public static Date parse(String dateAsString, String dateFormat) { - - if (dateFormat == null) { - throw new NullPointerException( - "O formato da data não pode ter valor [null]."); - } - - return parse(dateAsString, new SimpleDateFormat(dateFormat)); - } - - /** - *

- * Converte um objeto String em um objeto - * java.util.Date através do objeto - * java.text.DateFormat especificado. - *

- * - * @param dateAsString - * - um valor de data em forma de String. - * @param dateFormat - * - formatador para objetos java.util.Date. - * @return Objeto java.util.Date convertido a partir do objeto - * String - * - * @throws IllegalArgumentException - * caso o objeto String não seja um valor válido de - * data suportado pelo formatador. - * @since 0.2 - */ - public static Date parse(String dateAsString, DateFormat dateFormat) { - - Date date = null; - - if (dateAsString == null) { - throw new NullPointerException( - "A String a ser convertida não pode ter valor [null]."); - } - - if (dateFormat == null) { - throw new NullPointerException( - "O formatador não pode ter valor [null]."); - } - - try { - - date = dateFormat.parse(dateAsString); - - } catch (ParseException e) { - - String msg = "A String [" + dateAsString - + "] deve ser uma data válida no formato"; - if (dateFormat instanceof SimpleDateFormat) { - SimpleDateFormat sdf = (SimpleDateFormat) dateFormat; - msg += " [" + sdf.toPattern() + "]."; - - } else { - msg += " especificado."; - } - - IllegalArgumentException iae = new IllegalArgumentException(msg); - iae.initCause(e); - throw iae; - } - - return date; - } - - /** - *

- * Calcula a diferença de dias entre duas datas. O resultado é modular, ou - * seja, maior ou igual a zero, logo a data final não precisa ser - * necessariamente maior que a data inicial. - *

- * - * @param dataInicial - * - data inicial do intervalo. - * @param dataFinal - * - data final do intervalo. - * @return número(módulo) de dias entre as datas. - * - * @throws IllegalArgumentException - * Caso pelo menos uma das duas datas seja null. - * @since 0.2 - */ - public static long calculeDiferencaEmDias(final Date dataInicial, - final Date dataFinal) { - - long fator = 0; - Date dataInicialTruncada, dataFinalTruncada; - - if (isNotNull(dataInicial) && isNotNull(dataFinal)) { - - dataInicialTruncada = DateUtils - .truncate(dataInicial, Calendar.DATE); - dataFinalTruncada = DateUtils.truncate(dataFinal, Calendar.DATE); - - fator = ((dataFinalTruncada.getTime() - dataInicialTruncada - .getTime()) / DateUtils.MILLIS_PER_DAY); - - if (fator < 0) { - fator *= -1; - } - } else { - throw new IllegalArgumentException("A data inicial [" + dataInicial - + "] e a data final [" + dataFinal + "] " - + "não podem ter valor 'null'."); - } - - return fator; - } - -} diff --git a/src/br/com/nordestefomento/jrimum/utilix/ObjectUtil.java b/src/br/com/nordestefomento/jrimum/utilix/ObjectUtil.java deleted file mode 100644 index 949cf11..0000000 --- a/src/br/com/nordestefomento/jrimum/utilix/ObjectUtil.java +++ /dev/null @@ -1,624 +0,0 @@ -/* - * Copyright 2008 JRimum Project - * - * 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. - * - * Created at: 30/03/2008 - 18:02:40 - * - * ================================================================================ - * - * Direitos autorais 2008 JRimum Project - * - * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar - * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma - * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que - * haja exigência legal ou acordo por escrito, a distribuição de software sob - * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER - * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a - * reger permissões e limitações sob esta LICENÇA. - * - * Criado em: 30/03/2008 - 18:02:40 - * - */ - -package br.com.nordestefomento.jrimum.utilix; - -import java.io.Serializable; -import java.util.Collection; -import java.util.Map; - -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.log4j.Logger; - -/** - *

- * Classe utilitária para validações de objetos em geral, como verificações - * de objetos nulos, coleções/arrays vazios. - *

- *

- * Fornece métodos booleanos e métodos que verificam se o valor do objeto está de acordo - * com o desejado e, caso não estejam, lançam exceção. - *

- * - * @author Gilmar P.S.L. - * @author Rômulo Augusto - * - * @since 0.2 - * - * @version 0.2 - */ -public class ObjectUtil implements Serializable { - - private static final long serialVersionUID = -6790981191128287923L; - - private static Logger log = Logger.getLogger(ObjectUtil.class); - - /** - * Construtor privado para previnir a instanciação. - * - * @throws AssertionError caso haja alguma tentativa de utilização deste construtor. - */ - private ObjectUtil() { - throw new AssertionError(); - } - - /** - *

- * Método privado para fins de reutilização de código. Deve ser utilizado para verificar se - * coleções ou mapas são vazios. - *

- *

- * Verifica se o objeto passado por parâmetro é null ou se tem tamanho zero. Para verificar - * o tamanho, primeiro realiza um "cast" para Collection, caso seja instância de Collection, - * ou para Map, caso seja instância de Map, e utiliza o método "size()". - *

- * - * @param object - Objeto analisado - * @return isNull(object) || size == 0; - */ - private static boolean isEmpty(Object object) { - - int size = 0; - - if (object instanceof Collection) { - size = ((Collection) object).size(); - - } else if (object instanceof Map) { - size = ((Map) object).size(); - } - - return isNull(object) || size == 0; - } - - /** - *

- * Método privado para fins de reutilização de código. Deve ser utilizado para verificar se - * coleções ou mapas são vazios. - *

- *

- * Verifica se o objeto passado por parâmetro é null ou se tem tamanho zero. - * Para verificar o tamanho, primeiro realiza um "cast" para Collection, caso seja instância de Collection, - * ou para Map, caso seja instância de Map, e utiliza o método "size()". - *

- * - * @param object - Objeto analisado - * @param message - Mensagem utilizada na exceção - * - * @throws IllegalArgumentException Caso o objeto não seja vazio - */ - private static void checkEmpty(Object object, String message) { - - if (isNotEmpty(object)) { - throw new IllegalArgumentException(message); - } - } - - /** - *

- * Método privado para fins de reutilização de código. Deve ser utilizado para verificar se - * coleções ou mapas não são vazios. - *

- *

- * Verifica se o objeto passado por parâmetro não é null ou se tem tamanho zero. - * Para verificar o tamanho, primeiro realiza um "cast" para Collection, caso seja instância de Collection, - * ou para Map, caso seja instância de Map, e utiliza o método "size()". - *

- *

- * Caso o objeto seja null, lança NullPointerException com a mensagem informada no - * parâmetro messageNullPointer (primeiro parâmetro String). Caso o objeto não seja - * null e não possua elementos, lança IllegalArgumentException com a mensagem - * informada no parâmetro messageIllegalArgument (segundo parâmetro String). - *

- * - * @param object - Objeto analisado - * @param messageNullPointer - Mensagem utiliada na exceção NullPointerException - * @param messageIllegalArgument - Mensagem utiliada na exceção IllegalArgumentException - */ - private static void checkNotEmpty(Object object, String messageNullPointer, String messageIllegalArgument) { - - if (isNull(object)) { - throw new NullPointerException(messageNullPointer); - } - - if (isEmpty(object)) { - throw new IllegalArgumentException(messageIllegalArgument); - } - } - - /** - *

- * Verifica a referência ao objeto e lança uma exceção para casos onde a - * referência é nula incluíndo na mensagem de exceção o nome do parâmetro - * passado. - *

- * - * @param object - * @param name - * - * @return (object == null ? true : false) - * - * @throws IllegalArgumentException - * - * @see #isNotNull(Object, String) - * - * @since 0.2 - */ - @Deprecated - public static boolean isNull(Object object, String name) throws IllegalArgumentException { - - boolean is = true; - - if (object != null) { - is = false; - - } else { - - IllegalArgumentException e = new IllegalArgumentException( - (name != null ? name : "Objeto ") + " inválido : [" - + object + "]!"); - - log.error(StringUtils.EMPTY, e); - - throw e; - } - - return is; - } - - /** - *

- * Verifica a referência ao objeto e lança uma exceção para casos onde a - * referência é nula incluíndo na mensagem de exceção o nome do parâmetro - * passado. - *

- * - *

- * É o mesmo que usar !isNull(obj1,"obj1") a diferença é que - * utiliza-se um símbolo ! a menos. - *

- * - * @param object - * @param name - * - * @return (object != null ? true : false) - * - * @throws IllegalArgumentException - * - * @see #isNull(Object, String) - * - * @since 0.2 - */ - @Deprecated - public static boolean isNotNull(Object object, String name) throws IllegalArgumentException { - return !isNull(object, name); - } - - /** - *

- * Verifica se o objeto passado por parâmetro é null. - *

- * - * @param object - Objeto analisado - * - * @return (object == null ? true : false) - * - * @since 0.2 - */ - public static boolean isNull(Object object) { - return (object == null); - } - - /** - *

- * Verifica se o objeto passado por parâmetro não é null. - *

- *

- * É o mesmo que usar o método isNull da forma !isNull(obj), porém - * de forma mais legível. - *

- * - * @param object - Objeto analisado - * - * @return (object != null ? true : false) - * - * @see #isNull(Object) - * - * @since 0.2 - */ - public static boolean isNotNull(Object object) { - return !isNull(object); - } - - /** - *

- * Verifica se existe uma referência ao objeto dado. - *

- * - * @param object - Objeto analisado - * - * @return (object != null ? true : false) - * - * @see #isNotNull(Object) - * - * @since 0.2 - */ - public static boolean exists(Object object) { - return isNotNull(object); - } - - /** - *

- * Verifica se a Collection passada por parâmetro é null ou - * não possui elementos. - *

- * - * @param collection - Instância de Collection analisada - * @return (collection == null || collection.size() == 0 ? true : false) - * - * @since 0.2 - */ - public static boolean isEmpty(Collection collection) { - return isEmpty((Object) collection); - } - - /** - *

- * Verifica se a Collection passada por parâmetro não é null - * e possui elementos. - *

- * - * @param collection - Instância de Collection analisada - * @return (collection != null && collection.size() > 0 ? true : false) - * - * @see #isEmpty(Collection) - * - * @since 0.2 - */ - public static boolean isNotEmpty(Collection collection) { - return isNotEmpty((Object) collection); - } - - /** - *

- * Verifica se o Map passado por parâmetro é null ou - * não possui elementos. - *

- * - * @param map - Instância de Map analisada - * @return (map == null || map.size() == 0 ? true : false) - * - * @since 0.2 - */ - public static boolean isEmpty(Map map) { - return isEmpty((Object) map); - } - - /** - *

- * Verifica se o Map passado por parâmetro não é null - * e possui elementos. - *

- * - * @param map - Instância de Map analisada - * @return (map != null && map.size() > 0 ? true : false) - * - * @see #isEmpty(Map) - * - * @since 0.2 - */ - public static boolean isNotEmpty(Map map) { - return isNotEmpty((Object) map); - } - - /** - *

- * Método privado para fins de reutilização de código. Deve ser utilizado para verificar se - * coleções ou mapas não são vazios. - *

- *

- * Verifica se o objeto passado por parâmetro não é null ou se tem tamanho zero. - * Para verificar o tamanho, primeiro realiza um "cast" para Collection, caso seja instância de Collection, - * ou para Map, caso seja instância de Map, e utiliza o método "size()". - *

- * - * @param object - Objecto analisado - * @return (object != null && size > 0 ? true : false) - * - * @since 0.2 - */ - public static boolean isNotEmpty(Object object) { - return !isEmpty(object); - } - - /** - *

- * Verifica se o objeto é nulo e lança IllegalArgumentException, com a mensagem - * informada, caso não seja. - *

- * - * @thows IllegalArgumentException - Caso o objeto não seja null. - * - * @see #isNull(Object) - * @see #isNotNull(Object) - * - * @since 0.2 - * - * @param object - Objeto analisado - * @param message - Mensagem utilizada na exceção - */ - public static void checkNull(Object object, String message) { - - if (isNotNull(object)) { - throw new IllegalArgumentException(message); - } - } - - /** - *

- * Verifica se o objeto é nulo e lança IllegalArgumentException caso - * não seja. - *

- * - * @param object - Objeto analisado - * - * @thows IllegalArgumentException - Caso o objeto não seja null. - * - * @see #checkNull(Object, String) - * @see #isNull(Object) - * @see #isNotNull(Object) - * - * @since 0.2 - */ - public static void checkNull(Object object) { - checkNull(object, "Objeto não nulo. Valor [" + object + "]"); - } - - /** - *

- * Verifica se o objeto não é nulo e lança NullPointerException, com - * a mensagem informada, caso seja. - *

- * - * @param object - Objeto analisado - * @param message - Mensagem utilizada na exceção - * - * @thows NullPointerException - Caso o objeto seja null. - * - * @see #isNull(Object) - * @see #isNotNull(Object) - * - * @since 0.2 - */ - public static void checkNotNull(Object object, String message) { - - if (isNull(object)) { - throw new NullPointerException(message); - } - } - - /** - *

- * Verifica se o objeto não é nulo e lança NullPointerException - * caso seja. - *

- * - * @param object - Objeto analisado - * - * @thows NullPointerException - Caso o objeto seja null. - * - * @see #checkNotNull(Object, String) - * @see #isNull(Object) - * @see #isNotNull(Object) - * - * @since 0.2 - */ - public static void checkNotNull(Object object) { - checkNotNull(object, "Objeto nulo"); - } - - /** - *

- * Verifica se a Collection passado por parâmetro é null ou - * não possui elementos e lança exceção, com a mensagem informada, - * caso não preencha estes requisitos. - *

- * - * @param collection - Instância de Collection analisada - * @param message - Mensagem utilizada na exceção - * - * @thows IllegalArgumentException - Caso a coleção não seja null e possua elementos. - * - * @see #isEmpty(Collection) - * @see #isNotEmpty(Collection) - * - * @since 0.2 - */ - public static void checkEmpty(Collection collection, String message) { - checkEmpty((Object) collection, message); - } - - /** - *

- * Verifica se a Collection passada por parâmetro é null ou - * não possui elementos e lança exceção caso não preencha estes requisitos. - *

- * - * @param collection - Instância de Collection analisada - * - * @thows IllegalArgumentException - Caso a coleção não seja null e possua elementos. - * - * @see #checkEmpty(Collection, String) - * @see #isEmpty(Collection) - * @see #isNotEmpty(Collection) - * - * @since 0.2 - */ - public static void checkEmpty(Collection collection) { - checkEmpty(collection, "Collection não nulo e com elementos. Valor [" + collection + "]"); - } - - /** - *

- * Verifica se a Collection passada por parâmetro não é null e - * possui elementos e lança exceção, com a mensagem informada, caso não preencha estes requisitos. - *

- * - * @param collection - Instância de Collection analisada - * @param message - Mensagem utiliada na exceção - * - * @throws NullPointerException - Caso a coleção seja null. - * @thows IllegalArgumentException - Caso a coleção não possua elementos. - * - * @see #isEmpty(Collection) - * @see #isNotEmpty(Collection) - * - * @since 0.2 - */ - public static void checkNotEmpty(Collection collection, String message) { - checkNotEmpty(collection, message, message); - } - - /** - *

- * Verifica se a Collection passada por parâmetro não é null e - * possui elementos e lança exceção caso não preencha estes requisitos. - *

- * - * @param map - Instância de Collection analisada - * - * @throws NullPointerException - Caso a coleção seja null. - * @thows IllegalArgumentException - Caso a coleção não possua elementos. - * - * @see #checkNotEmpty(Collection, String) - * @see #isEmpty(Collection) - * @see #isNotEmpty(Collection) - * - * @since 0.2 - */ - public static void checkNotEmpty(Collection collection) { - checkNotEmpty(collection, "Objeto nulo", "Collection sem elementos"); - } - - /** - *

- * Verifica se o Map passado por parâmetro é null ou - * não possui elementos e lança exceção, com a mensagem informada, - * caso não preencha estes requisitos. - *

- * - * @param map - Instância de Map analisada - * @param message - Mensagem utilizada na exceção - * - * @thows IllegalArgumentException - Caso o mapa não seja null e possua elementos. - * - * @see #isEmpty(Map) - * @see #isNotEmpty(Map) - * - * @since 0.2 - */ - public static void checkEmpty(Map map, String message) { - checkEmpty((Object) map, message); - } - - /** - *

- * Verifica se o Map passado por parâmetro é null ou - * não possui elementos e lança exceção caso não preencha estes requisitos. - *

- * - * @param map - Instância de Map analisada - * - * @thows IllegalArgumentException - Caso o mapa não seja null e possua elementos. - * - * @see #checkEmpty(Map, String) - * @see #isEmpty(Map) - * @see #isNotEmpty(Map) - * - * @since 0.2 - */ - public static void checkEmpty(Map map) { - checkEmpty(map, "Map não nulo e com elementos. Valor [" + map + "]"); - } - - /** - *

- * Verifica se o Map passado por parâmetro não é null e - * possui elementos e lança exceção, com a mensagem informada, caso não preencha estes requisitos. - *

- * - * @param map - Instância de Map analisada - * @param message - Mensagem utiliada na exceção - * - * @throws NullPointerException - Caso o mapa seja null. - * @thows IllegalArgumentException - Caso o mapa não possua elementos. - * - * @see #isEmpty(Map) - * @see #isNotEmpty(Map) - * - * @since 0.2 - */ - public static void checkNotEmpty(Map map, String message) { - checkNotEmpty(map, message, message); - } - - /** - *

- * Verifica se o Map passado por parâmetro não é null e - * possui elementos e lança exceção caso não preencha estes requisitos. - *

- * - * @param map - Instância de Map analisada - * - * @throws NullPointerException - Caso o mapa seja null. - * @thows IllegalArgumentException - Caso o mapa não possua elementos. - * - * @see #checkNotEmpty(Map, String) - * @see #isEmpty(Map) - * @see #isNotEmpty(Map) - * - * @since 0.2 - */ - public static void checkNotEmpty(Map map) { - checkNotEmpty(map, "Objeto nulo", "Map sem elementos"); - } - - /** - * Exibe os valores de instância para um objeto JRimum. - * - * @see org.apache.commons.lang.builder.ToStringBuilder#reflectionToString - * - * @since 0.2 - * - * @see java.lang.Object#toString() - */ - public static String toString(Object obj) { - return "JRimumObject: " + ToStringBuilder.reflectionToString(obj); - } -} diff --git a/src/br/com/nordestefomento/jrimum/utilix/StringUtil.java b/src/br/com/nordestefomento/jrimum/utilix/StringUtil.java deleted file mode 100644 index f28a5bc..0000000 --- a/src/br/com/nordestefomento/jrimum/utilix/StringUtil.java +++ /dev/null @@ -1,337 +0,0 @@ -/* - * Copyright 2008 JRimum Project - * - * 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. - * - * Created at: 30/03/2008 - 18:18:19 - * - * ================================================================================ - * - * Direitos autorais 2008 JRimum Project - * - * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar - * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma - * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que - * haja exigência legal ou acordo por escrito, a distribuição de software sob - * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER - * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a - * reger permissões e limitações sob esta LICENÇA. - * - * Criado em: 30/03/2008 - 18:18:19 - * - */ - -package br.com.nordestefomento.jrimum.utilix; - -import static br.com.nordestefomento.jrimum.utilix.ObjectUtil.isNotNull; - -import java.io.Serializable; - -import org.apache.commons.lang.StringUtils; - -/** - *

- * Esta classe tem a responsabilidade de prover serviços utilitários - * relacionados a manipulação de Strings - *

- * - * - * @author Gilmar P.S.L - * @author Misael Barreto - * @author Rômulo Augusto - * @author Nordeste Fomento - * Mercantil - * - * @since 0.2 - * - * @version 0.2 - */ -public class StringUtil implements Serializable { - - public static final String WHITE_SPACE = " "; - - /** - * - */ - private static final long serialVersionUID = 7425529940068032055L; - - /** - *

- * Construtor privado que previne a instanciação da classe até por - * reflection - *

- * - * @since 0.2 - */ - private StringUtil() { - throw new AssertionError(); - } - - /** - *

- * Método privado para fins de reutilização de código. - *

- *

- * Verifica se a String passada por parâmetro não é null, - * não é vazia (StringUtils.EMPTY) e não possui apenas espaços em branco. - *

- *

- * Lança NullPointerException, com a mensagem definida em messageNullPointer - * (segundo parâmetro String), caso o valor passado seja null - *

- *

- * Lança IllegalArgumentException, com a mensagem definida em messageIllegalArgument - * (terceiro parâmetro String), caso o valor passado seja vazio ou contenha apenas espaços em branco. - *

- * - * @param value - String analisada - * - * @throws NullPointerException - Caso a string seja null. - * @thows IllegalArgumentException - Caso a string seja vazia ou contenha apenas espaços em branco. - * - * @since 0.2 - */ - private static void checkNotBlank(String value, String messageNullPointer, String messageIllegalArgument) { - - ObjectUtil.checkNotNull(value, messageNullPointer); - - if (StringUtils.isBlank(value)) { - throw new IllegalArgumentException(messageIllegalArgument); - } - } - - /** - *

- * Elimina simbolos como:

><,;.:!*&%+-_<>[]\/
- *

- * - * @param str - * String com os símbolos a serem removidos. - * @return String sem símbolos. - * @since 0.2 - */ - public static String eliminateSymbols(final String str) { - - String modifiedStr = str; - - if (isNotNull(modifiedStr)) { - - modifiedStr = StringUtils.replace(str, "-", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, "_", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, "=", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, "+", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, "%", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, "*", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, "@", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, "#", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, "&", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, ":", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, ".", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, ";", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, ",", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, "!", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, "?", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, "(", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, ")", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, "{", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, "}", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, "[", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, "]", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, "/", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, "\\", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, ">", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, "<", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, "\"", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, "'", StringUtils.EMPTY); - modifiedStr = StringUtils.replace(str, "`", StringUtils.EMPTY); - } - - return modifiedStr; - } - - /** - *

- * Remove os zeros iniciais de uma String, seja ela numérica ou - * não. - *

- *

- * removeStartWithZeros("00000") => 0
- * removeStartWithZeros("00023") => 23
- * removeStartWithZeros("02003") => 2003 - *

- * - * @param str - * @return a string sem zeros inicias ou um único zero. - * - * @since 0.2 - */ - - public static String removeStartWithZeros(final String str) { - - String withoutZeros = StringUtils.EMPTY; - final String zero = "0"; - - if (isNotNull(str)) { - - if (StringUtils.startsWith(str, zero)) { - - withoutZeros = StringUtils.removeStart(str, zero); - - while (StringUtils.startsWith(withoutZeros, zero)) { - withoutZeros = StringUtils.removeStart(withoutZeros, zero); - } - - if (withoutZeros.trim().length() == 0) { - withoutZeros = zero; - } - - } else { - withoutZeros = str; - } - } - - return withoutZeros; - } - - /** - *

- * Remove a acentuação do texto, que inclui os acentos: - *

    - *
  • Agudo. ex.: á
  • - *
  • Grave. ex.: à
  • - *
  • Til. ex.: ã
  • - *
  • Trema. ex.: ä
  • - *
  • Circunflexo. ex.: â
  • - *
- * e o Cedilha (ç). - *

- *

- * Os acentos são removidos tanto para letras minúsculas como para letras - * maiúsculas. - *

- * - * @param value - * String com os caracteres a serem removidos. - * @return String sem acentuação. - * @since 0.2 - */ - public static String eliminateAccent(final String value) { - - String modifiedValue = value; - - // Para ç e Ç - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00E7', 'c'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00C7', 'C'); - - // Para à, á, â, ã e ä - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00E0', 'a'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00E1', 'a'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00E2', 'a'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00E3', 'a'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00E4', 'a'); - - // Para è, é, ê e ë - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00E8', 'e'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00E9', 'e'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00EA', 'e'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00EB', 'e'); - - // Para ì, í, î e ï - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00EC', 'i'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00ED', 'i'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00EE', 'i'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00EF', 'i'); - - // Para ò, ó, ô, õ e ö - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00F2', 'o'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00F3', 'o'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00F4', 'o'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00F5', 'o'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00F6', 'o'); - - // Para ù, ú, û e ü - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00F9', 'u'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00FA', 'u'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00FB', 'u'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00FC', 'u'); - - // Para À, Á, Â, Ã e Ä - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00C0', 'A'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00C1', 'A'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00C2', 'A'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00C3', 'A'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00C4', 'A'); - - // Para È, É, Ê e Ë - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00C8', 'E'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00C9', 'E'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00CA', 'E'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00CB', 'E'); - - // Para Ì, Í, Î e Ï - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00CC', 'I'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00CD', 'I'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00CE', 'I'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00CF', 'I'); - - // Para Ò, Ó, Ô, Õ e Ö - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00D2', 'O'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00D3', 'O'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00D4', 'O'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00D5', 'O'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00D6', 'O'); - - // Para Ù, Ú, Û e Ü - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00D9', 'U'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00DA', 'U'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00DB', 'U'); - modifiedValue = StringUtils.replaceChars(modifiedValue, '\u00DC', 'U'); - - return modifiedValue; - } - - /** - *

- * Verifica se a String passada por parâmetro não é null, - * não é vazia (StringUtils.EMPTY) e não possui apenas espaços em branco. - *

- *

- * Lança exceção, com a mensagem passada por parâmetro (segundo parâmetro String), - * caso não preencha estes requisitos. - *

- * - * @param value - String analisada - * - * @throws NullPointerException - Caso a string seja null. - * @thows IllegalArgumentException - Caso a string seja vazia ou contenha apenas espaços em branco. - * - * @since 0.2 - */ - public static void checkNotBlank(String value, String message) { - checkNotBlank(value, message, message); - } - - /** - *

- * Verifica se a String passada por parâmetro não é null, - * não é vazia (StringUtils.EMPTY) e não possui apenas espaços em branco. - * Lança exceção caso não preencha estes requisitos. - *

- * - * @param value - String analisada - * - * @throws NullPointerException - Caso a string seja null. - * @thows IllegalArgumentException - Caso a string seja vazia ou contenha apenas espaços em branco. - * - * @since 0.2 - */ - public static void checkNotBlank(String value) { - checkNotBlank(value, "String nula", "Valor inválido. String vazia ou contendo apenas espaços em brancos"); - } -} diff --git a/src/main/assembly/jrimum-texgit-examples.xml b/src/main/assembly/jrimum-texgit-examples.xml new file mode 100644 index 0000000..4b921d4 --- /dev/null +++ b/src/main/assembly/jrimum-texgit-examples.xml @@ -0,0 +1,27 @@ + + examples + + zip + + + + src/examples/java + true + / + + **/*.java + + + + src/examples/resources + true + /resources + + **/** + + + + \ No newline at end of file diff --git a/src/main/assembly/jrimum-texgit-with-dependencies.xml b/src/main/assembly/jrimum-texgit-with-dependencies.xml new file mode 100644 index 0000000..92a944e --- /dev/null +++ b/src/main/assembly/jrimum-texgit-with-dependencies.xml @@ -0,0 +1,24 @@ + + dep + + jar + + false + + + / + true + true + runtime + + commons-lang:commons-lang + log4j:log4j + sun-jaxb:jaxb-api + sun-jaxb:jaxb-impl + + + + \ No newline at end of file diff --git a/src/main/java/org/jrimum/texgit/FlatFile.java b/src/main/java/org/jrimum/texgit/FlatFile.java new file mode 100644 index 0000000..4054a4d --- /dev/null +++ b/src/main/java/org/jrimum/texgit/FlatFile.java @@ -0,0 +1,66 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit; + +import java.util.Collection; + +/** + * @author Gilmar P.S.L. + * + * @param + */ +public interface FlatFile extends TextListStream { + + // Registros individuais + + public G createRecord(String idType); + + public FlatFile addRecord(G record); + + public G getRecord(String idName); + + public G removeRecord(String idName); + + // Grupos de Registros (Registros que se repetem) + + public FlatFile addRecords(String idName, Collection records); + + public FlatFile setRecords(String idName, Collection records); + + public Collection getRecords(String idName); + + // Todos os Registros + + public FlatFile addAllRecords(Collection records); + + public FlatFile setAllRecords(Collection records); + + public Collection getAllRecords(); + +} diff --git a/src/br/com/nordestefomento/jrimum/utilix/ReadWriteStream.java b/src/main/java/org/jrimum/texgit/ReadWriteStream.java similarity index 89% rename from src/br/com/nordestefomento/jrimum/utilix/ReadWriteStream.java rename to src/main/java/org/jrimum/texgit/ReadWriteStream.java index 2b959a2..3435366 100644 --- a/src/br/com/nordestefomento/jrimum/utilix/ReadWriteStream.java +++ b/src/main/java/org/jrimum/texgit/ReadWriteStream.java @@ -27,12 +27,11 @@ * */ -package br.com.nordestefomento.jrimum.utilix; +package org.jrimum.texgit; import java.io.Serializable; /** - * *

* Interface genérica e representativa de coisas que necessitam de operações de * fluxo de escrita e leitura. @@ -44,7 +43,6 @@ * * @version 0.2 */ - public interface ReadWriteStream extends Serializable { /** @@ -55,17 +53,17 @@ public interface ReadWriteStream extends Serializable { * @return Um valor no mesmo tipo do tipo parametrizado * @since 0.2 */ - public abstract G write(); + G write(); /** *

* Lê o tipo informado. *

* - * @param g - * valor a ser lido + * @param g - Valor a ser lido + * * @since 0.2 */ - public abstract void read(G g); + void read(G g); } diff --git a/src/main/java/org/jrimum/texgit/Record.java b/src/main/java/org/jrimum/texgit/Record.java new file mode 100644 index 0000000..9271f4f --- /dev/null +++ b/src/main/java/org/jrimum/texgit/Record.java @@ -0,0 +1,46 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit; + +import java.util.List; + +/** + * @author Gilmar P.S.L. + * + */ +public interface Record extends TextStream { + + public Record setValue(String fieldName, G value); + + public G getValue(String fieldName); + + public Record addInnerRecord(Record record); + + public List getInnerRecords(); +} diff --git a/src/main/java/org/jrimum/texgit/Texgit.java b/src/main/java/org/jrimum/texgit/Texgit.java new file mode 100644 index 0000000..514eee1 --- /dev/null +++ b/src/main/java/org/jrimum/texgit/Texgit.java @@ -0,0 +1,126 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit; + +import static org.apache.commons.lang.StringUtils.isNotBlank; +import static org.jrimum.utilix.Objects.isNotNull; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.net.URL; + +import org.jrimum.texgit.engine.TexgitManager; + +/** + * @author Gilmar P.S.L. + * + */ +public final class Texgit { + + public static final FlatFile createFlatFile(String xmlDefFilePath) + throws TexgitException { + + try { + + if (isNotBlank(xmlDefFilePath)) + return createFlatFile(new File(xmlDefFilePath)); + + } catch (Exception e) { + throw new TexgitException(e); + } + + return null; + } + + public static final FlatFile createFlatFile(File xmlDefFile) + throws TexgitException { + + try { + + if (isNotNull(xmlDefFile)) { + + return createFlatFile(new FileInputStream(xmlDefFile)); + } + + } catch (Exception e) { + throw new TexgitException(e); + } + + return null; + } + + public static final FlatFile createFlatFile(URL xmlDefUrl) + throws TexgitException { + + try { + + if (isNotNull(xmlDefUrl)) { + + return TexgitManager.buildFlatFile(xmlDefUrl.openStream()); + } + + } catch (Exception e) { + throw new TexgitException(e); + } + + + return null; + } + + public static final FlatFile createFlatFile(byte[] xmlDefBytes) + throws TexgitException { + + try { + + if (isNotNull(xmlDefBytes)) { + + return TexgitManager.buildFlatFile(new ByteArrayInputStream(xmlDefBytes)); + } + + } catch (Exception e) { + throw new TexgitException(e); + } + + return null; + } + + public static final FlatFile createFlatFile(InputStream xmlDefStream) + throws TexgitException { + + if (isNotNull(xmlDefStream)) { + + return TexgitManager.buildFlatFile(xmlDefStream); + } + + return null; + } + +} diff --git a/src/main/java/org/jrimum/texgit/TexgitException.java b/src/main/java/org/jrimum/texgit/TexgitException.java new file mode 100644 index 0000000..b518c31 --- /dev/null +++ b/src/main/java/org/jrimum/texgit/TexgitException.java @@ -0,0 +1,76 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit; + +/** + * + *

+ * Invólucro para exceções ocorridas no componente. + *

+ * + * @author Gilmar P.S.L. + * + * */ +@SuppressWarnings("serial") +public class TexgitException extends RuntimeException { + + /** + * + */ + public TexgitException() { + super(); + + } + + /** + * @param arg0 + * @param arg1 + */ + public TexgitException(String arg0, Throwable arg1) { + super(arg0, arg1); + + } + + /** + * @param arg0 + */ + public TexgitException(String arg0) { + super(arg0); + + } + + /** + * @param arg0 + */ + public TexgitException(Throwable arg0) { + super(arg0); + + } + +} diff --git a/src/main/java/org/jrimum/texgit/TextListStream.java b/src/main/java/org/jrimum/texgit/TextListStream.java new file mode 100644 index 0000000..24cb50e --- /dev/null +++ b/src/main/java/org/jrimum/texgit/TextListStream.java @@ -0,0 +1,39 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit; + +import java.util.List; + +/** + * @author Gilmar P.S.L. + * + */ +public interface TextListStream extends ReadWriteStream> { + +} diff --git a/src/br/com/nordestefomento/jrimum/utilix/TextStream.java b/src/main/java/org/jrimum/texgit/TextStream.java similarity index 85% rename from src/br/com/nordestefomento/jrimum/utilix/TextStream.java rename to src/main/java/org/jrimum/texgit/TextStream.java index 36b5f27..a37cced 100644 --- a/src/br/com/nordestefomento/jrimum/utilix/TextStream.java +++ b/src/main/java/org/jrimum/texgit/TextStream.java @@ -27,18 +27,16 @@ * */ +package org.jrimum.texgit; -package br.com.nordestefomento.jrimum.utilix; /** - * *

Interface usada para objetos com serviços de leitura e escrita de textos.

* - * * @author Gilmar P.S.L - * @author Misael Barreto - * @author Rômulo Augusto - * @author Nordeste Fomento + * @author Misael Barreto + * @author Rômulo Augusto + * @author Nordeste Fomento * Mercantil * * @since 0.2 diff --git a/src/br/com/nordestefomento/jrimum/texgit/engine/Builder4FixedField.java b/src/main/java/org/jrimum/texgit/engine/FixedFieldBuilder.java similarity index 61% rename from src/br/com/nordestefomento/jrimum/texgit/engine/Builder4FixedField.java rename to src/main/java/org/jrimum/texgit/engine/FixedFieldBuilder.java index 4ed797a..6e94526 100644 --- a/src/br/com/nordestefomento/jrimum/texgit/engine/Builder4FixedField.java +++ b/src/main/java/org/jrimum/texgit/engine/FixedFieldBuilder.java @@ -1,9 +1,37 @@ -package br.com.nordestefomento.jrimum.texgit.engine; +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit.engine; -import static br.com.nordestefomento.jrimum.utilix.ObjectUtil.isNotNull; import static org.apache.commons.lang.StringUtils.EMPTY; import static org.apache.commons.lang.StringUtils.countMatches; import static org.apache.commons.lang.StringUtils.isNotBlank; +import static org.jrimum.utilix.Objects.isNotNull; import java.math.BigDecimal; import java.text.DateFormat; @@ -13,18 +41,24 @@ import java.text.SimpleDateFormat; import java.util.Date; -import br.com.nordestefomento.jrimum.texgit.TexgitException; -import br.com.nordestefomento.jrimum.texgit.language.EnumFormats; -import br.com.nordestefomento.jrimum.texgit.language.EnumFormatsTypes; -import br.com.nordestefomento.jrimum.texgit.language.MetaField; -import br.com.nordestefomento.jrimum.texgit.type.component.CommonFiller; -import br.com.nordestefomento.jrimum.texgit.type.component.Side; -import br.com.nordestefomento.jrimum.texgit.type.component.Filler; -import br.com.nordestefomento.jrimum.texgit.type.component.FixedField; -import br.com.nordestefomento.jrimum.utilix.DateUtil; - -class Builder4FixedField { - +import org.jrimum.texgit.TexgitException; +import org.jrimum.texgit.language.EnumFormats; +import org.jrimum.texgit.language.EnumFormatsTypes; +import org.jrimum.texgit.language.MetaField; +import org.jrimum.texgit.type.Filler; +import org.jrimum.texgit.type.component.Fillers; +import org.jrimum.texgit.type.component.FixedField; +import org.jrimum.texgit.type.component.Side; +import org.jrimum.utilix.Dates; + +/** + * @author Gilmar P.S.L. + * + */ +class FixedFieldBuilder { + + private final static String BASE_DECIMAL_FORMAT = "0."; + static FixedField build(MetaField metaField) { FixedField fixedField = null; @@ -73,7 +107,7 @@ private static FixedField getInstance(MetaField metaField) if (isNotBlank(metaField.getValue())) fINT.setValue(Integer.parseInt(metaField.getValue())); else - fINT.setValue(new Integer(0)); + fINT.setValue(Integer.valueOf(0)); fField = fINT; break; case LONG: @@ -81,7 +115,7 @@ private static FixedField getInstance(MetaField metaField) if (isNotBlank(metaField.getValue())) fLNG.setValue(Long.parseLong(metaField.getValue())); else - fLNG.setValue(new Long(0)); + fLNG.setValue(Long.valueOf(0)); fField = fLNG; break; case FLOAT: @@ -89,7 +123,7 @@ private static FixedField getInstance(MetaField metaField) if (isNotBlank(metaField.getValue())) fFLT.setValue(Float.parseFloat(metaField.getValue())); else - fFLT.setValue(new Float(0)); + fFLT.setValue(Float.valueOf(0)); fField = fFLT; break; case DOUBLE: @@ -97,7 +131,7 @@ private static FixedField getInstance(MetaField metaField) if (isNotBlank(metaField.getValue())) fDBE.setValue(Double.parseDouble(metaField.getValue())); else - fDBE.setValue(new Double(0)); + fDBE.setValue(Double.valueOf(0)); fField = fDBE; break; case BIGDECIMAL: @@ -107,16 +141,20 @@ private static FixedField getInstance(MetaField metaField) .cast(formatter).parse(metaField.getValue()) .doubleValue())); else - fBDL.setValue(new BigDecimal(0)); + fBDL.setValue(BigDecimal.ZERO); fField = fBDL; break; case DATE: FixedField fDTE = new FixedField(); - if (isNotBlank(metaField.getValue())) + if (isNotBlank(metaField.getValue())){ + fDTE.setValue(DateFormat.class.cast(formatter).parse( metaField.getValue())); - else - fDTE.setValue(DateUtil.DATE_NULL); + } + else{ + + fDTE.setValue(Dates.invalidDate()); + } fField = fDTE; break; } @@ -125,6 +163,7 @@ private static FixedField getInstance(MetaField metaField) fField.setFixedLength(metaField.getLength()); fField.setFiller(getFiller(metaField)); fField.setBlankAccepted(metaField.isBlankAccepted()); + fField.setTruncate(metaField.isTruncate()); if(isNotNull(formatter)) fField.setFormatter(formatter); @@ -132,21 +171,20 @@ private static FixedField getInstance(MetaField metaField) return fField; } - private static Filler getFiller(MetaField metaField) { + private static Filler getFiller(MetaField metaField) { - Filler filler = null; + Filler filler = null; if (isNotNull(metaField.getFiller())) { - Filler filr = new Filler(); + org.jrimum.texgit.type.component.Filler filr = new org.jrimum.texgit.type.component.Filler(); filr.setPadding(metaField.getFiller().getPadding()); filr.setSideToFill(Side.valueOf(metaField.getFiller() .getSideToFill().name())); filler = filr; } else { - filler = CommonFiller.valueOf(metaField.getPadding().name()) - .getOne(); + filler = Fillers.valueOf(metaField.getPadding().name()); } return filler; @@ -195,8 +233,6 @@ private static Format buildFormat(String strFormat, EnumFormatsTypes type) { private static String buildFormat(EnumFormats format, EnumFormatsTypes type) { - final String BASE_DECIMAL_FORMAT = "0."; - String strFormat = EMPTY; /* * DATE_DDMMYY, DATE_DDMMYYYY, DATE_YYMMDD, DATE_YYYYMMDD, @@ -216,7 +252,7 @@ private static String buildFormat(EnumFormats format, EnumFormatsTypes type) { int lengthToFill = BASE_DECIMAL_FORMAT.length() + countMatches(defFormat, "D"); - strFormat = CommonFiller.ZERO_RIGHT.getOne().fill( + strFormat = Fillers.ZERO_RIGHT.fill( BASE_DECIMAL_FORMAT, lengthToFill); break; diff --git a/src/main/java/org/jrimum/texgit/engine/FlatFileBuilder.java b/src/main/java/org/jrimum/texgit/engine/FlatFileBuilder.java new file mode 100644 index 0000000..e0a64c7 --- /dev/null +++ b/src/main/java/org/jrimum/texgit/engine/FlatFileBuilder.java @@ -0,0 +1,82 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit.engine; + +import static org.jrimum.utilix.Objects.isNotNull; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.jrimum.texgit.language.MetaFlatFile; +import org.jrimum.texgit.language.MetaRecord; +import org.jrimum.texgit.type.component.FlatFile; + + + +/** + * @author Gilmar P.S.L. + * + */ +public class FlatFileBuilder { + + static FlatFile build(MetaFlatFile mFlatFile) { + + FlatFile ff = null; + + List metaRecords = mFlatFile.getGroupOfRecords().getRecords(); + + ff = new FlatFile(new RecordFactory(metaRecords)); + + Set repitables = new HashSet(); + + List recordsOrder = new ArrayList(); + + if (isNotNull(metaRecords)) { + + if (!metaRecords.isEmpty()) { + + for (MetaRecord mRec : metaRecords) { + + recordsOrder.add(mRec.getName()); + + if (mRec.isRepeatable()) + repitables.add(mRec.getName()); + } + } + } + + ff.setRecordsOrder(recordsOrder); + ff.setRepitablesRecords(repitables); + + return ff; + } + +} diff --git a/src/main/java/org/jrimum/texgit/engine/RecordBuilder.java b/src/main/java/org/jrimum/texgit/engine/RecordBuilder.java new file mode 100644 index 0000000..388591c --- /dev/null +++ b/src/main/java/org/jrimum/texgit/engine/RecordBuilder.java @@ -0,0 +1,137 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit.engine; + +import static org.jrimum.utilix.Objects.isNotNull; +import static org.jrimum.utilix.Objects.isNull; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; + +import org.jrimum.texgit.language.MetaField; +import org.jrimum.texgit.language.MetaOrderedField; +import org.jrimum.texgit.language.MetaRecord; +import org.jrimum.texgit.type.component.FixedField; +import org.jrimum.texgit.type.component.Record; + + + +/** + * @author Gilmar P.S.L. + * + */ +class RecordBuilder { + + @SuppressWarnings("unchecked") + static Record build(MetaRecord metaRecord) { + + int strLength = getStringLength(metaRecord.getGroupOfFields().getFields()); + int fldSize = metaRecord.getGroupOfFields().getFields().size(); + + MetaOrderedField id = metaRecord.getGroupOfFields().getIdType(); + MetaOrderedField sequencialNumber = metaRecord.getGroupOfFields().getSequencialNumber(); + + if(isNotNull(id)){ + fldSize += 1; + strLength += id.getLength(); + } + + if(isNotNull(sequencialNumber)){ + fldSize += 1; + strLength += sequencialNumber.getLength(); + } + + Record record = new Record(strLength,fldSize); + + record.setName(metaRecord.getName()); + record.setDescription(metaRecord.getDescription()); + + /* + * getPossition eh de 1 a X + * e nao de 0 a X. + */ + if(isNotNull(id)){ + record.setIdType((FixedField) FixedFieldBuilder.build(id)); + record.set(id.getPosition()-1, record.getIdType()); + } + + if(isNotNull(sequencialNumber)){ + record.setSequencialNumber((FixedField) FixedFieldBuilder.build(sequencialNumber)); + record.set(sequencialNumber.getPosition()-1,record.getSequencialNumber()); + } + + List fields = metaRecord.getGroupOfFields().getFields(); + + /* + * As somas sao para caso id ou sequencia jah + * estejam na devida posicao. + */ + for(MetaField mField : fields){ + + if(isNull(record.get(fields.indexOf(mField)))) + record.set(fields.indexOf(mField), FixedFieldBuilder.build(mField)); + else + if(isNull(record.get(fields.indexOf(mField)+1))) + record.set(fields.indexOf(mField) + 1, FixedFieldBuilder.build(mField)); + else + record.set(fields.indexOf(mField) + 2, FixedFieldBuilder.build(mField)); + } + + // innerRecords + if (isNotNull(metaRecord.getGroupOfInnerRecords())){ + + record.setHeadOfGroup(true); + record.setDeclaredInnerRecords(new ArrayList(metaRecord.getGroupOfInnerRecords().getRecords().size())); + record.setRepitablesRecords(new HashSet()); + + List metaInnerRecords = metaRecord.getGroupOfInnerRecords().getRecords(); + + for(MetaRecord mRecord : metaInnerRecords){ + record.getDeclaredInnerRecords().add(mRecord.getName()); + if(mRecord.isRepeatable()) + record.getRepitablesRecords().add(mRecord.getName()); + } + + }else + record.setHeadOfGroup(false); + + return record; + } + + private static int getStringLength(List fields){ + int length = 0; + + for(MetaField mField : fields) + length += mField.getLength(); + + return length; + } + +} diff --git a/src/main/java/org/jrimum/texgit/engine/RecordFactory.java b/src/main/java/org/jrimum/texgit/engine/RecordFactory.java new file mode 100644 index 0000000..ea99f8f --- /dev/null +++ b/src/main/java/org/jrimum/texgit/engine/RecordFactory.java @@ -0,0 +1,100 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit.engine; + +import static org.apache.commons.lang.StringUtils.isNotBlank; +import static org.jrimum.utilix.Objects.isNotNull; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.jrimum.texgit.language.MetaRecord; +import org.jrimum.texgit.type.component.Record; + + + +/** + * @author Gilmar P.S.L. + * + */ +public class RecordFactory implements org.jrimum.texgit.type.component.RecordFactory { + + private Map name_record; + + RecordFactory(List metaRecords) { + + if (isNotNull(metaRecords)) { + if (!metaRecords.isEmpty()) { + + name_record = new HashMap(metaRecords + .size()); + + for (MetaRecord mRecord : metaRecords) { + + name_record.put(mRecord.getName(), mRecord); + + if (isNotNull(mRecord.getGroupOfInnerRecords())) + loadInnerRecords(name_record, mRecord + .getGroupOfInnerRecords().getRecords()); + } + } + } + } + + private void loadInnerRecords(Map name_record, + List innerMetaRecords) { + + if (isNotNull(innerMetaRecords)) { + if (!innerMetaRecords.isEmpty()) { + + for (MetaRecord iMetaRecord : innerMetaRecords) { + + name_record.put(iMetaRecord.getName(), iMetaRecord); + + if (isNotNull(iMetaRecord.getGroupOfInnerRecords())) + loadInnerRecords(name_record, iMetaRecord + .getGroupOfInnerRecords().getRecords()); + } + } + } + + } + + public Record create(String name) { + + Record record = null; + + if (isNotBlank(name)) + if (name_record.containsKey(name)) + record = RecordBuilder.build(name_record.get(name)); + + return record; + } +} diff --git a/src/main/java/org/jrimum/texgit/engine/TexgitLanguageException.java b/src/main/java/org/jrimum/texgit/engine/TexgitLanguageException.java new file mode 100644 index 0000000..8c64d4b --- /dev/null +++ b/src/main/java/org/jrimum/texgit/engine/TexgitLanguageException.java @@ -0,0 +1,73 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit.engine; + +import org.jrimum.texgit.TexgitException; + +/** + * @author Gilmar P.S.L. + * + */ +@SuppressWarnings("serial") +public class TexgitLanguageException extends TexgitException { + + /** + * + */ + public TexgitLanguageException() { + super(); + + } + + /** + * @param arg0 + * @param arg1 + */ + public TexgitLanguageException(String arg0, Throwable arg1) { + super(arg0, arg1); + + } + + /** + * @param arg0 + */ + public TexgitLanguageException(String arg0) { + super(arg0); + + } + + /** + * @param arg0 + */ + public TexgitLanguageException(Throwable arg0) { + super(arg0); + + } + +} diff --git a/src/main/java/org/jrimum/texgit/engine/TexgitManager.java b/src/main/java/org/jrimum/texgit/engine/TexgitManager.java new file mode 100644 index 0000000..773cfdf --- /dev/null +++ b/src/main/java/org/jrimum/texgit/engine/TexgitManager.java @@ -0,0 +1,60 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit.engine; + +import java.io.InputStream; + +import org.jrimum.texgit.FlatFile; +import org.jrimum.texgit.Record; +import org.jrimum.texgit.TexgitException; +import org.jrimum.texgit.language.MetaTexgit; + +/** + * @author Gilmar P.S.L. + * + */ +public class TexgitManager { + + public static FlatFile buildFlatFile(InputStream xmlDefStream) { + + FlatFile iFlatFile = null; + + try { + + MetaTexgit tgMeta = TexgitXmlReader.parse(xmlDefStream); + + iFlatFile = FlatFileBuilder.build(tgMeta.getFlatFile()); + + } catch (Exception e) { + throw new TexgitException(e); + } + + return iFlatFile; + } +} \ No newline at end of file diff --git a/src/main/java/org/jrimum/texgit/engine/TexgitSchemaValidator.java b/src/main/java/org/jrimum/texgit/engine/TexgitSchemaValidator.java new file mode 100644 index 0000000..41056e5 --- /dev/null +++ b/src/main/java/org/jrimum/texgit/engine/TexgitSchemaValidator.java @@ -0,0 +1,68 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit.engine; + +import javax.xml.bind.ValidationEvent; +import javax.xml.bind.ValidationEventHandler; +import javax.xml.bind.ValidationEventLocator; + +/** + * @author Gilmar P.S.L. + * + */ +class TexgitSchemaValidator implements ValidationEventHandler { + + public boolean handleEvent(ValidationEvent event) { + + boolean handled = false; + + if (event.getSeverity() == ValidationEvent.WARNING) { + + System.err.println(getMensagem("ATENÇÃO LAYOUT INCONSISTENTE!\n", + event)); + + handled = true; + + } else + // ERROR + System.err.println(getMensagem("ERRO NO LAYOUT!\n", event)); + + return handled; + } + + private String getMensagem(String msg, ValidationEvent event) { + + ValidationEventLocator local = event.getLocator(); + + return msg + + + "Linha { " + local.getLineNumber() + " } " + "Conluna [ " + + local.getColumnNumber() + " ] " + event.getMessage(); + } +} diff --git a/src/main/java/org/jrimum/texgit/engine/TexgitXmlReader.java b/src/main/java/org/jrimum/texgit/engine/TexgitXmlReader.java new file mode 100644 index 0000000..cfd47a0 --- /dev/null +++ b/src/main/java/org/jrimum/texgit/engine/TexgitXmlReader.java @@ -0,0 +1,94 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit.engine; + +import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI; +import static org.jrimum.utilix.Objects.isNotNull; + +import java.io.InputStream; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; + +import org.jrimum.texgit.Texgit; +import org.jrimum.texgit.TexgitException; +import org.jrimum.texgit.language.MetaTexgit; +import org.jrimum.utilix.ClassLoaders; +import org.xml.sax.SAXException; + + + +/** + * @author Gilmar P.S.L. + * + */ +class TexgitXmlReader { + + public static MetaTexgit parse(InputStream xmlDefStream) throws TexgitException { + + MetaTexgit txg = null; + + if (isNotNull(xmlDefStream)) { + + try { + + JAXBContext aJaxbContext = JAXBContext + .newInstance(MetaTexgit.class); + + Unmarshaller aUnmarshaller = aJaxbContext.createUnmarshaller(); + + SchemaFactory aSchemaFactory = SchemaFactory + .newInstance(W3C_XML_SCHEMA_NS_URI); + + Schema schema = aSchemaFactory.newSchema(ClassLoaders.getResource("TexgitSchema.xsd",Texgit.class)); + + aUnmarshaller.setSchema(schema); + + aUnmarshaller.setEventHandler(new TexgitSchemaValidator()); + + txg = (MetaTexgit) aUnmarshaller.unmarshal(xmlDefStream); + + } catch (SAXException e) { + + throw new TexgitLanguageException(e); + + } catch (JAXBException e) { + + throw new TexgitLanguageException(e); + + } + } + + return txg; + } + +} diff --git a/src/br/com/nordestefomento/jrimum/texgit/language/EnumFormats.java b/src/main/java/org/jrimum/texgit/language/EnumFormats.java similarity index 51% rename from src/br/com/nordestefomento/jrimum/texgit/language/EnumFormats.java rename to src/main/java/org/jrimum/texgit/language/EnumFormats.java index 7e7580e..c0ab828 100644 --- a/src/br/com/nordestefomento/jrimum/texgit/language/EnumFormats.java +++ b/src/main/java/org/jrimum/texgit/language/EnumFormats.java @@ -1,3 +1,31 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 03/08/2008 - 12:27:56 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 03/08/2008 - 12:27:56 + * + */ // // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6 // See http://java.sun.com/xml/jaxb @@ -5,7 +33,7 @@ // Generated on: 2008.08.03 at 12:27:56 AM GMT-03:00 // -package br.com.nordestefomento.jrimum.texgit.language; +package org.jrimum.texgit.language; import javax.xml.bind.annotation.XmlEnum; diff --git a/src/main/java/org/jrimum/texgit/language/EnumFormatsTypes.java b/src/main/java/org/jrimum/texgit/language/EnumFormatsTypes.java new file mode 100644 index 0000000..e9e48da --- /dev/null +++ b/src/main/java/org/jrimum/texgit/language/EnumFormatsTypes.java @@ -0,0 +1,81 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 03/08/2008 - 12:27:56 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 03/08/2008 - 12:27:56 + * + */ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2008.08.03 at 12:27:56 AM GMT-03:00 +// + +package org.jrimum.texgit.language; + +import javax.xml.bind.annotation.XmlEnum; + +/** + * + * + *

+ * Tipo de formatadores suportados. Usados junto a defini��o de novos + * formatadores. + *

+ * + * + * + *

+ * Java class for enumFormatsTypes. + * + *

+ * The following schema fragment specifies the expected content contained within + * this class. + *

+ * + *

+ * <simpleType name="enumFormatsTypes">
+ *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ *     <enumeration value="DATE"/>
+ *     <enumeration value="DECIMAL"/>
+ *   </restriction>
+ * </simpleType>
+ * 
+ * + */ +@XmlEnum +public enum EnumFormatsTypes { + + DATE, DECIMAL; + + public String value() { + return name(); + } + + public static EnumFormatsTypes fromValue(String v) { + return valueOf(v); + } + +} diff --git a/src/main/java/org/jrimum/texgit/language/EnumPaddings.java b/src/main/java/org/jrimum/texgit/language/EnumPaddings.java new file mode 100644 index 0000000..33587c5 --- /dev/null +++ b/src/main/java/org/jrimum/texgit/language/EnumPaddings.java @@ -0,0 +1,82 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 03/08/2008 - 12:27:56 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 03/08/2008 - 12:27:56 + * + */ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2008.08.03 at 12:27:56 AM GMT-03:00 +// + +package org.jrimum.texgit.language; + +import javax.xml.bind.annotation.XmlEnum; + +/** + * + * + *

+ * Preenchimentos suportados por padr�o pelo componente. + *

+ * + * + * + *

+ * Java class for enumPaddings. + * + *

+ * The following schema fragment specifies the expected content contained within + * this class. + *

+ * + *

+ * <simpleType name="enumPaddings">
+ *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ *     <enumeration value="ZERO_RIGHT"/>
+ *     <enumeration value="ZERO_LEFT"/>
+ *     <enumeration value="WHITE_SPACE_RIGHT"/>
+ *     <enumeration value="WHITE_SPACE_LEFT"/>
+ *   </restriction>
+ * </simpleType>
+ * 
+ * + */ +@XmlEnum +public enum EnumPaddings { + + ZERO_RIGHT, ZERO_LEFT, WHITE_SPACE_RIGHT, WHITE_SPACE_LEFT; + + public String value() { + return name(); + } + + public static EnumPaddings fromValue(String v) { + return valueOf(v); + } + +} diff --git a/src/main/java/org/jrimum/texgit/language/EnumSide.java b/src/main/java/org/jrimum/texgit/language/EnumSide.java new file mode 100644 index 0000000..32ba029 --- /dev/null +++ b/src/main/java/org/jrimum/texgit/language/EnumSide.java @@ -0,0 +1,80 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 03/08/2008 - 12:27:56 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 03/08/2008 - 12:27:56 + * + */ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2008.08.03 at 12:27:56 AM GMT-03:00 +// + +package org.jrimum.texgit.language; + +import javax.xml.bind.annotation.XmlEnum; + +/** + * + * + *

+ * Basicamente s�o defini��es de dire��es de escrita e leitura. + *

+ * + * + * + *

+ * Java class for enumSide. + * + *

+ * The following schema fragment specifies the expected content contained within + * this class. + *

+ * + *

+ * <simpleType name="enumSide">
+ *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ *     <enumeration value="LEFT"/>
+ *     <enumeration value="RIGHT"/>
+ *   </restriction>
+ * </simpleType>
+ * 
+ * + */ +@XmlEnum +public enum EnumSide { + + LEFT, RIGHT; + + public String value() { + return name(); + } + + public static EnumSide fromValue(String v) { + return valueOf(v); + } + +} diff --git a/src/br/com/nordestefomento/jrimum/texgit/language/EnumTypes.java b/src/main/java/org/jrimum/texgit/language/EnumTypes.java similarity index 51% rename from src/br/com/nordestefomento/jrimum/texgit/language/EnumTypes.java rename to src/main/java/org/jrimum/texgit/language/EnumTypes.java index 7582f91..ddd4cad 100644 --- a/src/br/com/nordestefomento/jrimum/texgit/language/EnumTypes.java +++ b/src/main/java/org/jrimum/texgit/language/EnumTypes.java @@ -1,3 +1,31 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 03/08/2008 - 12:27:56 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 03/08/2008 - 12:27:56 + * + */ // // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6 // See http://java.sun.com/xml/jaxb @@ -5,7 +33,7 @@ // Generated on: 2008.08.03 at 12:27:56 AM GMT-03:00 // -package br.com.nordestefomento.jrimum.texgit.language; +package org.jrimum.texgit.language; import javax.xml.bind.annotation.XmlEnum; diff --git a/src/br/com/nordestefomento/jrimum/texgit/language/MetaField.java b/src/main/java/org/jrimum/texgit/language/MetaField.java similarity index 68% rename from src/br/com/nordestefomento/jrimum/texgit/language/MetaField.java rename to src/main/java/org/jrimum/texgit/language/MetaField.java index e43342a..2ac6d74 100644 --- a/src/br/com/nordestefomento/jrimum/texgit/language/MetaField.java +++ b/src/main/java/org/jrimum/texgit/language/MetaField.java @@ -1,3 +1,31 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 03/08/2008 - 12:27:56 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 03/08/2008 - 12:27:56 + * + */ // // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6 // See http://java.sun.com/xml/jaxb @@ -5,7 +33,7 @@ // Generated on: 2008.08.03 at 12:27:56 AM GMT-03:00 // -package br.com.nordestefomento.jrimum.texgit.language; +package org.jrimum.texgit.language; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -39,6 +67,8 @@ public class MetaField { @XmlAttribute protected Boolean blankAccepted; @XmlAttribute + protected Boolean truncate; + @XmlAttribute protected EnumFormats format; @XmlAttribute(required = true) protected int length; @@ -117,6 +147,31 @@ public boolean isBlankAccepted() { public void setBlankAccepted(Boolean value) { this.blankAccepted = value; } + + /** + * Gets the value of the truncate property. + * + * @return possible object is {@link Boolean } + * + */ + public boolean isTruncate() { + if (truncate == null) { + return false; + } else { + return truncate; + } + } + + /** + * Sets the value of the blankAccepted property. + * + * @param value + * allowed object is {@link Boolean } + * + */ + public void setTruncate(Boolean value) { + this.truncate = value; + } /** * Gets the value of the format property. diff --git a/src/br/com/nordestefomento/jrimum/texgit/language/MetaFiller.java b/src/main/java/org/jrimum/texgit/language/MetaFiller.java similarity index 52% rename from src/br/com/nordestefomento/jrimum/texgit/language/MetaFiller.java rename to src/main/java/org/jrimum/texgit/language/MetaFiller.java index 17809c2..d911be7 100644 --- a/src/br/com/nordestefomento/jrimum/texgit/language/MetaFiller.java +++ b/src/main/java/org/jrimum/texgit/language/MetaFiller.java @@ -1,3 +1,31 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 03/08/2008 - 12:27:56 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 03/08/2008 - 12:27:56 + * + */ // // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6 // See http://java.sun.com/xml/jaxb @@ -5,13 +33,15 @@ // Generated on: 2008.08.03 at 12:27:56 AM GMT-03:00 // -package br.com.nordestefomento.jrimum.texgit.language; +package org.jrimum.texgit.language; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlType; +import org.jrimum.texgit.type.component.Side; + /** * * diff --git a/src/br/com/nordestefomento/jrimum/texgit/language/MetaFlatFile.java b/src/main/java/org/jrimum/texgit/language/MetaFlatFile.java similarity index 55% rename from src/br/com/nordestefomento/jrimum/texgit/language/MetaFlatFile.java rename to src/main/java/org/jrimum/texgit/language/MetaFlatFile.java index a7e2231..f1c2f16 100644 --- a/src/br/com/nordestefomento/jrimum/texgit/language/MetaFlatFile.java +++ b/src/main/java/org/jrimum/texgit/language/MetaFlatFile.java @@ -1,3 +1,31 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 03/08/2008 - 12:27:56 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 03/08/2008 - 12:27:56 + * + */ // // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6 // See http://java.sun.com/xml/jaxb @@ -5,7 +33,7 @@ // Generated on: 2008.08.03 at 12:27:56 AM GMT-03:00 // -package br.com.nordestefomento.jrimum.texgit.language; +package org.jrimum.texgit.language; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/src/br/com/nordestefomento/jrimum/texgit/language/MetaFormatter.java b/src/main/java/org/jrimum/texgit/language/MetaFormatter.java similarity index 51% rename from src/br/com/nordestefomento/jrimum/texgit/language/MetaFormatter.java rename to src/main/java/org/jrimum/texgit/language/MetaFormatter.java index 4e579ad..e712fca 100644 --- a/src/br/com/nordestefomento/jrimum/texgit/language/MetaFormatter.java +++ b/src/main/java/org/jrimum/texgit/language/MetaFormatter.java @@ -1,3 +1,31 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 03/08/2008 - 12:27:56 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 03/08/2008 - 12:27:56 + * + */ // // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6 // See http://java.sun.com/xml/jaxb @@ -5,7 +33,7 @@ // Generated on: 2008.08.03 at 12:27:56 AM GMT-03:00 // -package br.com.nordestefomento.jrimum.texgit.language; +package org.jrimum.texgit.language; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/src/br/com/nordestefomento/jrimum/texgit/language/MetaGroupFields.java b/src/main/java/org/jrimum/texgit/language/MetaGroupFields.java similarity index 61% rename from src/br/com/nordestefomento/jrimum/texgit/language/MetaGroupFields.java rename to src/main/java/org/jrimum/texgit/language/MetaGroupFields.java index 6e8d489..e43ae9f 100644 --- a/src/br/com/nordestefomento/jrimum/texgit/language/MetaGroupFields.java +++ b/src/main/java/org/jrimum/texgit/language/MetaGroupFields.java @@ -1,3 +1,31 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 03/08/2008 - 12:27:56 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 03/08/2008 - 12:27:56 + * + */ // // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6 // See http://java.sun.com/xml/jaxb @@ -5,10 +33,11 @@ // Generated on: 2008.08.03 at 12:27:56 AM GMT-03:00 // -package br.com.nordestefomento.jrimum.texgit.language; +package org.jrimum.texgit.language; import java.util.ArrayList; import java.util.List; + import javax.xml.bind.JAXBElement; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -23,10 +52,6 @@ * Agregado de fields. *

* - * - * - * - * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "MetaGroupFields", propOrder = { "idType", "fields", @@ -112,27 +137,33 @@ public void setSequencialNumber(MetaOrderedField value) { this.sequencialNumber = value; } - @SuppressWarnings("serial") public static class IdType extends JAXBElement { + /** + * {@code serialVersionUID = -8934480908648452108L} + */ + private static final long serialVersionUID = -8934480908648452108L; + protected final static QName NAME = new QName("", "IdType"); - @SuppressWarnings("unchecked") public IdType(MetaOrderedField value) { - super(NAME, ((Class) MetaOrderedField.class), + super(NAME, ((Class) MetaOrderedField.class), MetaGroupFields.class, value); } } - @SuppressWarnings("serial") public static class SequencialNumber extends JAXBElement { + /** + * {@code serialVersionUID = 3923837730914132777L} + */ + private static final long serialVersionUID = 3923837730914132777L; + protected final static QName NAME = new QName("", "SequencialNumber"); - @SuppressWarnings("unchecked") public SequencialNumber(MetaOrderedField value) { - super(NAME, ((Class) MetaOrderedField.class), + super(NAME, ((Class) MetaOrderedField.class), MetaGroupFields.class, value); } diff --git a/src/br/com/nordestefomento/jrimum/texgit/language/MetaGroupRecords.java b/src/main/java/org/jrimum/texgit/language/MetaGroupRecords.java similarity index 52% rename from src/br/com/nordestefomento/jrimum/texgit/language/MetaGroupRecords.java rename to src/main/java/org/jrimum/texgit/language/MetaGroupRecords.java index 4988a34..d55309b 100644 --- a/src/br/com/nordestefomento/jrimum/texgit/language/MetaGroupRecords.java +++ b/src/main/java/org/jrimum/texgit/language/MetaGroupRecords.java @@ -1,3 +1,31 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 03/08/2008 - 12:27:56 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 03/08/2008 - 12:27:56 + * + */ // // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6 // See http://java.sun.com/xml/jaxb @@ -5,10 +33,11 @@ // Generated on: 2008.08.03 at 12:27:56 AM GMT-03:00 // -package br.com.nordestefomento.jrimum.texgit.language; +package org.jrimum.texgit.language; import java.util.ArrayList; import java.util.List; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; diff --git a/src/br/com/nordestefomento/jrimum/texgit/language/MetaLayout.java b/src/main/java/org/jrimum/texgit/language/MetaLayout.java similarity index 55% rename from src/br/com/nordestefomento/jrimum/texgit/language/MetaLayout.java rename to src/main/java/org/jrimum/texgit/language/MetaLayout.java index 37565a6..128c7bd 100644 --- a/src/br/com/nordestefomento/jrimum/texgit/language/MetaLayout.java +++ b/src/main/java/org/jrimum/texgit/language/MetaLayout.java @@ -1,3 +1,31 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 03/08/2008 - 12:27:56 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 03/08/2008 - 12:27:56 + * + */ // // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6 // See http://java.sun.com/xml/jaxb @@ -5,7 +33,7 @@ // Generated on: 2008.08.03 at 12:27:56 AM GMT-03:00 // -package br.com.nordestefomento.jrimum.texgit.language; +package org.jrimum.texgit.language; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/src/main/java/org/jrimum/texgit/language/MetaOrderedField.java b/src/main/java/org/jrimum/texgit/language/MetaOrderedField.java new file mode 100644 index 0000000..3638719 --- /dev/null +++ b/src/main/java/org/jrimum/texgit/language/MetaOrderedField.java @@ -0,0 +1,78 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 03/08/2008 - 12:27:56 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 03/08/2008 - 12:27:56 + * + */ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2008.08.03 at 12:27:56 AM GMT-03:00 +// + +package org.jrimum.texgit.language; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlType; + +/** + * + * + *

+ * Para defini��o da posi��o. + *

+ * + * + * + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "MetaOrderedField") +public class MetaOrderedField extends MetaField { + + @XmlAttribute(required = true) + protected int position; + + /** + * Gets the value of the position property. + * + */ + public int getPosition() { + return position; + } + + /** + * Sets the value of the position property. + * + */ + public void setPosition(int value) { + this.position = value; + } + +} diff --git a/src/br/com/nordestefomento/jrimum/texgit/language/MetaRecord.java b/src/main/java/org/jrimum/texgit/language/MetaRecord.java similarity index 67% rename from src/br/com/nordestefomento/jrimum/texgit/language/MetaRecord.java rename to src/main/java/org/jrimum/texgit/language/MetaRecord.java index 6efc7cc..fbd3568 100644 --- a/src/br/com/nordestefomento/jrimum/texgit/language/MetaRecord.java +++ b/src/main/java/org/jrimum/texgit/language/MetaRecord.java @@ -1,3 +1,32 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 03/08/2008 - 12:27:56 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 03/08/2008 - 12:27:56 + * + */ + // // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6 // See http://java.sun.com/xml/jaxb @@ -5,7 +34,7 @@ // Generated on: 2008.08.03 at 12:27:56 AM GMT-03:00 // -package br.com.nordestefomento.jrimum.texgit.language; +package org.jrimum.texgit.language; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/src/br/com/nordestefomento/jrimum/texgit/language/MetaTexgit.java b/src/main/java/org/jrimum/texgit/language/MetaTexgit.java similarity index 54% rename from src/br/com/nordestefomento/jrimum/texgit/language/MetaTexgit.java rename to src/main/java/org/jrimum/texgit/language/MetaTexgit.java index 1bb9318..8ae0fb5 100644 --- a/src/br/com/nordestefomento/jrimum/texgit/language/MetaTexgit.java +++ b/src/main/java/org/jrimum/texgit/language/MetaTexgit.java @@ -1,3 +1,32 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 03/08/2008 - 12:27:56 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 03/08/2008 - 12:27:56 + * + */ + // // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6 // See http://java.sun.com/xml/jaxb @@ -5,7 +34,7 @@ // Generated on: 2008.08.03 at 12:27:56 AM GMT-03:00 // -package br.com.nordestefomento.jrimum.texgit.language; +package org.jrimum.texgit.language; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/src/br/com/nordestefomento/jrimum/texgit/language/ObjectFactory.java b/src/main/java/org/jrimum/texgit/language/ObjectFactory.java similarity index 65% rename from src/br/com/nordestefomento/jrimum/texgit/language/ObjectFactory.java rename to src/main/java/org/jrimum/texgit/language/ObjectFactory.java index 71f7d09..b7a513b 100644 --- a/src/br/com/nordestefomento/jrimum/texgit/language/ObjectFactory.java +++ b/src/main/java/org/jrimum/texgit/language/ObjectFactory.java @@ -1,3 +1,31 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 03/08/2008 - 12:27:56 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 03/08/2008 - 12:27:56 + * + */ // // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6 // See http://java.sun.com/xml/jaxb @@ -5,7 +33,7 @@ // Generated on: 2008.08.03 at 12:27:56 AM GMT-03:00 // -package br.com.nordestefomento.jrimum.texgit.language; +package org.jrimum.texgit.language; import javax.xml.bind.JAXBElement; import javax.xml.bind.annotation.XmlElementDecl; @@ -26,8 +54,8 @@ @XmlRegistry public class ObjectFactory { - private final static QName _Texgit_QNAME = new QName( - "http://gilmatryx.googlepages.com/Texgit", "Texgit"); + private final static QName TEXGIT_QNAME = new QName( + "http://jrimum.org/texgit", "Texgit"); /** * Create a new ObjectFactory that can be used to create new instances of @@ -121,9 +149,9 @@ public MetaFiller createMetaFiller() { * Create an instance of {@link JAXBElement }{@code <}{@link MetaTexgit }{@code >}} * */ - @XmlElementDecl(namespace = "http://gilmatryx.googlepages.com/Texgit", name = "Texgit") + @XmlElementDecl(namespace = "http://jrimum.org/texgit", name = "Texgit") public JAXBElement createTexgit(MetaTexgit value) { - return new JAXBElement(_Texgit_QNAME, MetaTexgit.class, + return new JAXBElement(TEXGIT_QNAME, MetaTexgit.class, null, value); } diff --git a/src/main/java/org/jrimum/texgit/language/package-info.java b/src/main/java/org/jrimum/texgit/language/package-info.java new file mode 100644 index 0000000..8c9b7fb --- /dev/null +++ b/src/main/java/org/jrimum/texgit/language/package-info.java @@ -0,0 +1,40 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 03/08/2008 - 12:27:56 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 03/08/2008 - 12:27:56 + * + */ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) +// Reference Implementation, vJAXB 2.0 in JDK 1.6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source +// schema. +// Generated on: 2008.08.03 at 12:27:56 AM GMT-03:00 +// + +@javax.xml.bind.annotation.XmlSchema(namespace = "http://jrimum.org/texgit") +package org.jrimum.texgit.language; + diff --git a/src/br/com/nordestefomento/jrimum/texgit/type/AbstractStringOfFields.java b/src/main/java/org/jrimum/texgit/type/AbstractStringOfFields.java similarity index 62% rename from src/br/com/nordestefomento/jrimum/texgit/type/AbstractStringOfFields.java rename to src/main/java/org/jrimum/texgit/type/AbstractStringOfFields.java index 38b72e9..c25e88d 100644 --- a/src/br/com/nordestefomento/jrimum/texgit/type/AbstractStringOfFields.java +++ b/src/main/java/org/jrimum/texgit/type/AbstractStringOfFields.java @@ -1,4 +1,34 @@ -package br.com.nordestefomento.jrimum.texgit.type; +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit.type; + +import static java.lang.String.format; import java.util.ArrayList; import java.util.Collection; @@ -7,10 +37,15 @@ import java.util.ListIterator; import org.apache.commons.lang.StringUtils; - -import br.com.nordestefomento.jrimum.utilix.ObjectUtil; -import br.com.nordestefomento.jrimum.utilix.TextStream; - +import org.jrimum.texgit.TextStream; +import org.jrimum.utilix.Collections; +import org.jrimum.utilix.Objects; + +/** + * @author Gilmar P.S.L. + * + * @param + */ @SuppressWarnings("serial") public abstract class AbstractStringOfFields> implements TextStream, List, Cloneable{ @@ -32,7 +67,7 @@ public AbstractStringOfFields() { */ public AbstractStringOfFields(Integer size) { - ObjectUtil.checkNotNull(size, "size"); + Objects.checkNotNull(size, "size"); if (size > 0) { fields = new ArrayList(size); @@ -40,8 +75,7 @@ public AbstractStringOfFields(Integer size) { fields.add(null); } } else { - throw new IllegalArgumentException("A quantidade de campos [ " - + size + " ] deve ser um número natural > 0!"); + throw new IllegalArgumentException(format("A quantidade de campos [%s] deve ser um número natural > 0!", size)); } } @@ -68,7 +102,7 @@ protected AbstractStringOfFields clone() throws CloneNotSupportedException { * cada subclasse. *

* - * @see br.com.nordestefomento.jrimum.utilix.IReadWriteStream#read(java.lang.Object) + * @see org.jrimum.texgit.ReadWriteStream#read(Object) */ public abstract void read(String lineOfField); @@ -77,16 +111,29 @@ protected AbstractStringOfFields clone() throws CloneNotSupportedException { * Escreve os campos na ordem em que estão dispostos na lista em uma única linha (string). *

* - * @see br.com.nordestefomento.jrimum.utilix.IReadWriteStream#write() + * @see org.jrimum.texgit.ReadWriteStream#write() */ public String write() { StringBuilder lineOfFields = new StringBuilder(StringUtils.EMPTY); - ObjectUtil.checkNotNull(fields, "fields"); + Objects.checkNotNull(fields, "Fields == null"); + Collections.checkNotEmpty(fields, "Coleção de fields vazia!"); for (G field : fields) { - lineOfFields.append(field.write()); + + try { + + lineOfFields.append(field.write()); + + } catch (Exception e) { + + throw new IllegalStateException( + format( + "Erro ao tentar escrever o campo \"%s\" com valor [%s] na posição [%s] no layout do registro.", + field.getName(), field.getValue(), fields + .indexOf(field)+1),e); + } } return lineOfFields.toString(); @@ -102,7 +149,6 @@ public List getFields() { /** * @see java.util.List#add(java.lang.Object) */ - @Override public boolean add(G e) { return fields.add(e); @@ -111,7 +157,6 @@ public boolean add(G e) { /** * @see java.util.List#add(int, java.lang.Object) */ - @Override public void add(int index, G element) { fields.add(index, element); @@ -120,7 +165,6 @@ public void add(int index, G element) { /** * @see java.util.List#addAll(java.util.Collection) */ - @Override public boolean addAll(Collection c) { return fields.addAll(c); @@ -129,7 +173,6 @@ public boolean addAll(Collection c) { /** * @see java.util.List#addAll(int, java.util.Collection) */ - @Override public boolean addAll(int index, Collection c) { return fields.addAll(index, c); @@ -138,7 +181,6 @@ public boolean addAll(int index, Collection c) { /** * @see java.util.List#clear() */ - @Override public void clear() { fields.clear(); @@ -147,7 +189,6 @@ public void clear() { /** * @see java.util.List#contains(java.lang.Object) */ - @Override public boolean contains(Object o) { return fields.contains(o); @@ -156,7 +197,6 @@ public boolean contains(Object o) { /** * @see java.util.List#containsAll(java.util.Collection) */ - @Override public boolean containsAll(Collection c) { return fields.containsAll(c); @@ -165,7 +205,6 @@ public boolean containsAll(Collection c) { /** * @see java.util.List#get(int) */ - @Override public G get(int index) { return fields.get(index); @@ -174,7 +213,6 @@ public G get(int index) { /** * @see java.util.List#indexOf(java.lang.Object) */ - @Override public int indexOf(Object o) { return fields.indexOf(o); @@ -183,7 +221,6 @@ public int indexOf(Object o) { /** * @see java.util.List#isEmpty() */ - @Override public boolean isEmpty() { return fields.isEmpty(); @@ -192,7 +229,6 @@ public boolean isEmpty() { /** * @see java.util.List#iterator() */ - @Override public Iterator iterator() { return fields.iterator(); @@ -201,7 +237,6 @@ public Iterator iterator() { /** * @see java.util.List#lastIndexOf(java.lang.Object) */ - @Override public int lastIndexOf(Object o) { return fields.indexOf(o); @@ -210,7 +245,6 @@ public int lastIndexOf(Object o) { /** * @see java.util.List#listIterator() */ - @Override public ListIterator listIterator() { return fields.listIterator(); @@ -219,7 +253,6 @@ public ListIterator listIterator() { /** * @see java.util.List#listIterator(int) */ - @Override public ListIterator listIterator(int index) { return fields.listIterator(index); @@ -228,7 +261,6 @@ public ListIterator listIterator(int index) { /** * @see java.util.List#remove(int) */ - @Override public G remove(int index) { return fields.remove(index); @@ -237,7 +269,6 @@ public G remove(int index) { /** * @see java.util.List#remove(java.lang.Object) */ - @Override public boolean remove(Object o) { return fields.remove(o); @@ -246,7 +277,6 @@ public boolean remove(Object o) { /** * @see java.util.List#removeAll(java.util.Collection) */ - @Override public boolean removeAll(Collection c) { return fields.removeAll(c); @@ -255,7 +285,6 @@ public boolean removeAll(Collection c) { /** * @see java.util.List#retainAll(java.util.Collection) */ - @Override public boolean retainAll(Collection c) { return fields.retainAll(c); @@ -264,7 +293,6 @@ public boolean retainAll(Collection c) { /** * @see java.util.List#set(int, java.lang.Object) */ - @Override public G set(int index, G element) { return fields.set(index, element); @@ -273,7 +301,6 @@ public G set(int index, G element) { /** * @see java.util.List#size() */ - @Override public int size() { return fields.size(); @@ -282,7 +309,6 @@ public int size() { /** * @see java.util.List#subList(int, int) */ - @Override public List subList(int fromIndex, int toIndex) { return fields.subList(fromIndex, toIndex); @@ -291,16 +317,14 @@ public List subList(int fromIndex, int toIndex) { /** * @see java.util.List#toArray() */ - @Override public Object[] toArray() { return fields.toArray(); } /** - * @see java.util.List#toArray(T[]) + * @see java.util.List#toArray(Object[]) */ - @Override public T[] toArray(T[] a) { return fields.toArray(a); diff --git a/src/main/java/org/jrimum/texgit/type/Field.java b/src/main/java/org/jrimum/texgit/type/Field.java new file mode 100644 index 0000000..d9a3902 --- /dev/null +++ b/src/main/java/org/jrimum/texgit/type/Field.java @@ -0,0 +1,59 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit.type; + +import java.text.Format; + +import org.jrimum.texgit.TextStream; + +/** + * @author Gilmar P.S.L. + * + * @param + */ +public interface Field extends TextStream, Cloneable{ + + public abstract String getName(); + + public abstract void setName(String name); + + public abstract G getValue(); + + public abstract void setValue(G value); + + public abstract Format getFormatter(); + + public abstract void setFormatter(Format formatter); + + public abstract boolean isBlankAccepted(); + + public abstract void setBlankAccepted(boolean blankAccepted); + + public abstract Field clone() throws CloneNotSupportedException; +} diff --git a/src/main/java/org/jrimum/texgit/type/Filler.java b/src/main/java/org/jrimum/texgit/type/Filler.java new file mode 100644 index 0000000..7ee56e6 --- /dev/null +++ b/src/main/java/org/jrimum/texgit/type/Filler.java @@ -0,0 +1,162 @@ +package org.jrimum.texgit.type; + +import java.io.Serializable; + +import org.jrimum.texgit.TextStream; + +public interface Filler extends Serializable{ + + /** + * Preenche o campo com o caracter especificado e no lado especificado. + * + *

+ * Exemplo: + *
+ * Se sideToFill == SideToFill.LEFT, o caracter especificado será adicionado à String + * no lado esquerdo até que o campo fique com o tamanho que foi definido. + *

+ * + * @param toFill + * @param length + * @return String preenchida + * + * @since 0.2 + */ + String fill(String toFill, int length); + + /** + * Executa o método fill(String, int) passando o parâmetro + * toFill como String.valueOf(toFill). + * + * @param tofill + * @param length + * @return String preenchida + * + * @see Filler#fill(String, int) + * + * @since 0.2 + */ + String fill(long tofill, int length); + + /** + * Executa o método fill(String, int) passando o parâmetro + * toFill como String.valueOf(toFill). + * + * @param tofill + * @param length + * @return String preenchida + * + * @see Filler#fill(String, int) + * + * @since 0.2 + */ + String fill(int tofill, int length); + + /** + * Executa o método fill(String, int) passando o parâmetro + * toFill como String.valueOf(toFill). + * + * @param tofill + * @param length + * @return String preenchida + * + * @see Filler#fill(String, int) + * + * @since 0.2 + */ + String fill(short tofill, int length); + + /** + * Executa o método fill(String, int) passando o parâmetro + * toFill como String.valueOf(toFill). + * + * @param tofill + * @param length + * @return String preenchida + * + * @see Filler#fill(String, int) + * + * @since 0.2 + */ + String fill(byte tofill, int length); + + /** + * Executa o método fill(String, int) passando o parâmetro + * toFill como String.valueOf(toFill). + * + * @param tofill + * @param length + * @return String preenchida + * + * @see Filler#fill(String, int) + * + * @since 0.2 + */ + String fill(char tofill, int length); + + /** + * Executa o método fill(String, int) passando o parâmetro + * toFill como String.valueOf(toFill). + * + * @param tofill + * @param length + * @return String preenchida + * + * @see Filler#fill(String, int) + * + * @since 0.2 + */ + String fill(double tofill, int length); + + /** + * Executa o método fill(String, int) passando o parâmetro + * toFill como String.valueOf(toFill). + * + * @param tofill + * @param length + * @return String preenchida + * + * @see Filler#fill(String, int) + * + * @since + */ + String fill(float tofill, int length); + + /** + * Executa o método fill(String, int) passando o parâmetro + * toFill como toFill.toString(). + * + *

+ * Caso toFill seja null, o método + * fill(String, int) receberá uma String nula como parâmetro. + *

+ * + * @param tofill + * @param length + * @return String preenchida + * + * @see Filler#fill(String, int) + * + * @since 0.2 + */ + String fill(Object tofill, int length); + + /** + * Executa o método fill(String, int) passando o parâmetro + * toFill como toFill.write(). + * + *

+ * Caso toFill seja null, o método + * fill(String, int) receberá uma String nula como parâmetro. + *

+ * + * @param tofill + * @param length + * @return String preenchida + * + * @see Filler#fill(String, int) + * + * @since 0.2 + */ + String fill(TextStream tofill, int length); +} \ No newline at end of file diff --git a/src/main/java/org/jrimum/texgit/type/Fixed.java b/src/main/java/org/jrimum/texgit/type/Fixed.java new file mode 100644 index 0000000..9fbd384 --- /dev/null +++ b/src/main/java/org/jrimum/texgit/type/Fixed.java @@ -0,0 +1,52 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit.type; + +/** + * @author Gilmar P.S.L. + * + */ +public interface Fixed { + + /** + * Informa a validade para a fixação de uma ou mais medidas. Exemplo:
+ * + *
+	 * {
+	 * 	isLenghtAsDefine();
+	 * 	isSizeAsDefine();
+	 * }
+	 * 
+ * + * @return Indicativo se está de acordo com o definido + * + * @throws IllegalStateException + */ + public abstract boolean isFixedAsDefined() throws IllegalStateException; +} diff --git a/src/main/java/org/jrimum/texgit/type/FixedField.java b/src/main/java/org/jrimum/texgit/type/FixedField.java new file mode 100644 index 0000000..e1073cc --- /dev/null +++ b/src/main/java/org/jrimum/texgit/type/FixedField.java @@ -0,0 +1,48 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit.type; + + +/** + * @author Gilmar P.S.L. + * + * @param + */ +public interface FixedField extends Field, FixedLength{ + + /** + * @return the filler + */ + public abstract Filler getFiller(); + + /** + * @param filler the filler to set + */ + public abstract void setFiller(Filler filler); +} \ No newline at end of file diff --git a/src/main/java/org/jrimum/texgit/type/FixedLength.java b/src/main/java/org/jrimum/texgit/type/FixedLength.java new file mode 100644 index 0000000..c4f9143 --- /dev/null +++ b/src/main/java/org/jrimum/texgit/type/FixedLength.java @@ -0,0 +1,42 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit.type; + +/** + * @author Gilmar P.S.L. + * + */ +public interface FixedLength extends Fixed{ + + public Integer getFixedLength(); + + public boolean isTruncate(); + + public void setTruncate(boolean truncate); +} diff --git a/src/main/java/org/jrimum/texgit/type/FixedSize.java b/src/main/java/org/jrimum/texgit/type/FixedSize.java new file mode 100644 index 0000000..1e52106 --- /dev/null +++ b/src/main/java/org/jrimum/texgit/type/FixedSize.java @@ -0,0 +1,38 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit.type; + +/** + * @author Gilmar P.S.L. + * + */ +public interface FixedSize extends Fixed{ + + public Integer getFixedSize(); +} diff --git a/src/main/java/org/jrimum/texgit/type/component/BlockOfFields.java b/src/main/java/org/jrimum/texgit/type/component/BlockOfFields.java new file mode 100644 index 0000000..b54572e --- /dev/null +++ b/src/main/java/org/jrimum/texgit/type/component/BlockOfFields.java @@ -0,0 +1,228 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit.type.component; + +import static java.lang.String.format; +import static org.jrimum.utilix.Objects.isNotNull; + +import org.jrimum.texgit.type.AbstractStringOfFields; +import org.jrimum.texgit.type.FixedLength; +import org.jrimum.texgit.type.FixedSize; +import org.jrimum.utilix.Collections; +import org.jrimum.utilix.Objects; + +/** + * @author Gilmar P.S.L. + * + */ +@SuppressWarnings("serial") +public class BlockOfFields extends AbstractStringOfFields> implements FixedSize, FixedLength{ + + /** + * Definição + */ + private Integer length; + + /** + * Definição + */ + private Integer size; + + /** + *

+ * Tamanho da string de escrita do bloco. + *

+ */ + private Integer instantLength; + + /** + *

+ * Ao ultrapassar o tamanho, define se pode truncar ou se dispara uma exceção. + *

+ */ + private boolean truncate; + + /** + * + */ + public BlockOfFields() { + super(); + } + + /** + * @param length + * @param size + */ + public BlockOfFields(Integer length, Integer size) { + + super(size); + + Objects.checkNotNull(length, "length"); + + if (length > 0) { + + setLength(length); + setSize(size); + + } else + throw new IllegalArgumentException(format("O comprimento do bloco [%s] deve ser um número natural > 0!", length)); + } + + @Override + public BlockOfFields clone() throws CloneNotSupportedException { + + return(BlockOfFields) super.clone(); + } + + @Override + public void read(String lineOfFields) { + + Objects.checkNotNull(lineOfFields, "String de leitura nula!"); + + Objects.checkNotNull(getFields(), "Fields == null"); + Collections.checkNotEmpty(getFields(), "Coleção de fields vazia!"); + + if (isSizeAsDefinaed() && isLengthWithDefinaed(lineOfFields.length())) { + + StringBuilder builder = new StringBuilder(lineOfFields); + + for (FixedField field : getFields()) { + + try { + + field.read(builder.substring(0, field.getFixedLength())); + builder.delete(0, field.getFixedLength()); + + } catch (Exception e) { + + throw new IllegalStateException( + format( + "Erro ao tentar ler o campo \"%s\" na posição [%s] no layout do registro.", + field.getName(), getFields().indexOf(field)+1),e); + } + } + + builder = null; + } + } + + @Override + public String write() { + + Objects.checkNotNull(getFields(), "Fields == null"); + Collections.checkNotEmpty(getFields(), "Coleção de fields vazia!"); + + String str = null; + + isSizeAsDefinaed(); + + str = super.write(); + + instantLength = str.length(); + + if (isTruncate() && instantLength > getFixedLength()) { + str = str.substring(0, getFixedLength()); + instantLength = getFixedLength(); + } + + isFixedAsDefined(); + + return str; + } + + public boolean isFixedAsDefined() throws IllegalStateException { + + return (isSizeAsDefinaed() && isLengthWithDefinaed()); + } + + private boolean isLengthWithDefinaed(){ + + return isLengthWithDefinaed(instantLength); + } + + private boolean isLengthWithDefinaed(int length){ + + if(length == getFixedLength()) + return true; + else + throw new IllegalStateException(format("O comprimento da string [%s] é incompátivel com o definido [%s] no layout do registro!",length,getFixedLength())); + } + + private boolean isSizeAsDefinaed(){ + + if(size() == getFixedSize()) + return true; + else + throw new IllegalStateException(format("O número de fields [%s] é incompátivel com o definido [%s]!", size(), getFixedSize())); + } + + /** + * @return the length + */ + public Integer getFixedLength() { + return length; + } + + /** + * @param length the length to set + */ + protected void setLength(Integer length) { + + if (isNotNull(length)) + this.length = length; + else + throw new IllegalArgumentException(format("Comprimento inválido [%s]!", length)); + } + + /** + * @return the size + */ + public Integer getFixedSize() { + return size; + } + + /** + * @param size the size to set + */ + protected void setSize(Integer size) { + + if (isNotNull(size)) + this.size = size; + else + throw new IllegalArgumentException(format("Tamanho inválido [%s]!", size)); + } + + public boolean isTruncate() { + return this.truncate; + } + + public void setTruncate(boolean truncate) { + this.truncate = truncate; + } +} diff --git a/src/main/java/org/jrimum/texgit/type/component/Field.java b/src/main/java/org/jrimum/texgit/type/component/Field.java new file mode 100644 index 0000000..bae9ab5 --- /dev/null +++ b/src/main/java/org/jrimum/texgit/type/component/Field.java @@ -0,0 +1,406 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit.type.component; + +import static java.lang.String.format; +import static org.apache.commons.lang.StringUtils.EMPTY; +import static org.apache.commons.lang.StringUtils.isBlank; +import static org.apache.commons.lang.StringUtils.isNumeric; +import static org.jrimum.utilix.Objects.isNotNull; + +import java.lang.reflect.Constructor; +import java.math.BigDecimal; +import java.text.DecimalFormat; +import java.text.Format; +import java.text.ParseException; +import java.util.Date; + +import org.jrimum.texgit.TextStream; +import org.jrimum.utilix.Dates; +import org.jrimum.utilix.Objects; + +/** + * @author Gilmar P.S.L. + * + * @param + */ +@SuppressWarnings("serial") +public class Field implements org.jrimum.texgit.type.Field{ + + /** + *

+ *Nome do campo, também pode ser usado como id. + *

+ */ + private String name; + + /** + *

+ * Valor do campo. + *

+ */ + private G value; + + /** + *

+ * Formatador utilizado na leitura e escrita do valor do campo. + *

+ */ + private Format formatter; + + /** + *

+ * Necessário para ler campos númericos em branco. + *

+ */ + private boolean blankAccepted; + + /** + * + */ + public Field() { + super(); + } + + /** + * @param value + */ + public Field(G value) { + super(); + setValue(value); + } + + /** + *

+ * Cria um Field com um valor e um formatador para o valor. Isto significa que a leitura e escrita do valor informado + * será de acordo com o formatador. + *

+ * + * @param value + * @param formatter + */ + public Field(G value, Format formatter){ + + setValue(value); + setFormatter(formatter); + } + + /** + * @param name + * @param value + */ + public Field(String name, G value) { + super(); + setName(name); + setValue(value); + } + + + /** + *

+ * Cria um Field com nome para identificação, valor e um formatador. + *

+ * + * @param name + * @param value + * @param formatter + * + * @see #Field(Object, Format) + */ + public Field(String name, G value, Format formatter){ + + setName(name); + setValue(value); + setFormatter(formatter); + } + + @SuppressWarnings("unchecked") + @Override + public Field clone() throws CloneNotSupportedException { + + return (Field) super.clone(); + } + + public void read(String str) { + + Objects.checkNotNull(str, "String inválida [null]!"); + + try{ + + if (this.value instanceof TextStream) { + + TextStream reader = (TextStream) this.value; + reader.read(str); + + } else if (this.value instanceof BigDecimal) { + + readDecimalField(str); + + } else if (this.value instanceof Date) { + + readDateField(str); + + } else if (this.value instanceof Character) { + + readCharacter(str); + + } else { + + readStringOrNumericField(str); + } + + }catch (Exception e) { + + throw new IllegalStateException(format("Falha na leitura do campo! %s",toString()),e); + } + } + + @SuppressWarnings("unchecked") + private void readCharacter(String str) { + + if(str.length() == 1){ + + value = (G) new Character(str.charAt(0)); + + }else + throw new IllegalArgumentException("String com mais de 1 character!"); + } + + @SuppressWarnings("unchecked") + private void readDecimalField(String str) { + + DecimalFormat decimalFormat = (DecimalFormat) formatter; + + try { + + String number = parseNumber(str); + + Long parsedValue = (Long) formatter.parseObject(number); + + BigDecimal decimalValue = new BigDecimal(parsedValue.longValue()); + + decimalValue = decimalValue.movePointLeft(decimalFormat.getMaximumFractionDigits()); + + value = (G) decimalValue; + + } + catch (ParseException e) { + + throwReadError(e, str); + } + } + + @SuppressWarnings("unchecked") + private void readDateField(String str) { + + try { + + if(isBlank(str)){ + + if(isBlankAccepted()){ + + value = (G) Dates.invalidDate(); + + }else{ + + new IllegalArgumentException(format("Campo data vazio não permitido: [%s]!",str)); + } + + }else{ + + value = (G) formatter.parseObject(str); + } + + } catch (ParseException e) { + + throwReadError(e, str); + } + } + + @SuppressWarnings("unchecked") + private void readStringOrNumericField(String str) { + + str = parseNumber(str); + + Class clazz = value.getClass(); + + if(clazz.equals(String.class)){ + value = (G) str; + }else{ + readNumeric(clazz,str); + } + } + + @SuppressWarnings("unchecked") + private void readNumeric(Class clazz, String str) { + + for (Constructor cons : clazz.getConstructors()) { + + if (cons.getParameterTypes().length == 1){ + + if (cons.getParameterTypes()[0].equals(String.class)){ + try { + + value = (G) cons.newInstance(str); + + } catch (Exception e) { + + throwReadError(e, str); + } + } + } + } + } + + public String write() { + + try{ + + String str = null; + + if (value instanceof TextStream) { + + TextStream its = (TextStream) value; + + str = its.write(); + + } else if (value instanceof Date) { + + str = writeDateField(); + } + + else if (value instanceof BigDecimal) + str = writeDecimalField(); + + else + str = value.toString(); + + return str; + + }catch (Exception e) { + + throw new IllegalStateException(format("Falha na escrita do campo escrita! %s",toString()),e); + } + } + + private String writeDecimalField(){ + + BigDecimal decimalValue = (BigDecimal) value; + + decimalValue = decimalValue.movePointRight(((DecimalFormat)formatter).getMaximumFractionDigits()); + + return decimalValue.toString(); + } + + private String writeDateField(){ + + if (!Dates.equalsInvalidDate((Date) value)){ + + return formatter.format(value); + } + + return EMPTY; + } + + private String parseNumber(String str){ + + if(isBlank(str)){ + + if(isBlankAccepted()) + str = "0"; + else + new IllegalArgumentException(format("Campo numérico vazio não permitido: [%s]!",str)); + }else + if(!isNumeric(str)) + new IllegalArgumentException(format("O campo deve ser numérico e não: [%s]!",str)); + + return str; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + + if (isNotNull(name)) + this.name = name; + else + throw new IllegalArgumentException(format("Nome Inválido: [%s]!",name)); + } + + public boolean isBlankAccepted() { + return this.blankAccepted; + } + + public void setBlankAccepted(boolean blankAccepted) { + this.blankAccepted = blankAccepted; + } + + public G getValue() { + return value; + } + + public void setValue(G value) { + + if (isNotNull(value)) + this.value = value; + else + throw new IllegalArgumentException(format("Valor Inválido: [%s]!",value)); + } + + public Format getFormatter() { + return formatter; + } + + public void setFormatter(Format formatter) { + + if (isNotNull(formatter)) + this.formatter = formatter; + else + throw new IllegalArgumentException(format("Formato inválido: [%s]!",formatter)); + } + + private void throwReadError(Exception e, String value){ + + throw new IllegalArgumentException(format("Falha na leitura da string: [\"%s\"]! %s",value,toString()), e); + } + + @Override + public String toString() { + + return format("Field [name=\"%s\", value=\"%s\", isBlankAccepted=%s, formatter=%s]" + , Objects.whenNull(this.name, EMPTY) + , Objects.whenNull(this.value, EMPTY) + , Objects.whenNull(this.isBlankAccepted(), EMPTY) + , Objects.whenNull(this.formatter, EMPTY)); + + } +} diff --git a/src/br/com/nordestefomento/jrimum/texgit/type/component/Filler.java b/src/main/java/org/jrimum/texgit/type/component/Filler.java similarity index 52% rename from src/br/com/nordestefomento/jrimum/texgit/type/component/Filler.java rename to src/main/java/org/jrimum/texgit/type/component/Filler.java index 7e9d305..2ffeb96 100644 --- a/src/br/com/nordestefomento/jrimum/texgit/type/component/Filler.java +++ b/src/main/java/org/jrimum/texgit/type/component/Filler.java @@ -26,17 +26,15 @@ * Criado em: 30/03/2008 - 18:17:00 * */ +package org.jrimum.texgit.type.component; - -package br.com.nordestefomento.jrimum.texgit.type.component; - -import static br.com.nordestefomento.jrimum.utilix.ObjectUtil.isNotNull; - -import java.io.Serializable; +import static java.lang.String.format; +import static org.apache.commons.lang.StringUtils.EMPTY; +import static org.jrimum.utilix.Objects.isNotNull; import org.apache.commons.lang.StringUtils; - -import br.com.nordestefomento.jrimum.utilix.TextStream; +import org.jrimum.texgit.TextStream; +import org.jrimum.utilix.Objects; /** *

@@ -58,8 +56,8 @@ * *

* @author Gilmar P.S.L - * @author Misael Barreto - * @author Rômulo Augusto + * @author Misael Barreto + * @author Rômulo Augusto * @author Nordeste Fomento * Mercantil * @@ -68,10 +66,9 @@ * @version 0.2.1-inc * */ - @SuppressWarnings("serial") -public class Filler implements Serializable{ - +public class Filler implements org.jrimum.texgit.type.Filler{ + private G padding; private Side sideToFill; @@ -81,7 +78,7 @@ public Filler() { } /** - * @param padding + * @param fillWith */ public Filler(G fillWith) { @@ -90,7 +87,7 @@ public Filler(G fillWith) { } /** - * @param padding + * @param fillWith * @param sideToFill */ public Filler(G fillWith, Side sideToFill) { @@ -99,55 +96,46 @@ public Filler(G fillWith, Side sideToFill) { setSideToFill(sideToFill); } + /** + * @see org.jrimum.texgit.type#getPadding() + */ public G getPadding() { return padding; } /** - * @param filler + * @see org.jrimum.texgit.type#setPadding(G) */ public void setPadding(G fillWith) { - if(isNotNull(fillWith)) + if(isNotNull(fillWith)){ this.padding = fillWith; - - else - throw new IllegalArgumentException("Preenchimento inválido [ " + fillWith + " ]!"); + }else{ + throw new IllegalArgumentException(format("Preenchimento inválido [%s]!",fillWith)); + } } /** - * @return + * @see org.jrimum.texgit.type#getSideToFill() */ public Side getSideToFill() { return sideToFill; } /** - * @param sideToFill + * @see org.jrimum.texgit.type#setSideToFill(org.jrimum.texgit.type.component.Side) */ public void setSideToFill(Side sideToFill) { - if(isNotNull(sideToFill)) + if(isNotNull(sideToFill)){ this.sideToFill = sideToFill; - - else - throw new IllegalArgumentException("Lado para preenchimento [ " + sideToFill + " ]!"); + }else{ + throw new IllegalArgumentException(format("Lado para preenchimento [%s]!",sideToFill)); + } } /** - *

- * Preenche o campo com o caracter especificado e no lado especificado. - *

- *

- * Exemplo: - *
- * Se sideToFill == SideToFill.LEFT, o caracter especificado será adicionado à String - * no lado esquerdo até que o campo fique com o tamanho que foi definido. - *

- * - * @param toFill - * @param length - * @return + * @see org.jrimum.texgit.type#fill(java.lang.String, int) */ public String fill(String toFill, int length){ @@ -168,194 +156,78 @@ public String fill(String toFill, int length){ } /** - * - *

- * Executa o método fill(String, int) passando o parâmetro - * toFill como String.valueOf(toFill). - *

- * - * @param tofill - * @param length - * @return - * - * @see Filler#fill(String, int) - * - * @since + * @see org.jrimum.texgit.type#fill(long, int) */ public String fill(long tofill, int length){ return fill(String.valueOf(tofill), length); } /** - * - *

- * Executa o método fill(String, int) passando o parâmetro - * toFill como String.valueOf(toFill). - *

- * - * @param tofill - * @param length - * @return - * - * @see Filler#fill(String, int) - * - * @since + * @see org.jrimum.texgit.type#fill(int, int) */ public String fill(int tofill, int length){ return fill(String.valueOf(tofill), length); } /** - * - *

- * Executa o método fill(String, int) passando o parâmetro - * toFill como String.valueOf(toFill). - *

- * - * @param tofill - * @param length - * @return - * - * @see Filler#fill(String, int) - * - * @since + * @see org.jrimum.texgit.type#fill(short, int) */ public String fill(short tofill, int length){ return fill(String.valueOf(tofill), length); } /** - * - *

- * Executa o método fill(String, int) passando o parâmetro - * toFill como String.valueOf(toFill). - *

- * - * @param tofill - * @param length - * @return - * - * @see Filler#fill(String, int) - * - * @since + * @see org.jrimum.texgit.type#fill(byte, int) */ public String fill(byte tofill, int length){ return fill(String.valueOf(tofill), length); } /** - * - *

- * Executa o método fill(String, int) passando o parâmetro - * toFill como String.valueOf(toFill). - *

- * - * @param tofill - * @param length - * @return - * - * @see Filler#fill(String, int) - * - * @since + * @see org.jrimum.texgit.type#fill(char, int) */ public String fill(char tofill, int length){ return fill(String.valueOf(tofill), length); } /** - * - *

- * Executa o método fill(String, int) passando o parâmetro - * toFill como String.valueOf(toFill). - *

- * - * @param tofill - * @param length - * @return - * - * @see Filler#fill(String, int) - * - * @since + * @see org.jrimum.texgit.type#fill(double, int) */ public String fill(double tofill, int length){ return fill(String.valueOf(tofill), length); } /** - * - *

- * Executa o método fill(String, int) passando o parâmetro - * toFill como String.valueOf(toFill). - *

- * - * @param tofill - * @param length - * @return - * - * @see Filler#fill(String, int) - * - * @since + * @see org.jrimum.texgit.type#fill(float, int) */ public String fill(float tofill, int length){ return fill(String.valueOf(tofill), length); } /** - * - *

- * Executa o método fill(String, int) passando o parâmetro - * toFill como toFill.toString(). - *
- *

- *

- * Caso toFill seja null, o método - * fill(String, int) receberá uma String nula como parâmetro. - *

- * - * @param tofill - * @param length - * @return - * - * @see Filler#fill(String, int) - * - * @since + * @see org.jrimum.texgit.type#fill(java.lang.Object, int) */ public String fill(Object tofill, int length){ String toFillTemp = null; - if(isNotNull(tofill)) + if(isNotNull(tofill)){ toFillTemp = tofill.toString(); + } return fill(toFillTemp, length); } /** - * - *

- * Executa o método fill(String, int) passando o parâmetro - * toFill como toFill.write(). - *
- *

- *

- * Caso toFill seja null, o método - * fill(String, int) receberá uma String nula como parâmetro. - *

- * - * @param tofill - * @param length - * @return - * - * @see Filler#fill(String, int) - * - * @since + * @see org.jrimum.texgit.type#fill(org.jrimum.texgit.TextStream, int) */ public String fill(TextStream tofill, int length){ String toFillTemp = null; - if(isNotNull(tofill)) + if(isNotNull(tofill)){ toFillTemp = tofill.write(); + } return fill(toFillTemp, length); } @@ -363,7 +235,7 @@ public String fill(TextStream tofill, int length){ /** * @param toFill * @param length - * @return + * @return String preenchida */ private String fillRight(String toFill, int length) { @@ -373,11 +245,20 @@ private String fillRight(String toFill, int length) { /** * @param toFill * @param length - * @return + * @return String preenchida */ private String fillLeft(String toFill, int length) { return StringUtils.leftPad(toFill, length, padding.toString()); } + @Override + public String toString() { + + return format( + "Filler [padding=\"%s\", sideToFill=%s]" + , Objects.whenNull(this.padding, EMPTY) + , Objects.whenNull(this.sideToFill, EMPTY)); + } + } diff --git a/src/main/java/org/jrimum/texgit/type/component/Fillers.java b/src/main/java/org/jrimum/texgit/type/component/Fillers.java new file mode 100644 index 0000000..b6aa9ed --- /dev/null +++ b/src/main/java/org/jrimum/texgit/type/component/Fillers.java @@ -0,0 +1,167 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit.type.component; + +import org.jrimum.texgit.TextStream; +import org.jrimum.utilix.text.Strings; + + +/** + * @author Gilmar P.S.L. + * + */ +public enum Fillers implements org.jrimum.texgit.type.Filler{ + + /** + * Filler padrão para preenchimento com zeros a esquerda. + */ + ZERO_LEFT(new Filler(0, Side.LEFT)), + + /** + * Filler padrão para preenchimento com zeros a direita. + */ + ZERO_RIGHT(new Filler(0, Side.RIGHT)), + + /** + * Filler padrão para preenchimento com espaços em branco a esquerda. + */ + WHITE_SPACE_LEFT(new Filler(Strings.WHITE_SPACE, Side.LEFT)), + + /** + * Filler padrão para preenchimento com espaços em branco a direita. + */ + WHITE_SPACE_RIGHT(new Filler(Strings.WHITE_SPACE, Side.RIGHT)); + + private Filler filler; + + private Fillers(Filler filler){ + this.filler = filler; + } + + /** + * @param toFill + * @param length + * @return String preenchida + * @see org.jrimum.texgit.type.component.Filler#fill(java.lang.String, int) + */ + public String fill(String toFill, int length) { + return filler.fill(toFill, length); + } + + /** + * @param tofill + * @param length + * @return String preenchida + * @see org.jrimum.texgit.type.component.Filler#fill(long, int) + */ + public String fill(long tofill, int length) { + return filler.fill(tofill, length); + } + + /** + * @param tofill + * @param length + * @return String preenchida + * @see org.jrimum.texgit.type.component.Filler#fill(int, int) + */ + public String fill(int tofill, int length) { + return filler.fill(tofill, length); + } + + /** + * @param tofill + * @param length + * @return String preenchida + * @see org.jrimum.texgit.type.component.Filler#fill(short, int) + */ + public String fill(short tofill, int length) { + return filler.fill(tofill, length); + } + + /** + * @param tofill + * @param length + * @return String preenchida + * @see org.jrimum.texgit.type.component.Filler#fill(byte, int) + */ + public String fill(byte tofill, int length) { + return filler.fill(tofill, length); + } + + /** + * @param tofill + * @param length + * @return String preenchida + * @see org.jrimum.texgit.type.component.Filler#fill(char, int) + */ + public String fill(char tofill, int length) { + return filler.fill(tofill, length); + } + + /** + * @param tofill + * @param length + * @return String preenchida + * @see org.jrimum.texgit.type.component.Filler#fill(double, int) + */ + public String fill(double tofill, int length) { + return filler.fill(tofill, length); + } + + /** + * @param tofill + * @param length + * @return String preenchida + * @see org.jrimum.texgit.type.component.Filler#fill(float, int) + */ + public String fill(float tofill, int length) { + return filler.fill(tofill, length); + } + + /** + * @param tofill + * @param length + * @return String preenchida + * @see org.jrimum.texgit.type.component.Filler#fill(java.lang.Object, int) + */ + public String fill(Object tofill, int length) { + return filler.fill(tofill, length); + } + + /** + * @param tofill + * @param length + * @return String preenchida + * @see org.jrimum.texgit.type.component.Filler#fill(org.jrimum.texgit.TextStream, int) + */ + public String fill(TextStream tofill, int length) { + return filler.fill(tofill, length); + } + +} diff --git a/src/main/java/org/jrimum/texgit/type/component/FixedField.java b/src/main/java/org/jrimum/texgit/type/component/FixedField.java new file mode 100644 index 0000000..9adcd7f --- /dev/null +++ b/src/main/java/org/jrimum/texgit/type/component/FixedField.java @@ -0,0 +1,233 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit.type.component; + +import static java.lang.String.format; +import static org.apache.commons.lang.StringUtils.EMPTY; +import static org.jrimum.utilix.Objects.isNotNull; + +import java.text.Format; + +import org.jrimum.texgit.type.Filler; +import org.jrimum.utilix.Objects; + + +/** + * @author Gilmar P.S.L. + * + * @param + */ +@SuppressWarnings("serial") +public class FixedField extends Field implements org.jrimum.texgit.type.FixedField{ + + /** + *

+ * Tamanho de especificação e parâmetro da string de leitura ou escrita do campo. + *

+ */ + private Integer length; + + /** + *

+ * Preenchedor do valor utilizado na hora da escrita. + *

+ */ + private Filler filler; + + + /** + *

+ * Tamanho da string de escrita do campo. + *

+ */ + private Integer instantLength; + + /** + *

+ * Ao ultrapassar o tamanho, define se pode truncar ou se dispara uma exceção. + *

+ */ + private boolean truncate; + + + /** + * + */ + public FixedField() { + super(); + } + + public FixedField(G value, Integer length) { + super(value); + setFixedLength(length); + } + + public FixedField(G value, Integer length, Filler filler) { + super(value); + setFixedLength(length); + setFiller(filler); + } + + public FixedField(G value, Integer length, Format formatter) { + super(value,formatter); + setFixedLength(length); + } + + public FixedField(G value, Integer length, Format formatter, Filler filler) { + super(value,formatter); + setFixedLength(length); + setFiller(filler); + } + + public FixedField(String name, G value, Integer length) { + super(name,value); + setFixedLength(length); + } + + public FixedField(String name, G value, Integer length, Filler filler) { + super(name,value); + setFixedLength(length); + setFiller(filler); + } + + public FixedField(String name, G value, Integer length, Format formatter) { + super(name,value,formatter); + setFixedLength(length); + } + + public FixedField(String name, G value, Integer length, Format formatter, Filler filler) { + super(name,value,formatter); + setFixedLength(length); + setFiller(filler); + } + + @Override + public FixedField clone() throws CloneNotSupportedException { + + return (FixedField) super.clone(); + } + + /** + * @see org.jrimum.texgit.type.component.Field#read(java.lang.String) + */ + @Override + public void read(String str) { + + Objects.checkNotNull(str, "String inválida [null]!"); + + if (str.length() == getFixedLength()) { + super.read(str); + } else + throw new IllegalArgumentException(format("Tamanho da string [%s] diferente do especificado [%s]! %s",str.length(),getFixedLength(),toString())); + } + + /** + * @see org.jrimum.texgit.type.component.Field#write() + */ + @Override + public String write() { + + String str = fill(super.write()); + + instantLength = str.length(); + + if (isTruncate() && instantLength > getFixedLength()) { + str = str.substring(0, getFixedLength()); + instantLength = getFixedLength(); + } + + isFixedAsDefined(); + + return str; + } + + private String fill(String str) { + + if(isNotNull(filler)) + str = filler.fill(str, length); + + return str; + } + + public boolean isFixedAsDefined() throws IllegalStateException { + + if(instantLength.equals(getFixedLength())) + return true; + else + throw new IllegalStateException(format("Tamanho da string [%s] diferente do especificado [%s]! %s",instantLength,getFixedLength(),toString())); + } + + public Integer getFixedLength() { + + return this.length; + } + + public void setFixedLength(Integer length) { + + if (isNotNull(length) && length.intValue() > 0) + this.length = length; + else + throw new IllegalArgumentException(format("Comprimento inválido [%s]!",length)); + + } + + public Filler getFiller() { + return filler; + } + + public void setFiller(Filler filler) { + + if(isNotNull(filler)) + this.filler = filler; + else + throw new IllegalArgumentException(format("Preenchedor inválido [%s]!",filler)); + } + + public boolean isTruncate() { + return this.truncate; + } + + public void setTruncate(boolean truncate) { + this.truncate = truncate; + } + + + @Override + public String toString() { + + return format( + "%s FixedField [length=%s, instantLength=%s, filler=%s, truncate=%s]", + super.toString() + , Objects.whenNull(this.length, EMPTY) + , Objects.whenNull(this.instantLength, EMPTY) + , Objects.whenNull(this.filler, EMPTY) + , Objects.whenNull(this.truncate, EMPTY)); + } + +} diff --git a/src/main/java/org/jrimum/texgit/type/component/FlatFile.java b/src/main/java/org/jrimum/texgit/type/component/FlatFile.java new file mode 100644 index 0000000..0a858f2 --- /dev/null +++ b/src/main/java/org/jrimum/texgit/type/component/FlatFile.java @@ -0,0 +1,321 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit.type.component; + +import static java.lang.String.format; +import static org.apache.commons.lang.StringUtils.EMPTY; +import static org.apache.commons.lang.StringUtils.isNotBlank; +import static org.jrimum.utilix.Objects.isNotNull; +import static org.jrimum.utilix.Objects.isNull; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Set; + + +/** + * @author Gilmar P.S.L. + * + */ +@SuppressWarnings("serial") +public class FlatFile implements org.jrimum.texgit.FlatFile{ + + private List records; + + private Set repitablesRecords; + + private List recordsOrder; + + private RecordFactory recordFactory; + + public FlatFile(RecordFactory iFac4Rec) { + + this.recordFactory = iFac4Rec; + this.records = new ArrayList(); + } + + public Record getRecord(String idName){ + + Record record = null; + + if (isNotBlank(idName)) { + if (!isRepitable(idName)){ + if (!records.isEmpty()) { + for (Record rec : records) { + if (idName.equals(rec.getName())) + record = rec; + } + } + } + } + + return record; + } + + public boolean isRepitable(String idName){ + + return (isNotNull(repitablesRecords) && !repitablesRecords.isEmpty() && repitablesRecords.contains(idName)); + } + + public org.jrimum.texgit.Record createRecord(String idName){ + + return recordFactory.create(idName); + } + + public void addRecord(Record record){ + + if(isNotNull(record)) + if(isMyRecord(record.getName())) + records.add(record); + else + throw new IllegalArgumentException("Record fora de scopo!"); + } + + public boolean isMyRecord(String idName){ + boolean is = false; + + if (isNotBlank(idName)) { + if(!recordsOrder.isEmpty()) + if(recordsOrder.contains(idName)) + is = true; + } + return is; + } + + public void read(List str) { + + if(isNotNull(str)){ + if(!str.isEmpty()){ + + String line = null; + int lineIndex = 0; + + FixedField typeRecord = null; + Record record = null; + + for(String id : recordsOrder){ + + record = recordFactory.create(id); + + try{ + + if(isRepitable(id)){ + + boolean read = true; + + while(read){ + + if(isNull(record)) + record = recordFactory.create(id); + + if(lineIndex < str.size()) + line = str.get(lineIndex); + + typeRecord = record.readID(line); + + read = record.getIdType().getValue().equals(typeRecord.getValue()) && (lineIndex < str.size()); + + if(read){ + + record.read(line); + lineIndex++; + addRecord(record); + + if(record.isHeadOfGroup()){ + lineIndex = record.readInnerRecords(str,lineIndex,recordFactory); + } + + record = null; + } + } + + }else{ + if((lineIndex < str.size())){ + + line = str.get(lineIndex); + typeRecord = record.readID(line); + + if(record.getIdType().getValue().equals(typeRecord.getValue())){ + + record.read(line); + lineIndex++; + addRecord(record); + + if(record.isHeadOfGroup()){ + lineIndex = record.readInnerRecords(str,lineIndex,recordFactory); + } + + record = null; + } + } + } + + } catch (Exception e) { + + throw new IllegalStateException(format( + "Erro ao tentar ler o registro \"%s\".", record.getName()), e); + } + } + } + } + } + + public List write() { + + return write(EMPTY); + } + + public List write(String lineEnding) { + + ArrayList out = new ArrayList(records.size()); + + for(String id : recordsOrder){ + + if(isRepitable(id)){ + + Record rec = null; + + for(org.jrimum.texgit.Record record : getRecords(id)){ + + rec = Record.class.cast(record); + + try{ + + out.add(rec.write()+lineEnding); + + } catch (Exception e) { + + throw new IllegalStateException(format( + "Erro ao tentar escrever o registro \"%s\".", rec.getName()), e); + } + + if(rec.isHeadOfGroup() && rec.hasInnerRecords()){ + out.addAll(rec.writeInnerRecords(lineEnding)); + } + } + + }else{ + + Record rec = getRecord(id); + + try{ + + out.add(rec.write()+lineEnding); + + } catch (Exception e) { + + throw new IllegalStateException(format( + "Erro ao tentar escrever o registro \"%s\".", rec.getName()), e); + } + + if(rec.isHeadOfGroup() && rec.hasInnerRecords()){ + out.addAll(rec.writeInnerRecords(lineEnding)); + } + } + } + + return out; + } + + public org.jrimum.texgit.FlatFile addRecord(org.jrimum.texgit.Record record) { + + if(isNotNull(record)){ + Record rec = Record.class.cast(record); + addRecord(rec); + } + + return this; + } + + public Collection getRecords(String idName) { + + List secRecords = new ArrayList(); + + if (isNotBlank(idName)) { + if (isRepitable(idName)) { + if (!records.isEmpty()) { + for (Record rec : records) { + if (idName.equals(rec.getName())) + secRecords.add(rec); + } + } + } + } + + return secRecords; + } + + public org.jrimum.texgit.FlatFile addAllRecords(Collection records) { + // TODO IMPLEMENTAR + throw new UnsupportedOperationException("AINDA NÃO IMPLEMENTADO!"); + } + + public org.jrimum.texgit.FlatFile addRecords(String idName, Collection records) { + // TODO IMPLEMENTAR + throw new UnsupportedOperationException("AINDA NÃO IMPLEMENTADO!"); + } + + public Collection getAllRecords() { + // TODO IMPLEMENTAR + throw new UnsupportedOperationException("AINDA NÃO IMPLEMENTADO!"); + } + + public org.jrimum.texgit.Record removeRecord(String idName) { + // TODO IMPLEMENTAR + throw new UnsupportedOperationException("AINDA NÃO IMPLEMENTADO!"); + } + + public org.jrimum.texgit.FlatFile setAllRecords(Collection records) { + // TODO IMPLEMENTAR + throw new UnsupportedOperationException("AINDA NÃO IMPLEMENTADO!"); + } + + public org.jrimum.texgit.FlatFile setRecords(String idName, Collection records) { + // TODO IMPLEMENTAR + throw new UnsupportedOperationException("AINDA NÃO IMPLEMENTADO!"); + } + + public Set getRepitablesRecords() { + return repitablesRecords; + } + + public void setRepitablesRecords(Set repitablesRecords) { + this.repitablesRecords = repitablesRecords; + } + + public List getRecordsOrder() { + return recordsOrder; + } + + public void setRecordsOrder(List recordsOrder) { + this.recordsOrder = recordsOrder; + } + +} diff --git a/src/br/com/nordestefomento/jrimum/texgit/type/component/Record.java b/src/main/java/org/jrimum/texgit/type/component/Record.java similarity index 52% rename from src/br/com/nordestefomento/jrimum/texgit/type/component/Record.java rename to src/main/java/org/jrimum/texgit/type/component/Record.java index 0e30f00..39de234 100644 --- a/src/br/com/nordestefomento/jrimum/texgit/type/component/Record.java +++ b/src/main/java/org/jrimum/texgit/type/component/Record.java @@ -1,18 +1,54 @@ -package br.com.nordestefomento.jrimum.texgit.type.component; - -import static br.com.nordestefomento.jrimum.utilix.ObjectUtil.isNotNull; -import static br.com.nordestefomento.jrimum.utilix.ObjectUtil.isNull; +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit.type.component; + +import static java.lang.String.format; +import static org.apache.commons.lang.StringUtils.EMPTY; import static org.apache.commons.lang.StringUtils.isNotBlank; +import static org.jrimum.utilix.Objects.isNotNull; +import static org.jrimum.utilix.Objects.isNull; import java.util.ArrayList; import java.util.List; import java.util.Set; -import br.com.nordestefomento.jrimum.texgit.type.Field; +import org.jrimum.texgit.type.Field; +import org.jrimum.utilix.Objects; + +/** + * @author Gilmar P.S.L. + * + */ @SuppressWarnings("serial") -public class Record extends BlockOfFields implements br.com.nordestefomento.jrimum.texgit.Record{ +public class Record extends BlockOfFields implements org.jrimum.texgit.Record{ private String name; @@ -24,7 +60,7 @@ public class Record extends BlockOfFields implements br.com.nordestefomento.jrim private boolean headOfGroup; - private List innerRecords; + private List innerRecords; private Set repitablesRecords; @@ -48,6 +84,7 @@ public Record clone() throws CloneNotSupportedException { return (Record) super.clone(); } + @SuppressWarnings("null") public FixedField readID(String lineRecord) { FixedField ffID = null; @@ -58,7 +95,8 @@ public FixedField readID(String lineRecord) { ffID.setName(""); } catch (CloneNotSupportedException e) { - e.printStackTrace(); + + throw new UnsupportedOperationException(format("Quebra de contrato [%s] não suporta clonagem!",Objects.whenNull(ffID, "FixedField", ffID.getClass())), e); } getIdType().read(lineRecord.substring(getIdPosition(), getIdPosition() + getIdType().getFixedLength())); @@ -66,9 +104,9 @@ public FixedField readID(String lineRecord) { return ffID; } - public br.com.nordestefomento.jrimum.texgit.type.FixedField getField(String fieldName) { + public org.jrimum.texgit.type.FixedField getField(String fieldName) { - br.com.nordestefomento.jrimum.texgit.type.FixedField field = null; + org.jrimum.texgit.type.FixedField field = null; if (isNotBlank(fieldName)) if (!getFields().isEmpty()) @@ -86,7 +124,7 @@ public boolean isMyField(String idName){ if (isNotBlank(idName)) { if(!getFields().isEmpty()) - for(br.com.nordestefomento.jrimum.texgit.type.Field f : getFields()) + for(org.jrimum.texgit.type.Field f : getFields()) if(idName.equals(f.getName())){ is = true; break; @@ -115,6 +153,7 @@ public int readInnerRecords(List lines, int lineIndex, RecordFactory lines, int lineIndex, RecordFactory iFactory) { if(isNotNull(record)){ + if(isNotNull(record.getDeclaredInnerRecords()) && !record.getDeclaredInnerRecords().isEmpty()){ boolean read = true; @@ -127,51 +166,60 @@ private int readInnerRecords(Record record, List lines, int lineIndex, R innerRec = iFactory.create(id); - if(isRepitable(id)){ + try{ - while(read){ - - if(isNull(innerRec)) - innerRec = iFactory.create(id); + if(isRepitable(id)){ - if(lineIndex < lines.size()) - line = lines.get(lineIndex); - - typeRecord = innerRec.readID(line); - - read = innerRec.getIdType().getValue().equals(typeRecord.getValue()) && (lineIndex < lines.size()); - - if(read){ + while(read){ - innerRec.read(line); - lineIndex++; - record.addInnerRecord(innerRec); + if(isNull(innerRec)) + innerRec = iFactory.create(id); - if(innerRec.isHeadOfGroup()) - innerRec.readInnerRecords(lines,lineIndex,iFactory); + if(lineIndex < lines.size()) + line = lines.get(lineIndex); - innerRec = null; + typeRecord = innerRec.readID(line); + + read = innerRec.getIdType().getValue().equals(typeRecord.getValue()) && (lineIndex < lines.size()); + + if(read){ + + innerRec.read(line); + lineIndex++; + record.addInnerRecord(innerRec); + + if(innerRec.isHeadOfGroup()) + innerRec.readInnerRecords(lines,lineIndex,iFactory); + + innerRec = null; + } } - } - - }else{ - if((lineIndex < lines.size())){ - line = lines.get(lineIndex); - typeRecord = innerRec.readID(line); - - if(innerRec.getIdType().getValue().equals(typeRecord.getValue())){ - - innerRec.read(line); - lineIndex++; - record.addInnerRecord(innerRec); + }else{ + if((lineIndex < lines.size())){ - if(innerRec.isHeadOfGroup()) - innerRec.readInnerRecords(lines,lineIndex,iFactory); + line = lines.get(lineIndex); + typeRecord = innerRec.readID(line); - innerRec = null; + if(innerRec.getIdType().getValue().equals(typeRecord.getValue())){ + + innerRec.read(line); + lineIndex++; + record.addInnerRecord(innerRec); + + if(innerRec.isHeadOfGroup()) + innerRec.readInnerRecords(lines,lineIndex,iFactory); + + innerRec = null; + } } } + + } catch (Exception e) { + + throw new IllegalStateException(format( + "Erro ao tentar ler o registro \"%s\".", + innerRec.getName()), e); } } } @@ -182,10 +230,15 @@ private int readInnerRecords(Record record, List lines, int lineIndex, R public List writeInnerRecords(){ - return writeInnerRecords(this); + return writeInnerRecords(this,EMPTY); + } + + public List writeInnerRecords(String lineEnding){ + + return writeInnerRecords(this,lineEnding); } - private List writeInnerRecords(Record record){ + private List writeInnerRecords(Record record, String lineEnding){ ArrayList out = new ArrayList(record.getInnerRecords().size()); @@ -195,7 +248,15 @@ private List writeInnerRecords(Record record){ for(Record rec : getRecords(id)){ - out.add(rec.write()+"\r\n"); + try{ + + out.add(rec.write()+lineEnding); + + } catch (Exception e) { + + throw new IllegalStateException(format( + "Erro ao tentar escrever o registro \"%s\".", rec.getName()), e); + } if(rec.isHeadOfGroup()) out.addAll(rec.writeInnerRecords()); @@ -205,7 +266,15 @@ private List writeInnerRecords(Record record){ Record rec = getRecord(id); - out.add(rec.write()+"\r\n"); + try{ + + out.add(rec.write()+lineEnding); + + } catch (Exception e) { + + throw new IllegalStateException(format( + "Erro ao tentar escrever o registro \"%s\".", rec.getName()), e); + } if(rec.isHeadOfGroup()) out.addAll(rec.writeInnerRecords()); @@ -222,7 +291,7 @@ public Record getRecord(String idName){ if (isNotBlank(idName)) { if (!isRepitable(idName)){ if (!getInnerRecords().isEmpty()) { - for (br.com.nordestefomento.jrimum.texgit.Record iRec : getInnerRecords()) { + for (org.jrimum.texgit.Record iRec : getInnerRecords()) { Record rec = (Record) iRec; if (idName.equals(rec.getName())) record = rec; @@ -241,7 +310,7 @@ public List getRecords(String idName) { if (isNotBlank(idName)) { if (isRepitable(idName)) { if (!getInnerRecords().isEmpty()) { - for (br.com.nordestefomento.jrimum.texgit.Record iRec : getInnerRecords()) { + for (org.jrimum.texgit.Record iRec : getInnerRecords()) { Record rec = (Record) iRec; if (idName.equals(rec.getName())) secRecords.add(rec); @@ -269,12 +338,11 @@ public boolean isMyRecord(String idName){ return is; } - @Override - public void addInnerRecord(br.com.nordestefomento.jrimum.texgit.Record record) { + public org.jrimum.texgit.Record addInnerRecord(org.jrimum.texgit.Record record) { if(isNotNull(record)){ if(isNull(this.innerRecords)) - this.innerRecords = new ArrayList(); + this.innerRecords = new ArrayList(); if(isMyRecord(Record.class.cast(record).getName())) this.innerRecords.add(record); @@ -282,21 +350,21 @@ public void addInnerRecord(br.com.nordestefomento.jrimum.texgit.Record record) { throw new IllegalArgumentException("Record fora de scopo!"); } + + return this; } - @Override - public List getInnerRecords() { + public List getInnerRecords() { return this.innerRecords; } @SuppressWarnings("unchecked") - @Override public G getValue(String fieldName) { G value = null; - br.com.nordestefomento.jrimum.texgit.type.Field f = getField(fieldName); + org.jrimum.texgit.type.Field f = getField(fieldName); if(isNotNull(f)) value = (G) f.getValue(); @@ -305,13 +373,18 @@ public G getValue(String fieldName) { } @SuppressWarnings("unchecked") - @Override - public void setValue(String fieldName, G value) { + public org.jrimum.texgit.Record setValue(String fieldName, G value) { - br.com.nordestefomento.jrimum.texgit.type.Field f = (Field) getField(fieldName); + org.jrimum.texgit.type.Field f = (Field) getField(fieldName); if(isNotNull(f)) f.setValue(value); + + return this; + } + + public boolean hasInnerRecords(){ + return getInnerRecords() != null && !getInnerRecords().isEmpty(); } public String getName() { diff --git a/src/main/java/org/jrimum/texgit/type/component/RecordFactory.java b/src/main/java/org/jrimum/texgit/type/component/RecordFactory.java new file mode 100644 index 0000000..734d742 --- /dev/null +++ b/src/main/java/org/jrimum/texgit/type/component/RecordFactory.java @@ -0,0 +1,41 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 26/07/2008 - 12:44:41 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 26/07/2008 - 12:44:41 + * + */ +package org.jrimum.texgit.type.component; + +import org.jrimum.texgit.Record; + +/** + * @author Gilmar P.S.L. + * + * @param + */ +public interface RecordFactory { + + public abstract G create(String name); +} diff --git a/src/main/java/org/jrimum/texgit/type/component/Side.java b/src/main/java/org/jrimum/texgit/type/component/Side.java new file mode 100644 index 0000000..bd52fcf --- /dev/null +++ b/src/main/java/org/jrimum/texgit/type/component/Side.java @@ -0,0 +1,13 @@ +package org.jrimum.texgit.type.component; + +/** + * Lados para alinhar campos, preenchimento ou orientações em geral. + * + * @author Gilmar P.S.L. + */ +public enum Side { + + LEFT, + + RIGHT; +} diff --git a/src/resource/TexgitSchema.xsd b/src/main/resources/TexgitSchema.xsd similarity index 85% rename from src/resource/TexgitSchema.xsd rename to src/main/resources/TexgitSchema.xsd index 71ac0ba..35d80b4 100644 --- a/src/resource/TexgitSchema.xsd +++ b/src/main/resources/TexgitSchema.xsd @@ -1,10 +1,42 @@ + + + + - + xmlns:txg="http://jrimum.org/texgit" + targetNamespace="http://jrimum.org/texgit"> Representação de classes e atributos usados para definição @@ -229,6 +261,8 @@ default=" " /> + diff --git a/src/test/java/org/jrimum/texgit/type/component/TestFiller.java b/src/test/java/org/jrimum/texgit/type/component/TestFiller.java new file mode 100644 index 0000000..a9006d0 --- /dev/null +++ b/src/test/java/org/jrimum/texgit/type/component/TestFiller.java @@ -0,0 +1,257 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 30/03/2008 - 18:15:42 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 30/03/2008 - 18:15:42 + * + */ + +package org.jrimum.texgit.type.component; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.jrimum.texgit.TextStream; +import org.jrimum.texgit.type.component.Filler; +import org.jrimum.utilix.text.Strings; +import org.junit.Before; +import org.junit.Test; + +/** + *

+ * Teste unitário para a classe Filler. + *

+ * + * @author Gilmar P.S.L. + * @author Rômulo Augusto + * + * @since 0.2 + * + * @version 0.2 + */ +public class TestFiller { + + private static final String CAMPO = "TESTE"; + + private static final int TAMANHO = 10; + + private Filler fillerString; + private Filler fillerInteger; + private Filler fillerDouble; + private Filler fillerSide; + private Filler whiteSpaceLeft; + private Filler zeroLeft ; + private Filler zeroRight; + + @Before + public void setup(){ + whiteSpaceLeft = new Filler(Strings.WHITE_SPACE, Side.LEFT); + zeroLeft = new Filler(0, Side.LEFT); + zeroRight = new Filler(0, Side.RIGHT); + } + + @Test(expected = IllegalArgumentException.class) + public void testSetSideNullValue() { + + whiteSpaceLeft.setSideToFill(null); + } + + @Test(expected = IllegalArgumentException.class) + public void testSetToFillNullValue() { + + whiteSpaceLeft.setPadding(null); + } + + @Test + public void testSetToFill() { + + whiteSpaceLeft.setPadding(CAMPO); + + assertTrue(whiteSpaceLeft.getPadding() instanceof String); + assertEquals(whiteSpaceLeft.getPadding(), CAMPO); + } + + @Test + public void testSetSide() { + + whiteSpaceLeft.setSideToFill(Side.RIGHT); + + assertEquals(whiteSpaceLeft.getSideToFill(), Side.RIGHT); + } + + @Test(expected = IllegalArgumentException.class) + public void testFiller() { + + new Filler(null, null); + new Filler("", null); + new Filler(null, Side.LEFT); + } + + @Test + public void testFillString() { + + assertEquals(CAMPO + "00000", zeroRight.fill(CAMPO, TAMANHO)); + assertEquals("00000" + CAMPO, zeroLeft.fill(CAMPO, TAMANHO)); + } + + @Test + public void testFillLong() { + + assertEquals(1L + "000000000", zeroRight.fill(1L, TAMANHO)); + assertEquals("000000000" + 1L, zeroLeft.fill(1L, TAMANHO)); + } + + @Test + public void testFillInt() { + + assertEquals(1 + "000000000", zeroRight.fill(1, TAMANHO)); + assertEquals("000000000" + 1, zeroLeft.fill(1, TAMANHO)); + } + + @Test + public void testFillShort() { + + assertEquals((short) 1 + "000000000", zeroRight.fill((short) 1, + TAMANHO)); + assertEquals("000000000" + (short) 1, zeroLeft.fill((short) 1, + TAMANHO)); + } + + @Test + public void testFillByte() { + + assertEquals((byte) 1 + "000000000", zeroRight.fill((byte) 1, + TAMANHO)); + assertEquals("000000000" + (byte) 1, zeroLeft.fill((byte) 1, + TAMANHO)); + } + + @Test + public void testFillChar() { + + assertEquals('1' + "000000000", zeroRight.fill('1', TAMANHO)); + assertEquals("000000000" + '1', zeroLeft.fill('1', TAMANHO)); + } + + @Test + public void testFillDouble() { + + assertEquals(1.0 + "0000000", zeroRight.fill(1.0, TAMANHO)); + assertEquals("0000000" + 1.0, zeroLeft.fill(1.0, TAMANHO)); + } + + @Test + public void testFillFloat() { + + assertEquals(1.0f + "0000000", zeroRight.fill(1.0f, TAMANHO)); + assertEquals("0000000" + 1.0f, zeroLeft.fill(1.0f, TAMANHO)); + } + + @Test + public void testFillObject() { + + Object object = new Object() { + + @Override + public String toString() { + return CAMPO; + } + }; + + assertEquals(object + "00000", zeroRight.fill(object, TAMANHO)); + assertEquals("00000" + object, zeroLeft.fill(object, TAMANHO)); + } + + @Test + public void testFillITextStream() { + + TextStream textStream = new TextStream() { + + private static final long serialVersionUID = 1L; + + public void read(String g) { + } + + public String write() { + + return CAMPO; + } + }; + + assertEquals(textStream.write() + "00000", zeroRight.fill( + textStream, TAMANHO)); + assertEquals("00000" + textStream.write(), zeroLeft.fill( + textStream, TAMANHO)); + } + + @Test + public void testFill() { + + fillerString = new Filler("ABC", Side.LEFT); + assertTrue(fillerString.getPadding() instanceof String); + assertEquals("ABCAB" + CAMPO, fillerString.fill(CAMPO, TAMANHO)); + assertEquals(CAMPO, fillerString.fill(CAMPO, 0)); + assertEquals(CAMPO, fillerString.fill(CAMPO, -TAMANHO)); + + fillerString.setSideToFill(Side.RIGHT); + assertEquals(CAMPO + "ABCAB", fillerString.fill(CAMPO, TAMANHO)); + assertEquals(CAMPO, fillerString.fill(CAMPO, 0)); + assertEquals(CAMPO, fillerString.fill(CAMPO, -TAMANHO)); + + fillerInteger = new Filler(new Integer(TAMANHO), + Side.LEFT); + assertTrue(fillerInteger.getPadding() instanceof Integer); + assertEquals("10101" + CAMPO, fillerInteger.fill(CAMPO, TAMANHO)); + assertEquals(CAMPO, fillerInteger.fill(CAMPO, 0)); + assertEquals(CAMPO, fillerInteger.fill(CAMPO, -TAMANHO)); + + fillerInteger.setSideToFill(Side.RIGHT); + assertEquals(CAMPO + "10101", fillerInteger.fill(CAMPO, TAMANHO)); + assertEquals(CAMPO, fillerInteger.fill(CAMPO, 0)); + assertEquals(CAMPO, fillerInteger.fill(CAMPO, -TAMANHO)); + + fillerDouble = new Filler(new Double(10.9), Side.LEFT); + assertTrue(fillerDouble.getPadding() instanceof Double); + assertEquals("10.91" + CAMPO, fillerDouble.fill(CAMPO, TAMANHO)); + assertEquals(CAMPO, fillerDouble.fill(CAMPO, 0)); + assertEquals(CAMPO, fillerDouble.fill(CAMPO, -TAMANHO)); + + fillerDouble.setSideToFill(Side.RIGHT); + assertEquals(CAMPO + "10.91", fillerDouble.fill(CAMPO, TAMANHO)); + assertEquals(CAMPO, fillerDouble.fill(CAMPO, 0)); + assertEquals(CAMPO, fillerDouble.fill(CAMPO, -TAMANHO)); + + fillerSide = new Filler(Side.LEFT, Side.LEFT); + assertTrue(fillerSide.getPadding() instanceof Side); + assertEquals("LEFTL" + CAMPO, fillerSide.fill(CAMPO, TAMANHO)); + assertEquals(CAMPO, fillerSide.fill(CAMPO, 0)); + assertEquals(CAMPO, fillerSide.fill(CAMPO, -TAMANHO)); + + fillerSide.setSideToFill(Side.RIGHT); + assertEquals(CAMPO + "LEFTL", fillerSide.fill(CAMPO, TAMANHO)); + assertEquals(CAMPO, fillerSide.fill(CAMPO, 0)); + assertEquals(CAMPO, fillerSide.fill(CAMPO, -TAMANHO)); + } + +} diff --git a/src/test/java/org/jrimum/texgit/type/component/TestFixedField.java b/src/test/java/org/jrimum/texgit/type/component/TestFixedField.java new file mode 100644 index 0000000..fc24b3b --- /dev/null +++ b/src/test/java/org/jrimum/texgit/type/component/TestFixedField.java @@ -0,0 +1,228 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 30/03/2008 - 18:15:56 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 30/03/2008 - 18:15:56 + * + */ + +package org.jrimum.texgit.type.component; + +import static org.jrimum.utilix.text.DateFormat.DDMMYYYY_B; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.math.BigDecimal; +import java.text.DateFormat; +import java.text.Format; +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.apache.commons.lang.StringUtils; +import org.jrimum.utilix.Dates; +import org.jrimum.utilix.text.DecimalFormat; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + *

+ * Teste unitário para a classe utilitária de coleções. + *

+ * + * @author Gilmar P.S.L. + * @author Rômulo Augusto + * + * @since 0.2 + * + * @version 0.2 + */ +public class TestFixedField { + + private static final DateFormat FORMAT_DDMMYY = new SimpleDateFormat("ddMMyy"); + + private FixedField campoString; + + private FixedField campoInteger; + + private FixedField campoLong; + + private FixedField campoDate; + + private FixedField campoDecimal; + + private FixedField campoDecimal_v9; + + @Before + public void setUp() { + + campoString = new FixedField(StringUtils.EMPTY, 8, Fillers.WHITE_SPACE_RIGHT); + + campoDate = new FixedField(DDMMYYYY_B.parse("22/07/2007"), 6, FORMAT_DDMMYY); + + campoInteger = new FixedField(0, 6, Fillers.ZERO_LEFT); + + campoLong = new FixedField(0L, 6, Fillers.ZERO_LEFT); + + campoDecimal = new FixedField(new BigDecimal("875.98"), 11, DecimalFormat.NUMBER_DD_BR.copy(), Fillers.ZERO_LEFT); + + campoDecimal_v9 = new FixedField(new BigDecimal("875.9"), 10, DecimalFormat.NUMBER_D_BR.copy(), Fillers.ZERO_LEFT); + } + + @After + public void tearDown() { + + campoString = null; + campoDate = null; + campoInteger = null; + campoLong = null; + campoDecimal = null; + campoDecimal_v9 = null; + } + + @Test(expected = IllegalArgumentException.class) + public void testCampo() { + + Format format = null; + + campoDate = new FixedField(new Date(), 0, FORMAT_DDMMYY); + campoDate = new FixedField(null, 1, FORMAT_DDMMYY); + campoDate = new FixedField(new Date(), 0, format); + } + + @Test + public void testLer() { + + campoString.read("COBRANCA"); + assertNotNull(campoString.getValue()); + assertTrue(campoString.getValue() instanceof String); + assertEquals("COBRANCA", campoString.getValue().toString()); + + campoDate.read("011002"); + assertNotNull(campoDate.getValue()); + assertTrue(campoDate.getValue() instanceof Date); + assertEquals("011002", FORMAT_DDMMYY.format(campoDate + .getValue())); + + campoInteger.read("000001"); + assertNotNull(campoInteger.getValue()); + assertTrue(campoInteger.getValue() instanceof Integer); + assertTrue(new Integer(1).compareTo(campoInteger.getValue()) == 0); + + campoLong.read("000001"); + assertNotNull(campoLong.getValue()); + assertTrue(campoLong.getValue() instanceof Long); + assertTrue(new Long(1L).compareTo(campoLong.getValue()) == 0); + + campoDecimal.read("00000087598"); + assertNotNull(campoDecimal.getValue()); + assertTrue(campoDecimal.getValue() instanceof BigDecimal); + assertTrue(new BigDecimal("875.98").compareTo(campoDecimal.getValue()) == 0); + + campoDecimal_v9.read("0000008759"); + assertNotNull(campoDecimal_v9.getValue()); + assertTrue(campoDecimal_v9.getValue() instanceof BigDecimal); + assertTrue(new BigDecimal("875.9").compareTo(campoDecimal_v9 + .getValue()) == 0); + } + + @Test(expected = IllegalArgumentException.class) + public void testLerException() { + + campoString.read(null); + campoDate.read(null); + campoDate.read(""); + campoDate.read("abcd"); + campoDate.read("1a2MA1205"); + } + + @Test + public void testEscrever() { + + assertNotNull(campoString.write()); + assertEquals(" ", campoString.write()); + assertEquals(8, campoString.write().length()); + + assertNotNull(campoDate.write()); + assertEquals("220707", campoDate.write()); + assertEquals(6, campoDate.write().length()); + + campoDate.setValue(Dates.invalidDate()); + campoDate.setFiller(Fillers.ZERO_LEFT); + assertNotNull(campoDate.write()); + assertEquals("000000", campoDate.write()); + assertEquals(6, campoDate.write().length()); + + assertNotNull(campoInteger.write()); + assertEquals("000000", campoInteger.write()); + assertEquals(6, campoInteger.write().length()); + + assertNotNull(campoLong.write()); + assertEquals("000000", campoLong.write()); + assertEquals(6, campoLong.write().length()); + + assertNotNull(campoDecimal.write()); + assertEquals("00000087598", campoDecimal.write()); + assertEquals(11, campoDecimal.write().length()); + + assertNotNull(campoDecimal_v9.write()); + assertEquals("0000008759", campoDecimal_v9.write()); + assertEquals(10, campoDecimal_v9.write().length()); + } + + @Test(expected = IllegalStateException.class) + public void testEscreverException() { + + FixedField campo = new FixedField("tamanho", 5); + assertEquals(5, campo.write().length()); + + FixedField campo1 = new FixedField(1234, 3); + assertEquals(3, campo1.write().length()); + + FixedField campo2 = new FixedField(12, 3); + assertEquals(3, campo2.write().length()); + } + + @Test(expected = IllegalArgumentException.class) + public void testSetCampo() { + campoInteger.setValue(null); + } + + @Test(expected = IllegalArgumentException.class) + public void testSetTamanhoZero() { + campoString.setFixedLength(0); + } + + @Test(expected = IllegalArgumentException.class) + public void testSetTamanhoNegativo() { + campoString.setFixedLength(-1); + } + + @Test(expected = IllegalArgumentException.class) + public void testSetFiller() { + campoString.setFiller(null); + } + +} diff --git a/src/test/java/org/jrimum/utilix/excludes/TestUtil.java b/src/test/java/org/jrimum/utilix/excludes/TestUtil.java new file mode 100644 index 0000000..141502d --- /dev/null +++ b/src/test/java/org/jrimum/utilix/excludes/TestUtil.java @@ -0,0 +1,80 @@ +/* + * Copyright 2008 JRimum Project + * + * 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. + * + * Created at: 30/03/2008 - 18:15:56 + * + * ================================================================================ + * + * Direitos autorais 2008 JRimum Project + * + * Licenciado sob a Licença Apache, Versão 2.0 ("LICENÇA"); você não pode usar + * esse arquivo exceto em conformidade com a esta LICENÇA. Você pode obter uma + * cópia desta LICENÇA em http://www.apache.org/licenses/LICENSE-2.0 A menos que + * haja exigência legal ou acordo por escrito, a distribuição de software sob + * esta LICENÇA se dará “COMO ESTÁ”, SEM GARANTIAS OU CONDIÇÕES DE QUALQUER + * TIPO, sejam expressas ou tácitas. Veja a LICENÇA para a redação específica a + * reger permissões e limitações sob esta LICENÇA. + * + * Criado em: 30/03/2008 - 18:15:56 + * + */ +package org.jrimum.utilix.excludes; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.Date; + +import org.jrimum.texgit.type.FixedField; +import org.jrimum.texgit.type.component.Field; + +/** + *

+ * Classe para uso em testes com Fields. + *

+ * + * @author Gilmar P.S.L. + * + * @since 0.2 + * + * @version 0.2 + */ +public class TestUtil { + + public static void testEscritaCampo(FixedField campo, Class tipo, + G valorDeEntrada, String strEsperada, int tamanho) { + + // >>> + assertNotNull(campo); + assertTrue(tipo.isInstance(campo.getValue())); + assertEquals(valorDeEntrada, campo.getValue()); + assertNotNull(campo.write()); + assertEquals(strEsperada, campo.write()); + assertTrue(tamanho == campo.getFixedLength()); + assertTrue(tamanho == campo.write().length()); + } + + public static void testLeituraCampo(Field campo, Class tipo, + G valorEsperado, String strDeEntrada) { + + // <<< + campo.read(strDeEntrada); + assertTrue(tipo.isInstance(campo.getValue())); + + if (campo.getValue() instanceof Date)// compareNoFormatoEscrito + assertEquals(campo.getFormatter().format(valorEsperado), campo.write()); + else + assertEquals(valorEsperado, campo.getValue()); + + } + +}