Skip to content

Commit f9a4cea

Browse files
authored
Merge pull request #6 from jpdark007/master
Complete test and clean some code kevinseim#7
2 parents 988b00d + 189b7cb commit f9a4cea

File tree

6 files changed

+39
-14
lines changed

6 files changed

+39
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@
1616
hs_err_pid*
1717
/build/
1818
/classes/
19+
/bin/

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sonatypeUsername=
2+
sonatypePassword=

src/org/beanio/internal/compiler/ParserFactorySupport.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ protected void initializeGroup(GroupConfig config) throws BeanIOConfigurationExc
391391

392392
protected void initializeGroupIteration(GroupConfig config, Property property) {
393393
// wrap the segment in an iteration
394-
Component aggregation = createRecordAggregation(config, property);
394+
Component aggregation = createRecordAggregation(config);
395395

396396
pushParser(aggregation);
397397
if (property != null || config.getTarget() != null) {
@@ -476,7 +476,7 @@ protected void initializeRecord(RecordConfig config) throws BeanIOConfigurationE
476476

477477
protected void initializeRecordIteration(RecordConfig config, Property property) {
478478
// wrap the segment in an iteration
479-
Component collection = createRecordAggregation(config, property);
479+
Component collection = createRecordAggregation(config);
480480

481481
pushParser(collection);
482482
if (property != null || config.getTarget() != null) {
@@ -588,7 +588,7 @@ protected void finalizeRecord(RecordConfig config, Record record) {
588588

589589
}
590590

591-
private Property findTarget(Component segment, String name) {
591+
private static Property findTarget(Component segment, String name) {
592592
Component c = findDescendant("value", segment, name);
593593
if (c == null) {
594594
throw new BeanIOConfigurationException("Descendant value '" + name + "' not found");
@@ -604,7 +604,7 @@ private Property findTarget(Component segment, String name) {
604604
return property;
605605
}
606606

607-
private Component findDescendant(String type, Component c, String name) {
607+
private static Component findDescendant(String type, Component c, String name) {
608608
if (name.equals(c.getName())) {
609609
return c;
610610
}
@@ -1026,7 +1026,7 @@ else if (arrayType == null) {
10261026
* @return the created {@link RecordAggregation}
10271027
* @throws BeanIOConfigurationException
10281028
*/
1029-
protected RecordAggregation createRecordAggregation(PropertyConfig config, Property property)
1029+
protected RecordAggregation createRecordAggregation(PropertyConfig config)
10301030
throws BeanIOConfigurationException
10311031
{
10321032
boolean isMap = false;
@@ -1051,7 +1051,7 @@ protected RecordAggregation createRecordAggregation(PropertyConfig config, Prope
10511051
}
10521052

10531053
// create the appropriate iteration type
1054-
RecordAggregation aggregation;;
1054+
RecordAggregation aggregation;
10551055
if (collectionType == TypeUtil.ARRAY_TYPE) {
10561056
aggregation = new RecordArray();
10571057
}

src/org/beanio/internal/util/DomUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static Document newDocument() {
6565
* @param title the name of the DOM
6666
* @param document the DOM to print
6767
*/
68-
public static void print(String title, Node document) {
68+
public static void print(String title, Node document) throws BeanIOException{
6969
try {
7070
TransformerFactory factory = TransformerFactory.newInstance();
7171
Transformer trans = factory.newTransformer();
@@ -82,7 +82,7 @@ public static void print(String title, Node document) {
8282
System.out.println("-------------------------------------------");
8383
}
8484
catch (Exception ex) {
85-
ex.printStackTrace();
85+
throw new BeanIOException(ex);
8686
}
8787
}
8888
}

src/org/beanio/types/xml/AbstractXmlCalendarTypeHandler.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
*/
3232
public abstract class AbstractXmlCalendarTypeHandler extends CalendarTypeHandler {
3333

34-
protected static final DatatypeFactory dataTypeFactory;
34+
private static final String DATE_TIME = "dateTime";
35+
private static final String INVALID_XML = "Invalid XML ";
36+
protected static final DatatypeFactory dataTypeFactory;
3537
static {
3638
try {
3739
dataTypeFactory = DatatypeFactory.newInstance();
@@ -67,20 +69,20 @@ public Calendar parse(String text) throws TypeConversionException {
6769
try {
6870
XMLGregorianCalendar xcal = dataTypeFactory.newXMLGregorianCalendar(text);
6971
if (!lenientDatatype && type != null && !xcal.getXMLSchemaType().equals(type)) {
70-
throw new TypeConversionException("Invalid XML " + type.getLocalPart());
72+
throw new TypeConversionException(INVALID_XML + type.getLocalPart());
7173
}
7274

7375
if (!isTimeZoneAllowed() && xcal.getTimezone() != DatatypeConstants.FIELD_UNDEFINED) {
74-
String typeName = type == null ? "dateTime" : type.getLocalPart();
75-
throw new TypeConversionException("Invalid XML " + typeName +
76+
String typeName = type == null ? DATE_TIME : type.getLocalPart();
77+
throw new TypeConversionException(INVALID_XML + typeName +
7678
", time zone not allowed");
7779
}
7880

7981
return xcal.toGregorianCalendar();
8082
}
8183
catch (IllegalArgumentException ex) {
82-
String typeName = type == null ? "dateTime" : type.getLocalPart();
83-
throw new TypeConversionException("Invalid XML " + typeName);
84+
String typeName = type == null ? DATE_TIME : type.getLocalPart();
85+
throw new TypeConversionException(INVALID_XML + typeName);
8486
}
8587
}
8688

test/org/beanio/parser/inlinemaps/InlineMapParserTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.beanio.parser.inlinemaps;
22

3+
import static org.junit.Assert.assertEquals;
4+
35
import java.io.StringReader;
46
import java.util.Map;
57

@@ -104,5 +106,23 @@ public void testMapRecordGroup() {
104106
"entity,PERSON,-22.282174,166.441458,TEST_ENTITY_3\n";
105107

106108
BeanReader in = factory.createReader("stream5", new StringReader(text));
109+
110+
Map map = (Map) in.read();
111+
assertEquals("ACTIVE", map.get("status"));
112+
assertEquals("PERSON", map.get("subtype"));
113+
assertEquals (Double.valueOf(8.4), map.get("lat"));
114+
assertEquals(Double.valueOf(-77.2), map.get("lon"));
115+
116+
map = (Map) in.read();
117+
assertEquals ("ACTIVE", map.get("status"));
118+
assertEquals("PERSON", map.get("subtype"));
119+
assertEquals (Double.valueOf(-33.99367), map.get("lat"));
120+
assertEquals(Double.valueOf(25.67632), map.get("lon"));
121+
122+
map = (Map) in.read();
123+
assertEquals ("ACTIVE", map.get("status"));
124+
assertEquals("PERSON", map.get("subtype"));
125+
assertEquals (Double.valueOf(-22.282174), map.get("lat"));
126+
assertEquals(Double.valueOf(166.441458), map.get("lon"));
107127
}
108128
}

0 commit comments

Comments
 (0)