Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2003, 2010 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 API and implementation /
  
  package org.eclipse.osgi.framework.internal.core;
  
  import java.io.*;
  import java.net.*;
  import java.security.*;
  import java.util.*;
Core OSGi Framework class.
  
  public class Framework implements EventDispatcherEventPublisherRunnable {
  	// System property used to set the context classloader parent classloader type (ccl is the default)
  	private static final String PROP_CONTEXTCLASSLOADER_PARENT = "osgi.contextClassLoaderParent"//$NON-NLS-1$
  	private static final String CONTEXTCLASSLOADER_PARENT_APP = "app"//$NON-NLS-1$
  	private static final String CONTEXTCLASSLOADER_PARENT_EXT = "ext"//$NON-NLS-1$
  	private static final String CONTEXTCLASSLOADER_PARENT_BOOT = "boot"//$NON-NLS-1$
  	private static final String CONTEXTCLASSLOADER_PARENT_FWK = "fwk"//$NON-NLS-1$
  
  	public static final String PROP_FRAMEWORK_THREAD = "osgi.framework.activeThreadType"//$NON-NLS-1$
  	public static final String THREAD_NORMAL = "normal"//$NON-NLS-1$
  	public static final String PROP_EQUINOX_SECURITY = "eclipse.security"//$NON-NLS-1$
  	public static final String SECURITY_OSGI = "osgi"//$NON-NLS-1$
  
  	private static String J2SE = "J2SE-"//$NON-NLS-1$
  	private static String JAVASE = "JavaSE-"//$NON-NLS-1$
  	private static String PROFILE_EXT = ".profile"//$NON-NLS-1$
  	
FrameworkAdaptor specific functions.
  
  	protected FrameworkAdaptor adaptor;
Framework properties object. A reference to the System.getProperies() object. The properties from the adaptor will be merged into these properties.
  
  	protected Properties properties;
Has the framework been started
  
  	protected boolean active;
Event indicating the reason for shutdow
  
  	private FrameworkEvent[] shutdownEvent;
The bundles installed in the framework
  
  	protected BundleRepository bundles;
Package Admin object. This object manages the exported packages.
  
  	protected PackageAdminImpl packageAdmin;
PermissionAdmin and ConditionalPermissionAdmin impl. This object manages the bundle permissions.
  
  	protected SecurityAdmin securityAdmin;
Startlevel object. This object manages the framework and bundle startlevels
  
The ServiceRegistry
  
  
  	/*
  	 * The following EventListeners objects keep track of event listeners
  	 * by BundleContext.  Each element is a EventListeners that is the list
  	 * of event listeners for a particular BundleContext.  The max number of
  	 * elements each of the following lists will have is the number of bundles
  	 * installed in the Framework.
  	 */
List of BundleContexts for bundle's BundleListeners.
  
  	protected Map bundleEvent;
  	protected static final int BUNDLEEVENT = 1;
List of BundleContexts for bundle's SynchronousBundleListeners.
  
  	protected Map bundleEventSync;
  	protected static final int BUNDLEEVENTSYNC = 2;
  	/* SERVICEEVENT(3) is now handled by ServiceRegistry */
List of BundleContexts for bundle's FrameworkListeners.
  
  	protected Map frameworkEvent;
  	protected static final int FRAMEWORKEVENT = 4;
  	protected static final int BATCHEVENT_BEGIN = . + 1;
  	protected static final int BATCHEVENT_END = .;
EventManager for event delivery.
  
 	/* Reservation object for install synchronization */
 	protected Hashtable installLock;
System Bundle object
 
 	private String[] bootDelegation;
 	private boolean bootDelegateAll = false;
 	public final boolean contextBootDelegation = "true".equals(FrameworkProperties.getProperty("osgi.context.bootdelegation""true")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 	public final boolean compatibiltyBootDelegation = "true".equals(FrameworkProperties.getProperty(."true")); //$NON-NLS-1$ //$NON-NLS-2$
 	private volatile boolean forcedRestart = false;
The AliasMapper used to alias OS Names.
 
 	protected static AliasMapper aliasMapper = new AliasMapper();
 	SecureAction secureAction = (SecureAction) AccessController.doPrivileged(SecureAction.createSecureAction());
 	// cache of AdminPermissions keyed by Bundle ID
 	private HashMap adminPermissions = new HashMap();
 
 	// we need to hold these so that we can unregister them at shutdown
 
 	private volatile ServiceTracker signedContentFactory;
 	private volatile ContextFinder contextFinder;
 
 	/* 
 	 * We need to make sure that the GetDataFileAction class loads early to prevent a ClassCircularityError when checking permissions.
 	 * see bug 161561
 	 */
 	static {
 		Class c;
 		c = GetDataFileAction.class;
 		c.getName(); // to prevent compiler warnings
 	}
 
 	static class GetDataFileAction implements PrivilegedAction {
 		private String filename;
 
 		public GetDataFileAction(AbstractBundle bundleString filename) {
 			this. = bundle;
 			this. = filename;
 		}
 
 		public Object run() {
 		}
 	}

Constructor for the Framework instance. This method initializes the framework to an unlaunched state.
 
 	public Framework(FrameworkAdaptor adaptor) {
 		initialize(adaptor);
 	}

Initialize the framework to an unlaunched state. This method is called by the Framework constructor.
 
 	protected void initialize(FrameworkAdaptor adaptor) {
 			Profile.logEnter("Framework.initialze()"null); //$NON-NLS-1$
 		long start = System.currentTimeMillis();
 		this. = adaptor;
 		 = adaptor instanceof BaseAdaptor ? ((BaseAdaptoradaptor).getHookRegistry().getClassLoaderDelegateHooks() : null;
 		 = false;
 			Debug.println("SecurityManager: " + System.getSecurityManager()); //$NON-NLS-1$
 			Debug.println("ProtectionDomain of Framework.class: \n" + this.getClass().getProtectionDomain()); //$NON-NLS-1$
 		}
 		// initialize ContextFinder
 		/* initialize the adaptor */
 		adaptor.initialize(this);
 			Profile.logTime("Framework.initialze()""adapter initialized"); //$NON-NLS-1$//$NON-NLS-2$
 		try {
 			adaptor.initializeStorage();
 		} catch (IOException e/* fatal error */{
 			throw new RuntimeException(e.getMessage(), e);
 		}
 			Profile.logTime("Framework.initialze()""adapter storage initialized"); //$NON-NLS-1$//$NON-NLS-2$
 		/*
 		 * This must be done before calling any of the framework getProperty
 		 * methods.
 		 */
 		/* initialize admin objects */
 		try {
 			// always create security admin even with security off
 			 = new SecurityAdmin(nullthisadaptor.getPermissionStorage());
 		} catch (IOException e/* fatal error */{
 			throw new RuntimeException(e.getMessage(), e);
 		}
 			Profile.logTime("Framework.initialze()""done init props & new PermissionAdminImpl"); //$NON-NLS-1$//$NON-NLS-2$
 		/* create the event manager and top level event dispatchers */
 		 = new EventManager("Framework Event Dispatcher"); //$NON-NLS-1$
 			Profile.logTime("Framework.initialze()""done new EventManager"); //$NON-NLS-1$ //$NON-NLS-2$
 		/* create the service registry */
 		// Initialize the installLock; there is no way of knowing 
 		// what the initial size should be, at most it will be the number
 		// of threads trying to install a bundle (probably a very low number).
 		 = new Hashtable(10);
 		/* create the system bundle */
 		loadVMProfile(); // load VM profile after the system bundle has been created
 		setBootDelegation(); //set boot delegation property after system exports have been set
 			Profile.logTime("Framework.initialze()""done createSystemBundle"); //$NON-NLS-1$ //$NON-NLS-2$
 		/* install URLStreamHandlerFactory */
 		/* install ContentHandlerFactory for OSGi URLStreamHandler support */
 			Profile.logTime("Framework.initialze()""done new URLStream/Content HandlerFactory"); //$NON-NLS-1$//$NON-NLS-2$
 		/* create bundle objects for all installed bundles. */
 		BundleData[] bundleDatas = adaptor.getInstalledBundles();
 		 = new BundleRepository(bundleDatas == null ? 10 : bundleDatas.length + 1);
 		/* add the system bundle to the Bundle Repository */
 		if (bundleDatas != null) {
 			for (int i = 0; i < bundleDatas.lengthi++) {
 				try {
 					AbstractBundle bundle = AbstractBundle.createBundle(bundleDatas[i], thistrue);
 					.add(bundle);
 				} catch (BundleException be) {
 					// This is not a fatal error. Publish the framework event.
 				}
 			}
 		}
 			..println("Initialize the framework: " + (System.currentTimeMillis() - start)); //$NON-NLS-1$
 			Profile.logExit("Framework.initialize()"); //$NON-NLS-1$
 	}
 
 		return ;
 	}
 
 		return ;
 	}
 
 		return ;
 	}
 
 	private void setNLSFrameworkLog() {
 		try {
 			Field frameworkLogField = NLS.class.getDeclaredField("frameworkLog"); //$NON-NLS-1$
 			frameworkLogField.setAccessible(true);
 			frameworkLogField.set(null.getFrameworkLog());
 		} catch (Exception e) {
 		}
 	}
 
 	private void createSystemBundle() {
 		try {
 		} catch (BundleException e) { // fatal error
 		}
 	}

Initialize the System properties by copying properties from the adaptor properties object. This method is called by the initialize method.
 
 	protected void initializeProperties(Properties adaptorProperties) {
 		 = FrameworkProperties.getProperties();
 		Enumeration enumKeys = adaptorProperties.propertyNames();
 		while (enumKeys.hasMoreElements()) {
 			String key = (StringenumKeys.nextElement();
 			if (.getProperty(key) == null) {
 				.put(keyadaptorProperties.getProperty(key));
 			}
 		}
 		if (value == null) {
 			if (value != null) {
 			}
 		}
 		if (value == null) {
 			try {
 				String canonicalValue = (String.aliasOSName(value);
 				if (canonicalValue != null) {
 					value = canonicalValue;
 				}
 			} catch (ClassCastException ex) {
 				//A vector was returned from the alias mapper.
 				//The alias mapped to more than one canonical value
 				//such as "win32" for example
 			}
 			if (value != null) {
 			}
 		}
 		if (value == null) {
 			if (value != null) {
 				// only use the value upto the first space
 				int space = value.indexOf(' ');
 				if (space > 0) {
 					value = value.substring(0, space);
 				}
 				// fix up cases where the os version does not make a valid Version string.
 				int major = 0, minor = 0, micro = 0;
 				String qualifier = ""//$NON-NLS-1$
 				try {
 					StringTokenizer st = new StringTokenizer(value"."true); //$NON-NLS-1$
 					major = parseVersionInt(st.nextToken());
 
 					if (st.hasMoreTokens()) {
 						st.nextToken(); // consume delimiter
 						minor = parseVersionInt(st.nextToken());
 
 						if (st.hasMoreTokens()) {
 							st.nextToken(); // consume delimiter
 							micro = parseVersionInt(st.nextToken());
 
 							if (st.hasMoreTokens()) {
 								st.nextToken(); // consume delimiter
 								qualifier = st.nextToken();
 							}
 						}
 					}
 				} catch (NoSuchElementException e) {
 					// ignore, use the values parsed so far
 				}
 				try {
 					value = new Version(majorminormicroqualifier).toString();
 				} catch (IllegalArgumentException e) {
 					// must be an invalid qualifier; just ignore it
 					value = new Version(majorminormicro).toString();
 				}
 			}
 		}
 		if (value == null)
 			// set the value of the framework language property
 		// set the support properties for fragments and require-bundle (bug 173090)
 	}
 
 	private int parseVersionInt(String value) {
 		try {
 			return Integer.parseInt(value);
 		} catch (NumberFormatException e) {
 			// try up to the first non-number char
 			StringBuffer sb = new StringBuffer(value.length());
 			char[] chars = value.toCharArray();
 			for (int i = 0; i < chars.lengthi++) {
 				if (!Character.isDigit(chars[i]))
 					break;
 				sb.append(chars[i]);
 			}
 			if (sb.length() > 0)
 				return Integer.parseInt(sb.toString());
 			return 0;
 		}
 	}
 
 	private void setBootDelegation() {
 		// set the boot delegation according to the osgi boot delegation property
 		if (bootDelegationProp == null)
 			return;
 		if (bootDelegationProp.trim().length() == 0)
 			return;
 		String[] bootPackages = ManifestElement.getArrayFromList(bootDelegationProp);
 		ArrayList exactMatch = new ArrayList(bootPackages.length);
 		ArrayList stemMatch = new ArrayList(bootPackages.length);
 		for (int i = 0; i < bootPackages.lengthi++) {
 			if (bootPackages[i].equals("*")) { //$NON-NLS-1$
 				 = true;
 				return;
 			} else if (bootPackages[i].endsWith("*")) { //$NON-NLS-1$
 				if (bootPackages[i].length() > 2 && bootPackages[i].endsWith(".*")) //$NON-NLS-1$
 					stemMatch.add(bootPackages[i].substring(0, bootPackages[i].length() - 1));
 			} else {
 				exactMatch.add(bootPackages[i]);
 			}
 		}
 		if (exactMatch.size() > 0)
 			 = (String[]) exactMatch.toArray(new String[exactMatch.size()]);
 		if (stemMatch.size() > 0)
 			 = (String[]) stemMatch.toArray(new String[stemMatch.size()]);
 	}
 
 	private void loadVMProfile() {
 		Properties profileProps = findVMProfile();
 		// set the system exports property using the vm profile; only if the property is not already set
 		if (systemExports == null) {
 			systemExports = profileProps.getProperty(.);
 			if (systemExports != null)
 		}
 		// set the org.osgi.framework.bootdelegation property according to the java profile
 		String type = .getProperty(.); // a null value means ignore
 		String profileBootDelegation = profileProps.getProperty(.);
 			if (profileBootDelegation == null)
 				.remove(.); // override with a null value
 			else
 				.put(.profileBootDelegation); // override with the profile value
 			.remove(.); // remove the bootdelegation property in case it was set
 		// set the org.osgi.framework.executionenvironment property according to the java profile
 			// get the ee from the java profile; if no ee is defined then try the java profile name
 			if (ee != null)
 		}
 	}
 
 	private Properties findVMProfile() {
 		Properties result = new Properties();
 		// Find the VM profile name using J2ME properties
 		String vmProfile = null;
 		String javaEdition = null;
 		Version javaVersion = null;
 		if (j2meConfig != null && j2meConfig.length() > 0 && j2meProfiles != null && j2meProfiles.length() > 0) {
 			// save the vmProfile based off of the config and profile
 			// use the last profile; assuming that is the highest one
 			String[] j2meProfileList = ManifestElement.getArrayFromList(j2meProfiles" "); //$NON-NLS-1$
 			if (j2meProfileList != null && j2meProfileList.length > 0)
 				vmProfile = j2meConfig + '_' + j2meProfileList[j2meProfileList.length - 1];
 		} else {
 			// No J2ME properties; use J2SE properties
 			// Note that the CDC spec appears not to require VM implementations to set the
 			// javax.microedition properties!!  So we will try to fall back to the 
 			// java.specification.name property, but this is pretty ridiculous!!
 			String javaSpecVersion = .getProperty("java.specification.version"); //$NON-NLS-1$
 			// set the profile and EE based off of the java.specification.version
 			// TODO We assume J2ME Foundation and J2SE here.  need to support other profiles J2EE ...
 			if (javaSpecVersion != null) {
 				StringTokenizer st = new StringTokenizer(javaSpecVersion" _-"); //$NON-NLS-1$
 				javaSpecVersion = st.nextToken();
 				String javaSpecName = .getProperty("java.specification.name"); //$NON-NLS-1$
 				// See bug 291269 we check for Foundation Specification and Foundation Profile Specification
 				if (javaSpecName != null && (javaSpecName.indexOf("Foundation Specification") >= 0 || javaSpecName.indexOf("Foundation Profile Specification") >= 0)) //$NON-NLS-1$ //$NON-NLS-2$
 					vmProfile = "CDC-" + javaSpecVersion + "_Foundation-" + javaSpecVersion//$NON-NLS-1$ //$NON-NLS-2$
 				else {
 					// look for JavaSE if 1.6 or greater; otherwise look for J2SE
 					Version v16 = new Version("1.6"); //$NON-NLS-1$
 					javaEdition = ;
 					try {
 						javaVersion = new Version(javaSpecVersion);
 						if (v16.compareTo(javaVersion) <= 0)
 							javaEdition = ;
 					} catch (IllegalArgumentException e) {
 						// do nothing
 					}
 					vmProfile = javaEdition + javaSpecVersion;
 				}
 			}
 		}
 		URL url = null;
 		// check for the java profile property for a url
 		String propJavaProfile = FrameworkProperties.getProperty(.);
 		if (propJavaProfile != null)
 			try {
 				// we assume a URL
 				url = new URL(propJavaProfile);
 			} catch (MalformedURLException e1) {
 				// try using a relative path in the system bundle
 				url = findInSystemBundle(propJavaProfile);
 			}
 		if (url == null && vmProfile != null) {
 			// look for a profile in the system bundle based on the vm profile
 			String javaProfile = vmProfile + ;
 			url = findInSystemBundle(javaProfile);
 			if (url == null)
 				url = getNextBestProfile(javaEditionjavaVersion);
 		}
 		if (url == null)
 			// the profile url is still null then use the osgi min profile in OSGi by default
 			url = findInSystemBundle("OSGi_Minimum-1.2.profile"); //$NON-NLS-1$
 		if (url != null) {
 			InputStream in = null;
 			try {
 				in = url.openStream();
 				result.load(new BufferedInputStream(in));
 			} catch (IOException e) {
 				// TODO consider logging ...
 			} finally {
 				if (in != null)
 					try {
 						in.close();
 					} catch (IOException ee) {
 						// do nothing
 					}
 			}
 		}
 		// set the profile name if it does not provide one
 			if (vmProfile != null)
 				result.put(.vmProfile.replace('_''/'));
 			else
 				// last resort; default to the absolute minimum profile name for the framework
 				result.put(."OSGi/Minimum-1.2"); //$NON-NLS-1$
 		return result;
 	}
 
 	private URL getNextBestProfile(String javaEditionVersion javaVersion) {
 		if (javaVersion == null || (javaEdition !=  && javaEdition != ))
 			return null// we cannot automatically choose the next best profile unless this is a J2SE or JavaSE vm
 		URL bestProfile = findNextBestProfile(javaEditionjavaVersion);
 		if (bestProfile == null && javaEdition == )
 			// if this is a JavaSE VM then search for a lower J2SE profile
 			bestProfile = findNextBestProfile(javaVersion);
 		return bestProfile;
 	}
 
 	private URL findNextBestProfile(String javaEditionVersion javaVersion) {
 		URL result = null;
 		int minor = javaVersion.getMinor();
 		do {
 			result = findInSystemBundle(javaEdition + javaVersion.getMajor() + "." + minor + ); //$NON-NLS-1$
 			minor = minor - 1;
 		} while (result == null && minor > 0);
 		return result;
 	}
 
 	private URL findInSystemBundle(String entry) {
 		URL result = .getEntry0(entry);
 		if (result == null) {
 			// Check the ClassLoader in case we're launched off the Java boot classpath
 			result = loader == null ? ClassLoader.getSystemResource(entry) : loader.getResource(entry);
 		}
 		return result;
 	}

This method return the state of the framework.
 
 	protected boolean isActive() {
 		return ();
 	}

This method is called to destory the framework instance.
 
 	public synchronized void close() {
 		if ( == null)
 			return;
 		if ()
 
 		synchronized () {
 			List allBundles = .getBundles();
 			int size = allBundles.size();
 			for (int i = 0; i < sizei++) {
 				AbstractBundle bundle = (AbstractBundleallBundles.get(i);
 				bundle.close();
 			}
 		}
 		 = null;
 		if ( != null) {
 			 = null;
 		}
 		if ( != null) {
 			 = null;
 		}
 		if ( != null) {
 			 = null;
 		}
 		if ( != null) {
 			 = null;
 		}
 		 = null;
 		 = null;
 		 = null;
 		if (System.getSecurityManager() instanceof EquinoxSecurityManager)
 			System.setSecurityManager(null);
 	}

Start the framework. When the framework is started. The following actions occur: 1. Event handling is enabled. Events can now be delivered to listeners. 2. All bundles which are recorded as started are started as described in the Bundle.start() method. These bundles are the bundles that were started when the framework was last stopped. Reports any exceptions that occur during startup using FrameworkEvents. 3. A FrameworkEvent of type FrameworkEvent.STARTED is broadcast.
 
 	public synchronized void launch() {
 		/* Return if framework already started */
 		if () {
 			return;
 		}
 		/* mark framework as started */
 		 = true;
 		if (.equals(FrameworkProperties.getProperty())) {
 			Thread fwkThread = new Thread(this"Framework Active Thread"); //$NON-NLS-1$
 			fwkThread.setDaemon(false);
 			fwkThread.start();
 		}
 		/* Resume systembundle */
 			Debug.println("Trying to launch framework"); //$NON-NLS-1$
 		}
 	}

Stop the framework. When the framework is stopped. The following actions occur: 1. Suspend all started bundles as described in the Bundle.stop method except that the bundle is recorded as started. These bundles will be restarted when the framework is next started. Reports any exceptions that occur during stopping using FrameworkEvents. 2. Event handling is disabled.
 
 	public synchronized void shutdown(int eventType) {
 		/* Return if framework already stopped */
 		if (!)
 			return;
 		this.[0] = new FrameworkEvent(eventTypenull);
 		/*
 		 * set the state of the System Bundle to STOPPING.
 		 * this must be done first according to section 4.19.2 from the OSGi R3 spec.  
 		 */
 		publishBundleEvent(.); // need to send system bundle stopping event 
 		/* call the FrameworkAdaptor.frameworkStopping method first */
 		try {
 		} catch (Throwable t) {
 		}
 		/* Suspend systembundle */
 			Debug.println("Trying to shutdown Framework"); //$NON-NLS-1$
 		}
 		try {
 		} catch (IOException e) {
 		}
 		if ( != null)
 		/* mark framework as stopped */
 		 = false;
 	}

Create a new Bundle object.

Parameters:
bundledata the BundleData of the Bundle to create
 
 	AbstractBundle createAndVerifyBundle(BundleData bundledataboolean setBundlethrows BundleException {
 		// Check for a bundle already installed with the same symbolic name and version.
 		if (bundledata.getSymbolicName() != null) {
 			AbstractBundle installedBundle = getBundleBySymbolicName(bundledata.getSymbolicName(), bundledata.getVersion());
 			if (installedBundle != null && installedBundle.getBundleId() != bundledata.getBundleID()) {
 				String msg = NLS.bind(.new Object[] {installedBundle.getSymbolicName(), installedBundle.getVersion().toString(), installedBundle.getLocation()});
 				throw new DuplicateBundleException(msginstalledBundle);
 			}
 		}
 		return AbstractBundle.createBundle(bundledatathissetBundle);
 	}
 
 	private class DuplicateBundleException extends BundleException implements StatusException {
 		private static final long serialVersionUID = 135669822846323624L;
 		private final Bundle duplicate;
 
 		public DuplicateBundleException(String msgBundle duplicate) {
 			this. = duplicate;
 		}
 
 		public Object getStatus() {
 			return ;
 		}
 
 		public int getStatusCode() {
 		}
 
 	}

Retrieve the value of the named environment property. Values are provided for the following properties:
org.osgi.framework.version
The version of the framework.
org.osgi.framework.vendor
The vendor of this framework implementation.
org.osgi.framework.language
The language being used. See ISO 639 for possible values.
org.osgi.framework.os.name
The name of the operating system of the hosting computer.
org.osgi.framework.os.version
The version number of the operating system of the hosting computer.
org.osgi.framework.processor
The name of the processor of the hosting computer.

Note: These last four properties are used by the Bundle-NativeCode manifest header's matching algorithm for selecting native code.

Parameters:
key The name of the requested property.
Returns:
The value of the requested property, or null if the property is undefined.
 
 	public String getProperty(String key) {
 		return .getProperty(key);
 	}

Retrieve the value of the named environment property. Values are provided for the following properties:
org.osgi.framework.version
The version of the framework.
org.osgi.framework.vendor
The vendor of this framework implementation.
org.osgi.framework.language
The language being used. See ISO 639 for possible values.
org.osgi.framework.os.name
The name of the operating system of the hosting computer.
org.osgi.framework.os.version
The version number of the operating system of the hosting computer.
org.osgi.framework.processor
The name of the processor of the hosting computer.

Note: These last four properties are used by the Bundle-NativeCode manifest header's matching algorithm for selecting native code.

Parameters:
key The name of the requested property.
def A default value is the requested property is not present.
Returns:
The value of the requested property, or the default value if the property is undefined.
 
 	protected String getProperty(String keyString def) {
 		return .getProperty(keydef);
 	}

Set a system property.

Parameters:
key The name of the property to set.
value The value to set.
Returns:
The previous value of the property or null if the property was not previously set.
 
 	protected Object setProperty(String keyString value) {
 		return .put(keyvalue);
 	}

Install a bundle from an InputStream.

This method performs all the steps listed in installBundle(java.lang.String,java.io.InputStream), except the bundle's content will be read from the InputStream. The location identifier specified will be used as the identity of the bundle.

Parameters:
location The location identifier of the bundle to install.
in The InputStream from which the bundle will be read. If null then the location is used to get the bundle content.
Returns:
The Bundle of the installed bundle.
 
 	protected AbstractBundle installBundle(final String locationfinal InputStream inthrows BundleException {
 			Debug.println("install from inputstream: " + location + ", " + in); //$NON-NLS-1$ //$NON-NLS-2$
 		}
 		final AccessControlContext callerContext = AccessController.getContext();
 		return installWorker(locationnew PrivilegedExceptionAction() {
 			public Object run() throws BundleException {
 				/* Map the InputStream or location to a URLConnection */
 				URLConnection source = in != null ? new BundleSource(in) : .mapLocationToURLConnection(location);
 				/* call the worker to install the bundle */
 				return installWorkerPrivileged(locationsourcecallerContext);
 			}
 		});
 	}

Worker method to install a bundle. It obtains the reservation for the location and calls the specified action.

Parameters:
location The location identifier of the bundle to install.
action A PrivilegedExceptionAction which calls the real worker.
Returns:
The AbstractBundleof the installed bundle.
Throws:
org.osgi.framework.BundleException If the action throws an error.
 
 	protected AbstractBundle installWorker(String locationPrivilegedExceptionAction actionthrows BundleException {
 		synchronized () {
 			while (true) {
 				/* Check that the bundle is not already installed. */
 				AbstractBundle bundle = getBundleByLocation(location);
 				/* If already installed, return bundle object */
 				if (bundle != null) {
 					return bundle;
 				}
 				Thread current = Thread.currentThread();
 				/* Check for and make reservation */
 				Thread reservation = (Thread.put(locationcurrent);
 				/* if the location is not already reserved */
 				if (reservation == null) {
 					/* we have made the reservation and can continue */
 					break;
 				}
 				/* the location was already reserved */
 				/*
 				 * If the reservation is held by the current thread, we have
 				 * recursed to install the same bundle!
 				 */
 				if (current.equals(reservation)) {
 				}
 				try {
 					/* wait for the reservation to be released */
 				} catch (InterruptedException e) {
 				}
 			}
 		}
 		/* Don't call adaptor while holding the install lock */
 		try {
 			AbstractBundle bundle = (AbstractBundle) AccessController.doPrivileged(action);
 			return bundle;
 		} catch (PrivilegedActionException e) {
 			if (e.getException() instanceof RuntimeException)
 		} finally {
 			synchronized () {
 				/* release reservation */
 				.remove(location);
 				/* wake up all waiters */
 			}
 		}
 	}

Worker method to install a bundle. It calls the FrameworkAdaptor object to install the bundle in persistent storage.

Parameters:
location The location identifier of the bundle to install.
source The URLConnection from which the bundle will be read.
Returns:
The AbstractBundleof the installed bundle.
Throws:
org.osgi.framework.BundleException If the provided stream cannot be read.
 
 	protected AbstractBundle installWorkerPrivileged(String locationURLConnection sourceAccessControlContext callerContextthrows BundleException {
 		BundleOperation storage = .installBundle(locationsource);
 		final AbstractBundle bundle;
 		try {
 			BundleData bundledata = storage.begin();
 			bundle = createAndVerifyBundle(bundledatatrue);
 			if (.) {
 				if (bundleStats != null)
 			}
 			try {
 				bundle.load();
 				if (System.getSecurityManager() != null) {
 					// must check for AllPermission before allow a bundle extension to be installed
 					if (extension && !bundle.hasPermission(new AllPermission()))
 					try {
 						AccessController.doPrivileged(new PrivilegedExceptionAction() {
 							public Object run() throws Exception {
 								if (extension// need special permission to install extension bundles
 								return null;
 							}
 						}, callerContext);
 					} catch (PrivilegedActionException e) {
 						throw e.getException();
 					}
 				}
 				storage.commit(false);
 			} catch (Throwable error) {
 				synchronized () {
 					bundle.unload();
 				}
 				bundle.close();
 				throw error;
 			} finally {
 				if (.) {
 					if (bundleStats != null)
 						bundleStats.watchBundle(bundle.);
 				}
 			}
 			/* bundle has been successfully installed */
 			.add(bundle);
 		} catch (Throwable t) {
 			try {
 				storage.undo();
 			} catch (BundleException ee) {
 			}
 			if (t instanceof SecurityException)
 				throw (SecurityExceptiont;
 			if (t instanceof BundleException)
 				throw (BundleExceptiont;
 			throw new BundleException(t.getMessage(), t);
 		}
 		return bundle;
 	}

Retrieve the bundle that has the given unique identifier.

Parameters:
id The identifier of the bundle to retrieve.
Returns:
A AbstractBundleobject, or null if the identifier doesn't match any installed bundle.
 
 	// changed visibility to gain access through the adaptor
 	public AbstractBundle getBundle(long id) {
 		synchronized () {
 			return .getBundle(id);
 		}
 	}
 
		if ( == null)
			return null;
	}

Retrieve the bundle that has the given symbolic name and version.

Parameters:
symbolicName The symbolic name of the bundle to retrieve
version The version of the bundle to retrieve
Returns:
A AbstractBundleobject, or null if the identifier doesn't match any installed bundle.
	public AbstractBundle getBundleBySymbolicName(String symbolicNameVersion version) {
		synchronized () {
			return .getBundle(symbolicNameversion);
	}

Retrieve the BundleRepository of all installed bundles. The list is valid at the time of the call to getBundles, but the framework is a very dynamic environment and bundles can be installed or uninstalled at anytime.

Returns:
The BundleRepository.
		return ();
	}

Retrieve a list of all installed bundles. The list is valid at the time of the call to getBundleAlls, but the framework is a very dynamic environment and bundles can be installed or uninstalled at anytime.

Returns:
An Array of AbstractBundleobjects, one object per installed bundle.
	protected AbstractBundle[] getAllBundles() {
		synchronized () {
			List allBundles = .getBundles();
			int size = allBundles.size();
			if (size == 0) {
				return (null);
			AbstractBundle[] bundlelist = new AbstractBundle[size];
			allBundles.toArray(bundlelist);
			return (bundlelist);
	}

Resume a bundle.

Parameters:
bundle Bundle to resume.
	protected void resumeBundle(AbstractBundle bundle) {
		if (bundle.isActive()) {
			// if bundle is active.
			return;
		try {
				Debug.println("Trying to resume bundle " + bundle); //$NON-NLS-1$
			bundle.resume();
catch (BundleException be) {
				Debug.println("Bundle resume exception: " + be.getMessage()); //$NON-NLS-1$
				Debug.printStackTrace(be.getNestedException() == null ? be : be.getNestedException());
	}

Suspend a bundle.

Parameters:
bundle Bundle to suspend.
lock true if state change lock should be held when returning from this method.
Returns:
true if bundle was active and is now suspended.
	protected boolean suspendBundle(AbstractBundle bundleboolean lock) {
		boolean changed = false;
		if (!bundle.isActive() || bundle.isFragment()) {
			// if bundle is not active or is a fragment then do nothing.
			return changed;
		try {
				Debug.println("Trying to suspend bundle " + bundle); //$NON-NLS-1$
			bundle.suspend(lock);
catch (BundleException be) {
				Debug.println("Bundle suspend exception: " + be.getMessage()); //$NON-NLS-1$
				Debug.printStackTrace(be.getNestedException() == null ? be : be.getNestedException());
		if (!bundle.isActive()) {
			changed = true;
		return (changed);
	}

Locate an installed bundle with a given identity.

Parameters:
location string for the bundle
Returns:
Bundle object for bundle with the specified location or null if no bundle is installed with the specified location.
	protected AbstractBundle getBundleByLocation(String location) {
		synchronized () {
			// this is not optimized; do not think it will get called
			// that much.
			final String finalLocation = location;
			//Bundle.getLocation requires AdminPermission (metadata)
			return (AbstractBundle) AccessController.doPrivileged(new PrivilegedAction() {
				public Object run() {
					List allBundles = .getBundles();
					int size = allBundles.size();
					for (int i = 0; i < sizei++) {
						AbstractBundle bundle = (AbstractBundleallBundles.get(i);
						if (finalLocation.equals(bundle.getLocation())) {
							return (bundle);
					return (null);
			});
	}

Locate an installed bundle with a given symbolic name

Parameters:
symbolicName The symbolic name for the bundle
Returns:
Bundle object for bundle with the specified Unique or null if no bundle is installed with the specified location.
	protected AbstractBundle[] getBundleBySymbolicName(String symbolicName) {
		synchronized () {
			return .getBundles(symbolicName);
	}

Creates a File object for a file in the persistent storage area provided for the bundle by the framework. If the adaptor does not have file system support, this method will return null.

A File object for the base directory of the persistent storage area provided for the context bundle by the framework can be obtained by calling this method with the empty string ("") as the parameter.

	protected File getDataFile(final AbstractBundle bundlefinal String filename) {
		return (File) AccessController.doPrivileged(new GetDataFileAction(bundlefilename));
	}

Check for specific AdminPermission (RFC 73)
	protected void checkAdminPermission(Bundle bundleString action) {
		if (sm != null)
	// gets AdminPermission objects from a cache to reduce the number of AdminPermission
	// objects that are created.
	private AdminPermission getAdminPermission(Bundle bundleString action) {
		synchronized () {
			Long ID = new Long(bundle.getBundleId());
			HashMap bundlePermissions = (HashMap.get(ID);
			if (bundlePermissions == null) {
				bundlePermissions = new HashMap();
				.put(IDbundlePermissions);
			AdminPermission result = (AdminPermissionbundlePermissions.get(action);
			if (result == null) {
				result = new AdminPermission(bundleaction);
				bundlePermissions.put(actionresult);
			return result;
	}

This is necessary for running from a JXE, otherwise the SecurityManager is set much later than we would like!
	protected void installSecurityManager() {
		String securityManager = FrameworkProperties.getProperty(, FrameworkProperties.getProperty("java.security.manager")); //$NON-NLS-1$
		if (securityManager != null) {
			if (sm == null) {
				if (securityManager.length() == 0)
					sm = new SecurityManager(); // use the default one from java
				else if (securityManager.equals())
					sm = new EquinoxSecurityManager(); // use an OSGi enabled manager that understands postponed conditions
				else {
					// try to use a specific classloader by classname
					try {
						Class clazz = Class.forName(securityManager);
						sm = (SecurityManagerclazz.newInstance();
catch (ClassNotFoundException e) {
						// do nothing
catch (ClassCastException e) {
						// do nothing
catch (InstantiationException e) {
						// do nothing
catch (