/**
 * 
 */
package controls;

import org.apache.beehive.controls.api.bean.ControlImplementation;
import org.apache.xmlbeans.XmlOptions;
import org.openuri.temp.exampleApp.application.InternalApplicationDocument;


import java.io.File;
import java.io.FileWriter;
import java.io.Serializable;

/**
 * @author Administrator
 *
 */
@ControlImplementation
public class ApplicationFileImpl implements ApplicationFile, Serializable {
	private static final long serialVersionUID = 1L;
	
	public void createApplicationFile(String fileName, InternalApplicationDocument application)
    {
        try
        {
            String fileNamePath = "C:\\" + fileName;
            
            File newFile = new File(fileNamePath);
            
            if(!newFile.exists())
            {
                newFile.createNewFile();
            }
            
            FileWriter fw = new FileWriter(newFile);
            
            XmlOptions format = new XmlOptions();
            format.setSavePrettyPrint();
            format.setSavePrettyPrintIndent(2);
            
            fw.write(application.getInternalApplication().xmlText(format));
            
            fw.close();
        }
        catch(Exception e)
        {
            throw new RuntimeException(e);
        }
    }
}