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

📄 framework.java

📁 OSGI这是一个中间件,与UPNP齐名,是用于移植到嵌入式平台之上
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 2003-2004, KNOPFLERFISH project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following * conditions are met: * * - Redistributions of source code must retain the above copyright *   notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above *   copyright notice, this list of conditions and the following *   disclaimer in the documentation and/or other materials *   provided with the distribution. * * - Neither the name of the KNOPFLERFISH project nor the names of its *   contributors may be used to endorse or promote products derived *   from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */package org.knopflerfish.framework;import java.io.*;import java.net.*;import java.security.*;import java.util.Collection;import java.util.Set;import java.util.List;import java.util.ArrayList;import java.util.Map;import java.util.HashSet;import java.util.HashMap;import java.util.Iterator;import java.util.Dictionary;import java.util.Enumeration;import java.util.Vector;import java.util.Locale;import org.osgi.framework.*;import org.osgi.service.permissionadmin.PermissionAdmin;import org.osgi.service.packageadmin.PackageAdmin;import org.osgi.service.startlevel.StartLevel;/** * This class contains references to all common data structures * inside the framework. * * @author Jan Stein, Erik Wistrand */public class Framework {  /**   * Specification version for this framework.   */  static final String SPEC_VERSION = "1.2";  /**   * AdminPermission used for permission check.   */  final static AdminPermission ADMIN_PERMISSION = new AdminPermission();  /**   * Boolean indicating that framework is running.   */  boolean active;  /**   * Set during shutdown process.   */  boolean shuttingdown = false;  /**   * All bundle in this framework.   */  protected Bundles bundles;  /**   * All listeners in this framework.   */  Listeners listeners = new Listeners();  /**   * All exported and imported packages in this framework.   */  Packages packages;  /**   * All registered services in this framework.   */  Services services = new Services();  /**   * PermissionAdmin service   */  PermissionAdminImpl permissions = null;  /**   * indicates that we use security   */  boolean bPermissions = false;  /**   * System bundle   */  SystemBundle systemBundle;  BundleContextImpl systemBC;  /**   * Bundle Storage   */  BundleStorage storage;  /**   * Private Bundle Data Storage   */  FileTree dataStorage = null;  /**   * Main handle so that main does get GCed.   */  Object mainHandle;  /**   * The start level service.   */  StartLevelImpl                 startLevelService;  /**   * Factory for handling service-based URLs   */  ServiceURLStreamHandlerFactory urlStreamHandlerFactory;  /**   * Factory for handling service-based URL contents   */  ServiceContentHandlerFactory   contentHandlerFactory;  /**   * Magic handler for bundle: URLs   */  URLStreamHandler bundleURLStreamhandler;  /**   * Property constants for the framework.   */  final static String osArch    = System.getProperty("os.arch");  final static String osName    = System.getProperty("os.name");  final static String osVersion = System.getProperty("os.version");  // Some tests conflicts with the R3 spec. If testcompliant=true  // prefer the tests, not the spec  public final static boolean R3_TESTCOMPLIANT =    "true".equals(System.getProperty("org.knopflerfish.osgi.r3.testcompliant",				     "false"));  // If set to true, set the bundle startup thread's context class  // loader to the bundle class loader. This is useful for tests  // but shouldn't really be used in production.  final static boolean SETCONTEXTCLASSLOADER =    "true".equals(System.getProperty("org.knopflerfish.osgi.setcontextclassloader", "false"));  final static boolean REGISTERBUNDLEURLHANDLER =    "true".equals(System.getProperty("org.knopflerfish.osgi.registerbundleurlhandler", "false"));  final static boolean REGISTERSERVICEURLHANDLER =    "true".equals(System.getProperty("org.knopflerfish.osgi.registerserviceurlhandler", "true"));  // Accepted execution environments.   static String defaultEE = "CDC-1.0/Foundation-1.0,OSGi/Minimum-1.0";  static boolean bIsMemoryStorage = false;  /**   * Contruct a framework.   *   */  public Framework(Object m) throws Exception {    // guard this for profiles without System.setProperty     try {      System.setProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT, defaultEE);    } catch (Throwable e) {      if(Debug.packages) {	Debug.println("Failed to set execution environment: " + e);      }    }    String whichStorageImpl = "org.knopflerfish.framework.bundlestorage." +       System.getProperty("org.knopflerfish.framework.bundlestorage", "file") +      ".BundleStorageImpl";    bIsMemoryStorage = whichStorageImpl.equals("org.knopflerfish.framework.bundlestorage.memory.BundleStorageImpl");        // We just happens to know that the memory storage impl isn't R3    // compatible. And it never will be since it isn't persistent    // by design.    if(R3_TESTCOMPLIANT && bIsMemoryStorage) {      throw new RuntimeException("Memory bundle storage is not compatible " + 				 "with R3 complicance");    }    Class storageImpl = Class.forName(whichStorageImpl);    storage           = (BundleStorage)storageImpl.newInstance();    dataStorage       = Util.getFileStorage("data");    packages          = new Packages(this);    // guard this for profiles without Class.getProtectionDomain     ProtectionDomain pd = null;    if(System.getSecurityManager() != null) {      try {        pd = getClass().getProtectionDomain();      } catch (Throwable t) {        if(Debug.classLoader) {          Debug.println("Failed to get protection domain: " + t);        }      }    }    systemBundle      = new SystemBundle(this, pd);    systemBC          = new BundleContextImpl(systemBundle);    bundles           = new Bundles(this);    systemBundle.setBundleContext(systemBC);        if (System.getSecurityManager() != null) {      bPermissions = true;      permissions       = new PermissionAdminImpl(this);      String [] classes = new String [] { PermissionAdmin.class.getName() };      services.register(systemBundle,			classes,			permissions,			null);      Policy.setPolicy(new FrameworkPolicy(permissions));    }    String[] classes = new String [] { PackageAdmin.class.getName() };    services.register(systemBundle,		      classes,		      new PackageAdminImpl(this),		      null);    String useStartLevel =       System.getProperty("org.knopflerfish.startlevel.use", "true");    if("true".equals(useStartLevel)) {      if(Debug.startlevel) {	Debug.println("[using startlevel service]");      }      startLevelService = new StartLevelImpl(this);      // restoreState just reads from persistant storage      // open() needs to be called to actually do the work      // This is done after framework has been launched.      startLevelService.restoreState();            services.register(systemBundle,			new String [] { StartLevel.class.getName() },			startLevelService,			null);    }    mainHandle = m;    urlStreamHandlerFactory = new ServiceURLStreamHandlerFactory(this);    contentHandlerFactory   = new ServiceContentHandlerFactory(this);    bundleURLStreamhandler  = new BundleURLStreamHandler(bundles);    // Only register bundle: URLs publicly if explicitly told so    // Note: registering bundle: URLs exports way to much.     if(REGISTERBUNDLEURLHANDLER) {      urlStreamHandlerFactory        .setURLStreamHandler(BundleURLStreamHandler.PROTOCOL,                             bundleURLStreamhandler);    }    urlStreamHandlerFactory      .setURLStreamHandler(ReferenceURLStreamHandler.PROTOCOL,			   new ReferenceURLStreamHandler());        // Install service based URL stream handler. This can be turned    // off if there is need    if(REGISTERSERVICEURLHANDLER) {      try {        URL.setURLStreamHandlerFactory(urlStreamHandlerFactory);                URLConnection.setContentHandlerFactory(contentHandlerFactory);      } catch (Throwable e) {        Debug.println("Cannot set global URL handlers, continuing without OSGi service URL handler (" + e + ")");        e.printStackTrace();      }    }    bundles.load();  }  /**   * Start this Framework.   * This method starts all the bundles that were started at   * the time of the last shutdown.   *

⌨️ 快捷键说明

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