Final big refactoring, one new test and initial work on a general intergration testing approach
diff --git a/org.eclipse.gemini.mgmt.tests/.classpath b/org.eclipse.gemini.mgmt.tests/.classpath
index 9aa40d0..e15292d 100644
--- a/org.eclipse.gemini.mgmt.tests/.classpath
+++ b/org.eclipse.gemini.mgmt.tests/.classpath
@@ -1,7 +1,7 @@
-<?xml version="1.0" encoding="UTF-8"?>

-<classpath>

-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>

-	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>

-	<classpathentry excluding="**/.svn/*" kind="src" path="src"/>

-	<classpathentry kind="output" path="bin"/>

-</classpath>

+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="output" path="target"/>
+</classpath>
diff --git a/org.eclipse.gemini.mgmt.tests/build.properties b/org.eclipse.gemini.mgmt.tests/build.properties
index 0db7570..9064190 100644
--- a/org.eclipse.gemini.mgmt.tests/build.properties
+++ b/org.eclipse.gemini.mgmt.tests/build.properties
@@ -1,3 +1,3 @@
 source.. = src/

-output.. = bin/

+output.. = target/

 bin.includes = META-INF/,.

diff --git a/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/AbstractOSGiMBeanTest.java b/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/AbstractOSGiMBeanTest.java
new file mode 100644
index 0000000..917280f
--- /dev/null
+++ b/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/AbstractOSGiMBeanTest.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2011 VMware Inc.
+ * 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:
+ *   VMware Inc. - initial contribution
+ *******************************************************************************/
+package org.eclipse.gemini.mgmt;
+
+import java.lang.management.ManagementFactory;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.management.openmbean.TabularData;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+import org.junit.BeforeClass;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+
+public class AbstractOSGiMBeanTest {
+
+	protected String mBeanObjectName;
+	
+	@BeforeClass
+	public static void setup(){
+		BundleContext bc = FrameworkUtil.getBundle(Activator.class).getBundleContext();
+		ServiceReference<MBeanServer> ref = bc.getServiceReference(MBeanServer.class);
+		if (ref == null) {
+			bc.registerService(MBeanServer.class.getCanonicalName(), ManagementFactory.getPlatformMBeanServer(), null);
+		}
+	}
+
+	protected TabularData jmxInvokeBundleState(String operation, Object[] arguments, String[] types) throws Exception {
+		JMXConnector connector;
+		String url = "service:jmx:rmi:///jndi/rmi://localhost:21045/jmxrmi";
+		JMXServiceURL jmxURL = new JMXServiceURL(url);
+		connector = JMXConnectorFactory.connect(jmxURL);
+		MBeanServerConnection connection = connector.getMBeanServerConnection();
+		ObjectName name = new ObjectName(mBeanObjectName);
+		return (TabularData) connection.invoke(name, operation, arguments, types);
+	}
+	
+}
diff --git a/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/framework/BundleStateTest.java b/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/framework/BundleStateTest.java
deleted file mode 100644
index de6d1e5..0000000
--- a/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/framework/BundleStateTest.java
+++ /dev/null
@@ -1,393 +0,0 @@
-package org.eclipse.gemini.mgmt.framework;

-

-import static org.junit.Assert.assertEquals;

-import static org.junit.Assert.assertTrue;

-import static org.junit.Assert.fail;

-

-import java.io.IOException;

-import java.lang.management.ManagementFactory;

-import java.net.MalformedURLException;

-import java.util.Arrays;

-import java.util.Collection;

-import java.util.Iterator;

-import java.util.Map;

-import java.util.Set;

-

-import javax.management.InstanceNotFoundException;

-import javax.management.MBeanException;

-import javax.management.MBeanServer;

-import javax.management.MBeanServerConnection;

-import javax.management.MalformedObjectNameException;

-import javax.management.ObjectName;

-import javax.management.ReflectionException;

-import javax.management.openmbean.CompositeData;

-import javax.management.openmbean.TabularData;

-import javax.management.openmbean.TabularDataSupport;

-import javax.management.remote.JMXConnector;

-import javax.management.remote.JMXConnectorFactory;

-import javax.management.remote.JMXServiceURL;

-

-import org.junit.Test;

-import org.osgi.framework.Bundle;

-import org.osgi.framework.BundleContext;

-import org.osgi.framework.FrameworkUtil;

-import org.osgi.framework.ServiceReference;

-import org.osgi.framework.startlevel.BundleStartLevel;

-import org.osgi.jmx.framework.BundleStateMBean;

-

-import org.eclipse.gemini.mgmt.Activator;

-import org.eclipse.gemini.mgmt.framework.internal.OSGiBundle;

-import org.eclipse.gemini.mgmt.framework.BundleState;

-import org.eclipse.gemini.mgmt.internal.BundleUtil;

-

-public class BundleStateTest {

-	

-	@Test

-	public void nameAndVersionTest() throws Exception {

-		BundleContext bc = FrameworkUtil.getBundle(Activator.class).getBundleContext();

-		ServiceReference<MBeanServer> ref = bc.getServiceReference(MBeanServer.class);

-		if (ref == null) {

-			bc.registerService(MBeanServer.class.getCanonicalName(), ManagementFactory.getPlatformMBeanServer(), null);

-		}

-		CompositeData bundleInfo;

-		String symbolicName;

-		String version;

-		Object key;

-		Object[] keysArray;

-		Bundle bundle;

-		int mask = BundleState.SYMBOLIC_NAME + BundleState.IDENTIFIER + BundleState.VERSION;

-		long start = System.currentTimeMillis();

-		TabularDataSupport table = jmxInvokeListBundles(mask);

-		long end = System.currentTimeMillis();

-		assertTrue((end - start) < 1000);

-		Set<?> keys = table.keySet();

-		Iterator<?> iter = keys.iterator();

-		while (iter.hasNext()) {

-			key = iter.next();

-			keysArray = ((Collection<?>) key).toArray();

-			bundleInfo = (CompositeData) table.get(keysArray);

-			symbolicName = (String) bundleInfo.get(BundleStateMBean.SYMBOLIC_NAME);

-			version = (String) bundleInfo.get(BundleStateMBean.VERSION);

-			bundle = bc.getBundle((Long) keysArray[0]);

-			assertEquals(symbolicName, bundle.getSymbolicName());

-			assertEquals(version, bundle.getVersion().toString());

-		}

-	}

-

-	@SuppressWarnings("unchecked")

-	@Test

-	public void fullMaskTest() throws Exception {

-		CompositeData bundleInfo;

-		String location;

-		String symbolicName;

-		String version;

-		int startLevel;

-		String state;

-		long lastModified;

-		boolean persistenlyStarted;

-		boolean removalPending;

-		boolean required;

-		boolean fragment;

-		Long[] registeredServices;

-		Long[] servicesInUse;

-		Map<String, CompositeData> headers;

-		String[] exportedPackages;

-		String[] importedPackages;

-		Long[] fragments;

-		Long[] hosts;

-		Long[] requiringBundles;

-		Long[] requiredBundles;

-		Object key;

-		Object[] keysArray;

-		Bundle bundle;

-		int mask = BundleState.LOCATION + BundleState.IDENTIFIER

-				+ BundleState.SYMBOLIC_NAME + BundleState.VERSION

-				+ BundleState.START_LEVEL + BundleState.STATE

-				+ BundleState.LAST_MODIFIED + BundleState.PERSISTENTLY_STARTED

-				+ BundleState.REMOVAL_PENDING + BundleState.REQUIRED

-				+ BundleState.FRAGMENT + BundleState.REGISTERED_SERVICES

-				+ BundleState.SERVICES_IN_USE + BundleState.HEADERS

-				+ BundleState.EXPORTED_PACKAGES + BundleState.IMPORTED_PACKAGES

-				+ BundleState.FRAGMENTS + BundleState.HOSTS

-				+ BundleState.REQUIRING_BUNDLES + BundleState.REQUIRED_BUNDLES;

-		TabularDataSupport table = jmxInvokeListBundles(mask);

-		Set<?> keys = table.keySet();

-		Iterator<?> iter = keys.iterator();

-		BundleContext bc = FrameworkUtil.getBundle(BundleState.class).getBundleContext();

-		while (iter.hasNext()) {

-			key = iter.next();

-			keysArray = ((Collection<?>) key).toArray();

-			bundleInfo = (CompositeData) table.get(keysArray);

-

-			location = (String) bundleInfo.get(BundleStateMBean.LOCATION);

-			symbolicName = (String) bundleInfo.get(BundleStateMBean.SYMBOLIC_NAME);

-			version = (String) bundleInfo.get(BundleStateMBean.VERSION);

-			startLevel = ((Integer) bundleInfo.get(BundleStateMBean.START_LEVEL)).intValue();

-			state = (String) bundleInfo.get(BundleStateMBean.STATE);

-			lastModified = ((Long) bundleInfo.get(BundleStateMBean.LAST_MODIFIED)).longValue();

-			persistenlyStarted = ((Boolean) bundleInfo.get(BundleStateMBean.PERSISTENTLY_STARTED)).booleanValue();

-			removalPending = ((Boolean) bundleInfo.get(BundleStateMBean.REMOVAL_PENDING)).booleanValue();

-			required = ((Boolean) bundleInfo.get(BundleStateMBean.REQUIRED)).booleanValue();

-			fragment = ((Boolean) bundleInfo.get(BundleStateMBean.FRAGMENT)).booleanValue();

-			registeredServices = (Long[]) bundleInfo.get(BundleStateMBean.REGISTERED_SERVICES);

-			servicesInUse = (Long[]) bundleInfo.get(BundleStateMBean.SERVICES_IN_USE);

-			headers = (Map<String, CompositeData>) bundleInfo.get(BundleStateMBean.HEADERS);

-			exportedPackages = (String[]) bundleInfo.get(BundleStateMBean.EXPORTED_PACKAGES);

-			importedPackages = (String[]) bundleInfo.get(BundleStateMBean.IMPORTED_PACKAGES);

-			fragments = (Long[]) bundleInfo.get(BundleStateMBean.FRAGMENTS);

-			hosts = (Long[]) bundleInfo.get(BundleStateMBean.HOSTS);

-			requiringBundles = (Long[]) bundleInfo.get(BundleStateMBean.REQUIRING_BUNDLES);

-			requiredBundles = (Long[]) bundleInfo.get(BundleStateMBean.REQUIRED_BUNDLES);

-

-			bundle = bc.getBundle((Long) keysArray[0]);

-			assertEquals(location, bundle.getLocation());

-			assertEquals(symbolicName, bundle.getSymbolicName());

-			assertEquals(version, bundle.getVersion().toString());

-			assertEquals(startLevel, bundle.adapt(BundleStartLevel.class).getStartLevel());

-			assertEquals(state, stateToString(bundle.getState()));

-			assertEquals(lastModified, bundle.getLastModified());

-			assertEquals(persistenlyStarted, BundleUtil.isBundlePersistentlyStarted(bundle));

-			assertEquals(removalPending, BundleUtil.isRemovalPending(bundle));

-			assertEquals(required, BundleUtil.isRequired(bundle));

-			assertEquals(fragment, BundleUtil.isBundleFragment(bundle));

-

-			long[] rs = new long[registeredServices.length];

-			for (int i = 0; i < registeredServices.length; i++) {

-				rs[i] = registeredServices[i].longValue();

-			}

-			long[] rs2 = BundleUtil.serviceIds(bundle.getRegisteredServices());

-			Arrays.sort(rs);

-			Arrays.sort(rs2);

-			assertTrue(Arrays.equals(rs, rs2));

-

-			long[] siu = new long[servicesInUse.length];

-			for (int i = 0; i < servicesInUse.length; i++) {

-				siu[i] = servicesInUse[i].longValue();

-			}

-			Arrays.sort(siu);

-			long[] siu2 = BundleUtil.serviceIds(bundle.getServicesInUse());

-			Arrays.sort(siu2);

-			assertTrue(Arrays.equals(siu, siu2));

-

-			assertEquals((TabularData) headers,	OSGiBundle.headerTable(BundleUtil.getBundleHeaders(bundle)));

-

-			String[] exportedPackages2 = BundleUtil.getBundleExportedPackages(bundle);

-			Arrays.sort(exportedPackages);

-			Arrays.sort(exportedPackages2);

-			assertTrue(Arrays.equals(exportedPackages, exportedPackages2));

-

-			String[] importedPackages2 = BundleUtil.getBundleImportedPackages(bundle);

-			Arrays.sort(importedPackages);

-			Arrays.sort(importedPackages2);

-			assertTrue(Arrays.equals(importedPackages, importedPackages2));

-

-			long[] frags = new long[fragments.length];

-			for (int i = 0; i < fragments.length; i++) {

-				frags[i] = fragments[i].longValue();

-			}

-			Arrays.sort(frags);

-			long[] frags2 = BundleUtil.getBundleFragments(bundle);

-			Arrays.sort(frags2);

-			assertTrue(Arrays.equals(frags, frags2));

-

-			long[] hst = new long[hosts.length];

-			for (int i = 0; i < hosts.length; i++) {

-				hst[i] = hosts[i].longValue();

-			}

-			Arrays.sort(hst);

-			long[] hst2 = BundleUtil.getBundleHosts(bundle);

-			Arrays.sort(hst2);

-			assertTrue(Arrays.equals(hst, hst2));

-

-			long[] reqB = new long[requiringBundles.length];

-			for (int i = 0; i < requiringBundles.length; i++) {

-				reqB[i] = requiringBundles[i].longValue();

-			}

-			Arrays.sort(reqB);

-			long[] reqB2 = BundleUtil.getRequiringBundles(bundle);

-			Arrays.sort(reqB2);

-			assertTrue(Arrays.equals(reqB, reqB2));

-

-			long[] requiredB = new long[requiredBundles.length];

-			for (int i = 0; i < requiredBundles.length; i++) {

-				requiredB[i] = requiredBundles[i].longValue();

-			}

-			Arrays.sort(requiredB);

-			long[] requiredB2 = BundleUtil.getRequiredBundles(bundle);

-			Arrays.sort(requiredB2);

-			assertTrue(Arrays.equals(requiredB, requiredB2));

-		}

-	}

-

-	@Test

-	public void randomMaskTest() throws Exception {

-		CompositeData bundleInfo;

-		String version;

-		String state;

-		long lastModified;

-		boolean persistenlyStarted;

-		boolean removalPending;

-		Long[] registeredServices;

-		Long[] servicesInUse;

-		String[] exportedPackages;

-		String[] importedPackages;

-		Long[] hosts;

-		Long[] requiringBundles;

-		Object key;

-		Object[] keysArray;

-		Bundle bundle;

-		int mask = BundleState.IDENTIFIER + BundleState.VERSION

-				+ BundleState.STATE + BundleState.LAST_MODIFIED

-				+ BundleState.PERSISTENTLY_STARTED + BundleState.REMOVAL_PENDING

-				+ BundleState.REGISTERED_SERVICES + BundleState.SERVICES_IN_USE

-				+ BundleState.EXPORTED_PACKAGES + BundleState.IMPORTED_PACKAGES

-				+ BundleState.HOSTS + BundleState.REQUIRING_BUNDLES;

-		TabularDataSupport table = jmxInvokeListBundles(mask);

-		Set<?> keys = table.keySet();

-		Iterator<?> iter = keys.iterator();

-		BundleContext bc = FrameworkUtil.getBundle(BundleState.class).getBundleContext();

-		while (iter.hasNext()) {

-			key = iter.next();

-			keysArray = ((Collection<?>) key).toArray();

-			bundleInfo = (CompositeData) table.get(keysArray);

-

-			version = (String) bundleInfo.get(BundleStateMBean.VERSION);

-			state = (String) bundleInfo.get(BundleStateMBean.STATE);

-			lastModified = ((Long) bundleInfo.get(BundleStateMBean.LAST_MODIFIED)).longValue();

-			persistenlyStarted = ((Boolean) bundleInfo.get(BundleStateMBean.PERSISTENTLY_STARTED)).booleanValue();

-			removalPending = ((Boolean) bundleInfo.get(BundleStateMBean.REMOVAL_PENDING)).booleanValue();

-			registeredServices = (Long[]) bundleInfo.get(BundleStateMBean.REGISTERED_SERVICES);

-			servicesInUse = (Long[]) bundleInfo.get(BundleStateMBean.SERVICES_IN_USE);

-			exportedPackages = (String[]) bundleInfo.get(BundleStateMBean.EXPORTED_PACKAGES);

-			importedPackages = (String[]) bundleInfo.get(BundleStateMBean.IMPORTED_PACKAGES);

-			hosts = (Long[]) bundleInfo.get(BundleStateMBean.HOSTS);

-			requiringBundles = (Long[]) bundleInfo.get(BundleStateMBean.REQUIRING_BUNDLES);

-			bundle = bc.getBundle((Long) keysArray[0]);

-

-			assertEquals(version, bundle.getVersion().toString());

-			assertEquals(state, stateToString(bundle.getState()));

-			assertEquals(lastModified, bundle.getLastModified());

-			assertEquals(persistenlyStarted, BundleUtil.isBundlePersistentlyStarted(bundle));

-			assertEquals(removalPending, BundleUtil.isRemovalPending(bundle));

-

-			long[] rs = new long[registeredServices.length];

-			for (int i = 0; i < registeredServices.length; i++) {

-				rs[i] = registeredServices[i].longValue();

-			}

-			long[] rs2 = BundleUtil.serviceIds(bundle.getRegisteredServices());

-			Arrays.sort(rs);

-			Arrays.sort(rs2);

-			assertTrue(Arrays.equals(rs, rs2));

-

-			long[] siu = new long[servicesInUse.length];

-			for (int i = 0; i < servicesInUse.length; i++) {

-				siu[i] = servicesInUse[i].longValue();

-			}

-			Arrays.sort(siu);

-			long[] siu2 = BundleUtil.serviceIds(bundle.getServicesInUse());

-			Arrays.sort(siu2);

-			assertTrue(Arrays.equals(siu, siu2));

-

-			String[] exportedPackages2 = BundleUtil.getBundleExportedPackages(bundle);

-			Arrays.sort(exportedPackages);

-			Arrays.sort(exportedPackages2);

-			assertTrue(Arrays.equals(exportedPackages, exportedPackages2));

-

-			String[] importedPackages2 = BundleUtil.getBundleImportedPackages(bundle);

-			Arrays.sort(importedPackages);

-			Arrays.sort(importedPackages2);

-			assertTrue(Arrays.equals(importedPackages, importedPackages2));

-

-			long[] hst = new long[hosts.length];

-			for (int i = 0; i < hosts.length; i++) {

-				hst[i] = hosts[i].longValue();

-			}

-			Arrays.sort(hst);

-			long[] hst2 = BundleUtil.getBundleHosts(bundle);

-			Arrays.sort(hst2);

-			assertTrue(Arrays.equals(hst, hst2));

-

-			long[] reqB = new long[requiringBundles.length];

-			for (int i = 0; i < requiringBundles.length; i++) {

-				reqB[i] = requiringBundles[i].longValue();

-			}

-			Arrays.sort(reqB);

-			long[] reqB2 = BundleUtil.getRequiringBundles(bundle);

-			Arrays.sort(reqB2);

-			assertTrue(Arrays.equals(reqB, reqB2));

-		}

-	}

-

-	private TabularDataSupport jmxInvokeListBundles(int mask)

-			throws MalformedURLException, IOException,

-			MalformedObjectNameException, InstanceNotFoundException,

-			MBeanException, ReflectionException {

-		JMXConnector connector;

-		String url = "service:jmx:rmi:///jndi/rmi://localhost:21045/jmxrmi";

-		JMXServiceURL jmxURL = new JMXServiceURL(url);

-		connector = JMXConnectorFactory.connect(jmxURL);

-		MBeanServerConnection connection = connector.getMBeanServerConnection();

-		ObjectName name = new ObjectName(CustomBundleStateMBean.OBJECTNAME);

-		TabularDataSupport table = (TabularDataSupport) connection.invoke(name,

-				"listBundles", new Object[] { new Integer(mask) },

-				new String[] { "int" });

-		return table;

-	}

-

-	@Test

-	public void illegalMaskTest() throws Exception {

-//		CompositeData bundleInfo;

-//		String version;

-//		String state;

-//		long lastModified;

-//		boolean persistenlyStarted;

-//		boolean removalPending;

-//		Long[] registeredServices;

-//		Long[] servicesInUse;

-//		String[] exportedPackages;

-//		String[] importedPackages;

-//		Long[] hosts;

-//		Long[] requiringBundles;

-//		Object key;

-//		Object[] keysArray;

-//		Bundle bundle;

-		int mask = 1048576;

-		try {

-			@SuppressWarnings("unused")

-			TabularDataSupport table = jmxInvokeListBundles(mask);

-			fail("Expected exception did not occur!");

-		} catch (Exception e) {

-			assertTrue(e.getCause() instanceof IllegalArgumentException);

-		}

-	}

-

-	private String stateToString(int state) {

-		String strState = null;

-		switch (state) {

-		case 1:

-			strState = "UNINSTALLED";

-			break;

-		case 2:

-			strState = "INSTALLED";

-			break;

-		case 4:

-			strState = "RESOLVED";

-			break;

-		case 8:

-			strState = "STARTING";

-			break;

-		case 16:

-			strState = "STOPPING";

-			break;

-		case 32:

-			strState = "ACTIVE";

-			break;

-		default:

-			strState = "UNKNOWN";

-			break;

-		}

-		return strState;

-	}

-	

-}

