Search in sources :

Example 1 with XMLInterface

use of org.pentaho.di.core.xml.XMLInterface in project pentaho-kettle by pentaho.

the class KettleFileRepository method save.

public void save(RepositoryElementInterface repositoryElement, String versionComment, ProgressMonitorListener monitor, ObjectId parentId, boolean used) throws KettleException {
    try {
        if (!(repositoryElement instanceof XMLInterface) && !(repositoryElement instanceof SharedObjectInterface)) {
            throw new KettleException("Class [" + repositoryElement.getClass().getName() + "] needs to implement the XML Interface in order to save it to disk");
        }
        if (!Utils.isEmpty(versionComment)) {
            insertLogEntry("Save repository element : " + repositoryElement.toString() + " : " + versionComment);
        }
        ObjectId objectId = new StringObjectId(calcObjectId(repositoryElement));
        FileObject fileObject = getFileObject(repositoryElement);
        String xml = ((XMLInterface) repositoryElement).getXML();
        OutputStream os = KettleVFS.getOutputStream(fileObject, false);
        os.write(xml.getBytes(Const.XML_ENCODING));
        os.close();
        if (repositoryElement instanceof ChangedFlagInterface) {
            ((ChangedFlagInterface) repositoryElement).clearChanged();
        }
        // 
        if (repositoryElement.getObjectId() != null && !repositoryElement.getObjectId().equals(objectId)) {
            delObject(repositoryElement.getObjectId());
        }
        repositoryElement.setObjectId(objectId);
        // 
        if (repositoryElement instanceof TransMeta) {
            ((TransMeta) repositoryElement).saveMetaStoreObjects(this, metaStore);
        }
        if (repositoryElement instanceof JobMeta) {
            ((JobMeta) repositoryElement).saveMetaStoreObjects(this, metaStore);
        }
    } catch (Exception e) {
        throw new KettleException("Unable to save repository element [" + repositoryElement + "] to XML file : " + calcFilename(repositoryElement), e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) ChangedFlagInterface(org.pentaho.di.core.changed.ChangedFlagInterface) OutputStream(java.io.OutputStream) TransMeta(org.pentaho.di.trans.TransMeta) SharedObjectInterface(org.pentaho.di.shared.SharedObjectInterface) FileObject(org.apache.commons.vfs2.FileObject) XMLInterface(org.pentaho.di.core.xml.XMLInterface) StringObjectId(org.pentaho.di.repository.StringObjectId) KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileSystemException(org.apache.commons.vfs2.FileSystemException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 FileObject (org.apache.commons.vfs2.FileObject)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 ChangedFlagInterface (org.pentaho.di.core.changed.ChangedFlagInterface)1 KettleException (org.pentaho.di.core.exception.KettleException)1 KettleFileException (org.pentaho.di.core.exception.KettleFileException)1 XMLInterface (org.pentaho.di.core.xml.XMLInterface)1 JobMeta (org.pentaho.di.job.JobMeta)1 ObjectId (org.pentaho.di.repository.ObjectId)1 StringObjectId (org.pentaho.di.repository.StringObjectId)1 SharedObjectInterface (org.pentaho.di.shared.SharedObjectInterface)1 TransMeta (org.pentaho.di.trans.TransMeta)1