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
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
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