-

diff --git a/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/framework/BundleStateTests.java b/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/framework/BundleStateTests.java
new file mode 100644
index 0000000..b3670b6
--- /dev/null
+++ b/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/framework/BundleStateTests.java
@@ -0,0 +1,454 @@
+/*******************************************************************************

+ * Copyright (c) 2010 SAP.

+ * All rights reserved. This program and the accompanying materials

+ * are made available under the terms of the Eclipse Public License v1.0

+ * and Apache License v2.0 which accompanies this distribution. 

+ * The Eclipse Public License is available at

+ *     http://www.eclipse.org/legal/epl-v10.html

+ * and the Apache License v2.0 is available at 

+ *     http://www.opensource.org/licenses/apache2.0.php.

+ * You may elect to redistribute this code under either of these licenses.

+ *

+ * Contributors:

+ *     SAP employees 

+ ******************************************************************************/

+package org.eclipse.gemini.mgmt.framework;

+

+import static org.junit.Assert.assertEquals;

+import static org.junit.Assert.assertTrue;

+import static org.junit.Assert.fail;

+

+import java.util.Arrays;

+import java.util.Collection;

+import java.util.Iterator;

+import java.util.List;

+import java.util.Map;

+import java.util.Set;

+

+import javax.management.openmbean.CompositeData;

+import javax.management.openmbean.TabularData;

+

+import org.eclipse.gemini.mgmt.AbstractOSGiMBeanTest;

+import org.eclipse.gemini.mgmt.framework.internal.OSGiBundle;

+import org.eclipse.gemini.mgmt.internal.BundleUtil;

+import org.junit.Before;

+import org.junit.Test;

+import org.osgi.framework.Bundle;

+import org.osgi.framework.BundleContext;

+import org.osgi.framework.Constants;

+import org.osgi.framework.FrameworkUtil;

+import org.osgi.framework.ServiceReference;

+import org.osgi.framework.startlevel.BundleStartLevel;

+import org.osgi.framework.wiring.BundleRevision;

+import org.osgi.framework.wiring.BundleWire;

+import org.osgi.framework.wiring.BundleWiring;

+import org.osgi.jmx.framework.BundleStateMBean;

+

+/**

+ * Integration tests for the {@link BundleState} implementation of {@link CustomBundleStateMBean} and {@link BundleStateMBean}

+ *

+ */

+public final class BundleStateTests extends AbstractOSGiMBeanTest{

+	

+	protected String mBeanObjectName = BundleStateMBean.OBJECTNAME;

+	

+	private CompositeData bundleInfo;

+	private String location;

+	private String symbolicName;

+	private String version;

+	private int startLevel;

+	private String state;

+	private long lastModified;

+	private boolean persistenlyStarted;

+	private boolean activationPolicyUsed;

+	private boolean removalPending;

+	private boolean required;

+	private boolean fragment;

+	private Long[] registeredServices;

+	private Long[] servicesInUse;

+	private Map<String, CompositeData> headers;

+	private String[] exportedPackages;

+	private String[] importedPackages;

+	private Long[] fragments;

+	private Long[] hosts;

+	private Long[] requiringBundles;

+	private Long[] requiredBundles;

+	private Object key;

+	private Object[] keysArray;

+	private Bundle bundle;

+	

+	@Before

+	public void before(){

+		this.bundleInfo = null;

+		this.location = null;

+		this.symbolicName = null;

+		this.version = null;

+		this.startLevel = 0;

+		this.state = null;

+		this.lastModified = 0L;

+		this.persistenlyStarted = false;

+		this.activationPolicyUsed = false;

+		this.removalPending = false;

+		this.required = false;

+		this.fragment = false;

+		this.registeredServices = null;

+		this.servicesInUse = null;

+		this.headers = null;

+		this.exportedPackages = null;

+		this.importedPackages = null;

+		this.fragments = null;

+		this.hosts = null;

+		this.requiringBundles = null;

+		this.requiredBundles = null;

+		this.key = null;

+		this.keysArray = null;

+		this.bundle = null;

+	}

+	

+	@Test

+	public void nameAndVersionTest() throws Exception {

+		int mask = BundleState.SYMBOLIC_NAME + BundleState.IDENTIFIER + BundleState.VERSION;

+		long start = System.currentTimeMillis();

+		TabularData table = jmxInvokeBundleState("listBundles", new Object[]{ new Integer(mask) }, new String[]{ "int" });

+		long end = System.currentTimeMillis();

+		assertTrue((end - start) < 1000);

+		Set<?> keys = table.keySet();

+		Iterator<?> iter = keys.iterator();

+		BundleContext bc = FrameworkUtil.getBundle(BundleState.class).getBundleContext();

+		while (iter.hasNext()) {

+			key = iter.next();

+			keysArray = ((Collection<?>) key).toArray();

+			bundleInfo = (CompositeData) table.get(keysArray);

+			symbolicName = (String) bundleInfo.get(BundleStateMBean.SYMBOLIC_NAME);

+			version = (String) bundleInfo.get(BundleStateMBean.VERSION);

+			bundle = bc.getBundle((Long) keysArray[0]);

+			assertEquals(symbolicName, bundle.getSymbolicName());

+			assertEquals(version, bundle.getVersion().toString());

+		}

+	}

+

+	@SuppressWarnings("unchecked")

+	@Test

+	public void listTest() throws Exception {

+		TabularData table = jmxInvokeBundleState("listBundles", new Object[]{}, new String[]{});

+		Set<?> keys = table.keySet();

+		Iterator<?> iter = keys.iterator();

+		BundleContext bc = FrameworkUtil.getBundle(BundleState.class).getBundleContext();

+		while (iter.hasNext()) {

+			key = iter.next();

+			keysArray = ((Collection<?>) key).toArray();

+			bundleInfo = table.get(keysArray);

+

+			location = (String) bundleInfo.get(BundleStateMBean.LOCATION);

+			symbolicName = (String) bundleInfo.get(BundleStateMBean.SYMBOLIC_NAME);

+			version = (String) bundleInfo.get(BundleStateMBean.VERSION);

+			startLevel = (Integer) bundleInfo.get(BundleStateMBean.START_LEVEL);

+			state = (String) bundleInfo.get(BundleStateMBean.STATE);

+			lastModified = (Long) bundleInfo.get(BundleStateMBean.LAST_MODIFIED);

+			persistenlyStarted = (Boolean) bundleInfo.get(BundleStateMBean.PERSISTENTLY_STARTED);

+			activationPolicyUsed = (Boolean) bundleInfo.get(CustomBundleStateMBean.ACTIVATION_POLICY_USED);

+			removalPending = (Boolean) bundleInfo.get(BundleStateMBean.REMOVAL_PENDING);

+			required = (Boolean) bundleInfo.get(BundleStateMBean.REQUIRED);

+			fragment = (Boolean) bundleInfo.get(BundleStateMBean.FRAGMENT);

+			registeredServices = (Long[]) bundleInfo.get(BundleStateMBean.REGISTERED_SERVICES);

+			servicesInUse = (Long[]) bundleInfo.get(BundleStateMBean.SERVICES_IN_USE);

+			headers = (Map<String, CompositeData>) bundleInfo.get(BundleStateMBean.HEADERS);

+			exportedPackages = (String[]) bundleInfo.get(BundleStateMBean.EXPORTED_PACKAGES);

+			importedPackages = (String[]) bundleInfo.get(BundleStateMBean.IMPORTED_PACKAGES);

+			fragments = (Long[]) bundleInfo.get(BundleStateMBean.FRAGMENTS);

+			hosts = (Long[]) bundleInfo.get(BundleStateMBean.HOSTS);

+			requiringBundles = (Long[]) bundleInfo.get(BundleStateMBean.REQUIRING_BUNDLES);

+			requiredBundles = (Long[]) bundleInfo.get(BundleStateMBean.REQUIRED_BUNDLES);

+

+			bundle = bc.getBundle((Long) keysArray[0]);

+			assertEquals(location, bundle.getLocation());

+			assertEquals(symbolicName, bundle.getSymbolicName());

+			assertEquals(version, bundle.getVersion().toString());

+			assertEquals(startLevel, bundle.adapt(BundleStartLevel.class).getStartLevel());

+			assertEquals(state, stateToString(bundle.getState()));

+			assertEquals(lastModified, bundle.getLastModified());

+			assertEquals(persistenlyStarted, BundleUtil.isBundlePersistentlyStarted(bundle));

+			assertEquals(activationPolicyUsed, BundleUtil.isBundleActivationPolicyUsed(bundle));

+			assertEquals(removalPending, BundleUtil.isRemovalPending(bundle));

+			assertEquals(required, BundleUtil.isRequired(bundle));

+			assertEquals(fragment, BundleUtil.isBundleFragment(bundle));

+

+			Long[] rs2 = serviceIds(bundle.getRegisteredServices());

+			Arrays.sort(registeredServices);

+			Arrays.sort(rs2);

+			assertTrue(Arrays.equals(registeredServices, rs2));

+

+			Long[] siu2 = serviceIds(bundle.getServicesInUse());

+			Arrays.sort(servicesInUse);

+			Arrays.sort(siu2);

+			assertTrue(Arrays.equals(servicesInUse, siu2));

+

+			assertEquals((TabularData) headers,	OSGiBundle.headerTable(bundle.getHeaders()));

+

+			String[] exportedPackages2 = BundleUtil.getBundleExportedPackages(bundle);

+			Arrays.sort(exportedPackages);

+			Arrays.sort(exportedPackages2);

+			assertTrue(Arrays.equals(exportedPackages, exportedPackages2));

+

+			String[] importedPackages2 = BundleUtil.getBundleImportedPackages(bundle);

+			Arrays.sort(importedPackages);

+			Arrays.sort(importedPackages2);

+			assertTrue(Arrays.equals(importedPackages, importedPackages2));

+

+			Long[] frags2 = getBundleFragments(bundle);

+			Arrays.sort(fragments);

+			Arrays.sort(frags2);

+			assertTrue(Arrays.equals(fragments, frags2));

+

+			Long[] hst2 = getBundleHosts(bundle);

+			Arrays.sort(hosts);

+			Arrays.sort(hst2);

+			assertTrue(Arrays.equals(hosts, hst2));

+

+			Long[] reqB2 = getRequiringBundles(bundle);

+			Arrays.sort(requiringBundles);

+			Arrays.sort(reqB2);

+			assertTrue(Arrays.equals(requiringBundles, reqB2));

+

+			Long[] requiredB2 = getRequiredBundles(bundle);

+			Arrays.sort(requiredBundles);

+			Arrays.sort(requiredB2);

+			assertTrue(Arrays.equals(requiredBundles, requiredB2));

+		}

+	}

+

+	@SuppressWarnings("unchecked")

+	@Test

+	public void fullMaskTest() throws Exception {

+		TabularData table = jmxInvokeBundleState("listBundles", new Object[]{ new Integer(CustomBundleStateMBean.DEFAULT) }, new String[]{ "int" });

+		Set<?> keys = table.keySet();

+		Iterator<?> iter = keys.iterator();

+		BundleContext bc = FrameworkUtil.getBundle(BundleState.class).getBundleContext();

+		while (iter.hasNext()) {

+			key = iter.next();

+			keysArray = ((Collection<?>) key).toArray();

+			bundleInfo = table.get(keysArray);

+

+			location = (String) bundleInfo.get(BundleStateMBean.LOCATION);

+			symbolicName = (String) bundleInfo.get(BundleStateMBean.SYMBOLIC_NAME);

+			version = (String) bundleInfo.get(BundleStateMBean.VERSION);

+			startLevel = (Integer) bundleInfo.get(BundleStateMBean.START_LEVEL);

+			state = (String) bundleInfo.get(BundleStateMBean.STATE);

+			lastModified = (Long) bundleInfo.get(BundleStateMBean.LAST_MODIFIED);

+			persistenlyStarted = (Boolean) bundleInfo.get(BundleStateMBean.PERSISTENTLY_STARTED);

+			activationPolicyUsed = (Boolean) bundleInfo.get(CustomBundleStateMBean.ACTIVATION_POLICY_USED);

+			removalPending = (Boolean) bundleInfo.get(BundleStateMBean.REMOVAL_PENDING);

+			required = (Boolean) bundleInfo.get(BundleStateMBean.REQUIRED);

+			fragment = (Boolean) bundleInfo.get(BundleStateMBean.FRAGMENT);

+			registeredServices = (Long[]) bundleInfo.get(BundleStateMBean.REGISTERED_SERVICES);

+			servicesInUse = (Long[]) bundleInfo.get(BundleStateMBean.SERVICES_IN_USE);

+			headers = (Map<String, CompositeData>) bundleInfo.get(BundleStateMBean.HEADERS);

+			exportedPackages = (String[]) bundleInfo.get(BundleStateMBean.EXPORTED_PACKAGES);

+			importedPackages = (String[]) bundleInfo.get(BundleStateMBean.IMPORTED_PACKAGES);

+			fragments = (Long[]) bundleInfo.get(BundleStateMBean.FRAGMENTS);

+			hosts = (Long[]) bundleInfo.get(BundleStateMBean.HOSTS);

+			requiringBundles = (Long[]) bundleInfo.get(BundleStateMBean.REQUIRING_BUNDLES);

+			requiredBundles = (Long[]) bundleInfo.get(BundleStateMBean.REQUIRED_BUNDLES);

+

+			bundle = bc.getBundle((Long) keysArray[0]);

+			assertEquals(location, bundle.getLocation());

+			assertEquals(symbolicName, bundle.getSymbolicName());

+			assertEquals(version, bundle.getVersion().toString());

+			assertEquals(startLevel, bundle.adapt(BundleStartLevel.class).getStartLevel());

+			assertEquals(state, stateToString(bundle.getState()));

+			assertEquals(lastModified, bundle.getLastModified());

+			assertEquals(persistenlyStarted, BundleUtil.isBundlePersistentlyStarted(bundle));

+			assertEquals(activationPolicyUsed, BundleUtil.isBundleActivationPolicyUsed(bundle));

+			assertEquals(removalPending, BundleUtil.isRemovalPending(bundle));

+			assertEquals(required, BundleUtil.isRequired(bundle));

+			assertEquals(fragment, BundleUtil.isBundleFragment(bundle));

+

+			Long[] rs2 = serviceIds(bundle.getRegisteredServices());

+			Arrays.sort(registeredServices);

+			Arrays.sort(rs2);

+			assertTrue(Arrays.equals(registeredServices, rs2));

+

+			Long[] siu2 = serviceIds(bundle.getServicesInUse());

+			Arrays.sort(servicesInUse);

+			Arrays.sort(siu2);

+			assertTrue(Arrays.equals(servicesInUse, siu2));

+

+			assertEquals((TabularData) headers,	OSGiBundle.headerTable(bundle.getHeaders()));

+

+			String[] exportedPackages2 = BundleUtil.getBundleExportedPackages(bundle);

+			Arrays.sort(exportedPackages);

+			Arrays.sort(exportedPackages2);

+			assertTrue(Arrays.equals(exportedPackages, exportedPackages2));

+

+			String[] importedPackages2 = BundleUtil.getBundleImportedPackages(bundle);

+			Arrays.sort(importedPackages);

+			Arrays.sort(importedPackages2);

+			assertTrue(Arrays.equals(importedPackages, importedPackages2));

+

+			Long[] frags2 = getBundleFragments(bundle);

+			Arrays.sort(fragments);

+			Arrays.sort(frags2);

+			assertTrue(Arrays.equals(fragments, frags2));

+

+			Long[] hst2 = getBundleHosts(bundle);

+			Arrays.sort(hosts);

+			Arrays.sort(hst2);

+			assertTrue(Arrays.equals(hosts, hst2));

+

+			Long[] reqB2 = getRequiringBundles(bundle);

+			Arrays.sort(requiringBundles);

+			Arrays.sort(reqB2);

+			assertTrue(Arrays.equals(requiringBundles, reqB2));

+

+			Long[] requiredB2 = getRequiredBundles(bundle);

+			Arrays.sort(requiredBundles);

+			Arrays.sort(requiredB2);

+			assertTrue(Arrays.equals(requiredBundles, requiredB2));

+		}

+	}

+

+	@Test

+	public void randomMaskTest() throws Exception {

+		int mask = BundleState.IDENTIFIER + BundleState.VERSION

+				+ BundleState.STATE + BundleState.LAST_MODIFIED

+				+ BundleState.PERSISTENTLY_STARTED + BundleState.REMOVAL_PENDING

+				+ BundleState.REGISTERED_SERVICES + BundleState.SERVICES_IN_USE

+				+ BundleState.EXPORTED_PACKAGES + BundleState.IMPORTED_PACKAGES

+				+ BundleState.HOSTS + BundleState.REQUIRING_BUNDLES;

+		TabularData table = jmxInvokeBundleState("listBundles", new Object[]{ new Integer(mask) }, new String[]{ "int" });

+		Set<?> keys = table.keySet();

+		Iterator<?> iter = keys.iterator();

+		BundleContext bc = FrameworkUtil.getBundle(BundleState.class).getBundleContext();

+		while (iter.hasNext()) {

+			key = iter.next();

+			keysArray = ((Collection<?>) key).toArray();

+			bundleInfo = (CompositeData) table.get(keysArray);

+

+			version = (String) bundleInfo.get(BundleStateMBean.VERSION);

+			state = (String) bundleInfo.get(BundleStateMBean.STATE);

+			lastModified = (Long) bundleInfo.get(BundleStateMBean.LAST_MODIFIED);

+			persistenlyStarted = (Boolean) bundleInfo.get(BundleStateMBean.PERSISTENTLY_STARTED);

+			removalPending = (Boolean) bundleInfo.get(BundleStateMBean.REMOVAL_PENDING);

+			registeredServices = (Long[]) bundleInfo.get(BundleStateMBean.REGISTERED_SERVICES);

+			servicesInUse = (Long[]) bundleInfo.get(BundleStateMBean.SERVICES_IN_USE);

+			exportedPackages = (String[]) bundleInfo.get(BundleStateMBean.EXPORTED_PACKAGES);

+			importedPackages = (String[]) bundleInfo.get(BundleStateMBean.IMPORTED_PACKAGES);

+			hosts = (Long[]) bundleInfo.get(BundleStateMBean.HOSTS);

+			requiringBundles = (Long[]) bundleInfo.get(BundleStateMBean.REQUIRING_BUNDLES);

+			bundle = bc.getBundle((Long) keysArray[0]);

+

+			assertEquals(version, bundle.getVersion().toString());

+			assertEquals(state, stateToString(bundle.getState()));

+			assertEquals(lastModified, bundle.getLastModified());

+			assertEquals(persistenlyStarted, BundleUtil.isBundlePersistentlyStarted(bundle));

+			assertEquals(removalPending, BundleUtil.isRemovalPending(bundle));

+

+			Long[] rs2 = serviceIds(bundle.getRegisteredServices());

+			Arrays.sort(registeredServices);

+			Arrays.sort(rs2);

+			assertTrue(Arrays.equals(registeredServices, rs2));

+

+			Long[] siu2 = serviceIds(bundle.getServicesInUse());

+			Arrays.sort(servicesInUse);

+			Arrays.sort(siu2);

+			assertTrue(Arrays.equals(servicesInUse, siu2));

+

+			String[] exportedPackages2 = BundleUtil.getBundleExportedPackages(bundle);

+			Arrays.sort(exportedPackages);

+			Arrays.sort(exportedPackages2);

+			assertTrue(Arrays.equals(exportedPackages, exportedPackages2));

+

+			String[] importedPackages2 = BundleUtil.getBundleImportedPackages(bundle);

+			Arrays.sort(importedPackages);

+			Arrays.sort(importedPackages2);

+			assertTrue(Arrays.equals(importedPackages, importedPackages2));

+

+			Long[] hst2 = getBundleHosts(bundle);

+			Arrays.sort(hosts);

+			Arrays.sort(hst2);

+			assertTrue(Arrays.equals(hosts, hst2));

+

+			Long[] reqB2 = getRequiringBundles(bundle);

+			Arrays.sort(requiringBundles);

+			Arrays.sort(reqB2);

+			assertTrue(Arrays.equals(requiringBundles, reqB2));

+		}

+	}

+

+	@Test

+	public void illegalMaskTest() throws Exception {

+		int mask = 2097152;

+		try {

+			@SuppressWarnings("unused")

+			TabularData table = jmxInvokeBundleState("listBundles", new Object[]{ new Integer(mask) }, new String[]{ "int" });

+			fail("Expected exception did not occur!");

+		} catch (Exception e) {

+			assertTrue(e.getCause() instanceof IllegalArgumentException);

+		}

+	}

+

+	private String stateToString(int state) {

+		switch (state) {

+			case Bundle.ACTIVE:

+				return "ACTIVE";

+			case Bundle.INSTALLED:

+				return "INSTALLED";

+			case Bundle.RESOLVED:

+				return "RESOLVED";

+			case Bundle.STARTING:

+				return "STARTING";

+			case Bundle.STOPPING:

+				return "STOPPING";

+			case Bundle.UNINSTALLED:

+				return "UNINSTALLED";

+			default:

+				return "UNKNOWN";

+		}

+	}

+

+    private Long[] getRequiredBundles(Bundle bundle) {

+        BundleWiring wiring = bundle.adapt(BundleWiring.class);

+        List<BundleWire> requiredWires = wiring.getRequiredWires(BundleRevision.BUNDLE_NAMESPACE);

+        return bundleWiresToIds(requiredWires);

+    }

+

+    private Long[] getRequiringBundles(Bundle bundle) {

+        BundleWiring wiring = bundle.adapt(BundleWiring.class);

+        List<BundleWire> providedWires = wiring.getProvidedWires(BundleRevision.BUNDLE_NAMESPACE);

+        return bundleWiresToIds(providedWires);

+    }

+

+	private Long[] getBundleFragments(Bundle bundle) {

+		BundleWiring wiring = bundle.adapt(BundleWiring.class);

+		List<BundleWire> requiredWires = wiring.getRequiredWires(BundleRevision.HOST_NAMESPACE);

+        return bundleWiresToIds(requiredWires);

+	}

+

+	private Long[] getBundleHosts(Bundle bundle) {

+		BundleWiring wiring = bundle.adapt(BundleWiring.class);

+		List<BundleWire> providedWires = wiring.getProvidedWires(BundleRevision.HOST_NAMESPACE);

+        return bundleWiresToIds(providedWires);

+	}

+

+	private Long[] bundleWiresToIds(List<BundleWire> wires){

+        Long[] consumerWirings = new Long[wires.size()];

+        int i = 0;

+        for (BundleWire bundleWire : wires) {

+            consumerWirings[i] = bundleWire.getRequirerWiring().getBundle().getBundleId();

+            i++;

+        }

+        return consumerWirings;

+	}

+	

+	private Long[] serviceIds(ServiceReference<?>[] refs) {

+		if (refs == null) {

+			return new Long[0];

+		}

+		Long[] ids = new Long[refs.length];

+		for (int i = 0; i < refs.length; i++) {

+			ids[i] = (Long) refs[i].getProperty(Constants.SERVICE_ID);

+		}

+		return ids;

+	}

+}

