Search in sources :

Example 1 with CategorySwitch

use of org.talend.dataquality.analysis.category.util.CategorySwitch in project tdq-studio-se by Talend.

the class CategoryHandler method loadFromFile.

/**
 * DOC bZhou Comment method "loadFromFile".
 *
 * @return
 */
private static AnalysisCategories loadFromFile() {
    EMFUtil util = new EMFUtil();
    // $NON-NLS-1$
    String pathName = "/org.talend.cwm.management/My.category";
    URI uri = URI.createPlatformPluginURI(pathName, false);
    Resource catFile = null;
    try {
        catFile = util.getResourceSet().getResource(uri, true);
    } catch (RuntimeException e) {
        log.error(e.getMessage());
    }
    if (catFile == null) {
        // try to load from a local file
        // $NON-NLS-1$
        catFile = util.getResourceSet().getResource(URI.createFileURI(".." + File.separator + pathName), true);
    }
    if (catFile == null) {
        // $NON-NLS-1$
        log.error(Messages.getString("CategoryHandler.NORESOUTCEFOUND", pathName, uri));
        return null;
    }
    EList<EObject> contents = catFile.getContents();
    if (contents == null) {
        // $NON-NLS-1$
        log.error(Messages.getString("CategoryHandler.NOCATALOGFOUND", uri));
        return null;
    }
    CategorySwitch<AnalysisCategories> catSwitch = new CategorySwitch<AnalysisCategories>() {

        @Override
        public AnalysisCategories caseAnalysisCategories(AnalysisCategories object) {
            return object;
        }
    };
    return catSwitch.doSwitch(contents.get(0));
}
Also used : EMFUtil(org.talend.commons.emf.EMFUtil) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) AnalysisCategories(org.talend.dataquality.analysis.category.AnalysisCategories) CategorySwitch(org.talend.dataquality.analysis.category.util.CategorySwitch) URI(org.eclipse.emf.common.util.URI)

Aggregations

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 AnalysisCategories (org.talend.dataquality.analysis.category.AnalysisCategories)1 CategorySwitch (org.talend.dataquality.analysis.category.util.CategorySwitch)1