Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2013 Cloudera Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.kitesdk.maven.plugins;
 
 import java.io.File;
 import java.io.Writer;
 
 
   private final String encoding;
 
   private static final String WORKFLOW_ELEMENT = "workflow-app";
 
   WorkflowXmlWriter(String encoding) {
     this. = encoding;
   }
 
   protected Writer initializeWriter(final File destinationFilethrows
       MojoExecutionException {
     try {
       return WriterFactory.newXmlWriter(destinationFile);
     } catch (IOException e) {
       throw new MojoExecutionException("Exception while opening file[" +
           destinationFile.getAbsolutePath() + "]"e);
     }
   }
 
   protected XMLWriter initializeXmlWriter(final Writer writerfinal String docType) {
     return new PrettyPrintXMLWriter(writerdocType);
   }
 
   protected void write(Workflow workflowthrows MojoExecutionException {
     Writer w = initializeWriter(workflow.getDestinationFile());
     XMLWriter writer = initializeRootElement(wworkflow.getSchemaVersion(),
         workflow.getName());
 
     appendStart(writer);
     appendJavaAction(writerworkflow);
     appendKill(writer);
     appendEnd(writer);
 
     writer.endElement();
     close(w);
   }
 
   private XMLWriter initializeRootElement(Writer wString schemaVersion,
       String workflowName) {
     XMLWriter writer = initializeXmlWriter(wnull);
     writer.startElement();
     writer.addAttribute("xmlns""uri:oozie:workflow:" + schemaVersion);
     writer.addAttribute("name"workflowName);
     return writer;
   }
 
   private void appendStart(XMLWriter writer) {
     writer.startElement("start");
     writer.addAttribute("to""java-node");
     writer.endElement();
   }
 
   private void appendJavaAction(XMLWriter writerWorkflow workflowthrows
       MojoExecutionException {
     Properties hadoopConfiguration = workflow.getHadoopConfiguration();
 
     writer.startElement("action");
     writer.addAttribute("name""java-node");
 
     writer.startElement("java");
     doWriteElement(writer"job-tracker""${" + . + "}");
     doWriteElement(writer"name-node""${" + . + "}");
     doWriteElement(writer"main-class"workflow.getToolClass());
     for (String key : hadoopConfiguration.stringPropertyNames()) {
       String value = hadoopConfiguration.getProperty(key);
       doWriteElement(writer"arg""-D");
       doWriteElement(writer"arg"key + "=" + value);
     }
     if (!workflow.getLibJars().isEmpty()) {
       doWriteElement(writer"arg""-libjars");
      doWriteElement(writer"arg", Joiner.on(',').join(workflow.getLibJars()));
    }
    String[] args = workflow.getArgs();
    if (args != null) {
      for (String arg : args) {
        doWriteElement(writer"arg"arg);
      }
    }
    writer.endElement();
    doWriteElement(writer"ok""to""end");
    doWriteElement(writer"error""to""fail");
    writer.endElement();
  }
  private void appendKill(XMLWriter writer) {
    writer.startElement("kill");
    writer.addAttribute("name""fail");
    doWriteElement(writer"message""Java failed, error message[${wf:errorMessage(wf:lastErrorNode())}]");
    writer.endElement();
  }
  private void appendEnd(XMLWriter writer) {
    writer.startElement("end");
    writer.addAttribute("name""end");
    writer.endElement();
  }
  private void doWriteElement(XMLWriter writerString elementString attributeName,
      String attributeValue) {
    writer.startElement(element);
    writer.addAttribute(attributeNameattributeValue);
    writer.endElement();
  }
  private void doWriteElement(XMLWriter writerString elementString text) {
    writer.startElement(element);
    writer.writeText(text);
    writer.endElement();
  }
  protected void close(Writer closeable) {
    IOUtils.closeQuietly(closeable);
  }
New to GrepCode? Check out our FAQ X