+

diff --git a/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/framework/BundleWiringStateTests.java b/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/framework/BundleWiringStateTests.java
new file mode 100644
index 0000000..ef12075
--- /dev/null
+++ b/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/framework/BundleWiringStateTests.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2011 VMware Inc.
+ * 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:
+ *   VMware Inc. - initial contribution
+ *******************************************************************************/
+package org.eclipse.gemini.mgmt.framework;
+
+import org.eclipse.gemini.mgmt.AbstractOSGiMBeanTest;
+
+/**
+ * Integration tests for the {@link BundleWiringState} implementation of {@link CustomBundleWiringStateMBean}
+ *
+ */
+public final class BundleWiringStateTests extends AbstractOSGiMBeanTest {
+
+	protected String mBeanObjectName = CustomBundleWiringStateMBean.OBJECTNAME;
+	
+}
diff --git a/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/framework/FrameworkTests.java b/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/framework/FrameworkTests.java
new file mode 100644
index 0000000..0aae3e4
--- /dev/null
+++ b/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/framework/FrameworkTests.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2011 VMware Inc.
+ * 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:
+ *   VMware Inc. - initial contribution
+ *******************************************************************************/
+package org.eclipse.gemini.mgmt.framework;
+
+import org.eclipse.gemini.mgmt.AbstractOSGiMBeanTest;
+import org.osgi.jmx.framework.FrameworkMBean;
+
+/**
+ * Integration tests for the {@link Framework} implementation of {@link FrameworkMBean}
+ *
+ */
+public final class FrameworkTests extends AbstractOSGiMBeanTest {
+
+	protected String mBeanObjectName = FrameworkMBean.OBJECTNAME;
+	
+}
diff --git a/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/framework/PackageStateTests.java b/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/framework/PackageStateTests.java
new file mode 100644
index 0000000..46615c7
--- /dev/null
+++ b/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/framework/PackageStateTests.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2011 VMware Inc.
+ * 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:
+ *   VMware Inc. - initial contribution
+ *******************************************************************************/
+package org.eclipse.gemini.mgmt.framework;
+
+import org.eclipse.gemini.mgmt.AbstractOSGiMBeanTest;
+import org.osgi.jmx.framework.PackageStateMBean;
+
+/**
+ * Integration tests for the {@link PackageState} implementation {@link PackageStateMBean}
+ *
+ */
+public final class PackageStateTests extends AbstractOSGiMBeanTest {
+
+	protected String mBeanObjectName = PackageStateMBean.OBJECTNAME;
+	
+}
diff --git a/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/framework/ServiceStateTests.java b/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/framework/ServiceStateTests.java
new file mode 100644
index 0000000..69c7420
--- /dev/null
+++ b/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/framework/ServiceStateTests.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2011 VMware Inc.
+ * 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:
+ *   VMware Inc. - initial contribution
+ *******************************************************************************/
+package org.eclipse.gemini.mgmt.framework;
+
+import org.eclipse.gemini.mgmt.AbstractOSGiMBeanTest;
+import org.osgi.jmx.framework.ServiceStateMBean;
+
+/**
+ * Integration tests for the {@link ServiceState} implementation of {@link CustomServiceStateMBean} and {@link ServiceStateMBean}
+ *
+ */
+public final class ServiceStateTests extends AbstractOSGiMBeanTest {
+
+	protected String mBeanObjectName = ServiceStateMBean.OBJECTNAME;
+	
+}
diff --git a/org.eclipse.gemini.mgmt/.classpath b/org.eclipse.gemini.mgmt/.classpath
index 9aa40d0..39727ae 100644
--- a/org.eclipse.gemini.mgmt/.classpath
+++ b/org.eclipse.gemini.mgmt/.classpath
@@ -1,7 +1,8 @@
-<?xml version="1.0" encoding="UTF-8"?>

-<classpath>

-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>

-	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>

-	<classpathentry excluding="**/.svn/*" kind="src" path="src"/>

-	<classpathentry kind="output" path="bin"/>

-</classpath>

+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="src" path="src/main/java"/>
+	<classpathentry kind="src" path="src/test/java"/>
+	<classpathentry kind="output" path="target"/>
+</classpath>
diff --git a/org.eclipse.gemini.mgmt/build.properties b/org.eclipse.gemini.mgmt/build.properties
index 0db7570..60212e4 100644
--- a/org.eclipse.gemini.mgmt/build.properties
+++ b/org.eclipse.gemini.mgmt/build.properties
@@ -1,3 +1,3 @@
-source.. = src/

-output.. = bin/

+source.. = src/main/java/

+output.. = target/

 bin.includes = META-INF/,.

diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/Activator.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/Activator.java
similarity index 100%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/Activator.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/Activator.java
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/DefaultObjectNameTranslator.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/DefaultObjectNameTranslator.java
similarity index 100%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/DefaultObjectNameTranslator.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/DefaultObjectNameTranslator.java
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/Monitor.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/Monitor.java
similarity index 100%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/Monitor.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/Monitor.java
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/ObjectNameTranslator.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/ObjectNameTranslator.java
similarity index 100%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/ObjectNameTranslator.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/ObjectNameTranslator.java
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/configurationadmin/ConfigAdminManager.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/configurationadmin/ConfigAdminManager.java
similarity index 100%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/configurationadmin/ConfigAdminManager.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/configurationadmin/ConfigAdminManager.java
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/BundleState.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/BundleState.java
similarity index 78%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/BundleState.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/BundleState.java
index 8220e2f..36da3a8 100644
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/BundleState.java
+++ b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/BundleState.java
@@ -17,6 +17,7 @@
 

 import java.io.IOException;

 import java.util.ArrayList;

+import java.util.List;

 

 import javax.management.Notification;

 import javax.management.openmbean.CompositeData;

@@ -27,6 +28,11 @@
 import org.osgi.framework.BundleContext;

 import org.osgi.framework.BundleEvent;

 import org.osgi.framework.BundleListener;

+import org.osgi.framework.Constants;

+import org.osgi.framework.ServiceReference;

+import org.osgi.framework.wiring.BundleRevision;

+import org.osgi.framework.wiring.BundleWire;

+import org.osgi.framework.wiring.BundleWiring;

 import org.osgi.jmx.framework.BundleStateMBean;

 

 import org.eclipse.gemini.mgmt.Monitor;

