git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube...
authorSweidan Omar <TFS\sweidan.omar>
Mon, 25 Apr 2022 08:18:34 +0000 (08:18 +0000)
committerSweidan Omar <TFS\sweidan.omar>
Mon, 25 Apr 2022 08:18:34 +0000 (08:18 +0000)
server/user.jobengine.osgi.server/src/user/jobengine/server/ast/JobTemplate.java

index 9af669446e405e064e7649bb47a233ec8ce43cf9..12e48f8c8326284167c55f3abdd3865ff0841656 100644 (file)
@@ -5,8 +5,15 @@ import java.util.HashMap;
 import java.util.List;\r
 import java.util.Map;\r
 \r
+import javax.xml.parsers.DocumentBuilder;\r
+import javax.xml.parsers.DocumentBuilderFactory;\r
+import javax.xml.parsers.ParserConfigurationException;\r
+\r
 import org.apache.logging.log4j.LogManager;\r
 import org.apache.logging.log4j.Logger;\r
+import org.w3c.dom.Comment;\r
+import org.w3c.dom.Document;\r
+import org.w3c.dom.Element;\r
 \r
 /**\r
  * Gyökér osztály.\r
@@ -31,6 +38,15 @@ public class JobTemplate extends AST {
                this.declarationSequence = declarationSequence;\r
        }\r
 \r
+       public JobTemplate(JobTemplate templateToDuplicate) {\r
+               setDescription(templateToDuplicate.getDescription());\r
+               setName(templateToDuplicate.getName());\r
+               setMultiInstance(templateToDuplicate.isMultiInstance());\r
+               setUseSessionLog(templateToDuplicate.isUseSessionLog());\r
+               setDeclarationSequence(templateToDuplicate.getDeclarationSequence());\r
+               setCommandSequence(templateToDuplicate.getCommandSequence());\r
+       }\r
+\r
        public CommandSequence getCommandSequence() {\r
                return commandSequence;\r
        }\r
@@ -201,4 +217,89 @@ public class JobTemplate extends AST {
        public Object visit(Visitor v, Object o) {\r
                return v.visitJobTemplate(this, o);\r
        }\r
+\r
+       public Document toXmlDocument() {\r
+               DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();\r
+               DocumentBuilder documentBuilder;\r
+               Document document = null;\r
+               try {\r
+                       documentBuilder = dbf.newDocumentBuilder();\r
+                       document = documentBuilder.newDocument();\r
+\r
+                       if (getDescription() != null) {\r
+                               Comment description = document.createComment(getDescription());\r
+                               document.appendChild(description);\r
+                       }\r
+\r
+                       Element root = document.createElement("jobtemplate");\r
+                       document.appendChild(root);\r
+                       root.setAttribute("name", getName());\r
+                       root.setAttribute("useSessionLog", Boolean.toString(isUseSessionLog()));\r
+\r
+                       if (getDeclarationSequence() != null) {\r
+                               Element declarations = document.createElement("declarations");\r
+                               root.appendChild(declarations);\r
+                               for (int i = 0; i < getDeclarationSequence().getDeclarations().size(); i++) {\r
+                                       Element declarationElement = null;\r
+                                       if (getDeclarationSequence().getDeclarations().get(i).getClass().getSimpleName()\r
+                                                       .equals("ParameterDeclaration")) {\r
+                                               declarationElement = document.createElement("parameter");\r
+                                       } else {\r
+                                               declarationElement = document.createElement("variable");\r
+                                       }\r
+                                       declarationElement.setAttribute("name",\r
+                                                       getDeclarationSequence().getDeclarations().get(i).getName());\r
+                                       declarationElement.setAttribute("type",\r
+                                                       getDeclarationSequence().getDeclarations().get(i).getType());\r
+                                       declarations.appendChild(declarationElement);\r
+                               }\r
+                       }\r
+                       if (getCommandSequence() != null) {\r
+                               Element commands = document.createElement("commands");\r
+                               root.appendChild(commands);\r
+                               for (int i = 0; i < getCommandSequence().getCommands().size(); i++) {\r
+                                       CallJobStepCommand cjs = (CallJobStepCommand) getCommandSequence().getCommands().get(i);\r
+                                       Element command = document.createElement("calljobstep");\r
+                                       command.setAttribute("type", cjs.getType());\r
+                                       command.setAttribute("weight", Integer.toString(cjs.getWeight()));\r
+                                       commands.appendChild(command);\r
+\r
+                                       InputParameterSequence ips = (InputParameterSequence) cjs.getInputParameterSequence();\r
+                                       Element inputs = document.createElement("inputs");\r
+\r
+                                       for (int j = 0; j < ips.getParameters().size(); j++) {\r
+                                               InputParameter ip = (InputParameter) (ips.getParameters().get(j));\r
+                                               Element input = document.createElement("input");\r
+                                               Element parameter;\r
+                                               if (ip.getExpression().getClass().getSimpleName().equals("VariableExpression")) {\r
+                                                       parameter = document.createElement("variable");\r
+                                               } else {\r
+                                                       parameter = document.createElement("parameter");\r
+                                               }\r
+                                               parameter.setAttribute("name", ip.getExpression().getName());\r
+                                               input.appendChild(parameter);\r
+                                               inputs.appendChild(input);\r
+                                       }\r
+                                       command.appendChild(inputs);\r
+\r
+                                       OutputParameterSequence ops = (OutputParameterSequence) cjs.getOutputParameterSequence();\r
+                                       Element outputs = document.createElement("outputs");\r
+\r
+                                       for (int j = 0; j < ops.getParameters().size(); j++) {\r
+                                               OutputParameter op = (OutputParameter) (ops.getParameters().get(j));\r
+                                               Element output = document.createElement("output");\r
+                                               Element variable = document.createElement("variable");\r
+                                               variable.setAttribute("name", op.getVariableName().getName());\r
+                                               output.appendChild(variable);\r
+                                               outputs.appendChild(output);\r
+                                       }\r
+                                       command.appendChild(outputs);\r
+                               }\r
+                       }\r
+               } catch (ParserConfigurationException e) {\r
+                       e.printStackTrace();\r
+               }\r
+\r
+               return document;\r
+       }\r
 }\r