From e477210a8478fbbea2d6d10b983ec5fd1df2c4f4 Mon Sep 17 00:00:00 2001 From: Sweidan Omar Date: Mon, 25 Apr 2022 08:18:34 +0000 Subject: [PATCH] git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube;C33196 --- .../jobengine/server/ast/JobTemplate.java | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/server/user.jobengine.osgi.server/src/user/jobengine/server/ast/JobTemplate.java b/server/user.jobengine.osgi.server/src/user/jobengine/server/ast/JobTemplate.java index 9af66944..12e48f8c 100644 --- a/server/user.jobengine.osgi.server/src/user/jobengine/server/ast/JobTemplate.java +++ b/server/user.jobengine.osgi.server/src/user/jobengine/server/ast/JobTemplate.java @@ -5,8 +5,15 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.w3c.dom.Comment; +import org.w3c.dom.Document; +import org.w3c.dom.Element; /** * Gyökér osztály. @@ -31,6 +38,15 @@ public class JobTemplate extends AST { this.declarationSequence = declarationSequence; } + public JobTemplate(JobTemplate templateToDuplicate) { + setDescription(templateToDuplicate.getDescription()); + setName(templateToDuplicate.getName()); + setMultiInstance(templateToDuplicate.isMultiInstance()); + setUseSessionLog(templateToDuplicate.isUseSessionLog()); + setDeclarationSequence(templateToDuplicate.getDeclarationSequence()); + setCommandSequence(templateToDuplicate.getCommandSequence()); + } + public CommandSequence getCommandSequence() { return commandSequence; } @@ -201,4 +217,89 @@ public class JobTemplate extends AST { public Object visit(Visitor v, Object o) { return v.visitJobTemplate(this, o); } + + public Document toXmlDocument() { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder documentBuilder; + Document document = null; + try { + documentBuilder = dbf.newDocumentBuilder(); + document = documentBuilder.newDocument(); + + if (getDescription() != null) { + Comment description = document.createComment(getDescription()); + document.appendChild(description); + } + + Element root = document.createElement("jobtemplate"); + document.appendChild(root); + root.setAttribute("name", getName()); + root.setAttribute("useSessionLog", Boolean.toString(isUseSessionLog())); + + if (getDeclarationSequence() != null) { + Element declarations = document.createElement("declarations"); + root.appendChild(declarations); + for (int i = 0; i < getDeclarationSequence().getDeclarations().size(); i++) { + Element declarationElement = null; + if (getDeclarationSequence().getDeclarations().get(i).getClass().getSimpleName() + .equals("ParameterDeclaration")) { + declarationElement = document.createElement("parameter"); + } else { + declarationElement = document.createElement("variable"); + } + declarationElement.setAttribute("name", + getDeclarationSequence().getDeclarations().get(i).getName()); + declarationElement.setAttribute("type", + getDeclarationSequence().getDeclarations().get(i).getType()); + declarations.appendChild(declarationElement); + } + } + if (getCommandSequence() != null) { + Element commands = document.createElement("commands"); + root.appendChild(commands); + for (int i = 0; i < getCommandSequence().getCommands().size(); i++) { + CallJobStepCommand cjs = (CallJobStepCommand) getCommandSequence().getCommands().get(i); + Element command = document.createElement("calljobstep"); + command.setAttribute("type", cjs.getType()); + command.setAttribute("weight", Integer.toString(cjs.getWeight())); + commands.appendChild(command); + + InputParameterSequence ips = (InputParameterSequence) cjs.getInputParameterSequence(); + Element inputs = document.createElement("inputs"); + + for (int j = 0; j < ips.getParameters().size(); j++) { + InputParameter ip = (InputParameter) (ips.getParameters().get(j)); + Element input = document.createElement("input"); + Element parameter; + if (ip.getExpression().getClass().getSimpleName().equals("VariableExpression")) { + parameter = document.createElement("variable"); + } else { + parameter = document.createElement("parameter"); + } + parameter.setAttribute("name", ip.getExpression().getName()); + input.appendChild(parameter); + inputs.appendChild(input); + } + command.appendChild(inputs); + + OutputParameterSequence ops = (OutputParameterSequence) cjs.getOutputParameterSequence(); + Element outputs = document.createElement("outputs"); + + for (int j = 0; j < ops.getParameters().size(); j++) { + OutputParameter op = (OutputParameter) (ops.getParameters().get(j)); + Element output = document.createElement("output"); + Element variable = document.createElement("variable"); + variable.setAttribute("name", op.getVariableName().getName()); + output.appendChild(variable); + outputs.appendChild(output); + } + command.appendChild(outputs); + } + } + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } + + return document; + } } -- 2.54.0