@@ -56,7 +62,7 @@
 	 */

 	public TabularData listBundles() throws IOException {

 		try {

-			TabularDataSupport table = new TabularDataSupport(BundleStateMBean.BUNDLES_TYPE);

+			TabularDataSupport table = new TabularDataSupport(CustomBundleStateMBean.CUSTOM_BUNDLES_TYPE);

 			for (Bundle bundle : bundleContext.getBundles()) {

 				table.put(new OSGiBundle(bundle).asCompositeData());

 			}

@@ -70,7 +76,7 @@
 	 * {@inheritDoc}

 	 */

 	public TabularData listBundles(int mask) throws IOException {

-		if (mask < 1 || mask > 1048575) {

+		if (mask < 1 || mask > 2097151) {

 			throw new IllegalArgumentException("Mask out of range!");

 		}

 		try {

@@ -96,7 +102,9 @@
 	 * {@inheritDoc}

 	 */

 	public long[] getFragments(long bundleId) throws IOException {

-		return BundleUtil.getBundleFragments(retrieveBundle(bundleId));

+		BundleWiring wiring = retrieveBundle(bundleId).adapt(BundleWiring.class);

+		List<BundleWire> requiredWires = wiring.getRequiredWires(BundleRevision.HOST_NAMESPACE);

+        return bundleWiresToIds(requiredWires);

 	}

 

 	/**

@@ -110,9 +118,11 @@
 	 * {@inheritDoc}

 	 */

 	public long[] getHosts(long fragment) throws IOException {

-		return BundleUtil.getBundleHosts(retrieveBundle(fragment));

+		BundleWiring wiring = retrieveBundle(fragment).adapt(BundleWiring.class);

+		List<BundleWire> providedWires = wiring.getProvidedWires(BundleRevision.HOST_NAMESPACE);

+        return bundleWiresToIds(providedWires);

 	}

-

+	

 	/**

 	 * {@inheritDoc}

 	 */

@@ -131,21 +141,22 @@
 	 * {@inheritDoc}

 	 */

 	public long[] getRegisteredServices(long bundleId) throws IOException {

-		return BundleUtil.serviceIds(retrieveBundle(bundleId).getRegisteredServices());

+		return serviceIds(retrieveBundle(bundleId).getRegisteredServices());

 	}

 

 	/**

 	 * {@inheritDoc}

 	 */

 	public long[] getRequiringBundles(long bundleId) throws IOException {

-		return BundleUtil.getRequiringBundles(retrieveBundle(bundleId));

-	}

-

+        BundleWiring wiring = retrieveBundle(bundleId).adapt(BundleWiring.class);

+        List<BundleWire> providedWires = wiring.getProvidedWires(BundleRevision.BUNDLE_NAMESPACE);

+        return bundleWiresToIds(providedWires);

+    }

 	/**

 	 * {@inheritDoc}

 	 */

 	public long[] getServicesInUse(long bundleIdentifier) throws IOException {

-		return BundleUtil.serviceIds(retrieveBundle(bundleIdentifier).getServicesInUse());

+		return serviceIds(retrieveBundle(bundleIdentifier).getServicesInUse());

 	}

 

 	/**

@@ -180,8 +191,10 @@
 	 * {@inheritDoc}

 	 */

 	public long[] getRequiredBundles(long bundleIdentifier) throws IOException {

-		return BundleUtil.getRequiredBundles(retrieveBundle(bundleIdentifier));

-	}

+        BundleWiring wiring = retrieveBundle(bundleIdentifier).adapt(BundleWiring.class);

+        List<BundleWire> requiredWires = wiring.getRequiredWires(BundleRevision.BUNDLE_NAMESPACE);

+        return bundleWiresToIds(requiredWires);

+    }

 

 	/**

 	 * {@inheritDoc}

@@ -285,6 +298,29 @@
 		return b;

 	}

 

+	private long[] bundleWiresToIds(List<BundleWire> wires){

+        long[] consumerWirings = new long[wires.size()];

+        int i = 0;

+        for (BundleWire bundleWire : wires) {

+            consumerWirings[i] = bundleWire.getRequirerWiring().getBundle().getBundleId();

+            i++;

+        }

+        return consumerWirings;

+	}

+

+	private long[] serviceIds(ServiceReference<?>[] refs) {

+		if (refs == null) {

+			return new long[0];

+		}

+		long[] ids = new long[refs.length];

+		for (int i = 0; i < refs.length; i++) {

+			ids[i] = (Long) refs[i].getProperty(Constants.SERVICE_ID);

+		}

+		return ids;

+	}

+	

+	//Monitor methods

+	

 	/**

 	 * {@inheritDoc}

 	 */

diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/BundleWiringState.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/BundleWiringState.java
similarity index 82%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/BundleWiringState.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/BundleWiringState.java
index 345b58a..9460add 100644
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/BundleWiringState.java
+++ b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/BundleWiringState.java
@@ -23,11 +23,11 @@
 import org.eclipse.gemini.mgmt.framework.internal.OSGiBundleRevision;
 import org.eclipse.gemini.mgmt.framework.internal.OSGiBundleRevisionIdTracker;
 import org.eclipse.gemini.mgmt.framework.internal.OSGiBundleWiring;
-import org.eclipse.gemini.mgmt.internal.BundleWiringUtil;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.wiring.BundleRevision;
 import org.osgi.framework.wiring.BundleRevisions;
+import org.osgi.framework.wiring.BundleWire;
 import org.osgi.framework.wiring.BundleWiring;
 
 /**
@@ -79,7 +79,7 @@
 		namespace = processNamespace(namespace);
 		BundleWiring wiring = getBundle(rootBundleId).adapt(BundleWiring.class);
 		Map<BundleRevision, OSGiBundleWiring> mappings = new HashMap<BundleRevision, OSGiBundleWiring>();
-		BundleWiringUtil.processWiring(mappings, wiring, namespace);
+		processWiring(mappings, wiring, namespace);
 		TabularDataSupport table = new TabularDataSupport(CustomBundleWiringStateMBean.BUNDLE_REVISIONS_WIRINGS_CLOSURES_TYPE);
 		OSGiBundleRevisionIdTracker revisionTracker = new OSGiBundleRevisionIdTracker();
 		for(Entry<BundleRevision, OSGiBundleWiring> osgiBundleWiring : mappings.entrySet()){
@@ -140,7 +140,7 @@
 		List<BundleRevision> bundleRevisions = getBundle(rootBundleId).adapt(BundleRevisions.class).getRevisions();
 		Map<BundleRevision, OSGiBundleWiring> mappings = new HashMap<BundleRevision, OSGiBundleWiring>();
 		for (BundleRevision bundleRevision : bundleRevisions) {
-			BundleWiringUtil.processWiring(mappings, bundleRevision.getWiring(), namespace);
+			processWiring(mappings, bundleRevision.getWiring(), namespace);
 		}
 		TabularDataSupport table = new TabularDataSupport(CustomBundleWiringStateMBean.BUNDLE_REVISIONS_WIRINGS_CLOSURES_TYPE);
 		OSGiBundleRevisionIdTracker revisionTracker = new OSGiBundleRevisionIdTracker();
@@ -167,4 +167,37 @@
 		return namespace;
 	}
 	
+	/**
+	 * Add all related wirings to the provided map.
+	 * 
+	 * @param mappings of 
+	 * @param wiring
+	 * @param namespace
+	 */
+	private void processWiring(Map<BundleRevision, OSGiBundleWiring> mappings, BundleWiring wiring, String namespace){
+		BundleRevision bundleRevision = wiring.getRevision();
+		if(!mappings.containsKey(bundleRevision)) {
+			mappings.put(bundleRevision, new OSGiBundleWiring(wiring));
+			processRequiredWirings(mappings, wiring, namespace);
+			processProvidedWirings(mappings, wiring, namespace);
+		}
+	}
+	
+	private void processRequiredWirings(Map<BundleRevision, OSGiBundleWiring> mappings, BundleWiring wiring, String namespace){
+		List<BundleWire> requiredWires = wiring.getRequiredWires(namespace);
+		if(requiredWires != null) {
+			for (BundleWire bundleWire : requiredWires) {
+				processWiring(mappings, bundleWire.getProviderWiring(), namespace);
+			}
+		}
+	}
+	
+	private void processProvidedWirings(Map<BundleRevision, OSGiBundleWiring> mappings, BundleWiring wiring, String namespace){
+		List<BundleWire> providedWires = wiring.getProvidedWires(namespace);
+		if(providedWires != null) {
+			for (BundleWire bundleWire : providedWires) {
+				processWiring(mappings, bundleWire.getRequirerWiring(), namespace);
+			}
+		}
+	}
 }
\ No newline at end of file
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/CustomBundleStateMBean.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/CustomBundleStateMBean.java
similarity index 87%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/CustomBundleStateMBean.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/CustomBundleStateMBean.java
index 393225d..f5df475 100644
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/CustomBundleStateMBean.java
+++ b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/CustomBundleStateMBean.java
@@ -17,8 +17,10 @@
 import java.io.IOException;
 
 import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeType;
 import javax.management.openmbean.SimpleType;
 import javax.management.openmbean.TabularData;
+import javax.management.openmbean.TabularType;
 
 import org.osgi.jmx.Item;
 import org.osgi.jmx.framework.BundleStateMBean;
@@ -157,7 +159,7 @@
 	 */
 	public final static int DEFAULT = LOCATION + IDENTIFIER
 	+ SYMBOLIC_NAME + VERSION + START_LEVEL + STATE + LAST_MODIFIED 
-	+ PERSISTENTLY_STARTED + REMOVAL_PENDING + REQUIRED + FRAGMENT + REGISTERED_SERVICES
+	+ PERSISTENTLY_STARTED + ACTIVATION_POLICY + REMOVAL_PENDING + REQUIRED + FRAGMENT + REGISTERED_SERVICES
 	+ SERVICES_IN_USE + HEADERS + EXPORTED_PACKAGES + IMPORTED_PACKAGES + FRAGMENTS 
 	+ HOSTS + REQUIRING_BUNDLES + REQUIRED_BUNDLES;
 
@@ -172,6 +174,8 @@
 	 * @throws IOException
 	 */
 	TabularData listBundles(int mask) throws IOException;
+
+	//New methods from the JMX Update RFC 169
 	
 	/**
 	 * The key PERSISTENTLY_STARTED, used in {@link #PERSISTENTLY_STARTED_ITEM}.
@@ -185,7 +189,21 @@
 	 */
 	Item ACTIVATION_POLICY_ITEM = new Item(ACTIVATION_POLICY_USED,	"Whether the bundle is using an activation policy", SimpleType.BOOLEAN);
 	
-	//New methods from the JMX Update RFC 169
+	CompositeType CUSTOM_BUNDLE_TYPE = Item.compositeType("BUNDLE",
+			"This type encapsulates OSGi bundles", EXPORTED_PACKAGES_ITEM,
+			FRAGMENT_ITEM, FRAGMENTS_ITEM, HEADERS_ITEM, HOSTS_ITEM,
+			IDENTIFIER_ITEM, IMPORTED_PACKAGES_ITEM, LAST_MODIFIED_ITEM,
+			LOCATION_ITEM, PERSISTENTLY_STARTED_ITEM, ACTIVATION_POLICY_ITEM, 
+			REGISTERED_SERVICES_ITEM, REMOVAL_PENDING_ITEM, REQUIRED_ITEM, 
+			REQUIRED_BUNDLES_ITEM, REQUIRING_BUNDLES_ITEM, START_LEVEL_ITEM, 
+			STATE_ITEM, SERVICES_IN_USE_ITEM, SYMBOLIC_NAME_ITEM, VERSION_ITEM);
+
+	/**
+	 * The Tabular Type for a list of bundles. The row type is
+	 * {@link #BUNDLE_TYPE}.
+	 */
+	TabularType CUSTOM_BUNDLES_TYPE = Item.tabularType("BUNDLES", "A list of bundles",
+			BUNDLE_TYPE, new String[] { BundleStateMBean.IDENTIFIER });
 	
 	/**
 	 * 
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/CustomBundleWiringStateMBean.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/CustomBundleWiringStateMBean.java
similarity index 100%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/CustomBundleWiringStateMBean.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/CustomBundleWiringStateMBean.java
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/CustomServiceStateMBean.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/CustomServiceStateMBean.java
similarity index 100%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/CustomServiceStateMBean.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/CustomServiceStateMBean.java
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/Framework.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/Framework.java
similarity index 94%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/Framework.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/Framework.java
index 9a25864..334ef6a 100644
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/Framework.java
+++ b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/Framework.java
@@ -104,12 +104,12 @@
 		if (locations == null) {

 			throw new IOException("locations must not be null");

 		}

-		long ids[] = new long[locations.length];

+		Long ids[] = new Long[locations.length];

 		for (int i = 0; i < locations.length; i++) {

 			try {

 				ids[i] = bundleContext.installBundle(locations[i]).getBundleId();

 			} catch (Throwable e) {

-				long[] completed = new long[i];

+				Long[] completed = new Long[i];

 				System.arraycopy(ids, 0, completed, 0, completed.length);

 				String[] remaining = new String[locations.length - i - 1];

 				System.arraycopy(locations, i + 1, remaining, 0, remaining.length);

@@ -129,14 +129,14 @@
 		if (urls == null) {

 			throw new IOException("urls must not be null");

 		}

-		long ids[] = new long[locations.length];

+		Long ids[] = new Long[locations.length];

 		for (int i = 0; i < locations.length; i++) {

 			InputStream is = null;

 			try {

 				is = new URL(urls[i]).openStream();

 				ids[i] = bundleContext.installBundle(locations[i], is).getBundleId();

 			} catch (Throwable e) {

-				long[] completed = new long[i];

+				Long[] completed = new Long[i];

 				System.arraycopy(ids, 0, completed, 0, completed.length);

 				String[] remaining = new String[locations.length - i - 1];

 				System.arraycopy(locations, i + 1, remaining, 0, remaining.length);

@@ -245,9 +245,9 @@
 			try {

 				bundle(bundleIdentifiers[i]).adapt(BundleStartLevel.class).setStartLevel(newlevels[i]);

 			} catch (Throwable e) {

-				long[] completed = new long[i];

+				Long[] completed = new Long[i];

 				System.arraycopy(bundleIdentifiers, 0, completed, 0, completed.length);

-				long[] remaining = new long[bundleIdentifiers.length - i - 1];

+				Long[] remaining = new Long[bundleIdentifiers.length - i - 1];

 				System.arraycopy(bundleIdentifiers, i + 1, remaining, 0, remaining.length);

 				return new BundleBatchActionResult(e.toString(), completed, bundleIdentifiers[i], remaining).asCompositeData();

 			}

@@ -314,9 +314,9 @@
 			try {

 				bundle(bundleIdentifiers[i]).start();

 			} catch (Throwable e) {

-				long[] completed = new long[i];

+				Long[] completed = new Long[i];

 				System.arraycopy(bundleIdentifiers, 0, completed, 0, completed.length);

-				long[] remaining = new long[bundleIdentifiers.length - i - 1];

+				Long[] remaining = new Long[bundleIdentifiers.length - i - 1];

 				System.arraycopy(bundleIdentifiers, i + 1, remaining, 0, remaining.length);

 				return new BundleBatchActionResult(e.toString(), completed, bundleIdentifiers[i], remaining).asCompositeData();

 			}

@@ -346,9 +346,9 @@
 			try {

 				bundle(bundleIdentifiers[i]).stop();

 			} catch (Throwable e) {

-				long[] completed = new long[i];

+				Long[] completed = new Long[i];

 				System.arraycopy(bundleIdentifiers, 0, completed, 0, completed.length);

-				long[] remaining = new long[bundleIdentifiers.length - i - 1];

+				Long[] remaining = new Long[bundleIdentifiers.length - i - 1];

 				System.arraycopy(bundleIdentifiers, i + 1, remaining, 0, remaining.length);

 				return new BundleBatchActionResult(e.toString(), completed, bundleIdentifiers[i], remaining).asCompositeData();

 			}

@@ -378,9 +378,9 @@
 			try {

 				bundle(bundleIdentifiers[i]).uninstall();

 			} catch (Throwable e) {

-				long[] completed = new long[i];

+				Long[] completed = new Long[i];

 				System.arraycopy(bundleIdentifiers, 0, completed, 0, completed.length);

-				long[] remaining = new long[bundleIdentifiers.length - i - 1];

+				Long[] remaining = new Long[bundleIdentifiers.length - i - 1];

 				System.arraycopy(bundleIdentifiers, i + 1, remaining, 0, remaining.length);

 				return new BundleBatchActionResult(e.toString(), completed, bundleIdentifiers[i], remaining).asCompositeData();

 			}

@@ -430,9 +430,9 @@
 			try {

 				bundle(bundleIdentifiers[i]).update();

 			} catch (Throwable e) {

-				long[] completed = new long[i];

+				Long[] completed = new Long[i];

 				System.arraycopy(bundleIdentifiers, 0, completed, 0, completed.length);

-				long[] remaining = new long[bundleIdentifiers.length - i - 1];

+				Long[] remaining = new Long[bundleIdentifiers.length - i - 1];

 				System.arraycopy(bundleIdentifiers, i + 1, remaining, 0, remaining.length);

 				return new BundleBatchActionResult(e.toString(), completed, bundleIdentifiers[i], remaining).asCompositeData();

 			}

@@ -453,9 +453,9 @@
 				is = new URL(urls[i]).openStream();

 				bundle(bundleIdentifiers[i]).update(is);

 			} catch (Throwable e) {

-				long[] completed = new long[i];

+				Long[] completed = new Long[i];

 				System.arraycopy(bundleIdentifiers, 0, completed, 0, completed.length);

-				long[] remaining = new long[bundleIdentifiers.length - i - 1];

+				Long[] remaining = new Long[bundleIdentifiers.length - i - 1];

 				System.arraycopy(bundleIdentifiers, i + 1, remaining, 0, remaining.length);

 				return new BundleBatchActionResult(e.toString(), completed, bundleIdentifiers[i], remaining).asCompositeData();

 			} finally {

diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/PackageState.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/PackageState.java
similarity index 100%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/PackageState.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/PackageState.java
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/ServiceState.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/ServiceState.java
similarity index 98%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/ServiceState.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/ServiceState.java
index c2e144f..2cee22f 100644
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/ServiceState.java
+++ b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/ServiceState.java
@@ -29,7 +29,6 @@
 import org.eclipse.gemini.mgmt.framework.internal.OSGiService;

 import org.eclipse.gemini.mgmt.framework.internal.OSGiServiceEvent;

 import org.eclipse.gemini.mgmt.internal.OSGiProperties;

-import org.eclipse.gemini.mgmt.internal.ServiceUtil;

 import org.osgi.framework.AllServiceListener;

 import org.osgi.framework.Bundle;

 import org.osgi.framework.BundleContext;

@@ -101,7 +100,7 @@
 	 * {@inheritDoc}

 	 */

 	public long[] getUsingBundles(long serviceId) throws IOException {

-		return ServiceUtil.getBundlesUsing(getServiceReference(serviceId));

+		return OSGiService.getBundlesUsing(getServiceReference(serviceId));

 	}

 

 	//New methods from the JMX Update RFC 169

diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/BundleBatchActionResult.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/BundleBatchActionResult.java
similarity index 60%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/BundleBatchActionResult.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/BundleBatchActionResult.java
index d7572ab..43a9fe9 100644
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/BundleBatchActionResult.java
+++ b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/BundleBatchActionResult.java
@@ -15,8 +15,6 @@
 

 package org.eclipse.gemini.mgmt.framework.internal;

 

-import static org.eclipse.gemini.mgmt.internal.BundleUtil.LongArrayFrom;

-

 import java.util.HashMap;

 import java.util.Map;

 

@@ -56,11 +54,32 @@
  * </tr>

  * </table>

  */

-public final class BundleBatchActionResult extends BundleBatchResult {

+public final class BundleBatchActionResult {

 

+	/**

+	 * The list of bundles successfully completed

+	 */

+	private Long[] completed;

+	

+	/**

+	 * The error message of a failed result

+	 */

+	private String errorMessage;

+	

+	/**

+	 * True if the action completed without error

+	 */

+	private boolean success = true;

+	

+	/**

+	 * The bundle in error or -1L if no bundle is in error

+	 */

 	private long bundleInError;

 

-	private long[] remaining;

+	/**

+	 * The ids of the bundles remaining to be processed

+	 */

+	private Long[] remaining;

 	

 	/**

 	 * Construct a result signifying the successful completion of the batch

@@ -71,39 +90,6 @@
 	}

 

 	/**

-	 * Construct a result representing the contents of the supplied

-	 * CompositeData returned from a batch operation.

-	 * 

-	 * @param compositeData

-	 *            - the CompositeData representing the result of a batch

-	 *            operation.

-	 */

-	@SuppressWarnings("boxing")

-	public BundleBatchActionResult(CompositeData compositeData) {

-		success = ((Boolean) compositeData.get(FrameworkMBean.SUCCESS)).booleanValue();

-		errorMessage = (String) compositeData.get(FrameworkMBean.ERROR);

-		Long[] c = (Long[]) compositeData.get(FrameworkMBean.COMPLETED);

-		bundleInError = (Long) compositeData.get(FrameworkMBean.BUNDLE_IN_ERROR);

-		if (c != null) {

-			completed = new long[c.length];

-			for (int i = 0; i < c.length; i++) {

-				completed[i] = c[i];

-			}

-		} else {

-			completed = new long[0];

-		}

-		c = (Long[]) compositeData.get(FrameworkMBean.REMAINING);

-		if (c != null) {

-			remaining = new long[c.length];

-			for (int i = 0; i < c.length; i++) {

-				remaining[i] = c[i];

-			}

-		} else {

-			remaining = new long[0];

-		}

-	}

-

-	/**

 	 * Construct a result indictating the failure of a batch operation.

 	 * 

 	 * @param errorMessage

@@ -116,7 +102,7 @@
 	 * @param remaining

 	 *            - the list of bundle identifiers which remain unprocessed

 	 */

-	public BundleBatchActionResult(String errorMessage, long[] completed, long bundleInError, long[] remaining) {

+	public BundleBatchActionResult(String errorMessage, Long[] completed, long bundleInError, Long[] remaining) {

 		success = false;

 		this.errorMessage = errorMessage;

 		this.completed = completed;

@@ -129,14 +115,13 @@
 	 * 

 	 * @return the CompositeData encoding of the receiver.

 	 */

-	@SuppressWarnings("boxing")

 	public CompositeData asCompositeData() {

 		Map<String, Object> items = new HashMap<String, Object>();

 		items.put(FrameworkMBean.SUCCESS, success);

 		items.put(FrameworkMBean.ERROR, errorMessage);

-		items.put(FrameworkMBean.COMPLETED, LongArrayFrom(completed));

+		items.put(FrameworkMBean.COMPLETED, completed);

 		items.put(FrameworkMBean.BUNDLE_IN_ERROR, bundleInError);

-		items.put(FrameworkMBean.REMAINING, LongArrayFrom(remaining));

+		items.put(FrameworkMBean.REMAINING, remaining);

 

 		try {

 			return new CompositeDataSupport( FrameworkMBean.BATCH_ACTION_RESULT_TYPE, items);

@@ -145,26 +130,4 @@
 		}

 	}

 

-	/**

-	 * Answer the bundle identifier which indicates the bundle that produced an

-	 * error during the batch operation.

-	 * 

-	 * @return the bundle identifier of the bundle in error, or -1L if no error

-	 *         occurred

-	 */

-	public long getBundleInError() {

-		return bundleInError;

-	}

-

-	/**

-	 * If the operation was unsuccessful, answer the list of bundle identifiers

-	 * of the bundles that were not processed during the batch operation. If the

-	 * operation was a success, then answer null

-	 * 

-	 * @return the remaining bundle identifiers or null if the operation was a

-	 *         success

-	 */

-	public long[] getRemaining() {

-		return remaining;

-	}

 }

diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/BundleBatchInstallResult.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/BundleBatchInstallResult.java
similarity index 65%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/BundleBatchInstallResult.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/BundleBatchInstallResult.java
index d6ffcaa..0111110 100644
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/BundleBatchInstallResult.java
+++ b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/BundleBatchInstallResult.java
@@ -15,8 +15,6 @@
 

 package org.eclipse.gemini.mgmt.framework.internal;

 

-import static org.eclipse.gemini.mgmt.internal.BundleUtil.LongArrayFrom;

-

 import java.io.IOException;

 import java.util.HashMap;

 import java.util.Map;

@@ -58,36 +56,32 @@
  * </tr>

  * </table>

  */

-public final class BundleBatchInstallResult extends BundleBatchResult {

+public final class BundleBatchInstallResult {

 

-	private String bundleInError;

-

-	private String[] remaining;

+	/**

+	 * The list of bundles successfully completed

+	 */

+	private Long[] completed;

 	

 	/**

-	 * Construct a result representing the contents of the supplied

-	 * CompositeData returned from a batch operation.

-	 * 

-	 * @param compositeData

-	 *            - the CompositeData representing the result of a batch

-	 *            operation.

+	 * The error message of a failed result

 	 */

-	@SuppressWarnings("boxing")

-	public BundleBatchInstallResult(CompositeData compositeData) {

-		success = ((Boolean) compositeData.get(FrameworkMBean.SUCCESS)).booleanValue();

-		errorMessage = (String) compositeData.get(FrameworkMBean.ERROR);

-		Long[] c = (Long[]) compositeData.get(FrameworkMBean.COMPLETED);

-		if (c != null) {

-			completed = new long[c.length];

-			for (int i = 0; i < c.length; i++) {

-				completed[i] = c[i];

-			}

-		} else {

-			completed = new long[0];

-		}

-		bundleInError = (String) compositeData.get(FrameworkMBean.BUNDLE_IN_ERROR);

-		remaining = (String[]) compositeData.get(FrameworkMBean.REMAINING);

-	}

+	private String errorMessage;

+	

+	/**

+	 * True if the action completed without error

+	 */

+	private boolean success = true;

+	

+	/**

+	 * The bundle in error or -1L if no bundle is in error

+	 */

+	private String bundleInError;

+

+	/**

+	 * The locations of the bundles remaining to be processed

+	 */

+	private String[] remaining;

 

 	/**

 	 * Construct a result signifying the successful completion of the batch

@@ -96,7 +90,7 @@
 	 * @param completed

 	 *            - the resulting bundle identifiers of the installed bundles

 	 */

-	public BundleBatchInstallResult(long[] completed) {

+	public BundleBatchInstallResult(Long[] completed) {

 		success = true;

 		this.completed = completed;

 	}

@@ -114,7 +108,7 @@
 	 * @param remaining

 	 *            - the list of bundle identifiers which remain unprocessed

 	 */

-	public BundleBatchInstallResult(String errorMessage, long[] completed, String bundleInError, String[] remaining) {

+	public BundleBatchInstallResult(String errorMessage, Long[] completed, String bundleInError, String[] remaining) {

 		success = false;

 		this.errorMessage = errorMessage;

 		this.completed = completed;

@@ -128,12 +122,11 @@
 	 * @return the CompositeData encoding of the receiver.

 	 * @throws IOException

 	 */

-	@SuppressWarnings("boxing")

 	public CompositeData asCompositeData() throws IOException {

 		Map<String, Object> items = new HashMap<String, Object>();

 		items.put(FrameworkMBean.SUCCESS, success);

 		items.put(FrameworkMBean.ERROR, errorMessage);

-		items.put(FrameworkMBean.COMPLETED, LongArrayFrom(completed));

+		items.put(FrameworkMBean.COMPLETED, completed);

 		items.put(FrameworkMBean.BUNDLE_IN_ERROR, bundleInError);

 		items.put(FrameworkMBean.REMAINING, remaining);

 

@@ -146,26 +139,4 @@
 		}

 	}

 

-	/**

-	 * Answer the bundle location which indicates the bundle that produced an

-	 * error during the batch operation.

-	 * 

-	 * @return the bundle location of the bundle in error, or null if no error

-	 *         occurred

-	 */

-	public String getBundleInError() {

-		return bundleInError;

-	}

-

-	/**

-	 * Answer the list of locations of the bundles that were not processed

-	 * during the batch operation, or null if the operation was successsful

-	 * 

-	 * @return the remaining bundle locations if the operation was successful,

-	 *         or null if the operation was unsuccsesful.

-	 */

-	public String[] getRemaining() {

-		return remaining;

-	}

-

 }

diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundle.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiBundle.java
similarity index 85%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundle.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiBundle.java
index 070eb89..1eaa4b0 100644
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundle.java
+++ b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiBundle.java
@@ -15,6 +15,8 @@
 

 package org.eclipse.gemini.mgmt.framework.internal;

 

+import static org.osgi.framework.Constants.SERVICE_ID;

+

 import java.io.IOException;

 import java.util.ArrayList;

 import java.util.Arrays;

@@ -34,6 +36,10 @@
 import org.eclipse.gemini.mgmt.framework.CustomBundleStateMBean;

 import org.eclipse.gemini.mgmt.internal.BundleUtil;

 import org.osgi.framework.Bundle;

+import org.osgi.framework.ServiceReference;

+import org.osgi.framework.wiring.BundleRevision;

+import org.osgi.framework.wiring.BundleWire;

+import org.osgi.framework.wiring.BundleWiring;

 import org.osgi.jmx.Item;

 import org.osgi.jmx.framework.BundleStateMBean;

 

@@ -174,10 +180,10 @@
 			items.put(BundleStateMBean.FRAGMENT, isFragment());

 		}

 		if(bundleTypes.contains(BundleStateMBean.REGISTERED_SERVICES)) {

-			items.put(BundleStateMBean.REGISTERED_SERVICES, BundleUtil.LongArrayFrom(getRegisteredServices()));

+			items.put(BundleStateMBean.REGISTERED_SERVICES, getRegisteredServices());

 		}

 		if(bundleTypes.contains(BundleStateMBean.SERVICES_IN_USE)) {

-			items.put(BundleStateMBean.SERVICES_IN_USE, BundleUtil.LongArrayFrom(getServicesInUse()));

+			items.put(BundleStateMBean.SERVICES_IN_USE, getServicesInUse());

 		}

 		if(bundleTypes.contains(BundleStateMBean.HEADERS)) {

 			items.put(BundleStateMBean.HEADERS, headerTable(getHeaders()));

@@ -189,16 +195,16 @@
 			items.put(BundleStateMBean.IMPORTED_PACKAGES, getImportedPackages());

 		}

 		if(bundleTypes.contains(BundleStateMBean.FRAGMENTS)) {

-			items.put(BundleStateMBean.FRAGMENTS, BundleUtil.LongArrayFrom(getFragments()));

+			items.put(BundleStateMBean.FRAGMENTS, getFragments());

 		}

 		if(bundleTypes.contains(BundleStateMBean.HOSTS)) {

-			items.put(BundleStateMBean.HOSTS, BundleUtil.LongArrayFrom(getHosts()));

+			items.put(BundleStateMBean.HOSTS, getHosts());

 		}

 		if(bundleTypes.contains(BundleStateMBean.REQUIRING_BUNDLES)) {

-			items.put(BundleStateMBean.REQUIRING_BUNDLES, BundleUtil.LongArrayFrom(getRequiringBundles()));

+			items.put(BundleStateMBean.REQUIRING_BUNDLES, getRequiringBundles());

 		}

 		if(bundleTypes.contains(BundleStateMBean.REQUIRED_BUNDLES)) {

-			items.put(BundleStateMBean.REQUIRED_BUNDLES, BundleUtil.LongArrayFrom(getRequiredBundles()));

+			items.put(BundleStateMBean.REQUIRED_BUNDLES, getRequiredBundles());

 		}

 		try {

 			return new CompositeDataSupport(computeBundleType, items);

@@ -336,10 +342,10 @@
 			items.put(BundleStateMBean.FRAGMENT, isFragment());

 		}

 		if((mask | CustomBundleStateMBean.REGISTERED_SERVICES) == mask) {

-			items.put(BundleStateMBean.REGISTERED_SERVICES, BundleUtil.LongArrayFrom(getRegisteredServices()));

+			items.put(BundleStateMBean.REGISTERED_SERVICES, getRegisteredServices());

 		}

 		if((mask | CustomBundleStateMBean.SERVICES_IN_USE) == mask) {

-			items.put(BundleStateMBean.SERVICES_IN_USE, BundleUtil.LongArrayFrom(getServicesInUse()));

+			items.put(BundleStateMBean.SERVICES_IN_USE, getServicesInUse());

 		}

 		if((mask | CustomBundleStateMBean.HEADERS) == mask) {

 			items.put(BundleStateMBean.HEADERS, headerTable(getHeaders()));

@@ -351,16 +357,16 @@
 			items.put(BundleStateMBean.IMPORTED_PACKAGES, getImportedPackages());

 		}

 		if((mask | CustomBundleStateMBean.FRAGMENTS) == mask) {

-			items.put(BundleStateMBean.FRAGMENTS, BundleUtil.LongArrayFrom(getFragments()));

+			items.put(BundleStateMBean.FRAGMENTS, getFragments());

 		}

 		if((mask | CustomBundleStateMBean.HOSTS) == mask) {

-			items.put(BundleStateMBean.HOSTS, BundleUtil.LongArrayFrom(getHosts()));

+			items.put(BundleStateMBean.HOSTS, getHosts());

 		}

 		if((mask | CustomBundleStateMBean.REQUIRING_BUNDLES) == mask) {

-			items.put(BundleStateMBean.REQUIRING_BUNDLES, BundleUtil.LongArrayFrom(getRequiringBundles()));

+			items.put(BundleStateMBean.REQUIRING_BUNDLES, getRequiringBundles());

 		}

 		if((mask | CustomBundleStateMBean.REQUIRED_BUNDLES) == mask) {

-			items.put(BundleStateMBean.REQUIRED_BUNDLES, BundleUtil.LongArrayFrom(getRequiredBundles()));

+			items.put(BundleStateMBean.REQUIRED_BUNDLES, getRequiredBundles());

 		}

 

 		try {

@@ -391,17 +397,17 @@
 		items.put(BundleStateMBean.REMOVAL_PENDING, isRemovalPending());

 		items.put(BundleStateMBean.REQUIRED, isRequired());

 		items.put(BundleStateMBean.FRAGMENT, isFragment());

-		items.put(BundleStateMBean.REGISTERED_SERVICES, BundleUtil.LongArrayFrom(getRegisteredServices()));

-		items.put(BundleStateMBean.SERVICES_IN_USE, BundleUtil.LongArrayFrom(getServicesInUse()));

+		items.put(BundleStateMBean.REGISTERED_SERVICES, getRegisteredServices());

+		items.put(BundleStateMBean.SERVICES_IN_USE, getServicesInUse());

 		items.put(BundleStateMBean.HEADERS, headerTable(getHeaders()));

 		items.put(BundleStateMBean.EXPORTED_PACKAGES, getExportedPackages());

 		items.put(BundleStateMBean.IMPORTED_PACKAGES, getImportedPackages());

-		items.put(BundleStateMBean.FRAGMENTS, BundleUtil.LongArrayFrom(getFragments()));

-		items.put(BundleStateMBean.HOSTS, BundleUtil.LongArrayFrom(getHosts()));

-		items.put(BundleStateMBean.REQUIRING_BUNDLES, BundleUtil.LongArrayFrom(getRequiringBundles()));

-		items.put(BundleStateMBean.REQUIRED_BUNDLES, BundleUtil.LongArrayFrom(getRequiredBundles()));

+		items.put(BundleStateMBean.FRAGMENTS, getFragments());

+		items.put(BundleStateMBean.HOSTS, getHosts());

+		items.put(BundleStateMBean.REQUIRING_BUNDLES, getRequiringBundles());

+		items.put(BundleStateMBean.REQUIRED_BUNDLES, getRequiredBundles());

 		try {

-			return new CompositeDataSupport(BundleStateMBean.BUNDLE_TYPE, items);

+			return new CompositeDataSupport(CustomBundleStateMBean.CUSTOM_BUNDLE_TYPE, items);

 		} catch (OpenDataException e) {

 			throw new IllegalStateException("Cannot form bundle open data", e);

 		}

@@ -443,14 +449,6 @@
 	}

 

 	/**

-	 * @return the list of identifiers of the bundle fragments which use this

-	 *         bundle as a host

-	 */

-	private long[] getFragments() {

-		return  BundleUtil.getBundleFragments(bundle);			

-	}

-

-	/**

 	 * @return the map of headers for this bundle

 	 */

 	private Dictionary<String, String> getHeaders() {

@@ -458,10 +456,22 @@
 	}

 

 	/**

+	 * @return the list of identifiers of the bundle fragments which use this

+	 *         bundle as a host

+	 */

+	private Long[] getFragments() {

+		BundleWiring wiring = bundle.adapt(BundleWiring.class);

+		List<BundleWire> requiredWires = wiring.getRequiredWires(BundleRevision.HOST_NAMESPACE);

+        return bundleWiresToIds(requiredWires);

+	}

+

+	/**

 	 * @return list of identifiers of the bundles which host this fragment

 	 */

-	private long[] getHosts() {

-		return BundleUtil.getBundleHosts(bundle);

+	private Long[] getHosts() {

+		BundleWiring wiring = bundle.adapt(BundleWiring.class);

+		List<BundleWire> providedWires = wiring.getProvidedWires(BundleRevision.HOST_NAMESPACE);

+        return bundleWiresToIds(providedWires);

 	}

 

 	/**

@@ -496,31 +506,35 @@
 	/**

 	 * @return the list of identifiers of the services registered by this bundle

 	 */

-	private long[] getRegisteredServices() {

-		return BundleUtil.serviceIds(bundle.getRegisteredServices());

+	private Long[] getRegisteredServices() {

+		return serviceIds(bundle.getRegisteredServices());

 	}

-

+	

 	/**

 	 * @return the list of identifiers of bundles required by this bundle

 	 * @throws IOException 

 	 */

-	private long[] getRequiredBundles() throws IOException {

-		return BundleUtil.getRequiredBundles(bundle);

+	private Long[] getRequiredBundles() throws IOException {

+        BundleWiring wiring = bundle.adapt(BundleWiring.class);

+        List<BundleWire> requiredWires = wiring.getRequiredWires(BundleRevision.BUNDLE_NAMESPACE);

+        return bundleWiresToIds(requiredWires);

 	}

 

 	/**

 	 * @return the list of identifiers of bundles which require this bundle

 	 * @throws IOException 

 	 */

-	private long[] getRequiringBundles() throws IOException {

-		return BundleUtil.getRequiringBundles(bundle);

+	private Long[] getRequiringBundles() throws IOException {

+        BundleWiring wiring = bundle.adapt(BundleWiring.class);

+        List<BundleWire> providedWires = wiring.getProvidedWires(BundleRevision.BUNDLE_NAMESPACE);

+        return bundleWiresToIds(providedWires);

 	}

 

 	/**

 	 * @return the list of identifiers of services in use by this bundle

 	 */

-	private long[] getServicesInUse() {

-		return BundleUtil.serviceIds(bundle.getServicesInUse());

+	private Long[] getServicesInUse() {

+		return serviceIds(bundle.getServicesInUse());

 	}

 

 	/**

@@ -585,5 +599,26 @@
 	private boolean isRequired() {

 		return BundleUtil.isRequired(bundle);

 	}

+

+	private Long[] bundleWiresToIds(List<BundleWire> wires){

+        Long[] consumerWirings = new Long[wires.size()];

+        int i = 0;

+        for (BundleWire bundleWire : wires) {

+            consumerWirings[i] = bundleWire.getRequirerWiring().getBundle().getBundleId();

+            i++;

+        }

+        return consumerWirings;

+	}

+	

+	private Long[] serviceIds(ServiceReference<?>[] refs) {

+		if (refs == null) {

+			return new Long[0];

+		}

+		Long[] ids = new Long[refs.length];

+		for (int i = 0; i < refs.length; i++) {

+			ids[i] = (Long) refs[i].getProperty(SERVICE_ID);

+		}

+		return ids;

+	}

 	

 }

diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleCapability.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleCapability.java
similarity index 93%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleCapability.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleCapability.java
index df0ee43..98e35e7 100644
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleCapability.java
+++ b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleCapability.java
@@ -20,7 +20,6 @@
 import javax.management.openmbean.TabularDataSupport;
 
 import org.eclipse.gemini.mgmt.framework.CustomBundleWiringStateMBean;
-import org.eclipse.gemini.mgmt.internal.BundleWiringUtil;
 import org.eclipse.gemini.mgmt.internal.OSGiProperties;
 import org.osgi.framework.wiring.BundleCapability;
 
@@ -43,7 +42,7 @@
 			TabularDataSupport tabularDirectives = new TabularDataSupport(CustomBundleWiringStateMBean.DIRECTIVES_TYPE);
 			Map<String, String> directives = bundleCapability.getDirectives();
 			for (Entry<String, String> directive : directives.entrySet()) {
-				tabularDirectives.put(new CompositeDataSupport(CustomBundleWiringStateMBean.PROPERTY_TYPE, BundleWiringUtil.getDirectiveKeyValueItem(directive.getKey(), directive.getValue())));
+				tabularDirectives.put(new CompositeDataSupport(CustomBundleWiringStateMBean.PROPERTY_TYPE, OSGiProperties.getDirectiveKeyValueItem(directive.getKey(), directive.getValue())));
 			}
 			
 			Map<String, Object> items = new HashMap<String, Object>();
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleEvent.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleEvent.java
similarity index 100%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleEvent.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleEvent.java
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleRequirement.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleRequirement.java
similarity index 93%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleRequirement.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleRequirement.java
index c81e258..babe8cc 100644
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleRequirement.java
+++ b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleRequirement.java
@@ -20,7 +20,6 @@
 import javax.management.openmbean.TabularDataSupport;
 
 import org.eclipse.gemini.mgmt.framework.CustomBundleWiringStateMBean;
-import org.eclipse.gemini.mgmt.internal.BundleWiringUtil;
 import org.eclipse.gemini.mgmt.internal.OSGiProperties;
 import org.osgi.framework.wiring.BundleRequirement;
 
@@ -43,7 +42,7 @@
 			TabularDataSupport tabularDirectives = new TabularDataSupport(CustomBundleWiringStateMBean.DIRECTIVES_TYPE);
 			Map<String, String> directives = bundleRequirement.getDirectives();
 			for (Entry<String, String> directive : directives.entrySet()) {
-				tabularDirectives.put(new CompositeDataSupport(CustomBundleWiringStateMBean.PROPERTY_TYPE, BundleWiringUtil.getDirectiveKeyValueItem(directive.getKey(), directive.getValue())));
+				tabularDirectives.put(new CompositeDataSupport(CustomBundleWiringStateMBean.PROPERTY_TYPE, OSGiProperties.getDirectiveKeyValueItem(directive.getKey(), directive.getValue())));
 			}
 			
 			Map<String, Object> items = new HashMap<String, Object>();
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleRevision.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleRevision.java
similarity index 100%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleRevision.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleRevision.java
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleRevisionIdTracker.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleRevisionIdTracker.java
similarity index 100%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleRevisionIdTracker.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleRevisionIdTracker.java
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleWire.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleWire.java
similarity index 100%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleWire.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleWire.java
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleWiring.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleWiring.java
similarity index 100%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleWiring.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiBundleWiring.java
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiPackage.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiPackage.java
similarity index 91%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiPackage.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiPackage.java
index 707514a..a72239f 100644
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiPackage.java
+++ b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiPackage.java
@@ -15,8 +15,6 @@
 

 package org.eclipse.gemini.mgmt.framework.internal;

 

-import static org.eclipse.gemini.mgmt.internal.BundleUtil.LongArrayFrom;

-

 import java.util.HashMap;

 import java.util.Map;

 import java.util.Set;

@@ -64,8 +62,8 @@
  */

 public final class OSGiPackage {

 

-	private long[] exportingBundles;

-	private long[] importingBundles;

+	private Long[] exportingBundles;

+	private Long[] importingBundles;

 	private String name;

 	private boolean removalPending;

 	private String version;

@@ -93,11 +91,11 @@
 	 * @param bundles

 	 * @return the bundle ids of the bundles

 	 */

-	private static long[] bundleIds(Bundle[] bundles) {

+	private static Long[] bundleIds(Bundle[] bundles) {

 		if (bundles == null) {

-			return new long[0];

+			return new Long[0];

 		}

-		long[] ids = new long[bundles.length];

+		Long[] ids = new Long[bundles.length];

 		for (int i = 0; i < bundles.length; i++) {

 			ids[i] = bundles[i].getBundleId();

 		}

@@ -128,8 +126,8 @@
 		items.put(PackageStateMBean.NAME, name);

 		items.put(PackageStateMBean.VERSION, version);

 		items.put(PackageStateMBean.REMOVAL_PENDING, removalPending);

-		items.put(PackageStateMBean.EXPORTING_BUNDLES, LongArrayFrom(exportingBundles));

-		items.put(PackageStateMBean.IMPORTING_BUNDLES, LongArrayFrom(importingBundles));

+		items.put(PackageStateMBean.EXPORTING_BUNDLES, exportingBundles);

+		items.put(PackageStateMBean.IMPORTING_BUNDLES, importingBundles);

 

 		try {

 			return new CompositeDataSupport(PackageStateMBean.PACKAGE_TYPE, items);

diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiService.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiService.java
similarity index 87%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiService.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiService.java
index 67ab7ce..9afe179 100644
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiService.java
+++ b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiService.java
@@ -15,7 +15,7 @@
 

 package org.eclipse.gemini.mgmt.framework.internal;

 

-import static org.eclipse.gemini.mgmt.internal.BundleUtil.LongArrayFrom;

+//import static org.eclipse.gemini.mgmt.internal.BundleUtil.LongArrayFrom;

 import static org.osgi.framework.Constants.OBJECTCLASS;

 import static org.osgi.framework.Constants.SERVICE_ID;

 

@@ -33,7 +33,7 @@
 import javax.management.openmbean.TabularData;

 import javax.management.openmbean.TabularDataSupport;

 

-import org.eclipse.gemini.mgmt.internal.ServiceUtil;

+import org.osgi.framework.Bundle;

 import org.osgi.framework.ServiceReference;

 import org.osgi.jmx.Item;

 import org.osgi.jmx.framework.ServiceStateMBean;

@@ -74,7 +74,7 @@
 	

 	private String[] interfaces;

 	

-	private long[] usingBundles;

+	private Long[] usingBundles;

 

 	/**

 	 * Construct an OSGiService from the underlying

@@ -88,9 +88,34 @@
 		this.identifier = (Long) reference.getProperty(SERVICE_ID);

 		this.interfaces = (String[]) reference.getProperty(OBJECTCLASS);

 		this.bundle = reference.getBundle().getBundleId();

-		this.usingBundles = ServiceUtil.getBundlesUsing(reference);

+		this.usingBundles = longArrayFrom(OSGiService.getBundlesUsing(reference));

 	}

 

+	private Long[] longArrayFrom(long[] array) {

+		if (array == null) {

+			return new Long[0];

+		}

+		Long[] result = new Long[array.length];

+		for (int i = 0; i < array.length; i++) {

+			result[i] = array[i];

+		}

+		return result;

+	}

+	

+	/**

+	 * 

+	 * @param serviceRef

+	 * @return

+	 */

+	public static long[] getBundlesUsing(ServiceReference<?> serviceRef) {

+		Bundle[] bundles = serviceRef.getUsingBundles();

+		long[] ids = new long[bundles.length];

+		for (int i = 0; i < bundles.length; i++) {

+			ids[i] = bundles[i].getBundleId();

+		}

+		return ids;

+	}

+	

 	/**

 	 * Construct the TabularData representing a list of services

 	 * 

@@ -152,7 +177,7 @@
 		items.put(ServiceStateMBean.IDENTIFIER, identifier);

 		items.put(ServiceStateMBean.OBJECT_CLASS, interfaces);

 		items.put(ServiceStateMBean.BUNDLE_IDENTIFIER, bundle);

-		items.put(ServiceStateMBean.USING_BUNDLES, LongArrayFrom(usingBundles));

+		items.put(ServiceStateMBean.USING_BUNDLES, usingBundles);

 

 		try {

 			return new CompositeDataSupport(ServiceStateMBean.SERVICE_TYPE, items);

@@ -178,7 +203,7 @@
 			items.put(ServiceStateMBean.BUNDLE_IDENTIFIER, bundle);

 		}

 		if(serviceTypes.contains(ServiceStateMBean.USING_BUNDLES)){

-			items.put(ServiceStateMBean.USING_BUNDLES, LongArrayFrom(usingBundles));

+			items.put(ServiceStateMBean.USING_BUNDLES, usingBundles);

 		}

 		try {

 			return new CompositeDataSupport(ServiceStateMBean.SERVICE_TYPE, items);

diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiServiceEvent.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiServiceEvent.java
similarity index 100%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiServiceEvent.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/framework/internal/OSGiServiceEvent.java
diff --git a/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/internal/BundleUtil.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/internal/BundleUtil.java
new file mode 100644
index 0000000..2998511
--- /dev/null
+++ b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/internal/BundleUtil.java
@@ -0,0 +1,171 @@
+/*******************************************************************************

+ * Copyright (c) 2010 Oracle.

+ * All rights reserved. This program and the accompanying materials

+ * are made available under the terms of the Eclipse Public License v1.0

+ * and Apache License v2.0 which accompanies this distribution. 

+ * The Eclipse Public License is available at

+ *     http://www.eclipse.org/legal/epl-v10.html

+ * and the Apache License v2.0 is available at 

+ *     http://www.opensource.org/licenses/apache2.0.php.

+ * You may elect to redistribute this code under either of these licenses.

+ *

+ * Contributors:

+ *     Hal Hildebrand - Initial JMX support 

+ ******************************************************************************/

+

+package org.eclipse.gemini.mgmt.internal;

+

+import java.util.ArrayList;

+import java.util.List;

+

+import org.osgi.framework.Bundle;

+import org.osgi.framework.Constants;

+import org.osgi.framework.startlevel.BundleStartLevel;

+import org.osgi.framework.wiring.BundleRevision;

+import org.osgi.framework.wiring.BundleWire;

+import org.osgi.framework.wiring.BundleWiring;

+

+/**

+ * Static utilities

+ * 

+ */

+public final class BundleUtil {

+	

+	/**

+	 * Answer the string representation of the exported packages of the bundle

+	 * 

+	 * @param b

+	 * @param admin

+	 * @return the string representation of the exported packages of the bundle

+	 */

+	public static String[] getBundleExportedPackages(Bundle bundle) {

+		BundleWiring wiring = bundle.adapt(BundleWiring.class);

+		List<BundleWire> providedWires = wiring.getProvidedWires(BundleRevision.PACKAGE_NAMESPACE);

+		List<String> packages = new ArrayList<String>();

+        for(BundleWire wire: providedWires){

+        	String packageName = String.format("%s;%s", wire.getCapability().getAttributes().get(BundleRevision.PACKAGE_NAMESPACE), wire.getCapability().getAttributes().get(Constants.VERSION_ATTRIBUTE));

+        	if(!packages.contains(packageName)){

+        		packages.add(packageName);

+        	}

+        }

+        return packages.toArray(new String[packages.size()]);

+	}

+

+	/**

+	 * Answer the string representation of the packages imported by a bundle

+	 * 

+	 * @param b

+	 * @param bundleContext

+	 * @param admin

+	 * @return the string representation of the packages imported by a bundle

+	 */

+	public static String[] getBundleImportedPackages(Bundle bundle) {

+		BundleWiring wiring = bundle.adapt(BundleWiring.class);

+		List<BundleWire> providedWires = wiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);

+        List<String> packages = new ArrayList<String>();

+        for(BundleWire wire: providedWires){

+            String packageName = String.format("%s;%s", wire.getCapability().getAttributes().get(BundleRevision.PACKAGE_NAMESPACE), wire.getCapability().getAttributes().get(Constants.VERSION_ATTRIBUTE));

+            if(!packages.contains(packageName)){

+                packages.add(packageName);

+            }

+        }

+        return packages.toArray(new String[packages.size()]);

+	}

+

+	/**

+	 * Answer the string representation of the bundle state

+	 * 

+	 * @param b

+	 * @return the string representation of the bundle state

+	 */

+	public static String getBundleState(Bundle b) {

+		switch (b.getState()) {

+			case Bundle.ACTIVE:

+				return "ACTIVE";

+			case Bundle.INSTALLED:

+				return "INSTALLED";

+			case Bundle.RESOLVED:

+				return "RESOLVED";

+			case Bundle.STARTING:

+				return "STARTING";

+			case Bundle.STOPPING:

+				return "STOPPING";

+			case Bundle.UNINSTALLED:

+				return "UNINSTALLED";

+			default:

+				return "UNKNOWN";

+		}

+	}

+

+	/**

+	 * Answer true if the bundle is a fragment

+	 * 

+	 * @param bundle

+	 * @param admin

+	 * @return true if the bundle is a fragment

+	 */

+	public static boolean isBundleFragment(Bundle bundle) {

+		BundleWiring wiring = bundle.adapt(BundleWiring.class);

+		return 0 != (wiring.getRevision().getTypes() & BundleRevision.TYPE_FRAGMENT);

+	}

+

+	/**

+	 * Return the start level for the given bundle

+	 * 

+	 * @param bundle

+	 * @return

+	 */

+	public static int getBundleStartLevel(Bundle bundle) {

+		BundleStartLevel startLevel = bundle.adapt(BundleStartLevel.class);

+		return startLevel.getStartLevel();

+	}

+	

+	/**

+	 * Answer true if the bundle has been persitently started

+	 * 

+	 * @param bundle

+	 * @param sl

+	 * @return true if the bundle has been persitently started

+	 */

+	public static boolean isBundlePersistentlyStarted(Bundle bundle) {

+		BundleStartLevel startLevel = bundle.adapt(BundleStartLevel.class);

+		return startLevel.isPersistentlyStarted();

+	}

+	

+	/**

+	 * Answer true if the bundle has been persitently started

+	 * 

+	 * @param bundle

+	 * @param sl

+	 * @return true if the bundle has been persitently started

+	 */

+	public static boolean isBundleActivationPolicyUsed(Bundle bundle) {

+		BundleStartLevel startLevel = bundle.adapt(BundleStartLevel.class);

+		return startLevel.isActivationPolicyUsed();

+	}

+

+	/**

+	 * Answer true if the bundle is required

+	 * 

+	 * @param bundle

+	 * @param bc

+	 * @return true if the bundle is required

+	 */

+	public static boolean isRequired(Bundle bundle) {

+		BundleWiring wiring = bundle.adapt(BundleWiring.class);

+		return wiring.getProvidedWires(BundleRevision.BUNDLE_NAMESPACE).size() > 0;

+	}

+

+	/**

+	 * Answer true if the bundle is pending removal

+	 * 

+	 * @param bundle

+	 * @param bc

+	 * @return true if the bundle is pending removal

+	 */

+	public static boolean isRemovalPending(Bundle bundle) {

+        BundleWiring wiring = bundle.adapt(BundleWiring.class);

+        return (!wiring.isCurrent()) && wiring.isInUse();

+	}

+

+}

diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/internal/OSGiProperties.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/internal/OSGiProperties.java
similarity index 74%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/internal/OSGiProperties.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/internal/OSGiProperties.java
index 771edb5..59dcfda 100644
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/internal/OSGiProperties.java
+++ b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/internal/OSGiProperties.java
@@ -11,6 +11,7 @@
  *

  * Contributors:

  *     Hal Hildebrand - Initial JMX support 

+ *     Christopher Frost - Refactoring for Spec updates

  ******************************************************************************/

 

 package org.eclipse.gemini.mgmt.internal;

@@ -18,14 +19,15 @@
 import java.math.BigDecimal;

 import java.math.BigInteger;

 import java.util.ArrayList;

+import java.util.Arrays;

 import java.util.Collection;

+import java.util.Collections;

 import java.util.Dictionary;

 import java.util.Enumeration;

 import java.util.HashMap;

-import java.util.HashSet;

 import java.util.Hashtable;

+import java.util.List;

 import java.util.Map;

-import java.util.Set;

 import java.util.StringTokenizer;

 import java.util.Vector;

 

@@ -35,6 +37,7 @@
 import javax.management.openmbean.TabularData;

 import javax.management.openmbean.TabularDataSupport;

 

+import org.eclipse.gemini.mgmt.framework.CustomBundleWiringStateMBean;

 import org.osgi.framework.ServiceReference;

 import org.osgi.framework.Version;

 import org.osgi.jmx.JmxConstants;

@@ -86,38 +89,36 @@
  * The

  */

 public final class OSGiProperties {

-

+	

+	private static final String VERSION = "Version";

+	

 	/**

 	 * The scalar type

 	 */

-	private static final Set<String> SCALAR_TYPES = new HashSet<String>();

+	private static final List<String> SCALAR_TYPES = Collections.unmodifiableList(Arrays.asList(

+		JmxConstants.STRING,

+		JmxConstants.INTEGER,

+		JmxConstants.LONG,

+		JmxConstants.FLOAT,

+		JmxConstants.DOUBLE,

+		JmxConstants.BYTE,

+		JmxConstants.SHORT,

+		JmxConstants.CHARACTER,

+		JmxConstants.BOOLEAN,

+		JmxConstants.BIGDECIMAL,

+		JmxConstants.BIGINTEGER));

+	

 	/**

 	 * The primitive types

 	 */

-	private static final Set<String> PRIMITIVE_TYPES = new HashSet<String>();

-

-	static {

-		SCALAR_TYPES.add("String");

-		SCALAR_TYPES.add("Integer");

-		SCALAR_TYPES.add("Long");

-		SCALAR_TYPES.add("Float");

-		SCALAR_TYPES.add("Double");

-		SCALAR_TYPES.add("Byte");

-		SCALAR_TYPES.add("Short");

-		SCALAR_TYPES.add("Character");

-		SCALAR_TYPES.add("Boolean");

-		SCALAR_TYPES.add("BigDecimal");

-		SCALAR_TYPES.add("BigInteger");

-

-		PRIMITIVE_TYPES.add("int");

-		PRIMITIVE_TYPES.add("long");

-		PRIMITIVE_TYPES.add("float");

-		PRIMITIVE_TYPES.add("double");

-		PRIMITIVE_TYPES.add("byte");

-		PRIMITIVE_TYPES.add("short");

-		PRIMITIVE_TYPES.add("char");

-		PRIMITIVE_TYPES.add("boolean");

-	}

+	private static final List<String> PRIMITIVE_TYPES = Collections.unmodifiableList(Arrays.asList(

+		JmxConstants.P_BYTE,

+		JmxConstants.P_CHAR,

+		JmxConstants.P_SHORT,

+		JmxConstants.P_INT,

+		JmxConstants.P_LONG,

+		JmxConstants.P_DOUBLE,

+		JmxConstants.P_FLOAT));

 	

 	/**

 	 * Answer the tabular data representation of the properties dictionary

@@ -160,7 +161,6 @@
 	 */

 	public static CompositeData encode(String key, Object value) {

 		Class<?> clazz = value.getClass();

-

 		if (clazz.isArray()) {

 			return encodeArray(key, value, clazz.getComponentType());

 		} else if (clazz.equals(Vector.class)) {

@@ -176,7 +176,7 @@
 	 * @return the hashtable represented by the tabular data

 	 */

 	@SuppressWarnings("unchecked")

-	public static Hashtable<String, Object> propertiesFrom(TabularData table) {

+	public static Dictionary<String, Object> propertiesFrom(TabularData table) {

 		Hashtable<String, Object> props = new Hashtable<String, Object>();

 		if (table == null) {

 			return props;

@@ -184,10 +184,23 @@
 		for (CompositeData data : (Collection<CompositeData>) table.values()) {

 			props.put((String) data.get(JmxConstants.KEY), parse((String) data.get(JmxConstants.VALUE), (String) data.get(JmxConstants.TYPE)));

 		}

-

 		return props;

 	}

-

+	

+	/**

+	 * Convert a key-value directive in to the required format for representation over JMX

+	 * 

+	 * @param key

+	 * @param value

+	 * @return a map of key to the key and value to the value

+	 */

+	public static Map<String, ?> getDirectiveKeyValueItem(String key, Object value){

+		Map<String, Object> items = new HashMap<String, Object>();

+		items.put(CustomBundleWiringStateMBean.KEY, key);

+		items.put(CustomBundleWiringStateMBean.VALUE, value);

+		return items;

+	}

+	

 	/**

 	 * Encode the array as composite data

 	 * 

@@ -197,7 +210,6 @@
 	 * @return the composite data representation

 	 */

 	private static CompositeData encodeArray(String key, Object value, Class<?> componentClazz) {

-		String type = typeOf(componentClazz);

 		StringBuffer buf = new StringBuffer();

 		if (Integer.TYPE.equals(componentClazz)) {

 			int[] array = (int[]) value;

@@ -223,6 +235,14 @@
 					buf.append(',');

 				}

 			}

+		} else if (Float.TYPE.equals(componentClazz)) {

+			float[] array = (float[]) value;

+			for (int i = 0; i < array.length; i++) {

+				buf.append(array[i]);

+				if (i < array.length - 1) {

+					buf.append(',');

+				}

+			}

 		} else if (Byte.TYPE.equals(componentClazz)) {

 			byte[] array = (byte[]) value;

 			for (int i = 0; i < array.length; i++) {

@@ -264,6 +284,7 @@
 				}

 			}

 		}

+		String type = typeOf(componentClazz);

 		return propertyData(key, buf.toString(), "Array of " + type);

 	}

 

@@ -275,7 +296,7 @@
 	 * @return the composite data representation

 	 */

 	private static CompositeData encodeVector(String key, Vector<?> value) {

-		String type = "String";

+		String type = JmxConstants.STRING;

 		if (value.size() > 0) {

 			type = typeOf(value.get(0).getClass());

 		}

@@ -288,7 +309,7 @@
 		}

 		return propertyData(key, buf.toString(), "Vector of " + type);

 	}

-

+	

 	/**

 	 * Answer the string type of the class

 	 * 

@@ -296,59 +317,65 @@
 	 * @return the string type of the class

 	 */

 	private static String typeOf(Class<?> clazz) {

-		if (clazz.equals(Version.class)) {

-			return "Version";

-		}

 		if (clazz.equals(String.class)) {

-			return "String";

+			return JmxConstants.STRING;

+		}

+		if (clazz.equals(Version.class)) {

+			return VERSION;

 		}

 		if (clazz.equals(Integer.class)) {

-			return "Integer";

+			return JmxConstants.INTEGER;

 		}

 		if (clazz.equals(Long.class)) {

-			return "Long";

+			return JmxConstants.LONG;

 		}

 		if (clazz.equals(Double.class)) {

-			return "Double";

+			return JmxConstants.DOUBLE;

+		}

+		if (clazz.equals(Double.class)) {

+			return JmxConstants.FLOAT;

 		}

 		if (clazz.equals(Byte.class)) {

-			return "Byte";

+			return JmxConstants.BYTE;

 		}

 		if (clazz.equals(Short.class)) {

-			return "Short";

+			return JmxConstants.SHORT;

 		}

 		if (clazz.equals(Character.class)) {

-			return "Character";

+			return JmxConstants.CHARACTER;

 		}

 		if (clazz.equals(Boolean.class)) {

-			return "Boolean";

+			return JmxConstants.BOOLEAN;

 		}

 		if (clazz.equals(BigDecimal.class)) {

-			return "BigDecimal";

+			return JmxConstants.BIGDECIMAL;

 		}

 		if (clazz.equals(BigInteger.class)) {

-			return "BigInteger";

+			return JmxConstants.BIGINTEGER;

 		}

 		if (clazz.equals(Integer.TYPE)) {

-			return "int";

+			return JmxConstants.P_INT;

 		}

 		if (clazz.equals(Long.TYPE)) {

-			return "long";

+			return JmxConstants.P_LONG;

 		}

 		if (clazz.equals(Double.TYPE)) {

-			return "double";

+			return JmxConstants.P_DOUBLE;

+		}

+		if (clazz.equals(Double.TYPE)) {

+			return JmxConstants.P_FLOAT;

 		}

 		if (clazz.equals(Byte.TYPE)) {

-			return "byte";

+			return JmxConstants.P_BYTE;

 		}

 		if (clazz.equals(Short.TYPE)) {

-			return "short";

+			return JmxConstants.P_SHORT;

 		}

 		if (clazz.equals(Character.TYPE)) {

-			return "char";

+			return JmxConstants.P_CHAR;

 		}

 		if (clazz.equals(Boolean.TYPE)) {

-			return "boolean";

+			return JmxConstants.P_BOOLEAN;

 		}

 		throw new IllegalArgumentException("Illegal type: " + clazz);

 	}

@@ -392,8 +419,8 @@
 		if ("Vector".equals(token)) {

 			return parseVector(value, tokens);

 		}

-		if (SCALAR_TYPES.contains(token)) {

-			return parseScalar(value, token);

+		if (SCALAR_TYPES.contains(token) || PRIMITIVE_TYPES.contains(token)) {

+			return parseValue(value, token);

 		}

 		throw new IllegalArgumentException("Unknown type: " + type);

 	}

@@ -426,131 +453,6 @@
 	}

 

 	/**

-	 * Parse the array represented by the string value

-	 * 

-	 * @param value

-	 * @param type

-	 * @return the array represented by the string value

-	 */

-	private static Object parseScalarArray(String value, String type) {

-		ArrayList<Object> array = new ArrayList<Object>();

-		StringTokenizer values = new StringTokenizer(value, ",");

-		while (values.hasMoreTokens()) {

-			array.add(parseScalar(values.nextToken().trim(), type));

-		}

-		return array.toArray(createScalarArray(type, array.size()));

-	}

-

-	/**

-	 * Create the scalar array from the supplied type

-	 * 

-	 * @param type

-	 * @param size

-	 * @return the scalar array from the supplied type

-	 */

-	private static Object[] createScalarArray(String type, int size) {

-		if ("String".equals(type)) {

-			return new String[size];

-		}

-		if ("Integer".equals(type)) {

-			return new Integer[size];

-		}

-		if ("Long".equals(type)) {

-			return new Long[size];

-		}

-		if ("Double".equals(type)) {

-			return new Double[size];

-		}

-		if ("Byte".equals(type)) {

-			return new Byte[size];

-		}

-		if ("Short".equals(type)) {

-			return new Short[size];

-		}

-		if ("Character".equals(type)) {

-			return new Character[size];

-		}

-		if ("Boolean".equals(type)) {

-			return new Boolean[size];

-		}

-		if ("BigDecimal".equals(type)) {

-			return new BigDecimal[size];

-		}

-		if ("BigInteger".equals(type)) {

-			return new BigInteger[size];

-		}

-		throw new IllegalArgumentException("Unknown scalar type: " + type);

-	}

-

-	/**

-	 * Parse the array from the supplied values

-	 * 

-	 * @param value

-	 * @param type

-	 * @return the array from the supplied values

-	 */

-	private static Object parsePrimitiveArray(String value, String type) {

-		StringTokenizer values = new StringTokenizer(value, ",");

-		if ("int".equals(type)) {

-			int[] array = new int[values.countTokens()];

-			int i = 0;

-			while (values.hasMoreTokens()) {

-				array[i++] = Integer.parseInt(values.nextToken().trim());

-			}

-			return array;

-		}

-		if ("long".equals(type)) {

-			long[] array = new long[values.countTokens()];

-			int i = 0;

-			while (values.hasMoreTokens()) {

-				array[i++] = Long.parseLong(values.nextToken().trim());

-			}

-			return array;

-		}

-		if ("double".equals(type)) {

-			double[] array = new double[values.countTokens()];

-			int i = 0;

-			while (values.hasMoreTokens()) {

-				array[i++] = Double.parseDouble(values.nextToken().trim());

-			}

-			return array;

-		}

-		if ("byte".equals(type)) {

-			byte[] array = new byte[values.countTokens()];

-			int i = 0;

-			while (values.hasMoreTokens()) {

-				array[i++] = Byte.parseByte(values.nextToken().trim());

-			}

-			return array;

-		}

-		if ("short".equals(type)) {

-			short[] array = new short[values.countTokens()];

-			int i = 0;

-			while (values.hasMoreTokens()) {

-				array[i++] = Short.parseShort(values.nextToken().trim());

-			}

-			return array;

-		}

-		if ("char".equals(type)) {

-			char[] array = new char[values.countTokens()];

-			int i = 0;

-			while (values.hasMoreTokens()) {

-				array[i++] = values.nextToken().trim().charAt(0);

-			}

-			return array;

-		}

-		if ("boolean".equals(type)) {

-			boolean[] array = new boolean[values.countTokens()];

-			int i = 0;

-			while (values.hasMoreTokens()) {

-				array[i++] = Boolean.parseBoolean(values.nextToken().trim());

-			}

-			return array;

-		}

-		throw new IllegalArgumentException("Unknown primitive type: " + type);

-	}

-

-	/**

 	 * Parse the vector represented by the supplied string value

 	 * 

 	 * @param value

@@ -580,6 +482,145 @@
 	}

 

 	/**

+	 * Parse the array represented by the string value

+	 * 

+	 * @param value

+	 * @param type

+	 * @return the array represented by the string value

+	 */

+	private static Object[] parseScalarArray(String value, String type) {

+		ArrayList<Object> array = new ArrayList<Object>();

+		StringTokenizer values = new StringTokenizer(value, ",");

+		while (values.hasMoreTokens()) {

+			array.add(parseScalar(values.nextToken().trim(), type));

+		}

+		return array.toArray(createScalarArray(type, array.size()));

+	}

+

+	/**

+	 * Parse the array from the supplied values

+	 * 

+	 * @param value

+	 * @param type

+	 * @return the array from the supplied values

+	 */

+	private static Object parsePrimitiveArray(String value, String type) {

+		StringTokenizer values = new StringTokenizer(value, ",");

+		if (JmxConstants.P_INT.equals(type)) {

+			int[] array = new int[values.countTokens()];

+			int i = 0;

+			while (values.hasMoreTokens()) {

+				array[i++] = Integer.parseInt(values.nextToken().trim());

+			}

+			return array;

+		}

+		if (JmxConstants.P_LONG.equals(type)) {

+			long[] array = new long[values.countTokens()];

+			int i = 0;

+			while (values.hasMoreTokens()) {

+				array[i++] = Long.parseLong(values.nextToken().trim());

+			}

+			return array;

+		}

+		if (JmxConstants.P_DOUBLE.equals(type)) {

+			double[] array = new double[values.countTokens()];

+			int i = 0;

+			while (values.hasMoreTokens()) {

+				array[i++] = Double.parseDouble(values.nextToken().trim());

+			}

+			return array;

+		}

+		if (JmxConstants.P_FLOAT.equals(type)) {

+			float[] array = new float[values.countTokens()];

+			int i = 0;

+			while (values.hasMoreTokens()) {

+				array[i++] = Float.parseFloat(values.nextToken().trim());

+			}

+			return array;

+		}

+		if (JmxConstants.P_BYTE.equals(type)) {

+			byte[] array = new byte[values.countTokens()];

+			int i = 0;

+			while (values.hasMoreTokens()) {

+				array[i++] = Byte.parseByte(values.nextToken().trim());

+			}

+			return array;

+		}

+		if (JmxConstants.P_SHORT.equals(type)) {

+			short[] array = new short[values.countTokens()];

+			int i = 0;

+			while (values.hasMoreTokens()) {

+				array[i++] = Short.parseShort(values.nextToken().trim());

+			}

+			return array;

+		}

+		if (JmxConstants.P_CHAR.equals(type)) {

+			char[] array = new char[values.countTokens()];

+			int i = 0;

+			while (values.hasMoreTokens()) {

+				array[i++] = values.nextToken().trim().charAt(0);

+			}

+			return array;

+		}

+		if (JmxConstants.P_BOOLEAN.equals(type)) {

+			boolean[] array = new boolean[values.countTokens()];

+			int i = 0;

+			while (values.hasMoreTokens()) {

+				array[i++] = Boolean.parseBoolean(values.nextToken().trim());

+			}

+			return array;

+		}

+		throw new IllegalArgumentException("Unknown primitive type: " + type);

+	}

+	

+	/**

+	 * Create the scalar array from the supplied type

+	 * 

+	 * @param type

+	 * @param size

+	 * @return the scalar array from the supplied type

+	 */

+	private static Object[] createScalarArray(String type, int size) {

+		if (JmxConstants.STRING.equals(type)) {

+			return new String[size];

+		}

+		if (VERSION.equals(type)) {

+			return new Version[size];

+		}

+		if (JmxConstants.INTEGER.equals(type)) {

+			return new Integer[size];

+		}

+		if (JmxConstants.LONG.equals(type)) {

+			return new Long[size];

+		}

+		if (JmxConstants.DOUBLE.equals(type)) {

+			return new Double[size];

+		}

+		if (JmxConstants.FLOAT.equals(type)) {

+			return new Float[size];

+		}

+		if (JmxConstants.BYTE.equals(type)) {

+			return new Byte[size];

+		}

+		if (JmxConstants.SHORT.equals(type)) {

+			return new Short[size];

+		}

+		if (JmxConstants.CHARACTER.equals(type)) {

+			return new Character[size];

+		}

+		if (JmxConstants.BOOLEAN.equals(type)) {

+			return new Boolean[size];

+		}

+		if (JmxConstants.BIGDECIMAL.equals(type)) {

+			return new BigDecimal[size];

+		}

+		if (JmxConstants.BIGINTEGER.equals(type)) {

+			return new BigInteger[size];

+		}

+		throw new IllegalArgumentException("Unknown scalar type: " + type);

+	}

+

+	/**

 	 * Construct the scalar value represented by the string

 	 * 

 	 * @param value

@@ -587,37 +628,82 @@
 	 * @return the scalar value represented by the string

 	 */

 	private static Object parseScalar(String value, String type) {

-		if ("String".equals(type)) {

+		if (JmxConstants.STRING.equals(type)) {

 			return value;

 		}

-		if ("Integer".equals(type)) {

+		if (VERSION.equals(type)) {

+			return Version.parseVersion(value);

+		}

+		if (JmxConstants.INTEGER.equals(type)) {

 			return Integer.parseInt(value);

 		}

-		if ("Long".equals(type)) {

+		if (JmxConstants.LONG.equals(type)) {

 			return Long.parseLong(value);

 		}

-		if ("Double".equals(type)) {

+		if (JmxConstants.DOUBLE.equals(type)) {

 			return Double.parseDouble(value);

 		}

-		if ("Byte".equals(type)) {

+		if (JmxConstants.FLOAT.equals(type)) {

+			return Float.parseFloat(value);

+		}

+		if (JmxConstants.BYTE.equals(type)) {

 			return Byte.parseByte(value);

 		}

-		if ("Short".equals(type)) {

+		if (JmxConstants.SHORT.equals(type)) {

 			return Short.parseShort(value);

 		}

-		if ("Character".equals(type)) {

+		if (JmxConstants.CHARACTER.equals(type)) {

 			return value.charAt(0);

 		}

-		if ("Boolean".equals(type)) {

+		if (JmxConstants.BOOLEAN.equals(type)) {

 			return Boolean.parseBoolean(value);

 		}

-		if ("BigDecimal".equals(type)) {

+		if (JmxConstants.BIGDECIMAL.equals(type)) {

 			return new BigDecimal(value);

 		}

-		if ("BigInteger".equals(type)) {

+		if (JmxConstants.BIGINTEGER.equals(type)) {

 			return new BigInteger(value);

 		}

 		throw new IllegalArgumentException("Unknown scalar type: " + type);

 	}

 

+	/**

+	 * Construct the scalar value represented by the string

+	 * 

+	 * @param value

+	 * @param type

+	 * @return the scalar value represented by the string

+	 */

+	private static Object parseValue(String value, String type) {

+		try{

+			return parseScalar(value, type);

+		}catch (IllegalArgumentException e) {

+			if (JmxConstants.P_INT.equals(type)) {

+				return Integer.parseInt(value);

+			}

+			if (JmxConstants.P_LONG.equals(type)) {

+				return Long.parseLong(value);

+			}

+			if (JmxConstants.P_DOUBLE.equals(type)) {

+				return Double.parseDouble(value);

+			}

+			if (JmxConstants.P_FLOAT.equals(type)) {

+				return Float.parseFloat(value);

+			}

+			if (JmxConstants.P_BYTE.equals(type)) {

+				return Byte.parseByte(value);

+			}

+			if (JmxConstants.P_SHORT.equals(type)) {

+				return Short.parseShort(value);

+			}

+			if (JmxConstants.P_CHAR.equals(type)) {

+				return value.charAt(0);

+			}

+			if (JmxConstants.P_BOOLEAN.equals(type)) {

+				return Boolean.parseBoolean(value);

+			}

+			throw new IllegalArgumentException("Unknown scalar type: " + type);

+		}

+	}

+	

 }

diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/permissionadmin/PermissionManager.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/permissionadmin/PermissionManager.java
similarity index 100%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/permissionadmin/PermissionManager.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/permissionadmin/PermissionManager.java
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/provisioning/Provisioning.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/provisioning/Provisioning.java
similarity index 100%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/provisioning/Provisioning.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/provisioning/Provisioning.java
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/useradmin/UserManager.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/useradmin/UserManager.java
similarity index 100%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/useradmin/UserManager.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/useradmin/UserManager.java
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/useradmin/internal/OSGiAuthorization.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/useradmin/internal/OSGiAuthorization.java
similarity index 100%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/useradmin/internal/OSGiAuthorization.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/useradmin/internal/OSGiAuthorization.java
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/useradmin/internal/OSGiGroup.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/useradmin/internal/OSGiGroup.java
similarity index 100%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/useradmin/internal/OSGiGroup.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/useradmin/internal/OSGiGroup.java
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/useradmin/internal/OSGiRole.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/useradmin/internal/OSGiRole.java
similarity index 100%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/useradmin/internal/OSGiRole.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/useradmin/internal/OSGiRole.java
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/useradmin/internal/OSGiUser.java b/org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/useradmin/internal/OSGiUser.java
similarity index 100%
rename from org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/useradmin/internal/OSGiUser.java
rename to org.eclipse.gemini.mgmt/src/main/java/org/eclipse/gemini/mgmt/useradmin/internal/OSGiUser.java
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/BundleBatchResult.java b/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/BundleBatchResult.java
deleted file mode 100644
index 84fc9cb..0000000
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/BundleBatchResult.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*******************************************************************************

- * Copyright (c) 2010 Oracle.

- * All rights reserved. This program and the accompanying materials

- * are made available under the terms of the Eclipse Public License v1.0

- * and Apache License v2.0 which accompanies this distribution. 

- * The Eclipse Public License is available at

- *     http://www.eclipse.org/legal/epl-v10.html

- * and the Apache License v2.0 is available at 

- *     http://www.opensource.org/licenses/apache2.0.php.

- * You may elect to redistribute this code under either of these licenses.

- *

- * Contributors:

- *     Hal Hildebrand - Initial JMX support 

- ******************************************************************************/

-

-package org.eclipse.gemini.mgmt.framework.internal;

-

-/**

- * Abstract supertype to represent the result of an operation on multiple bundles. 

- * The bundles are identified by their id.

- */

-abstract public class BundleBatchResult {

-

-	/**

-	 * The list of bundles successfully completed

-	 */

-	protected long[] completed;

-	/**

-	 * The error message of a failed result

-	 */

-	protected String errorMessage;

-	/**

-	 * True if the action completed without error

-	 */

-	protected boolean success = true;

-	

-	/**

-	 * Answer the list of bundle identifiers that successfully completed the

-	 * batch operation. If the operation was unsuccessful, this will be a

-	 * partial list. If this operation was successful, this will be the full

-	 * list of bundle ids. This list corresponds one to one with the supplied

-	 * list of bundle locations provided to the batch install operations.

-	 * 

-	 * @return the list of identifiers of the bundles that successfully

-	 *         installed

-	 */

-	public long[] getCompleted() {

-		return completed;

-	}

-

-	/**

-	 * Answer the error message indicating the error that occurred during the

-	 * batch operation or null if the operation was successful

-	 * 

-	 * @return the String error message if the operation was unsuccessful, or

-	 *         null if the operation was successful

-	 */

-	public String getErrorMessage() {

-		return errorMessage;

-	}

-

-	/**

-	 * Answer true if the batch operation was successful, false otherwise.

-	 * 

-	 * @return the success of the batch operation

-	 */

-	public boolean isSuccess() {

-		return success;

-	}

-

-}

diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/internal/BundleUtil.java b/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/internal/BundleUtil.java
deleted file mode 100644
index 024990e..0000000
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/internal/BundleUtil.java
+++ /dev/null
@@ -1,275 +0,0 @@
-/*******************************************************************************

- * Copyright (c) 2010 Oracle.

- * All rights reserved. This program and the accompanying materials

- * are made available under the terms of the Eclipse Public License v1.0

- * and Apache License v2.0 which accompanies this distribution. 

- * The Eclipse Public License is available at

- *     http://www.eclipse.org/legal/epl-v10.html

- * and the Apache License v2.0 is available at 

- *     http://www.opensource.org/licenses/apache2.0.php.

- * You may elect to redistribute this code under either of these licenses.

- *

- * Contributors:

- *     Hal Hildebrand - Initial JMX support 

- ******************************************************************************/

-

-package org.eclipse.gemini.mgmt.internal;

-

-import static org.osgi.framework.Constants.SERVICE_ID;

-

-import java.io.IOException;

-import java.util.ArrayList;

-import java.util.List;

-

-import org.osgi.framework.Bundle;

-import org.osgi.framework.Constants;

-import org.osgi.framework.ServiceReference;

-import org.osgi.framework.startlevel.BundleStartLevel;

-import org.osgi.framework.wiring.BundleRevision;

-import org.osgi.framework.wiring.BundleWire;

-import org.osgi.framework.wiring.BundleWiring;

-

-/**

- * Static utilities

- * 

- */

-public final class BundleUtil {

-

-	/**

-	 * 

-	 * @param bundleId

-	 * @param bundleContext

-	 * @return

-	 * @throws IOException

-	 */

-    public static long[] getRequiredBundles(Bundle bundle) {

-        BundleWiring wiring = bundle.adapt(BundleWiring.class);

-        List<BundleWire> consumedWires = wiring.getRequiredWires(BundleRevision.BUNDLE_NAMESPACE);

-        long[] providerWires = new long[consumedWires.size()];

-        int i = 0;

-        for (BundleWire bundleWire : consumedWires) {

-            providerWires[i] = bundleWire.getProviderWiring().getBundle().getBundleId();

-        }

-        return providerWires;

-    }

-

-    /**

-     * 

-     * @param bundleId

-     * @param bundleContext

-     * @return

-     * @throws IOException

-     */

-    public static long[] getRequiringBundles(Bundle bundle) {

-        BundleWiring wiring = bundle.adapt(BundleWiring.class);

-        List<BundleWire> providedWirings = wiring.getProvidedWires(BundleRevision.BUNDLE_NAMESPACE);

-        long[] consumerWirings = new long[providedWirings.size()];

-        int i = 0;

-        for (BundleWire bundleWire : providedWirings) {

-            consumerWirings[i] = bundleWire.getRequirerWiring().getBundle().getBundleId();

-        }

-        return consumerWirings;

-    }

-	

-	/**

-	 * Answer the string representation of the exported packages of the bundle

-	 * 

-	 * @param b

-	 * @param admin

-	 * @return the string representation of the exported packages of the bundle

-	 */

-	public static String[] getBundleExportedPackages(Bundle bundle) {

-		BundleWiring wiring = bundle.adapt(BundleWiring.class);

-		List<BundleWire> providedWires = wiring.getProvidedWires(BundleRevision.PACKAGE_NAMESPACE);

-		List<String> packages = new ArrayList<String>();

-        for(BundleWire wire: providedWires){

-        	String packageName = String.format("%s;%s", wire.getCapability().getAttributes().get(BundleRevision.PACKAGE_NAMESPACE), wire.getCapability().getAttributes().get(Constants.VERSION_ATTRIBUTE));

-        	if(!packages.contains(packageName)){

-        		packages.add(packageName);

-        	}

-        }

-        return packages.toArray(new String[packages.size()]);

-	}

-

-	/**

-	 * Answer the ids of the fragments hosted by the bundle

-	 * 

-	 * @param bundle

-	 * @param admin

-	 * @return the ids of the fragments hosted by the bundle

-	 */

-	public static long[] getBundleFragments(Bundle bundle) {

-		BundleWiring wiring = bundle.adapt(BundleWiring.class);

-		List<BundleWire> consumedWires = wiring.getRequiredWires(BundleRevision.HOST_NAMESPACE);

-        long[] providerWires = new long[consumedWires.size()];

-        int i = 0;

-        for (BundleWire bundleWire : consumedWires) {

-            providerWires[i] = bundleWire.getProviderWiring().getBundle().getBundleId();

-        }

-        return providerWires;

-	}

-

-	/**

-	 * Answer the ids of the hosts this fragment is attached to

-	 * 

-	 * @param bundle

-	 * @param admin

-	 * @return the ids of the hosts this fragment is attached to

-	 */

-	public static long[] getBundleHosts(Bundle bundle) {

-		BundleWiring wiring = bundle.adapt(BundleWiring.class);

-		List<BundleWire> consumedWires = wiring.getProvidedWires(BundleRevision.HOST_NAMESPACE);

-        long[] providerWires = new long[consumedWires.size()];

-        int i = 0;

-        for (BundleWire bundleWire : consumedWires) {

-            providerWires[i] = bundleWire.getRequirerWiring().getBundle().getBundleId();

-        }

-        return providerWires;

-	}

-

-	/**

-	 * Answer the string representation of the packages imported by a bundle

-	 * 

-	 * @param b

-	 * @param bundleContext

-	 * @param admin

-	 * @return the string representation of the packages imported by a bundle

-	 */

-	public static String[] getBundleImportedPackages(Bundle bundle) {

-		BundleWiring wiring = bundle.adapt(BundleWiring.class);

-		List<BundleWire> providedWires = wiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);

-        List<String> packages = new ArrayList<String>();

-        for(BundleWire wire: providedWires){

-            String packageName = String.format("%s;%s", wire.getCapability().getAttributes().get(BundleRevision.PACKAGE_NAMESPACE), wire.getCapability().getAttributes().get(Constants.VERSION_ATTRIBUTE));

-            if(!packages.contains(packageName)){

-                packages.add(packageName);

-            }

-        }

-        return packages.toArray(new String[packages.size()]);

-	}

-

-	/**

-	 * Answer the string representation of the bundle state

-	 * 

-	 * @param b

-	 * @return the string representation of the bundle state

-	 */

-	public static String getBundleState(Bundle b) {

-		switch (b.getState()) {

-		case Bundle.ACTIVE:

-			return "ACTIVE";

-		case Bundle.INSTALLED:

-			return "INSTALLED";

-		case Bundle.RESOLVED:

-			return "RESOLVED";

-		case Bundle.STARTING:

-			return "STARTING";

-		case Bundle.STOPPING:

-			return "STOPPING";

-		case Bundle.UNINSTALLED:

-			return "UNINSTALLED";

-		default:

-			return "UNKNOWN";

-		}

-	}

-

-	/**

-	 * Answer true if the bundle is a fragment

-	 * 

-	 * @param bundle

-	 * @param admin

-	 * @return true if the bundle is a fragment

-	 */

-	public static boolean isBundleFragment(Bundle bundle) {

-		BundleWiring wiring = bundle.adapt(BundleWiring.class);

-		return 0 != (wiring.getRevision().getTypes() & BundleRevision.TYPE_FRAGMENT);

-	}

-

-	public static int getBundleStartLevel(Bundle bundle) {

-		BundleStartLevel startLevel = bundle.adapt(BundleStartLevel.class);

-		return startLevel.getStartLevel();

-	}

-	

-	/**

-	 * Answer true if the bundle has been persitently started

-	 * 

-	 * @param bundle

-	 * @param sl

-	 * @return true if the bundle has been persitently started

-	 */

-	public static boolean isBundlePersistentlyStarted(Bundle bundle) {

-		BundleStartLevel startLevel = bundle.adapt(BundleStartLevel.class);

-		return startLevel.isPersistentlyStarted();

-	}

-	

-	/**

-	 * Answer true if the bundle has been persitently started

-	 * 

-	 * @param bundle

-	 * @param sl

-	 * @return true if the bundle has been persitently started

-	 */

-	public static boolean isBundleActivationPolicyUsed(Bundle bundle) {

-		BundleStartLevel startLevel = bundle.adapt(BundleStartLevel.class);

-		return startLevel.isActivationPolicyUsed();

-	}

-

-	/**

-	 * Answer true if the bundle is required

-	 * 

-	 * @param bundle

-	 * @param bc

-	 * @return true if the bundle is required

-	 */

-	public static boolean isRequired(Bundle bundle) {

-		BundleWiring wiring = bundle.adapt(BundleWiring.class);

-		return wiring.getProvidedWires(BundleRevision.BUNDLE_NAMESPACE).size() > 0;

-	}

-

-	/**

-	 * Answer true if the bundle is pending removal

-	 * 

-	 * @param bundle

-	 * @param bc

-	 * @return true if the bundle is pending removal

-	 */

-	public static boolean isRemovalPending(Bundle bundle) {

-        BundleWiring wiring = bundle.adapt(BundleWiring.class);

-        return (!wiring.isCurrent()) && wiring.isInUse();

-	}

-

-	/**

-	 * Answer the ids of the service references

-	 * 

-	 * @param refs

-	 * @return the ids of the service references

-	 */

-	public static long[] serviceIds(ServiceReference<?>[] refs) {

-		if (refs == null) {

-			return new long[0];

-		}

-		long[] ids = new long[refs.length];

-		for (int i = 0; i < refs.length; i++) {

-			ids[i] = (Long) refs[i].getProperty(SERVICE_ID);

-		}

-		return ids;

-	}

-

-	/**

-	 * Answer a Long array from the supplied array of longs

-	 * 

-	 * @param array

-	 * @return a Long array from the supplied array of longs

-	 */

-	public static Long[] LongArrayFrom(long[] array) {

-		if (array == null) {

-			return new Long[0];

-		}

-		Long[] result = new Long[array.length];

-		for (int i = 0; i < array.length; i++) {

-			result[i] = array[i];

-		}

-		return result;

-	}

-

-}

diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/internal/BundleWiringUtil.java b/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/internal/BundleWiringUtil.java
deleted file mode 100644
index 327482b..0000000
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/internal/BundleWiringUtil.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 VMware Inc.
- * 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:
- *   VMware Inc. - initial contribution
- *******************************************************************************/
-package org.eclipse.gemini.mgmt.internal;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.gemini.mgmt.framework.CustomBundleWiringStateMBean;
-import org.eclipse.gemini.mgmt.framework.internal.OSGiBundleWiring;
-import org.osgi.framework.wiring.BundleRevision;
-import org.osgi.framework.wiring.BundleWire;
-import org.osgi.framework.wiring.BundleWiring;
-
-/**
- * Util methods when working with a {@link BundleWiring}
- *
- */
-public final class BundleWiringUtil {
-	
-	/**
-	 * Convert a key-value directive in to the required format for representation over JMX
-	 * 
-	 * @param key
-	 * @param value
-	 * @return
-	 */
-	public static Map<String, ?> getDirectiveKeyValueItem(String key, Object value){
-		Map<String, Object> items = new HashMap<String, Object>();
-		items.put(CustomBundleWiringStateMBean.KEY, key);
-		items.put(CustomBundleWiringStateMBean.VALUE, value);
-		return items;
-	}
-	
-	/**
-	 * Add all related wirings to the provided map.
-	 * 
-	 * @param mappings of 
-	 * @param wiring
-	 * @param namespace
-	 */
-	public static void processWiring(Map<BundleRevision, OSGiBundleWiring> mappings, BundleWiring wiring, String namespace){
-		BundleRevision bundleRevision = wiring.getRevision();
-		if(!mappings.containsKey(bundleRevision)) {
-			mappings.put(bundleRevision, new OSGiBundleWiring(wiring));
-			processRequiredWirings(mappings, wiring, namespace);
-			processProvidedWirings(mappings, wiring, namespace);
-		}
-	}
-	
-	private static void processRequiredWirings(Map<BundleRevision, OSGiBundleWiring> mappings, BundleWiring wiring, String namespace){
-		List<BundleWire> requiredWires = wiring.getRequiredWires(namespace);
-		if(requiredWires != null) {
-			for (BundleWire bundleWire : requiredWires) {
-				BundleWiringUtil.processWiring(mappings, bundleWire.getProviderWiring(), namespace);
-			}
-		}
-	}
-	
-	private static void processProvidedWirings(Map<BundleRevision, OSGiBundleWiring> mappings, BundleWiring wiring, String namespace){
-		List<BundleWire> providedWires = wiring.getProvidedWires(namespace);
-		if(providedWires != null) {
-			for (BundleWire bundleWire : providedWires) {
-				BundleWiringUtil.processWiring(mappings, bundleWire.getRequirerWiring(), namespace);
-			}
-		}
-	}
-}
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/internal/ServiceUtil.java b/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/internal/ServiceUtil.java
deleted file mode 100644
index bb9c320..0000000
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/internal/ServiceUtil.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 VMware Inc.
- * 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:
- *   VMware Inc. - initial contribution
- *******************************************************************************/
-package org.eclipse.gemini.mgmt.internal;
-
-import java.io.IOException;
-
-import org.osgi.framework.Bundle;
-import org.osgi.framework.ServiceReference;
-
-public final class ServiceUtil {
-	
-	/**
-	 * 
-	 * @param serviceRef
-	 * @return
-	 * @throws IOException
-	 */
-	public static long[] getBundlesUsing(ServiceReference<?> serviceRef) {
-		Bundle[] bundles = serviceRef.getUsingBundles();
-		long[] ids = new long[bundles.length];
-		for (int i = 0; i < bundles.length; i++) {
-			ids[i] = bundles[i].getBundleId();
-		}
-		return ids;
-	}
-}