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

📄 libraryimporter.java

📁 eclipseme的最新版本的source,欢迎j2me程序员使用
💻 JAVA
字号:
/**
 * Copyright (c) 2003-2005 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.importer;

import java.io.File;

import org.eclipse.jdt.core.IAccessRule;

import eclipseme.core.model.API;
import eclipseme.core.model.APIType;
import eclipseme.core.model.ILibrary;
import eclipseme.core.model.Version;
import eclipseme.core.model.impl.Library;

/**
 * A helper class for the importing of a Library instance
 * based on a java.io.File.
 * <p />
 * Copyright (c) 2003-2005 Craig Setera<br>
 * All Rights Reserved.<br>
 * Licensed under the Eclipse Public License - v 1.0<p/>
 * <br>
 * $Revision: 1.3 $
 * <br>
 * $Date: 2006/12/01 23:59:39 $
 * <br>
 * @author Craig Setera
 */
public class LibraryImporter {
	// A list of API import helpers.
	// This list is currently static, but may be extended via
	// extension point in the future.
	private static final 
	ILibraryAPIImportHelper[] API_HELPERS = new ILibraryAPIImportHelper[] {
		new LibraryManifestAPIImportHelper(),
		new GuessingAPIImportHelper(),
	};
	
	/**
	 * Construct a new library importer.
	 */
	public LibraryImporter() {
		super();
	}

	/**
	 * Construct and return a new Library instance for the specified 
	 * library file.
	 * 
	 * @param libraryFile the file to be wrapped up as a library.
	 * @return the newly created library wrapper
	 */
	public ILibrary createLibraryFor(File libraryFile) {
		API[] apis = calculateAPIs(libraryFile);

		Library library = new Library();
		library.setApis(apis);
		library.setLibraryFile(libraryFile);
		
		return library;
	}

	/**
	 * Construct and return a new Library instance for the specified 
	 * library file with the provided access rules.
	 * 
	 * @param libraryFile
	 * @param accessRules
	 * @return
	 */
	public ILibrary createLibraryFor(File libraryFile, IAccessRule[] accessRules) {
		API[] apis = calculateAPIs(libraryFile);

		Library library = new Library();
		library.setAccessRules(accessRules);
		library.setApis(apis);
		library.setLibraryFile(libraryFile);
		
		return library;
	}
	
	/**
	 * Calculate the API associated with this library file.
	 * 
	 * @param libraryFile
	 * @return
	 */
	private API[] calculateAPIs(File libraryFile) {
		API[] apis = null;
		
		// Run through the available helpers
		for (int i = 0; (apis == null) && (i < API_HELPERS.length); i++) {
			ILibraryAPIImportHelper apiHelper = API_HELPERS[i];
			apis = apiHelper.getAPIs(libraryFile);
		}
		
		if (apis == null) {
			// Fall back to an unknown library
			apis = new API[] { createUnknownAPI(libraryFile) };
		}
		
		return apis;
	}
	
	/**
	 * Return a new unknown API instance.
	 * 
	 * @param libraryFile
	 * @return
	 */
	private API createUnknownAPI(File libraryFile) {
		API api = new API();
		api.setIdentifier(libraryFile.getName());
		api.setName("Unknown Library");
		api.setType(APIType.UNKNOWN);
		api.setVersion(new Version("1.0"));
		
		return api;
	}
}

⌨️ 快捷键说明

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