Skip to content

Commit f462f65

Browse files
committed
feat(xsd-parser): update generated EipSchema to use eipIds for EipElements
1 parent 26f958d commit f462f65

24 files changed

+309
-138
lines changed

xsd-parser/eip-schema-definitions/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111

1212
<artifactId>eip-schema-definitions</artifactId>
13-
<version>0.2.0</version>
13+
<version>0.3.0</version>
1414

1515
<packaging>jar</packaging>
1616

@@ -22,7 +22,7 @@
2222
<dependency>
2323
<groupId>org.codice.keip.xsd</groupId>
2424
<artifactId>si-xsd-parser-cli</artifactId>
25-
<version>0.1.0</version>
25+
<version>0.2.0</version>
2626
</dependency>
2727
</dependencies>
2828

xsd-parser/eip-schema-definitions/xsd-sources.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ schemas:
6161
importedSchemaLocations:
6262
- namespace: "http://www.springframework.org/schema/integration"
6363
location: "https://www.springframework.org/schema/integration/spring-integration-5.2.xsd"
64-
- namespace: "http://www.springframework.org/schema/beans"
64+
- alias: "beans"
65+
namespace: "http://www.springframework.org/schema/beans"
6566
location: "https://www.springframework.org/schema/beans/spring-beans-4.3.xsd"
66-
- namespace: "http://www.springframework.org/schema/tool"
67+
- alias: "tools"
68+
namespace: "http://www.springframework.org/schema/tool"
6769
location: "https://www.springframework.org/schema/tool/spring-tool-4.3.xsd"

xsd-parser/si-xsd-parser-cli/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111

1212
<artifactId>si-xsd-parser-cli</artifactId>
13-
<version>0.1.0</version>
13+
<version>0.2.0</version>
1414

1515
<dependencies>
1616
<dependency>
@@ -79,7 +79,7 @@
7979
<dependency>
8080
<groupId>org.codice.keip.schemas</groupId>
8181
<artifactId>validation</artifactId>
82-
<version>0.2.0</version>
82+
<version>0.4.0</version>
8383
<scope>test</scope>
8484
</dependency>
8585

