⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oldplatformcomponentsaccess.java

📁 eclipseme的最新版本的source,欢迎j2me程序员使用
💻 JAVA
字号:
/**
 * Copyright (c) 2003-2006 Craig Setera
 * All Rights Reserved.
 * Licensed under the Eclipse Public License - v 1.0
 * For more information see http://www.eclipse.org/legal/epl-v10.html
 */
package eclipseme.core.internal.migration;

import java.io.File;
import java.util.ArrayList;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import eclipseme.core.internal.EclipseMECorePlugin;
import eclipseme.core.internal.utils.XMLUtils;

/**
 * This class is a helper class for accessing the information in
 * the old (pre-1.5) platform components file.  This is used to 
 * recognize whether the file exists and to attempt to grab some
 * file system directories to be searched during the migration
 * processing.
 * <p />
 * Copyright (c) 2003-2006 Craig Setera<br>
 * All Rights Reserved.<br>
 * Licensed under the Eclipse Public License - v 1.0<p/>
 * <br>
 * $Revision: 1.1 $
 * <br>
 * $Date: 2006/03/06 00:55:13 $
 * <br>
 * @author Craig Setera
 */
public class OldPlatformComponentsAccess {

	/*
   <component delegate="eclipseme.core.model.impl.WirelessToolkit$WirelessToolkitPersistenceDelegate" componentID="sun.toolkit.2_3" pluginID="eclipseme.toolkit.sun" toolkitTypeId="eclipseme.toolkit.sun.impl.sunWTK" root="c:\software\toolkits\WTK23"/>
   <component delegate="eclipseme.core.model.impl.WirelessToolkit$WirelessToolkitPersistenceDelegate" componentID="SMTK_3.X" pluginID="eclipseme.toolkit.siemens" toolkitTypeId="eclipseme.toolkit.siemens.impl.SiemensWTK" root="C:\siemens\SMTK_3.X"/>
   <component delegate="eclipseme.core.model.impl.WirelessToolkit$WirelessToolkitPersistenceDelegate" componentID="sun.toolkit.2_2" pluginID="eclipseme.toolkit.sun" toolkitTypeId="eclipseme.toolkit.sun.impl.sunWTK" root="c:\software\toolkits\wtk22"/>
   <component delegate="eclipseme.core.model.impl.WirelessToolkit$WirelessToolkitPersistenceDelegate" componentID="se.toolkit.2_2_x" pluginID="eclipseme.toolkit.sonyericsson" toolkitTypeId="eclipseme.toolkit.sonyericsson.impl.SEWTK" root="c:\software\toolkits\sonyericsson"/>
   <component delegate="eclipseme.core.model.impl.WirelessToolkit$WirelessToolkitPersistenceDelegate" componentID="moto.toolkit.5.1" pluginID="eclipseme.toolkit.motorola" toolkitTypeId="eclipseme.toolkit.motorola.toolkitType" root="C:\Program Files\Motorola\SDK v5.1.2 for J2ME"/>
   <component delegate="eclipseme.core.model.impl.WirelessToolkit$WirelessToolkitPersistenceDelegate" componentID="nokia.toolkit" pluginID="eclipseme.toolkit.nokia" toolkitTypeId="eclipseme.toolkit.nokia.impl.NokiaWTK" root="C:\Nokia"/>
 */
	private static final String STATE_FILE = "platcomp.xml";
	private static final String ELEMENT_COMPONENT = "component";
	private static final String ATTR_DELEGATE = "delegate";
	private static final String ATTR_ROOT = "root";
	private static final String ATTR_DELEGATE_MATCH = 
		"eclipseme.core.model.impl.WirelessToolkit$WirelessToolkitPersistenceDelegate";
	
	private File storeFile;
	
	/**
	 * Construct a new helper class
	 */
	public OldPlatformComponentsAccess() {
		super();
	}
	
	/**
	 * Return the file system roots that are referenced within
	 * the old platform components store file.
	 * 
	 * @return
	 */
	public String[] getRoots() {
		String[] roots = null;
		
		if (storeFileExists()) {
			roots = readRoots();
		} else {
			roots = new String[0];
		}
		
		return roots;
	}

	/**
	 * Return a boolean indicating whether the component store file exists.
	 * 
	 * @return
	 */
	public boolean storeFileExists() {
		return getComponentStoreFile().exists();
	}
	
	/**
	 * Get the file of the old platform component store.
	 * 
	 * @return
	 */
	private File getComponentStoreFile()
	{
		if (storeFile == null) {
			IPath pluginStatePath = EclipseMECorePlugin.getDefault().getStateLocation();
			IPath storePath = pluginStatePath.append(STATE_FILE);
			
			storeFile = storePath.toFile();
		}
		
		return storeFile;
	}

	/**
	 * Find the roots in the platform components document.
	 * 
	 * @param document
	 * @return
	 */
	private String[] findRoots(Document document) {
		ArrayList roots = new ArrayList();
		
		NodeList components = document.getElementsByTagName(ELEMENT_COMPONENT);
		for (int i = 0; i < components.getLength(); i++) {
			Element element = (Element) components.item(i);
			String delegate = element.getAttribute(ATTR_DELEGATE); 
			if (ATTR_DELEGATE_MATCH.equals(delegate)) {
				String root = element.getAttribute(ATTR_ROOT);
				if ((root != null) && (root.length() > 0)) {
					roots.add(root);
				}
			}
		}
		
		return (String[]) roots.toArray(new String[roots.size()]);
	}

	/**
	 * Read and return the referenced roots from the old components file.
	 * 
	 * @return
	 */
	private String[] readRoots() {
		String[] roots = null;
		
		// The lazy implementation, using an XML document instead of SAX
		File store = getComponentStoreFile();
		try {
			Document document = XMLUtils.readDocument(store);
			roots = findRoots(document);
		} catch (Exception e) {
			EclipseMECorePlugin.log(IStatus.WARNING, "Error reading old component store", e);
		}
		
		return roots;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -