Search in sources :

Example 1 with ResourceFileMap

use of org.talend.dq.helper.resourcehelper.ResourceFileMap in project tdq-studio-se by Talend.

the class UpdatePropertiesFileTask method doExecute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataprofiler.core.migration.AMigrationTask#doExecute()
     */
@Override
protected boolean doExecute() throws Exception {
    boolean ok = true;
    EMFUtil emfUtil = new EMFUtil();
    for (File file : fileList) {
        if (file.isFile()) {
            URI uri = URI.createFileURI(file.getAbsolutePath());
            if (log.isDebugEnabled()) {
                // $NON-NLS-1$
                log.debug("---------Translate " + uri.toString());
            }
            EObject eObject = null;
            try {
                Resource resource = emfUtil.getResourceSet().getResource(uri, true);
                ResourceFileMap resourceFileMap = ModelElementFileFactory.getResourceFileMap(uri.fileExtension());
                if (resourceFileMap != null) {
                    eObject = resourceFileMap.getModelElement(resource);
                }
            } catch (Exception e) {
                // $NON-NLS-1$
                log.warn(DefaultMessagesImpl.getString("UpdatePropertiesFileTask_2", file.getAbsolutePath()), e);
                ok = false;
            }
            if (eObject != null) {
                if (eObject instanceof ModelElement) {
                    try {
                        saveObject(emfUtil, file, uri, eObject);
                    } catch (Exception e) {
                        // $NON-NLS-1$
                        log.error(DefaultMessagesImpl.getString("UpdatePropertiesFileTask_3", eObject, file, uri), e);
                        ok = false;
                    }
                } else {
                    // $NON-NLS-1$
                    log.warn(DefaultMessagesImpl.getString("UpdatePropertiesFileTask_4", eObject.toString()));
                    ok = false;
                }
            }
        }
    }
    emfUtil = null;
    return ok;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) EMFUtil(org.talend.commons.emf.EMFUtil) ResourceFileMap(org.talend.dq.helper.resourcehelper.ResourceFileMap) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) File(java.io.File) URI(org.eclipse.emf.common.util.URI)

Aggregations

File (java.io.File)1 URI (org.eclipse.emf.common.util.URI)1 EObject (org.eclipse.emf.ecore.EObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 EMFUtil (org.talend.commons.emf.EMFUtil)1 ResourceFileMap (org.talend.dq.helper.resourcehelper.ResourceFileMap)1 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)1