diff --git a/src/main/java/org/bench4q/share/models/agent/scriptrecord/BatchModel.java b/src/main/java/org/bench4q/share/models/agent/scriptrecord/BatchModel.java index 90081d43..3cbec463 100644 --- a/src/main/java/org/bench4q/share/models/agent/scriptrecord/BatchModel.java +++ b/src/main/java/org/bench4q/share/models/agent/scriptrecord/BatchModel.java @@ -4,7 +4,6 @@ import java.util.List; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; -import javax.xml.bind.annotation.XmlElements; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name = "batch") @@ -12,7 +11,7 @@ public class BatchModel { private int Id; private int parentId; private int childId; - private List behaviors; + private List behaviors; @XmlElement public int getId() { @@ -42,14 +41,12 @@ public class BatchModel { } @XmlElementWrapper(name = "behaviors") - @XmlElements(value = { - @XmlElement(name = "userBehavior", type = UserBehaviorModel.class), - @XmlElement(name = "timerBehavior", type = TimerBehaviorModel.class) }) - public List getBehaviors() { + @XmlElement(name = "behaviorModel") + public List getBehaviors() { return behaviors; } - public void setBehaviors(List behaviors) { + public void setBehaviors(List behaviors) { this.behaviors = behaviors; } diff --git a/src/main/java/org/bench4q/share/models/agent/scriptrecord/BehaviorBaseModel.java b/src/main/java/org/bench4q/share/models/agent/scriptrecord/BehaviorBaseModel.java deleted file mode 100644 index e6f8b6fd..00000000 --- a/src/main/java/org/bench4q/share/models/agent/scriptrecord/BehaviorBaseModel.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.bench4q.share.models.agent.scriptrecord; - -import java.util.List; - -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; - -import org.bench4q.share.models.agent.ParameterModel; - -public abstract class BehaviorBaseModel { - private int id; - private String use; - private String name; - private List parameters; - - @XmlElement - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - @XmlElement - public String getUse() { - return use; - } - - public void setUse(String use) { - this.use = use; - } - - @XmlElement - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @XmlElementWrapper(name = "parameters") - @XmlElement(name = "parameter") - public List getParameters() { - return parameters; - } - - public void setParameters(List parameters) { - this.parameters = parameters; - } - -} diff --git a/src/main/java/org/bench4q/share/models/agent/scriptrecord/BehaviorModel.java b/src/main/java/org/bench4q/share/models/agent/scriptrecord/BehaviorModel.java new file mode 100644 index 00000000..e8a21e08 --- /dev/null +++ b/src/main/java/org/bench4q/share/models/agent/scriptrecord/BehaviorModel.java @@ -0,0 +1,93 @@ +package org.bench4q.share.models.agent.scriptrecord; + +import java.util.List; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; + +import org.bench4q.share.models.agent.ParameterModel; + +@XmlRootElement(name = "behaviorModel") +public class BehaviorModel { + private int id; + private String use; + private String name; + private String type; + private List parameters; + + @XmlElement + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @XmlElement + public String getUse() { + return use; + } + + public void setUse(String use) { + this.use = use; + } + + @XmlElement + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @XmlElement + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @XmlElementWrapper(name = "parameters") + @XmlElement(name = "parameter") + public List getParameters() { + return parameters; + } + + public void setParameters(List parameters) { + this.parameters = parameters; + } + + private BehaviorModel() { + } + + public static BehaviorModel TimerBehaviorBuilder(int id, String name, + String use, List parameters) { + BehaviorModel behaviorBaseModel = buildBehaviorModelWithoutType(id, + name, use, parameters); + behaviorBaseModel.setType("TIMERBEHAVIOR"); + return behaviorBaseModel; + } + + private static BehaviorModel buildBehaviorModelWithoutType(int id, + String name, String use, List parameters) { + BehaviorModel behaviorBaseModel = new BehaviorModel(); + behaviorBaseModel.setId(id); + behaviorBaseModel.setName(name); + behaviorBaseModel.setUse(use); + behaviorBaseModel.setParameters(parameters); + return behaviorBaseModel; + } + + public static BehaviorModel UserBehaviorBuilder(int id, String name, + String use, List parameters) { + BehaviorModel behaviorBaseModel = buildBehaviorModelWithoutType(id, + name, use, parameters); + behaviorBaseModel.setType("USERBEHAVIOR"); + return behaviorBaseModel; + } +} diff --git a/src/main/java/org/bench4q/share/models/agent/scriptrecord/TimerBehaviorModel.java b/src/main/java/org/bench4q/share/models/agent/scriptrecord/TimerBehaviorModel.java deleted file mode 100644 index de95f02b..00000000 --- a/src/main/java/org/bench4q/share/models/agent/scriptrecord/TimerBehaviorModel.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.bench4q.share.models.agent.scriptrecord; - -import java.io.ByteArrayOutputStream; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.Marshaller; -import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement(name = "timerBehavior") -public class TimerBehaviorModel extends BehaviorBaseModel { - - public String getModelString() { - ByteArrayOutputStream os = new ByteArrayOutputStream(); - try { - Marshaller marshaller = JAXBContext.newInstance(this.getClass()) - .createMarshaller(); - marshaller.marshal(this, os); - } catch (Exception e) { - e.printStackTrace(); - } - return os.toString(); - } - -} diff --git a/src/main/java/org/bench4q/share/models/agent/scriptrecord/UserBehaviorModel.java b/src/main/java/org/bench4q/share/models/agent/scriptrecord/UserBehaviorModel.java deleted file mode 100644 index 8257f80b..00000000 --- a/src/main/java/org/bench4q/share/models/agent/scriptrecord/UserBehaviorModel.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.bench4q.share.models.agent.scriptrecord; - -import java.io.ByteArrayOutputStream; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement(name = "userBehavior") -public class UserBehaviorModel extends BehaviorBaseModel { - public String getModelString() throws JAXBException { - ByteArrayOutputStream os = new ByteArrayOutputStream(); - Marshaller marshaller = JAXBContext.newInstance(this.getClass()) - .createMarshaller(); - marshaller.marshal(this, os); - return os.toString(); - } - -}