Added the ability to set custom methods instead of the auto-generated methods, and added custom methods for getActions/setActions in OFFlowMod implementation classes of version 1.3.
diff --git a/java_gen/templates/_field_accessors.java b/java_gen/templates/_field_accessors.java
index b64b29b..b0b3b76 100644
--- a/java_gen/templates/_field_accessors.java
+++ b/java_gen/templates/_field_accessors.java
@@ -1,4 +1,12 @@
+//:: import os
+
//:: for prop in msg.interface.members:
+
+//:: getter_template_file_name = "%s/custom/%s_%s.java" % (template_dir, msg.name if not builder else msg.name + '.Builder', prop.getter_name)
+//:: if os.path.exists(getter_template_file_name):
+//:: include(getter_template_file_name, msg=msg, builder=builder, has_parent=has_parent)
+//:: else:
+
@Override
public ${prop.java_type.public_type} ${prop.getter_name}()${ "" if prop in msg.members else "throws UnsupportedOperationException"} {
//:: if prop in msg.members:
@@ -17,17 +25,23 @@
throw new UnsupportedOperationException("Property ${prop.name} not supported in version #{version}");
//:: #endif
}
+//:: #endif
//:: if generate_setters and prop.is_writeable:
+ //:: setter_template_file_name = "%s/custom/%s_%s.java" % (template_dir, msg.name if not builder else msg.name + '.Builder', prop.setter_name)
+ //:: if os.path.exists(setter_template_file_name):
+ //:: include(setter_template_file_name, msg=msg, builder=builder, has_parent=has_parent)
+ //:: else:
@Override
public ${msg.interface.name}.Builder ${prop.setter_name}(${prop.java_type.public_type} ${prop.name})${ "" if prop in msg.members else " throws UnsupportedOperationException"} {
-//:: if prop in msg.members:
+ //:: if prop in msg.members:
this.${prop.name} = ${prop.name};
this.${prop.name}Set = true;
return this;
-//:: else:
+ //:: else:
throw new UnsupportedOperationException("Property ${prop.name} not supported in version #{version}");
-//:: #endif
+ //:: #endif
}
-//:: #endif
+ //:: #endif
+ //:: #endif
//:: #endfor
diff --git a/java_gen/templates/custom/OFFlowAddVer13.Builder_getActions.java b/java_gen/templates/custom/OFFlowAddVer13.Builder_getActions.java
new file mode 100644
index 0000000..c3a42e3
--- /dev/null
+++ b/java_gen/templates/custom/OFFlowAddVer13.Builder_getActions.java
@@ -0,0 +1,20 @@
+
+ @Override
+ public List<OFAction> getActions()throws UnsupportedOperationException {
+//:: if builder:
+ if (!this.instructionsSet)
+//:: if has_parent:
+ return parentMessage.getActions();
+//:: else:
+ return Collections.emptyList();
+//:: #endif
+//:: #endif
+ ImmutableList.Builder<OFAction> builder = ImmutableList.builder();
+ for (OFInstruction inst : this.instructions) {
+ if (inst instanceof OFInstructionApplyActions) {
+ OFInstructionApplyActions iap = (OFInstructionApplyActions)inst;
+ builder.addAll(iap.getActions());
+ }
+ }
+ return builder.build();
+ }
\ No newline at end of file
diff --git a/java_gen/templates/custom/OFFlowAddVer13.Builder_setActions.java b/java_gen/templates/custom/OFFlowAddVer13.Builder_setActions.java
new file mode 100644
index 0000000..725de24
--- /dev/null
+++ b/java_gen/templates/custom/OFFlowAddVer13.Builder_setActions.java
@@ -0,0 +1,9 @@
+
+ @Override
+ public OFFlowAdd.Builder setActions(List<OFAction> actions) throws UnsupportedOperationException {
+ OFInstructionApplyActionsVer13.Builder builder = new OFInstructionApplyActionsVer13.Builder();
+ builder.setActions(actions);
+ this.instructions = Collections.singletonList((OFInstruction)builder.build());
+ this.instructionsSet = true;
+ return this;
+ }
\ No newline at end of file
diff --git a/java_gen/templates/custom/OFFlowAddVer13_getActions.java b/java_gen/templates/custom/OFFlowAddVer13_getActions.java
new file mode 100644
index 0000000..3b56d52
--- /dev/null
+++ b/java_gen/templates/custom/OFFlowAddVer13_getActions.java
@@ -0,0 +1,12 @@
+
+ @Override
+ public List<OFAction> getActions()throws UnsupportedOperationException {
+ ImmutableList.Builder<OFAction> builder = ImmutableList.builder();
+ for (OFInstruction inst : this.instructions) {
+ if (inst instanceof OFInstructionApplyActions) {
+ OFInstructionApplyActions iap = (OFInstructionApplyActions)inst;
+ builder.addAll(iap.getActions());
+ }
+ }
+ return builder.build();
+ }
\ No newline at end of file
diff --git a/java_gen/templates/custom/OFFlowDeleteStrictVer13.Builder_getActions.java b/java_gen/templates/custom/OFFlowDeleteStrictVer13.Builder_getActions.java
new file mode 100644
index 0000000..c3a42e3
--- /dev/null
+++ b/java_gen/templates/custom/OFFlowDeleteStrictVer13.Builder_getActions.java
@@ -0,0 +1,20 @@
+
+ @Override
+ public List<OFAction> getActions()throws UnsupportedOperationException {
+//:: if builder:
+ if (!this.instructionsSet)
+//:: if has_parent:
+ return parentMessage.getActions();
+//:: else:
+ return Collections.emptyList();
+//:: #endif
+//:: #endif
+ ImmutableList.Builder<OFAction> builder = ImmutableList.builder();
+ for (OFInstruction inst : this.instructions) {
+ if (inst instanceof OFInstructionApplyActions) {
+ OFInstructionApplyActions iap = (OFInstructionApplyActions)inst;
+ builder.addAll(iap.getActions());
+ }
+ }
+ return builder.build();
+ }
\ No newline at end of file
diff --git a/java_gen/templates/custom/OFFlowDeleteStrictVer13.Builder_setActions.java b/java_gen/templates/custom/OFFlowDeleteStrictVer13.Builder_setActions.java
new file mode 100644
index 0000000..b2dafe5
--- /dev/null
+++ b/java_gen/templates/custom/OFFlowDeleteStrictVer13.Builder_setActions.java
@@ -0,0 +1,9 @@
+
+ @Override
+ public OFFlowDeleteStrict.Builder setActions(List<OFAction> actions) throws UnsupportedOperationException {
+ OFInstructionApplyActionsVer13.Builder builder = new OFInstructionApplyActionsVer13.Builder();
+ builder.setActions(actions);
+ this.instructions = Collections.singletonList((OFInstruction)builder.build());
+ this.instructionsSet = true;
+ return this;
+ }
\ No newline at end of file
diff --git a/java_gen/templates/custom/OFFlowDeleteStrictVer13_getActions.java b/java_gen/templates/custom/OFFlowDeleteStrictVer13_getActions.java
new file mode 100644
index 0000000..3b56d52
--- /dev/null
+++ b/java_gen/templates/custom/OFFlowDeleteStrictVer13_getActions.java
@@ -0,0 +1,12 @@
+
+ @Override
+ public List<OFAction> getActions()throws UnsupportedOperationException {
+ ImmutableList.Builder<OFAction> builder = ImmutableList.builder();
+ for (OFInstruction inst : this.instructions) {
+ if (inst instanceof OFInstructionApplyActions) {
+ OFInstructionApplyActions iap = (OFInstructionApplyActions)inst;
+ builder.addAll(iap.getActions());
+ }
+ }
+ return builder.build();
+ }
\ No newline at end of file
diff --git a/java_gen/templates/custom/OFFlowDeleteVer13.Builder_getActions.java b/java_gen/templates/custom/OFFlowDeleteVer13.Builder_getActions.java
new file mode 100644
index 0000000..c3a42e3
--- /dev/null
+++ b/java_gen/templates/custom/OFFlowDeleteVer13.Builder_getActions.java
@@ -0,0 +1,20 @@
+
+ @Override
+ public List<OFAction> getActions()throws UnsupportedOperationException {
+//:: if builder:
+ if (!this.instructionsSet)
+//:: if has_parent:
+ return parentMessage.getActions();
+//:: else:
+ return Collections.emptyList();
+//:: #endif
+//:: #endif
+ ImmutableList.Builder<OFAction> builder = ImmutableList.builder();
+ for (OFInstruction inst : this.instructions) {
+ if (inst instanceof OFInstructionApplyActions) {
+ OFInstructionApplyActions iap = (OFInstructionApplyActions)inst;
+ builder.addAll(iap.getActions());
+ }
+ }
+ return builder.build();
+ }
\ No newline at end of file
diff --git a/java_gen/templates/custom/OFFlowDeleteVer13.Builder_setActions.java b/java_gen/templates/custom/OFFlowDeleteVer13.Builder_setActions.java
new file mode 100644
index 0000000..5576aaa
--- /dev/null
+++ b/java_gen/templates/custom/OFFlowDeleteVer13.Builder_setActions.java
@@ -0,0 +1,9 @@
+
+ @Override
+ public OFFlowDelete.Builder setActions(List<OFAction> actions) throws UnsupportedOperationException {
+ OFInstructionApplyActionsVer13.Builder builder = new OFInstructionApplyActionsVer13.Builder();
+ builder.setActions(actions);
+ this.instructions = Collections.singletonList((OFInstruction)builder.build());
+ this.instructionsSet = true;
+ return this;
+ }
\ No newline at end of file
diff --git a/java_gen/templates/custom/OFFlowDeleteVer13_getActions.java b/java_gen/templates/custom/OFFlowDeleteVer13_getActions.java
new file mode 100644
index 0000000..3b56d52
--- /dev/null
+++ b/java_gen/templates/custom/OFFlowDeleteVer13_getActions.java
@@ -0,0 +1,12 @@
+
+ @Override
+ public List<OFAction> getActions()throws UnsupportedOperationException {
+ ImmutableList.Builder<OFAction> builder = ImmutableList.builder();
+ for (OFInstruction inst : this.instructions) {
+ if (inst instanceof OFInstructionApplyActions) {
+ OFInstructionApplyActions iap = (OFInstructionApplyActions)inst;
+ builder.addAll(iap.getActions());
+ }
+ }
+ return builder.build();
+ }
\ No newline at end of file
diff --git a/java_gen/templates/custom/OFFlowModifyStrictVer13.Builder_getActions.java b/java_gen/templates/custom/OFFlowModifyStrictVer13.Builder_getActions.java
new file mode 100644
index 0000000..c3a42e3
--- /dev/null
+++ b/java_gen/templates/custom/OFFlowModifyStrictVer13.Builder_getActions.java
@@ -0,0 +1,20 @@
+
+ @Override
+ public List<OFAction> getActions()throws UnsupportedOperationException {
+//:: if builder:
+ if (!this.instructionsSet)
+//:: if has_parent:
+ return parentMessage.getActions();
+//:: else:
+ return Collections.emptyList();
+//:: #endif
+//:: #endif
+ ImmutableList.Builder<OFAction> builder = ImmutableList.builder();
+ for (OFInstruction inst : this.instructions) {
+ if (inst instanceof OFInstructionApplyActions) {
+ OFInstructionApplyActions iap = (OFInstructionApplyActions)inst;
+ builder.addAll(iap.getActions());
+ }
+ }
+ return builder.build();
+ }
\ No newline at end of file
diff --git a/java_gen/templates/custom/OFFlowModifyStrictVer13.Builder_setActions.java b/java_gen/templates/custom/OFFlowModifyStrictVer13.Builder_setActions.java
new file mode 100644
index 0000000..fc04079
--- /dev/null
+++ b/java_gen/templates/custom/OFFlowModifyStrictVer13.Builder_setActions.java
@@ -0,0 +1,9 @@
+
+ @Override
+ public OFFlowModifyStrict.Builder setActions(List<OFAction> actions) throws UnsupportedOperationException {
+ OFInstructionApplyActionsVer13.Builder builder = new OFInstructionApplyActionsVer13.Builder();
+ builder.setActions(actions);
+ this.instructions = Collections.singletonList((OFInstruction)builder.build());
+ this.instructionsSet = true;
+ return this;
+ }
\ No newline at end of file
diff --git a/java_gen/templates/custom/OFFlowModifyStrictVer13_getActions.java b/java_gen/templates/custom/OFFlowModifyStrictVer13_getActions.java
new file mode 100644
index 0000000..3b56d52
--- /dev/null
+++ b/java_gen/templates/custom/OFFlowModifyStrictVer13_getActions.java
@@ -0,0 +1,12 @@
+
+ @Override
+ public List<OFAction> getActions()throws UnsupportedOperationException {
+ ImmutableList.Builder<OFAction> builder = ImmutableList.builder();
+ for (OFInstruction inst : this.instructions) {
+ if (inst instanceof OFInstructionApplyActions) {
+ OFInstructionApplyActions iap = (OFInstructionApplyActions)inst;
+ builder.addAll(iap.getActions());
+ }
+ }
+ return builder.build();
+ }
\ No newline at end of file
diff --git a/java_gen/templates/custom/OFFlowModifyVer13.Builder_getActions.java b/java_gen/templates/custom/OFFlowModifyVer13.Builder_getActions.java
new file mode 100644
index 0000000..c3a42e3
--- /dev/null
+++ b/java_gen/templates/custom/OFFlowModifyVer13.Builder_getActions.java
@@ -0,0 +1,20 @@
+
+ @Override
+ public List<OFAction> getActions()throws UnsupportedOperationException {
+//:: if builder:
+ if (!this.instructionsSet)
+//:: if has_parent:
+ return parentMessage.getActions();
+//:: else:
+ return Collections.emptyList();
+//:: #endif
+//:: #endif
+ ImmutableList.Builder<OFAction> builder = ImmutableList.builder();
+ for (OFInstruction inst : this.instructions) {
+ if (inst instanceof OFInstructionApplyActions) {
+ OFInstructionApplyActions iap = (OFInstructionApplyActions)inst;
+ builder.addAll(iap.getActions());
+ }
+ }
+ return builder.build();
+ }
\ No newline at end of file
diff --git a/java_gen/templates/custom/OFFlowModifyVer13.Builder_setActions.java b/java_gen/templates/custom/OFFlowModifyVer13.Builder_setActions.java
new file mode 100644
index 0000000..695b771
--- /dev/null
+++ b/java_gen/templates/custom/OFFlowModifyVer13.Builder_setActions.java
@@ -0,0 +1,9 @@
+
+ @Override
+ public OFFlowModify.Builder setActions(List<OFAction> actions) throws UnsupportedOperationException {
+ OFInstructionApplyActionsVer13.Builder builder = new OFInstructionApplyActionsVer13.Builder();
+ builder.setActions(actions);
+ this.instructions = Collections.singletonList((OFInstruction)builder.build());
+ this.instructionsSet = true;
+ return this;
+ }
\ No newline at end of file
diff --git a/java_gen/templates/custom/OFFlowModifyVer13_getActions.java b/java_gen/templates/custom/OFFlowModifyVer13_getActions.java
new file mode 100644
index 0000000..3b56d52
--- /dev/null
+++ b/java_gen/templates/custom/OFFlowModifyVer13_getActions.java
@@ -0,0 +1,12 @@
+
+ @Override
+ public List<OFAction> getActions()throws UnsupportedOperationException {
+ ImmutableList.Builder<OFAction> builder = ImmutableList.builder();
+ for (OFInstruction inst : this.instructions) {
+ if (inst instanceof OFInstructionApplyActions) {
+ OFInstructionApplyActions iap = (OFInstructionApplyActions)inst;
+ builder.addAll(iap.getActions());
+ }
+ }
+ return builder.build();
+ }
\ No newline at end of file
diff --git a/java_gen/templates/of_class.java b/java_gen/templates/of_class.java
index 93ab558..d03ffbf 100644
--- a/java_gen/templates/of_class.java
+++ b/java_gen/templates/of_class.java
@@ -71,7 +71,7 @@
//:: #endif
// Accessors for OF message fields
- //:: include("_field_accessors.java", msg=msg, generate_setters=False, builder=False)
+ //:: include("_field_accessors.java", msg=msg, generate_setters=False, builder=False, has_parent=False)
//:: if os.path.exists("%s/custom/%s.java" % (template_dir, msg.name)):
//:: include("custom/%s.java" % msg.name, msg=msg)
@@ -95,7 +95,7 @@
this.parentMessage = parentMessage;
}
-//:: include("_field_accessors.java", msg=msg, generate_setters=True, builder=True)
+//:: include("_field_accessors.java", msg=msg, generate_setters=True, builder=True, has_parent=True)
@Override
public ${msg.interface.name} build() {
@@ -118,7 +118,7 @@
private ${prop.java_type.public_type} ${prop.name};
//:: #endfor
-//:: include("_field_accessors.java", msg=msg, generate_setters=True, builder=True)
+//:: include("_field_accessors.java", msg=msg, generate_setters=True, builder=True, has_parent=False)
//
@Override
public ${msg.interface.name} build() {