package org.osgi.test.support.compatibility;

import java.net.URL;

import junit.framework.TestCase;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.ServiceReference;

public class DefaultTestBundleControl extends TestCase {
	BundleContext context;

	/**
	 * THis method is called by the JUnit runner for OSGi, and gives us a Bundle
	 * Context.
	 */
	public void setBundleContext(BundleContext context) {
		this.context = context;
	}

	/**
	 * Returns the current Bundle Context
	 */

	public BundleContext getContext() {
		if (context == null)
			fail("No valid Bundle context said, are you running in OSGi Test mode?");

		return context;
	}

	/**
	 * This returned a web server but we will just now, it is mostly used in
	 * installBundle and there we get the bundle from our resources.
	 */

	public String getWebServer() {
		return "/www/";
	}
	
	/**
	 * Uninstall a bundle.
	 * 
	 * @param bundle
	 * @throws BundleException
	 */
	public void uninstallBundle(Bundle bundle) throws BundleException {
		bundle.uninstall();
	}

	/**
	 * Uninstall a bundle.
	 * 
	 * @param bundle
	 * @throws BundleException
	 */
	public Bundle installBundle(String url) throws BundleException {
		URL resource = getClass().getResource(url);
		if ( resource == null )
			fail("Can not load bundle " + url);
		return getContext().installBundle(resource.toString());
	}

	/**
	 * Convenience getService method
	 */	
	public Object getService(Class clazz ) {
		ServiceReference ref = context.getServiceReference(clazz.getName());
		if ( ref == null )
			return null;
		
		return context.getService(ref);
	}

}

@@ -265,16 +265,25 @@
 %0Apublic 
+abstract 
 class De
@@ -325,16 +325,52 @@
 Case %7B%0A%09
+%0A%09/* @GuardedBy(%22this%22) */%0A%09private 
 BundleCo
@@ -370,25 +370,25 @@
 undleContext
- 
+%09
 context;%0A%0A%09/
@@ -490,24 +490,37 @@
  */%0A%09public 
+synchronized 
 void setBund
@@ -638,24 +638,37 @@
 */%0A%0A%09public 
+synchronized 
 BundleContex
@@ -953,25 +953,24 @@
 urces.%0A%09 */%0A
-%0A
 %09public Stri
@@ -1193,35 +1193,33 @@
 );%0A%09%7D%0A%0A%09/**%0A%09 * 
-Uni
+I
 nstall a bundle.
@@ -1601,16 +1601,50 @@
 azz ) %7B%0A
+%09%09BundleContext c = getContext();%0A
 %09%09Servic
@@ -1661,22 +1661,16 @@
  ref = c
-ontext
 .getServ
@@ -1750,22 +1750,16 @@
 return c
-ontext
 .getServ
@@ -1771,11 +1771,10 @@
 ef);%0A%09%7D%0A
-%0A
 %7D%0A

make abstract and also synchronize access to context