Skip to content

Commit 09d567f

Browse files
committed
[Java] Generalise description and sinceVersion on types when parsing XML. Issue aeron-io#415.
1 parent f7b11ac commit 09d567f

File tree

4 files changed

+23
-27
lines changed

4 files changed

+23
-27
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/CompositeType.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public class CompositeType extends Type
4545

4646
private final List<String> compositesPath = new ArrayList<>();
4747
private final Map<String, Type> containedTypeByNameMap = new LinkedHashMap<>();
48-
private final int sinceVersion;
4948

5049
public CompositeType(final Node node) throws XPathExpressionException
5150
{
@@ -68,7 +67,6 @@ public CompositeType(final Node node, final String givenName, final List<String>
6867
this.compositesPath.addAll(compositesPath);
6968
this.compositesPath.add(getAttributeValue(node, "name"));
7069

71-
sinceVersion = Integer.parseInt(XmlSchemaParser.getAttributeValue(node, "sinceVersion", "0"));
7270
final XPath xPath = XPathFactory.newInstance().newXPath();
7371
final NodeList list = (NodeList)xPath.compile(SUB_TYPES_EXP).evaluate(node, NODESET);
7472

@@ -121,16 +119,6 @@ public int encodedLength()
121119
return offset;
122120
}
123121

124-
/**
125-
* Return the sinceVersion value of the {@link CompositeType}
126-
*
127-
* @return the sinceVersion of the {@link CompositeType}
128-
*/
129-
public int sinceVersion()
130-
{
131-
return sinceVersion;
132-
}
133-
134122
/**
135123
* Return list of the Type that compose this composite
136124
*

sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/EncodedDataType.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public class EncodedDataType extends Type
4141
private final PrimitiveValue maxValue;
4242
private final PrimitiveValue nullValue;
4343
private final String characterEncoding;
44-
private final int sinceVersion;
4544
private boolean varLen;
4645

4746
/**
@@ -68,7 +67,6 @@ public EncodedDataType(final Node node, final String givenName)
6867
length = Integer.parseInt(getAttributeValue(node, "length", "1"));
6968
varLen = Boolean.parseBoolean(getAttributeValue(node, "variableLength", "false"));
7069
characterEncoding = getAttributeValue(node, "characterEncoding", "UTF-8");
71-
sinceVersion = Integer.parseInt(getAttributeValue(node, "sinceVersion", "0"));
7270

7371
if (presence() == CONSTANT)
7472
{
@@ -144,7 +142,7 @@ public EncodedDataType(
144142
final int length,
145143
final boolean varLen)
146144
{
147-
super(name, presence, description, semanticType);
145+
super(name, presence, description, 0, semanticType);
148146

149147
this.primitiveType = primitiveType;
150148
this.length = length;
@@ -154,7 +152,6 @@ public EncodedDataType(
154152
this.maxValue = null;
155153
this.nullValue = null;
156154
characterEncoding = null;
157-
sinceVersion = 0;
158155
}
159156

160157
/**
@@ -267,14 +264,4 @@ public String characterEncoding()
267264
{
268265
return characterEncoding;
269266
}
270-
271-
/**
272-
* Return the sinceVersion of the {@link EncodedDataType}
273-
*
274-
* @return the sinceVersion value of the {@link EncodedDataType}
275-
*/
276-
public int sinceVersion()
277-
{
278-
return sinceVersion;
279-
}
280267
}

sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/Type.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public abstract class Type
2828
private final String name;
2929
private final Presence presence;
3030
private final String description;
31+
private final int sinceVersion;
3132
private final String semanticType;
3233

3334
private int offsetAttribute;
@@ -48,8 +49,10 @@ public Type(final Node node, final String givenName)
4849
{
4950
name = givenName;
5051
}
52+
5153
presence = Presence.get(getAttributeValue(node, "presence", "required"));
5254
description = getAttributeValueOrNull(node, "description");
55+
sinceVersion = Integer.parseInt(getAttributeValue(node, "sinceVersion", "0"));
5356
semanticType = getAttributeValueOrNull(node, "semanticType");
5457
offsetAttribute = Integer.parseInt(getAttributeValue(node, "offset", "-1"));
5558
}
@@ -60,13 +63,20 @@ public Type(final Node node, final String givenName)
6063
* @param name of the type
6164
* @param presence of the type
6265
* @param description of the type or null
66+
* @param sinceVersion for the type
6367
* @param semanticType of the type or null
6468
*/
65-
public Type(final String name, final Presence presence, final String description, final String semanticType)
69+
public Type(
70+
final String name,
71+
final Presence presence,
72+
final String description,
73+
final int sinceVersion,
74+
final String semanticType)
6675
{
6776
this.name = name;
6877
this.presence = presence;
6978
this.description = description;
79+
this.sinceVersion = sinceVersion;
7080
this.semanticType = semanticType;
7181
this.offsetAttribute = -1;
7282
}
@@ -110,6 +120,16 @@ public String description()
110120
return description;
111121
}
112122

123+
/**
124+
* The version since this was added to the template.
125+
*
126+
* @return version since this was added to the template.
127+
*/
128+
public int sinceVersion()
129+
{
130+
return sinceVersion;
131+
}
132+
113133
/**
114134
* The semanticType of the Type
115135
*

sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/XmlSchemaParser.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ private static String formatLocationInfo(final Node node)
351351
">" : (" name=\"" + getAttributeValueOrNull(node, "name") + "\"> "));
352352
}
353353

354+
@FunctionalInterface
354355
interface NodeFunction
355356
{
356357
void execute(Node node) throws XPathExpressionException;

0 commit comments

Comments
 (0)