| //------------------------------------------------------------------------------ |
| // Copyright (c) 2005, 2006 IBM Corporation and others. |
| // All rights reserved. This program and the accompanying materials |
| // are made available under the terms of the Eclipse Public License v1.0 |
| // which accompanies this distribution, and is available at |
| // http://www.eclipse.org/legal/epl-v10.html |
| // |
| // Contributors: |
| // IBM Corporation - initial implementation |
| //------------------------------------------------------------------------------ |
| package org.eclipse.epf.importing.services; |
| |
| import java.io.File; |
| |
| import org.eclipse.core.runtime.IProgressMonitor; |
| import org.eclipse.epf.export.services.LibraryDocument; |
| import org.eclipse.epf.importing.ImportPlugin; |
| import org.eclipse.epf.importing.ImportResources; |
| import org.eclipse.epf.library.services.LibraryProcessor; |
| import org.eclipse.epf.library.util.LibraryUtil; |
| |
| import com.ibm.uma.MethodLibrary; |
| |
| /** |
| * Imports a library configuration. |
| * |
| * @author Jinhua Xi |
| * @since 1.0 |
| */ |
| public class ConfigurationImportService { |
| |
| private ConfigurationImportData data; |
| |
| LibraryDocument importingLibDoc = null; |
| |
| LibraryDiffManager diffMgr = null; |
| |
| ConfigSpecsImportManager specsMgr = null; |
| |
| public ConfigurationImportService(ConfigurationImportData data) { |
| this.data = data; |
| } |
| |
| public void analyze(IProgressMonitor monitor) { |
| try { |
| if (monitor != null) { |
| monitor.setTaskName(ImportResources |
| .getString("Import.ConfigurationImportService.MSG0")); //$NON-NLS-1$ |
| } |
| |
| data.getErrorInfo().clear(); |
| |
| // Prepare the library files. |
| String path = data.llData.getParentFolder(); |
| if (path.indexOf(File.separator + LibraryDocument.libraryFile) < 0) { |
| path += File.separator + LibraryDocument.libraryFile; |
| } |
| File importingLibPath = new File(path); |
| if (!importingLibPath.exists()) { |
| importingLibPath = new File(importingLibPath.getParentFile(), |
| LibraryDocument.exportFile); |
| } |
| |
| if (!importingLibPath.exists()) { |
| data |
| .getErrorInfo() |
| .addError( |
| ImportResources |
| .getString( |
| "Import.ConfigurationImportService.MSG1", importingLibPath.getParent())); //$NON-NLS-1$ |
| return; |
| } |
| |
| importingLibDoc = new LibraryDocument(importingLibPath); |
| |
| boolean isConfigSpecs = importingLibDoc.isConfigSpecsOnly(); |
| |
| if (isConfigSpecs) { |
| |
| specsMgr = new ConfigSpecsImportManager(); |
| |
| // Scan the library file for configuration information. |
| data.specs = specsMgr.getConfigSpecs(importingLibDoc); |
| |
| } else { |
| data.specs = null; |
| |
| // Open the library and compare the difference. |
| MethodLibrary importLibraty = LibraryUtil |
| .loadLibrary(importingLibPath.getAbsolutePath()); |
| MethodLibrary baseLibrary = LibraryProcessor.getInstance() |
| .getLibrary(); |
| |
| diffMgr = new LibraryDiffManager(baseLibrary, importLibraty); |
| diffMgr.buildDiffTree(); |
| } |
| } catch (Exception ex) { |
| ex.printStackTrace(); |
| } |
| |
| } |
| |
| public ConfigurationImportData getImportData() { |
| return data; |
| } |
| |
| public boolean isSpecsOnly() { |
| return (data.specs != null); |
| } |
| |
| public ElementDiffTree getDiffTree() { |
| return diffMgr.getDiffTree(); |
| } |
| |
| public MethodLibrary getImportingLibrary() { |
| return diffMgr.getImportingLibrary(); |
| } |
| |
| public void performImport(final IProgressMonitor monitor) { |
| try { |
| if (monitor != null) { |
| monitor.setTaskName(ImportResources |
| .getString("Import.ConfigurationImportService.MSG3")); //$NON-NLS-1$ |
| } |
| |
| if (isSpecsOnly()) { |
| specsMgr.doImport(data.specs); |
| } else { |
| LibraryImportManager importingMgr = new LibraryImportManager( |
| diffMgr.getDiffTree(), diffMgr.getDiffTreeMap(), |
| data.importList); |
| |
| importingMgr.doMerge(data.replaceExisting); |
| } |
| |
| // Reopen the library. |
| File libFile = new File(LibraryProcessor.getInstance() |
| .getLibraryURI().toFileString()); |
| LibraryProcessor.getInstance().openLibrary( |
| libFile.getAbsolutePath()); |
| |
| } catch (Exception e) { |
| ImportPlugin.getDefault().getLogger().logError(e); |
| } |
| } |
| |
| } |