Skip to content

Commit

Permalink
Merge 2924f0e into c7d357c
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeEdgar committed Oct 13, 2021
2 parents c7d357c + 2924f0e commit 9a802e1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ void readSyntax(XMLStreamReader reader, List<EDISyntaxRule> rules) {
EDISyntaxRule.Type typeInt = null;

try {
typeInt = EDISyntaxRule.Type.valueOf(type.toUpperCase());
typeInt = EDISyntaxRule.Type.fromString(type);
} catch (IllegalArgumentException e) {
throw schemaException("Invalid syntax 'type': [" + type + ']', reader, e);
}
Expand Down Expand Up @@ -607,7 +607,7 @@ List<Integer> readSyntaxPositions(XMLStreamReader reader) {
ElementType readSimpleType(XMLStreamReader reader) {
String name = parseAttribute(reader, "name", String::valueOf);
String code = parseAttribute(reader, "code", String::valueOf, name);
Base base = parseAttribute(reader, "base", val -> Base.valueOf(val.toUpperCase()), Base.STRING);
Base base = parseAttribute(reader, "base", val -> Base.fromString(val), Base.STRING);
int scale = (Base.NUMERIC == base) ? parseAttribute(reader, "scale", Integer::parseInt, 0) : -1;
int number = parseAttribute(reader, "number", Integer::parseInt, -1);
long minLength = parseAttribute(reader, "minLength", Long::parseLong, 1L);
Expand Down Expand Up @@ -793,7 +793,7 @@ void setReferences(StructureType struct, Map<String, EDIType> types) {

final EDIType.Type refType = target.getType();

if (refType != EDIType.Type.valueOf(impl.getRefTag().toUpperCase())) {
if (refType != EDIType.Type.fromString(impl.getRefTag())) {
throw schemaException(String.format(REFERR_ILLEGAL, impl.getRefId(), impl.getRefTag(), struct.getId()));
}

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/io/xlate/edi/schema/EDISimpleType.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ public enum Base {
TIME,
BINARY,
IDENTIFIER;

public static Base fromString(String value) {
for (Base entry : values()) {
if (entry.name().equalsIgnoreCase(value)) {
return entry;
}
}
throw new IllegalArgumentException("No enum constant for " + Base.class.getName() + "." + value);
}
}

Base getBase();
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/io/xlate/edi/schema/EDISyntaxRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ public enum Type {
* EDIFACT: (D7) If first, then none of the others
*/
FIRSTONLY;

public static Type fromString(String value) {
for (Type entry : values()) {
if (entry.name().equalsIgnoreCase(value)) {
return entry;
}
}
throw new IllegalArgumentException("No enum constant for " + Type.class.getName() + "." + value);
}
}

Type getType();
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/io/xlate/edi/schema/EDIType.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ public enum Type {
SEGMENT,
COMPOSITE,
ELEMENT;

public static Type fromString(String value) {
for (Type entry : values()) {
if (entry.name().equalsIgnoreCase(value)) {
return entry;
}
}
throw new IllegalArgumentException("No enum constant for " + Type.class.getName() + "." + value);
}
}

String getId();
Expand Down

0 comments on commit 9a802e1

Please sign in to comment.