| //------------------------------------------------------------------------------ |
| // Copyright (c) 2005, 2007 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.library.xmi.internal.migration; |
| |
| import java.io.File; |
| import java.util.Map; |
| |
| import org.eclipse.core.runtime.IProgressMonitor; |
| import org.eclipse.emf.ecore.xmi.XMLResource; |
| import org.eclipse.epf.library.edit.util.ExtensionManager; |
| import org.eclipse.epf.library.util.ResourceUtil; |
| import org.eclipse.epf.library.xmi.IDiagramMigration; |
| import org.eclipse.epf.persistence.MultiFileResourceSetImpl; |
| import org.eclipse.epf.persistence.migration.MigrationUtil; |
| import org.eclipse.epf.persistence.migration.UpgradeCallerInfo; |
| import org.eclipse.epf.persistence.util.PersistenceResources; |
| import org.eclipse.epf.uma.MethodElement; |
| import org.eclipse.epf.uma.MethodLibrary; |
| |
| /** |
| * @author Weiping Lu - Feb 12, 2007 |
| * @since 1.2 |
| */ |
| public class Migrator103 extends MigratorBase { |
| |
| public void migrate(String libPath, IProgressMonitor monitor) throws Exception { |
| migrate(libPath, monitor, null); |
| } |
| |
| public void migrate(String libPath, IProgressMonitor monitor, UpgradeCallerInfo info) throws Exception { |
| File libFile = new File(libPath); |
| |
| ResourceUtil.open(libFile.getParent(), monitor); |
| |
| MultiFileResourceSetImpl resourceSet = null; |
| try { |
| // load the library |
| // |
| updateStatus(monitor, PersistenceResources.loadLibraryTask_name); |
| |
| resourceSet = new MultiFileResourceSetImpl(false); |
| |
| resourceSet.getLoadOptions().put( |
| XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE); |
| |
| MethodLibrary lib = resourceSet.loadLibrary(libPath); |
| |
| // load all elements in memory |
| // |
| updateStatus(monitor, PersistenceResources.loadResourcesTask_name); |
| |
| updateAllContents(monitor, lib); |
| |
| // To do here: |
| // Call GMF diagram API to convert diagram data |
| |
| IDiagramMigration idm = (IDiagramMigration) ExtensionManager.getExtension("org.eclipse.epf.library.xmi", "diagramMigration"); //$NON-NLS-1$ //$NON-NLS-2$ |
| if (idm != null) { |
| idm.test(); |
| } |
| |
| // save all files |
| // |
| updateStatus(monitor, PersistenceResources.saveLibraryTask_name); |
| Map saveOptions = resourceSet.getDefaultSaveOptions(); |
| resourceSet.save(saveOptions, true); |
| |
| updateStatus(monitor, |
| PersistenceResources.refreshLibraryFilesTask_name); |
| ResourceUtil.refreshResources(lib, monitor); |
| } finally { |
| if (resourceSet != null) { |
| resourceSet.reset(); |
| resourceSet = null; |
| } |
| } |
| |
| } |
| |
| protected void updateElement(MethodElement element, IProgressMonitor monitor) throws Exception { |
| MigrationUtil.formatValue(element); |
| } |
| |
| } |