diff --git a/pom.xml b/pom.xml
index 6a10a82..e190088 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,85 +1,112 @@
-
- 4.0.0
-
- cb2java
- net.sf.cb2java
- cb2java
- 5.3
- https://github.com/devstopfix/cb2java
+ 4.0.0
- Library that allows dynamic access to Copybook structures at run-time from a Java application
+ cb2java
+ net.sf.cb2java
+ cb2java
+ 5.3
+ https://github.com/montoyaedu/cb2java
-
-
- dubwai
- http://sourceforge.net/users/dubwai
-
- developer
-
-
-
- ptrthomas
- Peter Thomas
- http://ptrthomas.users.sourceforge.net/
-
- developer
-
-
-
- montoyaedu
- H. Eduardo Montoya Sánchez
- https://github.com/montoyaedu
-
-
+ Library that allows dynamic access to Copybook structures at run-time from a Java application
-
-
- GNU GENERAL PUBLIC LICENSE Version 1, February 1989
- http://www.gnu.org/licenses/gpl-1.0.txt
- See ./LICENSE
-
-
+
+
+ dubwai
+ http://sourceforge.net/users/dubwai
+
+ developer
+
+
+
+ ptrthomas
+ Peter Thomas
+ http://ptrthomas.users.sourceforge.net/
+
+ developer
+
+
+
+ montoyaedu
+ H. Eduardo Montoya Sánchez
+ https://github.com/montoyaedu
+
+ developer
+
+
+
-
- https://github.com/devstopfix/cb2java
- scm:git:git://github.com/devstopfix/cb2java.git
-
+
+
+ GNU GENERAL PUBLIC LICENSE Version 1, February 1989
+ http://www.gnu.org/licenses/gpl-1.0.txt
+ See ./LICENSE
+
+
-
-
-
-
- src/main/java
-
- **/lexer.dat
- **/parser.dat
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 2.3.2
-
- 1.6
- 1.6
-
-
-
-
+
+ https://github.com/montoyaedu/cb2java
+ scm:git:git://github.com/montoyaedu/cb2java.git
+
-
-
- junit
- junit
- 3.8.1
- test
-
-
+
+
+
+
+ src/main/java
+
+ **/lexer.dat
+ **/parser.dat
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.3.2
+
+ 1.6
+ 1.6
+
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 2.2.1
+
+
+ attach-sources
+ package
+
+ jar
+
+
+
+
+
+
+
+
+
+
+ junit
+ junit
+ 3.8.1
+ test
+
+
+
+ org.slf4j
+ slf4j-api
+ 1.7.6
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/net/sf/cb2java/Settings.java b/src/main/java/net/sf/cb2java/Settings.java
index c678b01..fd665db 100644
--- a/src/main/java/net/sf/cb2java/Settings.java
+++ b/src/main/java/net/sf/cb2java/Settings.java
@@ -1,110 +1,107 @@
-/**
- * cb2java - Dynamic COBOL copybook parser for Java.
- * Copyright (C) 2006 James Watson
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 1, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package net.sf.cb2java;
-
-import java.util.Properties;
-import net.sf.cb2java.types.Numeric;
-import net.sf.cb2java.types.Numeric.Position;
-
-public interface Settings
-{
- public static Settings DEFAULT = new Default();
-
- String getEncoding();
-
- Values getValues();
-
- boolean getLittleEndian();
-
- String getFloatConversion();
-
- Numeric.Position getSignPosition();
-
- public static class Default implements Settings
- {
- private static final String DEFAULT_ENCODING;
- private static final boolean DEFAULT_LITTLE_ENDIAN;
- private static final String DEFAULT_FLOAT_CONVERSION;
- private static final Numeric.Position DEFAULT_DEFAULT_SIGN_POSITION;
- private static final Values DEFAULT_VALUES = new Values();
-
- static {
- Properties props = new Properties();
-
- try {
- props.load(ClassLoader.getSystemResourceAsStream("copybook.props"));
- } catch (Exception e) {
- // TODO logging
- }
-
- DEFAULT_ENCODING = getSetting("encoding", System.getProperty("file.encoding"), props);
- DEFAULT_LITTLE_ENDIAN = "false".equals(getSetting("little-endian", "false", props));
- DEFAULT_FLOAT_CONVERSION = getSetting("float-conversion",
- "net.sf.cb2java.copybook.floating.IEEE754", props);
- DEFAULT_DEFAULT_SIGN_POSITION = "leading".equalsIgnoreCase(
- getSetting("default-sign-position", "trailing", props)) ? Numeric.LEADING : Numeric.TRAILING;
- }
-
- private static String getSetting(String name, String defaultValue, Properties props)
- {
- try {
- String value = System.getProperty("cb2java." + name, defaultValue);
-
- try {
- try {
- value = props.getProperty("encoding", value);
- } catch (Exception e) {
- // TODO logging
- }
- } catch (Exception e) {
- // TODO logging
- }
-
- return value;
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
- public String getEncoding()
- {
- return DEFAULT_ENCODING;
- }
-
- public String getFloatConversion()
- {
- return DEFAULT_FLOAT_CONVERSION;
- }
-
- public boolean getLittleEndian()
- {
- return DEFAULT_LITTLE_ENDIAN;
- }
-
- public Values getValues()
- {
- return DEFAULT_VALUES;
- }
-
- public Position getSignPosition()
- {
- return DEFAULT_DEFAULT_SIGN_POSITION;
- }
- }
-}
+/**
+ * cb2java - Dynamic COBOL copybook parser for Java.
+ * Copyright (C) 2006 James Watson
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 1, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package net.sf.cb2java;
+
+import java.util.Properties;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import net.sf.cb2java.types.Numeric;
+import net.sf.cb2java.types.Numeric.Position;
+
+public interface Settings
+{
+ public static Settings DEFAULT = new Default();
+
+
+ String getEncoding();
+
+ Values getValues();
+
+ boolean getLittleEndian();
+
+ String getFloatConversion();
+
+ Numeric.Position getSignPosition();
+
+ public static class Default implements Settings
+ {
+ private static final Logger LOGGER = LoggerFactory.getLogger(Settings.class);
+
+ private static final String DEFAULT_ENCODING;
+ private static final boolean DEFAULT_LITTLE_ENDIAN;
+ private static final String DEFAULT_FLOAT_CONVERSION;
+ private static final Numeric.Position DEFAULT_DEFAULT_SIGN_POSITION;
+ private static final Values DEFAULT_VALUES = new Values();
+
+ static {
+ Properties props = new Properties();
+
+ try {
+ props.load(Settings.class.getResourceAsStream("/copybook.props"));
+ } catch (Exception e) {
+ LOGGER.warn("Could not load 'copybook.props' file, reverting to defaults.", e.getMessage());
+ }
+
+ DEFAULT_ENCODING = getSetting("encoding", System.getProperty("file.encoding"), props);
+ DEFAULT_LITTLE_ENDIAN = "false".equals(getSetting("little-endian", "false", props));
+ DEFAULT_FLOAT_CONVERSION = getSetting("float-conversion",
+ "net.sf.cb2java.copybook.floating.IEEE754", props);
+ DEFAULT_DEFAULT_SIGN_POSITION = "leading".equalsIgnoreCase(
+ getSetting("default-sign-position", "trailing", props)) ? Numeric.LEADING : Numeric.TRAILING;
+ }
+
+ private static String getSetting(String name, String defaultValue, Properties props)
+ {
+ try {
+ String value = System.getProperty("cb2java." + name, defaultValue);
+ value = props.getProperty(name, value);
+ return value;
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+ public String getEncoding()
+ {
+ return DEFAULT_ENCODING;
+ }
+
+ public String getFloatConversion()
+ {
+ return DEFAULT_FLOAT_CONVERSION;
+ }
+
+ public boolean getLittleEndian()
+ {
+ return DEFAULT_LITTLE_ENDIAN;
+ }
+
+ public Values getValues()
+ {
+ return DEFAULT_VALUES;
+ }
+
+ public Position getSignPosition()
+ {
+ return DEFAULT_DEFAULT_SIGN_POSITION;
+ }
+ }
+}
diff --git a/src/main/java/net/sf/cb2java/Value.java b/src/main/java/net/sf/cb2java/Value.java
index ab97b8b..99638c3 100644
--- a/src/main/java/net/sf/cb2java/Value.java
+++ b/src/main/java/net/sf/cb2java/Value.java
@@ -28,16 +28,17 @@ public abstract class Value
public static final Side LEFT = new Side();
public static final Side RIGHT = new Side();
- private final String encoding;
+ private final Values values;
- public Value(String encoding)
+ public Value(Values values)
{
- this.encoding = encoding;
+ this.values = values;
}
public String getEncoding()
{
- return encoding;
+ String valueEncoding = values.getEncoding();
+ return valueEncoding == null ? Settings.DEFAULT.getEncoding(): valueEncoding;
}
public byte[] get(int length)
diff --git a/src/main/java/net/sf/cb2java/Values.java b/src/main/java/net/sf/cb2java/Values.java
index 742402d..3311adf 100644
--- a/src/main/java/net/sf/cb2java/Values.java
+++ b/src/main/java/net/sf/cb2java/Values.java
@@ -22,7 +22,7 @@
public class Values
{
- protected String encoding;
+ private String encoding;
public Values()
{
@@ -41,13 +41,17 @@ public void setEncoding(String encoding)
}
}
+ protected String getEncoding() {
+ return encoding;
+ }
+
public class Literal extends Value
{
private final String value;
public Literal(final String value)
{
- super(encoding);
+ super(Values.this);
this.value = value;
}
@@ -73,7 +77,7 @@ private class StringBasedValue extends Value
{
public StringBasedValue(Values parent)
{
- super(encoding);
+ super(Values.this);
}
byte bite;
@@ -86,7 +90,7 @@ public byte getByte()
public final Value SPACES = new StringBasedValue(Values.this);
- public final Value LOW_VALUES = new Value(encoding) {
+ public final Value LOW_VALUES = new Value(Values.this) {
public byte getByte()
{
@@ -94,7 +98,7 @@ public byte getByte()
}
};
- public final Value HIGH_VALUES = new Value(encoding) {
+ public final Value HIGH_VALUES = new Value(Values.this) {
public byte getByte()
{
diff --git a/src/main/java/net/sf/cb2java/copybook/Copybook.java b/src/main/java/net/sf/cb2java/copybook/Copybook.java
index 67f0b71..70c0d6d 100644
--- a/src/main/java/net/sf/cb2java/copybook/Copybook.java
+++ b/src/main/java/net/sf/cb2java/copybook/Copybook.java
@@ -48,7 +48,7 @@ public class Copybook extends Group implements Settings
private String floatConversion = Settings.DEFAULT.getFloatConversion();
private Numeric.Position signPosition = Settings.DEFAULT.getSignPosition();
- private Map redefines = new HashMap();
+ private Map redefines = new HashMap();
private final Values values;
diff --git a/src/main/java/net/sf/cb2java/copybook/CopybookAnalyzer.java b/src/main/java/net/sf/cb2java/copybook/CopybookAnalyzer.java
index 25ac92e..ce088f1 100644
--- a/src/main/java/net/sf/cb2java/copybook/CopybookAnalyzer.java
+++ b/src/main/java/net/sf/cb2java/copybook/CopybookAnalyzer.java
@@ -1,25 +1,27 @@
/**
- * cb2java - Dynamic COBOL copybook parser for Java. Copyright (C) 2006 James
- * Watson
+ * cb2java - Dynamic COBOL copybook parser for Java.
+ * Copyright (C) 2006 James Watson
*
- * This program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 1, or (at your option) any later version.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 1, or (at your option)
+ * any later version.
*
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 675 Mass
- * Ave, Cambridge, MA 02139, USA.
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package net.sf.cb2java.copybook;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
+
import net.sf.cb2java.Values;
import net.sf.cb2java.types.Element;
import net.sf.cb2java.types.Group;
@@ -68,320 +70,308 @@
import net.sf.cb2xml.sablecc.parser.Parser;
/**
- * This class handles the hard part of the parsing work. It captures all the
- * parsing events of the sablecc parsing classes and marks up Item instances for
- * each field definition
- *
+ * This class handles the hard part of the parsing work.
+ * It captures all the parsing events of the sablecc
+ * parsing classes and marks up Item instances for each
+ * field definition
+ *
* @author James Watson (adapted from Cb2XML project)
*/
-class CopybookAnalyzer extends DepthFirstAdapter {
-
- Values values = new Values();
+class CopybookAnalyzer extends DepthFirstAdapter
+{
+ final Values values = new Values();
+
private Parser parser;
private Item document;
private Item current;
-
+
/**
- * Creates a new instance with the given parser and name
- *
+ * Creates a new instance with the given parser and
+ * name
+ *
* @param copyBookName the name to give this copybook
- * @param parser sablecc parser instance
+ * @param parser sablecc parser instance
*/
- CopybookAnalyzer(String copyBookName, Parser parser) {
+ CopybookAnalyzer(String copyBookName, Parser parser)
+ {
document = new Item(values, true);
document.name = copyBookName;
current = document;
- this.parser = parser;
- }
-
- /**
+ this.parser = parser;
+ }
+
+ /**
* getter for XML document
- */
- public Copybook getDocument() {
- return (Copybook) document.getElement();
- }
+ */
+ public Copybook getDocument()
+ {
+ return (Copybook) document.getElement();
+ }
- /**
+ /**
* enter copybook, set up XML DOM and root element
- */
- @Override
- public void inARecordDescription(ARecordDescription node) {
+ */
+ public void inARecordDescription(ARecordDescription node)
+ {
// TODO begin
- }
-
- /**
- * exit root element, save XML as file
+ }
+
+ /**
+ * exit root element, save XML as file
*/
- @Override
- public void outARecordDescription(ARecordDescription node) {
+ public void outARecordDescription(ARecordDescription node)
+ {
// TODO end
walkTree(document);
- }
+ }
- private void walkTree(Item item) {
+ private void walkTree(Item item)
+ {
item.getElement().setSettings((Copybook) document.getElement());
-
- for (Iterator i = item.children.iterator(); i.hasNext();) {
+
+ for (Iterator> i = item.children.iterator(); i.hasNext();) {
Item child = (Item) i.next();
-
+
if (child.redefines != null) {
((Copybook) document.getElement()).redefine(child.redefines, child.getElement());
} else {
((Group) item.getElement()).addChild(child.getElement());
}
-
+
walkTree(child);
}
}
-
+
/**
* check for comments before these Tokens and add to XML
*/
- @Override
- public void caseTNumberNot88(TNumberNot88 node) {
- checkForComments(node);
- }
-
- @Override
- public void caseTNumber88(TNumber88 node) {
- checkForComments(node);
- }
-
- public void checkForComments(Token node) {
- List list = (List) parser.ignoredTokens.getIn(node);
- if (list != null) {
- Iterator i = list.iterator();
- while (i.hasNext()) {
- String s = i.next().toString().trim();
- if (s.length() > 1) {
+ public void caseTNumberNot88(TNumberNot88 node)
+ {
+ checkForComments(node);
+ }
+
+ public void caseTNumber88(TNumber88 node)
+ {
+ checkForComments(node);
+ }
+
+ public void checkForComments(Token node)
+ {
+ List> list = (List>) parser.ignoredTokens.getIn(node);
+ if (list != null) {
+ Iterator> i = list.iterator();
+ while (i.hasNext()) {
+ String s = i.next().toString().trim();
+ if (s.length() > 1) {
// TODO
- }
- }
- }
- }
+ }
+ }
+ }
+ }
/**
- * main elementary item enter item, set up Item object
- */
- @Override
- public void inAItem(AItem node) {
+ * main elementary item
+ * enter item, set up Item object
+ */
+ public void inAItem(AItem node)
+ {
Item prevItem = current;
current = new Item(values, false);
current.level = Integer.parseInt(node.getNumberNot88().toString().trim());
current.name = node.getDataNameOrFiller().toString().trim();
-
- if (current.level <= 77) {
+
+ if (current.level <= 77) {
current.setParent(prevItem);
- }
- }
-
+ }
+ }
+
/**
* end of parsing the element?
*/
- @Override
- public void outAItem(AItem node) {
+ public void outAItem(AItem node)
+ {
current.createElement();
}
+
+ public void inARedefinesClause(ARedefinesClause node)
+ {
+ String dataName = node.getDataName().getText();
+ current.redefines = dataName;
+ }
- @Override
- public void inARedefinesClause(ARedefinesClause node) {
- String dataName = node.getDataName().getText();
- current.redefines = dataName;
- }
-
- @Override
- public void inAFixedOccursFixedOrVariable(AFixedOccursFixedOrVariable node) {
- current.occurs = Integer.parseInt(node.getNumber().toString().trim());
- }
+ public void inAFixedOccursFixedOrVariable(AFixedOccursFixedOrVariable node)
+ {
+ current.occurs = Integer.parseInt(node.getNumber().toString().trim());
+ }
- @Override
- public void inAVariableOccursFixedOrVariable(AVariableOccursFixedOrVariable node) {
+ public void inAVariableOccursFixedOrVariable(AVariableOccursFixedOrVariable node)
+ {
current.occurs = Integer.parseInt(node.getNumber().toString().trim());
current.dependsOn = node.getDataName().getText();
- }
+ }
- @Override
- public void inAOccursTo(AOccursTo node) {
- current.minOccurs = Integer.parseInt(node.getNumber().toString().trim());
- }
+ public void inAOccursTo(AOccursTo node)
+ {
+ current.minOccurs = Integer.parseInt(node.getNumber().toString().trim());
+ }
- @Override
- public void inAPictureClause(APictureClause node) {
+ public void inAPictureClause(APictureClause node)
+ {
current.picture = removeChars(node.getCharacterString()
- .toString().toUpperCase(), " ");
-
+ .toString().toUpperCase(), " ");
+
for (int i = 0; i < current.picture.length(); i++) {
char c = current.picture.charAt(i);
switch (c) {
- case 'A': /* alpha */
- case 'B': /* space */
- case 'X': /* number or alpha */
- case '/': /* '/' */
- case ',': /* ',' */
- current.isAlpha = true;
- break;
- case 'N': /* national */
- throw new IllegalArgumentException("national data not yet supported");
- case 'E': /* exponent */
- throw new IllegalArgumentException("E in picture String not yet supported");
- case 'G': /* ??? */
- throw new IllegalArgumentException("G in picture String not yet supported");
- case 'P': //decimal position?
- throw new IllegalArgumentException("P in picture String not yet supported");
- case 'C': /* CR - credit */
- case 'D': /* DR - debit */
- /* skip R */
- i++;
- case '.': /* decimal position */
- case 'V': /* decimal position */
- case '$': /* '$' */
- case 'Z':
- case '9':
- case '0':
- case '+':
- case '-':
- case '*':
- break;
+ case 'A': /* alpha */
+ case 'B': /* space */
+ case 'X': /* number or alpha */
+ case '/': /* '/' */
+ case ',': /* ',' */
+ current.isAlpha = true;
+ break;
+ case 'N': /* national */
+ throw new IllegalArgumentException("national data not yet supported");
+ case 'E': /* exponent */
+ throw new IllegalArgumentException("E in picture String not yet supported");
+ case 'G': /* ??? */
+ throw new IllegalArgumentException("G in picture String not yet supported");
+ case 'P': //decimal position?
+ throw new IllegalArgumentException("P in picture String not yet supported");
+ case 'C': /* CR - credit */
+ case 'D': /* DR - debit */
+ /* skip R */
+ i++;
+ case '.': /* decimal position */
+ case 'V': /* decimal position */
+ case '$': /* '$' */
+ case 'Z':
+ case '9':
+ case '0':
+ case '+':
+ case '-':
+ case '*':
+ break;
}
}
}
+
+ public void inASignClause(ASignClause node)
+ {
+ if (node.getSeparateCharacter() != null) {
+ current.signSeparate = true;
+ }
+ }
- @Override
- public void inASignClause(ASignClause node) {
- if (node.getSeparateCharacter() != null) {
- current.signSeparate = true;
- }
- }
-
- @Override
- public void inALeadingLeadingOrTrailing(ALeadingLeadingOrTrailing node) {
+ public void inALeadingLeadingOrTrailing(ALeadingLeadingOrTrailing node)
+ {
current.signPosition = SignedSeparate.LEADING;
}
- public void inATrailimngLeadingOrTrailing(ALeadingLeadingOrTrailing node) {
+ public void inATrailimngLeadingOrTrailing(ALeadingLeadingOrTrailing node)
+ {
current.signPosition = SignedSeparate.TRAILING;
}
- //======================= USAGE CLAUSE ==========================
- @Override
- public void inABinaryUsagePhrase(ABinaryUsagePhrase node) {
+ //======================= USAGE CLAUSE ==========================
+
+ public void inABinaryUsagePhrase(ABinaryUsagePhrase node) {
current.usage = Usage.BINARY;
- }
+ }
- @Override
- public void inACompUsagePhrase(ACompUsagePhrase node) {
+ public void inACompUsagePhrase(ACompUsagePhrase node) {
current.usage = Usage.COMPUTATIONAL;
- }
+ }
- @Override
- public void inAComp1UsagePhrase(AComp1UsagePhrase node) {
+ public void inAComp1UsagePhrase(AComp1UsagePhrase node) {
current.usage = Usage.COMPUTATIONAL_1;
- }
+ }
- @Override
- public void inAComp2UsagePhrase(AComp2UsagePhrase node) {
+ public void inAComp2UsagePhrase(AComp2UsagePhrase node) {
current.usage = Usage.COMPUTATIONAL_2;
- }
+ }
- @Override
- public void inAComp3UsagePhrase(AComp3UsagePhrase node) {
+ public void inAComp3UsagePhrase(AComp3UsagePhrase node) {
current.usage = Usage.COMPUTATIONAL_3;
- }
+ }
- @Override
- public void inAComp4UsagePhrase(AComp4UsagePhrase node) {
+ public void inAComp4UsagePhrase(AComp4UsagePhrase node) {
current.usage = Usage.COMPUTATIONAL_4;
- }
-
- @Override
- public void inAComp5UsagePhrase(AComp5UsagePhrase node) {
+ }
+
+ public void inAComp5UsagePhrase(AComp5UsagePhrase node) {
current.usage = Usage.COMPUTATIONAL_5;
- }
+ }
- @Override
- public void inADisplay1UsagePhrase(ADisplay1UsagePhrase node) {
+ public void inADisplay1UsagePhrase(ADisplay1UsagePhrase node) {
throw new IllegalArgumentException("display-1");
- }
+ }
- @Override
- public void inAIndexUsagePhrase(AIndexUsagePhrase node) {
+ public void inAIndexUsagePhrase(AIndexUsagePhrase node) {
throw new IllegalArgumentException("index");
- }
+ }
- @Override
- public void inANationalUsagePhrase(ANationalUsagePhrase node) {
+ public void inANationalUsagePhrase(ANationalUsagePhrase node) {
throw new IllegalArgumentException("national");
- }
+ }
- @Override
- public void inAObjectReferencePhrase(AObjectReferencePhrase node) {
+ public void inAObjectReferencePhrase(AObjectReferencePhrase node) {
throw new IllegalArgumentException("object-reference");//, node.getDataName().getText());
- }
-
- @Override
- public void inAPackedDecimalUsagePhrase(APackedDecimalUsagePhrase node) {
+ }
+
+ public void inAPackedDecimalUsagePhrase(APackedDecimalUsagePhrase node) {
current.usage = Usage.PACKED_DECIMAL;
- }
+ }
- @Override
- public void inAPointerUsagePhrase(APointerUsagePhrase node) {
+ public void inAPointerUsagePhrase(APointerUsagePhrase node) {
throw new IllegalArgumentException("pointer");
- }
+ }
- @Override
- public void inAProcedurePointerUsagePhrase(AProcedurePointerUsagePhrase node) {
+ public void inAProcedurePointerUsagePhrase(AProcedurePointerUsagePhrase node) {
throw new IllegalArgumentException("procedure-pointer");
- }
-
- @Override
- public void inAFunctionPointerUsagePhrase(AFunctionPointerUsagePhrase node) {
+ }
+
+ public void inAFunctionPointerUsagePhrase(AFunctionPointerUsagePhrase node) {
throw new IllegalArgumentException("function-pointer");
- }
-
- // ======================= 88 / VALUE CLAUSE ==========================
- @Override
- public void caseTZeros(TZeros node) {
- current.value = values.ZEROS;
- }
-
- @Override
- public void caseTSpaces(TSpaces node) {
+ }
+
+ // ======================= 88 / VALUE CLAUSE ==========================
+
+ public void caseTZeros(TZeros node) {
+ current.value = values.ZEROS;
+ }
+
+ public void caseTSpaces(TSpaces node) {
current.value = values.SPACES;
- }
-
- @Override
- public void caseTHighValues(THighValues node) {
+ }
+
+ public void caseTHighValues(THighValues node) {
current.value = values.HIGH_VALUES;
- }
-
- @Override
- public void caseTLowValues(TLowValues node) {
+ }
+
+ public void caseTLowValues(TLowValues node) {
current.value = values.LOW_VALUES;
- }
-
- @Override
- public void caseTQuotes(TQuotes node) {
+ }
+
+ public void caseTQuotes(TQuotes node) {
current.value = values.QUOTES;
- }
-
- @Override
- public void caseTNulls(TNulls node) {
+ }
+
+ public void caseTNulls(TNulls node) {
current.value = values.NULLS;
- }
-
- @Override
- public void caseTAlphanumericLiteral(TAlphanumericLiteral node) {
+ }
+
+ public void caseTAlphanumericLiteral(TAlphanumericLiteral node)
+ {
current.value = values.new Literal(node.getText());
- }
-
- @Override
- public void outAValueClause(AValueClause node) {
- current.value = values.new Literal(node.getLiteral().toString().trim());
- }
-
- // 88 LEVEL CONDITION NODE
- @Override
- public void inAValueItem(AValueItem node) {
+ }
+
+ public void outAValueClause(AValueClause node) {
+ current.value = values.new Literal(node.getLiteral().toString().trim());
+ }
+
+ // 88 LEVEL CONDITION NODE
+ public void inAValueItem(AValueItem node) {
// String name = node.getDataName().getText();
// curItem = new Item();
// curItem.element = document.createElement("condition");
@@ -389,10 +379,9 @@ public void inAValueItem(AValueItem node) {
// curItem.element.setAttribute("name", name);
// prevItem.element.appendChild(curItem.element);
throw new IllegalArgumentException("'a value item' not yet supported");
- }
-
- @Override
- public void outASingleLiteralSequence(ASingleLiteralSequence node) {
+ }
+
+ public void outASingleLiteralSequence(ASingleLiteralSequence node) {
// if (node.getAll() != null) {
// curItem.element.setAttribute("all", "true");
// }
@@ -400,61 +389,61 @@ public void outASingleLiteralSequence(ASingleLiteralSequence node) {
// element.setAttribute("value", node.getLiteral().toString().trim());
// curItem.element.appendChild(element);
throw new IllegalArgumentException("'a single literal sequence' not yet supported");
- }
-
- @Override
- public void outASequenceLiteralSequence(ASequenceLiteralSequence node) {
+ }
+
+ public void outASequenceLiteralSequence(ASequenceLiteralSequence node) {
// Element element = document.createElement("condition");
// element.setAttribute("value", node.getLiteral().toString().trim());
// curItem.element.appendChild(element);
throw new IllegalArgumentException("'a sequence literal sequence' not yet supported");
- }
+ }
- @Override
- public void outAThroughSingleLiteralSequence(AThroughSingleLiteralSequence node) {
+ public void outAThroughSingleLiteralSequence(AThroughSingleLiteralSequence node) {
// Element element = document.createElement("condition");
// element.setAttribute("value", node.getFrom().toString().trim());
// element.setAttribute("through", node.getTo().toString().trim());
// curItem.element.appendChild(element);
throw new IllegalArgumentException("'a through single literal sequence' not yet supported");
- }
+ }
- @Override
- public void outAThroughSequenceLiteralSequence(AThroughSequenceLiteralSequence node) {
+ public void outAThroughSequenceLiteralSequence(AThroughSequenceLiteralSequence node) {
// Element element = document.createElement("condition");
// element.setAttribute("value", node.getFrom().toString().trim());
// element.setAttribute("through", node.getTo().toString().trim());
// curItem.element.appendChild(element);
throw new IllegalArgumentException("'a through sequence literal sequence' not yet supported");
- }
-
- //===============================================================================
- private String removeChars(String s, String charToRemove) {
- StringTokenizer st = new StringTokenizer(s, charToRemove, false);
- StringBuffer b = new StringBuffer();
- while (st.hasMoreElements()) {
- b.append(st.nextElement());
- }
- return b.toString();
- }
-
- /**
- * This is for DOM post-processing of the XML before saving to resolve the
- * field lengths of each node and also calculate the start position of the
- * data field in the raw copybook buffer (mainframe equivalent) recursive
- * traversal. note that REDEFINES declarations are taken care of as well as
- * the OCCURS declarations
- */
- int getPosition(String name) {
- List children = document.getElement().getChildren();
-
- for (Iterator i = children.iterator(); i.hasNext();) {
+ }
+
+ //===============================================================================
+
+ private String removeChars(String s, String charToRemove) {
+ StringTokenizer st = new StringTokenizer(s, charToRemove, false);
+ StringBuffer b = new StringBuffer();
+ while (st.hasMoreElements()) {
+ b.append(st.nextElement());
+ }
+ return b.toString();
+ }
+
+ /**
+ * This is for DOM post-processing of the XML before saving to resolve the field lengths
+ * of each node and also calculate the start position of the data field in the
+ * raw copybook buffer (mainframe equivalent)
+ * recursive traversal. note that REDEFINES declarations are taken care of
+ * as well as the OCCURS declarations
+ */
+
+ int getPosition(String name)
+ {
+ List children = document.getElement().getChildren();
+
+ for (Iterator i = children.iterator(); i.hasNext();) {
Element testElement = (Element) i.next();
if (testElement.getName().equals(name)) {
return testElement.getPosition();
}
}
-
+
throw new IllegalArgumentException("no element named '" + name + "'");
}
}
\ No newline at end of file
diff --git a/src/main/java/net/sf/cb2java/copybook/Copybooks.java b/src/main/java/net/sf/cb2java/copybook/Copybooks.java
index 9e9467b..00c12fb 100644
--- a/src/main/java/net/sf/cb2java/copybook/Copybooks.java
+++ b/src/main/java/net/sf/cb2java/copybook/Copybooks.java
@@ -1,41 +1,51 @@
-package net.sf.cb2java.copybook;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-
-/**
- * A map of named Copybook definitions.
- *
- * @author
- */
-public class Copybooks {
-
- public static Map readCopybooks(List files) throws FileNotFoundException {
- return readCopybooks(files.toArray(new File[] {}));
- }
-
- public static Map readCopybooks(File[] files) throws FileNotFoundException {
- Map copybooks = new TreeMap();
- for(File f:files) {
- String copybookName = copybookNameOfFile(f);
- try {
- copybooks.put(copybookName, CopybookParser.parse(copybookName, new FileInputStream(f)));
- } catch (RuntimeException e) {
- throw new RuntimeException(String.format("Cannot parse copybook structure in file '%s'", f.getName()), e);
- }
- }
- return copybooks;
- }
-
- public static String copybookNameOfFile(File f) {
- if (f.getName().contains("."))
- return f.getName().toLowerCase().split("\\.")[0];
- else
- return f.getName().toLowerCase();
- }
-
-}
+package net.sf.cb2java.copybook;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * A map of named Copybook definitions.
+ *
+ * @author
+ */
+public class Copybooks {
+
+ public static Map readCopybooks(List files) throws FileNotFoundException {
+ return readCopybooks(files.toArray(new File[] {}));
+ }
+
+ /*
+ * Make a map of copybook name (the lowercase filename without extension)
+ * to Copybook instance for each given file.
+ */
+ public static Map readCopybooks(File[] files) throws FileNotFoundException {
+ Map copybooks = new TreeMap();
+ for(File f:files) {
+ String copybookName = copybookNameOfFile(f);
+ FileInputStream fin = new FileInputStream(f);
+ try {
+ copybooks.put(copybookName, CopybookParser.parse(copybookName, fin));
+ } catch (RuntimeException e) {
+ throw new RuntimeException(String.format("Cannot parse copybook structure in file '%s'", f.getName()), e);
+ } finally {
+ try {
+ fin.close();
+ } catch (IOException io) {};
+ }
+ }
+ return copybooks;
+ }
+
+ public static String copybookNameOfFile(File f) {
+ if (f.getName().contains("."))
+ return f.getName().toLowerCase().split("\\.")[0];
+ else
+ return f.getName().toLowerCase();
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/net/sf/cb2java/copybook/Item.java b/src/main/java/net/sf/cb2java/copybook/Item.java
index b72842a..5377535 100644
--- a/src/main/java/net/sf/cb2java/copybook/Item.java
+++ b/src/main/java/net/sf/cb2java/copybook/Item.java
@@ -57,7 +57,7 @@ class Item
Item parent;
int length;
- List children = new ArrayList();
+ List- children = new ArrayList
- ();
String redefines;
int occurs = 1;
diff --git a/src/main/java/net/sf/cb2java/data/GroupData.java b/src/main/java/net/sf/cb2java/data/GroupData.java
index 5c5e9bb..6284472 100644
--- a/src/main/java/net/sf/cb2java/data/GroupData.java
+++ b/src/main/java/net/sf/cb2java/data/GroupData.java
@@ -88,7 +88,7 @@ public List getChildren()
*/
public Data getChild(String name)
{
- for (Iterator i = wrapper.iterator(); i.hasNext();)
+ for (Iterator i = wrapper.iterator(); i.hasNext();)
{
Data child = (Data) i.next();
@@ -111,7 +111,7 @@ public String toString(String indent)
buffer.append(getName());
- for (Iterator i = wrapper.iterator(); i.hasNext();) {
+ for (Iterator i = wrapper.iterator(); i.hasNext();) {
buffer.append('\n');
buffer.append(((Data) i.next()).toString(indent + INDENT));
}
@@ -122,7 +122,7 @@ public String toString(String indent)
@Override
public void write(OutputStream stream) throws IOException
{
- for (Iterator i = wrapper.iterator(); i.hasNext();) {
+ for (Iterator i = wrapper.iterator(); i.hasNext();) {
Data child = (Data) i.next();
child.write(stream);
}
@@ -172,7 +172,7 @@ protected Object toPOJO() {
Data child = groupIterator.next();
int occurs = child.getDefinition().getOccurs();
if (occurs > 1) {
- List childOccurs = new ArrayList(occurs);
+ List