xsd-parser/si-xsd-parser-cli/src/main/java/org/codice/keip/xsd/EipSchemaTranslation.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import java.util.ArrayList;
44
import java.util.Collections;
55
import java.util.List;
6+
import java.util.Map;
7+
import java.util.Objects;
8+
import java.util.stream.Collectors;
9+
import java.util.stream.Stream;
610
import javax.xml.transform.TransformerException;
711
import org.apache.ws.commons.schema.XmlSchemaCollection;
812
import org.codice.keip.xsd.client.XmlSchemaClient;
@@ -18,6 +22,8 @@ public class EipSchemaTranslation {
1822

1923
private static final Logger LOGGER = LoggerFactory.getLogger(EipSchemaTranslation.class);
2024

25+
private final Map<String, String> uriToEipNamespace;
26+
2127
private final XmlSchemaClient xmlSchemaClient;
2228

2329
private final EipSchema eipSchema;
@@ -28,9 +34,20 @@ public EipSchemaTranslation(
2834
XsdSourceConfiguration sourceConfiguration, XmlSchemaClient xmlSchemaClient) {
2935
this.errors = new ArrayList<>();
3036
this.xmlSchemaClient = xmlSchemaClient;
37+
this.uriToEipNamespace = buildUriToNamespaceMap(sourceConfiguration);
3138
this.eipSchema = translate(sourceConfiguration);
3239
}
3340

41+
private Map<String, String> buildUriToNamespaceMap(XsdSourceConfiguration sourceConfiguration) {
42+
return Stream.concat(
43+
sourceConfiguration.getSchemas().stream(),
44+
sourceConfiguration.getImportedSchemaLocations().stream())
45+
.filter(conf -> Objects.nonNull(conf.getAlias()))
46+
.collect(
47+
Collectors.toUnmodifiableMap(
48+
SchemaIdentifier::getNamespace, SchemaIdentifier::getAlias));
49+
}
50+
3451
public EipSchema getEipSchema() {
3552
return eipSchema;
3653
}
@@ -46,7 +63,8 @@ private EipSchema translate(XsdSourceConfiguration sourceConfiguration) {
4663
try {
4764
XmlSchemaCollection schemaCollection = xmlSchemaClient.collect(targetSchema.getLocation());
4865

49-
var translator = new SchemaTranslator(targetSchema.getExcludedElements());
66+
var translator =
67+
new SchemaTranslator(targetSchema.getExcludedElements(), uriToEipNamespace);
5068

5169
List<EipComponent> components =
5270
translator.translate(

xsd-parser/si-xsd-parser-cli/src/main/java/org/codice/keip/xsd/config/XsdSourceConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void setSchemas(List<SchemaIdentifier> schemas) {
2525
this.schemas = schemas;
2626
}
2727

28-
List<SchemaIdentifier> getImportedSchemaLocations() {
28+
public List<SchemaIdentifier> getImportedSchemaLocations() {
2929
if (importedSchemaLocations == null) {
3030
return Collections.emptyList();
3131
}

xsd-parser/si-xsd-parser-cli/src/main/java/org/codice/keip/xsd/model/eip/EipChildElement.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public static class Builder extends EipElement.Builder<Builder> {
4141

4242
private Occurrence occurrence;
4343

44-
public Builder(String name) {
45-
this.name = Objects.requireNonNull(name);
44+
public Builder(EipId eipId) {
45+
this.eipId = Objects.requireNonNull(eipId);
4646
}
4747

4848
public Builder(EipChildElement element) {

xsd-parser/si-xsd-parser-cli/src/main/java/org/codice/keip/xsd/model/eip/EipComponent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public static class Builder extends EipElement.Builder<Builder> {
2828
private Role role;
2929
private ConnectionType connectionType;
3030

31-
public Builder(String name, Role role, ConnectionType connectionType) {
32-
this.name = Objects.requireNonNull(name);
31+
public Builder(EipId eipId, Role role, ConnectionType connectionType) {
32+
this.eipId = Objects.requireNonNull(eipId);
3333
this.role = Objects.requireNonNull(role);
3434
this.connectionType = Objects.requireNonNull(connectionType);
3535
}

xsd-parser/si-xsd-parser-cli/src/main/java/org/codice/keip/xsd/model/eip/EipElement.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66

77
public abstract class EipElement {
88

9-
protected final String name;
9+
protected final EipId eipId;
1010
protected final String description;
1111
protected Set<Attribute> attributes;
1212
protected ChildComposite childGroup;
1313

1414
protected EipElement(Builder<?> builder) {
15-
this.name = builder.name;
15+
this.eipId = builder.eipId;
1616
this.description = builder.description;
1717
this.attributes = builder.attributes;
1818
this.childGroup = builder.childGroup;
1919
}
2020

21-
public String getName() {
22-
return name;
21+
public EipId getEipId() {
22+
return eipId;
2323
}
2424

2525
public String getDescription() {
@@ -50,28 +50,28 @@ public void addAttribute(Attribute attribute) {
5050

5151
@Override
5252
public String toString() {
53-
return this.name;
53+
return this.eipId.toString();
5454
}
5555

5656
// Effective Java - Hierarchical builder pattern
5757
protected abstract static class Builder<T extends Builder<T>> {
5858

59-
protected String name;
59+
protected EipId eipId;
6060
protected String description;
6161
protected Set<Attribute> attributes;
6262
protected ChildComposite childGroup;
6363

6464
public Builder() {}
6565

6666
public Builder(EipElement element) {
67-
this.name = element.name;
67+
this.eipId = element.eipId;
6868
this.description = element.description;
6969
this.attributes = element.attributes;
7070
this.childGroup = element.childGroup;
7171
}
7272

73-
public T name(String name) {
74-
this.name = name;
73+
public T eipId(EipId eipId) {
74+
this.eipId = eipId;
7575
return self();
7676
}
7777

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.codice.keip.xsd.model.eip;
2+
3+
public record EipId(String namespace, String name) {
4+
@Override
5+
public String toString() {
6+
return namespace + ":" + name;
7+
}
8+
}

xsd-parser/si-xsd-parser-cli/src/main/java/org/codice/keip/xsd/xml/ChildGroupReducer.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.codice.keip.xsd.model.eip.ChildComposite;
1313
import org.codice.keip.xsd.model.eip.ChildGroup;
1414
import org.codice.keip.xsd.model.eip.EipChildElement;
15+
import org.codice.keip.xsd.model.eip.EipId;
1516
import org.codice.keip.xsd.model.eip.Indicator;
1617
import org.codice.keip.xsd.model.eip.Occurrence;
1718

@@ -92,14 +93,14 @@ private EipChildElement makeTerminalNode(EipChildElement element) {
9293

9394
/** Remove any duplicate (by name) element siblings in a child group. */
9495
ChildGroup deDuplicateElements(ChildGroup group) {
95-
Set<String> names = new HashSet<>();
96+
Set<EipId> names = new HashSet<>();
9697
List<ChildComposite> deDuplicated =
9798
group.children().stream()
9899
.map(
99100
child ->
100101
switch (child) {
101102
case EipChildElement element -> {
102-
if (names.add(element.getName())) {
103+
if (names.add(element.getEipId())) {
103104
yield element;
104105
}
105106
yield null;
@@ -248,7 +249,7 @@ private String concatChildNames(ChildGroup group) {
248249
.map(
249250
child ->
250251
switch (child) {
251-
case EipChildElement element -> element.getName();
252+
case EipChildElement element -> eipIdToString(element.getEipId());
252253
case ChildGroup ignored -> null;
253254
})
254255
.filter(Objects::nonNull)
@@ -260,4 +261,8 @@ private String concatChildNames(ChildGroup group) {
260261
private boolean allChildrenAreElements(ChildGroup cg) {
261262
return cg.children().stream().allMatch(c -> c instanceof EipChildElement);
262263
}
264+
265+
private String eipIdToString(EipId id) {
266+
return id.namespace() + "_" + id.name();
267+
}
263268
}

0 commit comments

Comments
 (0)