Apply patch 1/2 for submodule web
diff --git a/web/org.eclipse.virgo.web.core/src/main/java/org/eclipse/virgo/web/core/internal/WebAppClassLoaderDelegateHook.java b/web/org.eclipse.virgo.web.core/src/main/java/org/eclipse/virgo/web/core/internal/WebAppClassLoaderDelegateHook.java
index 6578ede..5ce7482 100644
--- a/web/org.eclipse.virgo.web.core/src/main/java/org/eclipse/virgo/web/core/internal/WebAppClassLoaderDelegateHook.java
+++ b/web/org.eclipse.virgo.web.core/src/main/java/org/eclipse/virgo/web/core/internal/WebAppClassLoaderDelegateHook.java
@@ -16,12 +16,10 @@
 import java.util.Enumeration;
 import java.util.concurrent.ConcurrentHashMap;
 
-import org.eclipse.osgi.framework.adaptor.BundleClassLoader;
-import org.eclipse.osgi.framework.adaptor.BundleData;
-import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegateHook;
-import org.osgi.framework.Bundle;
-
 import org.eclipse.gemini.web.core.WebApplication;
+import org.eclipse.osgi.internal.hookregistry.ClassLoaderHook;
+import org.eclipse.osgi.internal.loader.ModuleClassLoader;
+import org.osgi.framework.Bundle;
 
 
 /**
@@ -34,7 +32,7 @@
  * Thread-safe.
  *
  */
-final class WebAppClassLoaderDelegateHook implements ClassLoaderDelegateHook {
+final class WebAppClassLoaderDelegateHook extends ClassLoaderHook {
     
     private static final Object DELEGATION_IN_PROGRESS_MARKER = new Object();
     
@@ -53,7 +51,7 @@
     /** 
      * {@inheritDoc}
      */
-    public Class<?> postFindClass(String name, BundleClassLoader classLoader, BundleData data) throws ClassNotFoundException {
+    public Class<?> postFindClass(String name, ModuleClassLoader classLoader) throws ClassNotFoundException {
         if (this.delegationInProgress.get() == null) {
             try {
                 this.delegationInProgress.set(DELEGATION_IN_PROGRESS_MARKER);
@@ -75,14 +73,14 @@
     /** 
      * {@inheritDoc}
      */
-    public String postFindLibrary(String name, BundleClassLoader classLoader, BundleData data) {        
+    public String postFindLibrary(String name, ModuleClassLoader classLoader) {        
         return null;
     }
 
     /** 
      * {@inheritDoc}
      */
-    public URL postFindResource(String name, BundleClassLoader classLoader, BundleData data) throws FileNotFoundException {  
+    public URL postFindResource(String name, ModuleClassLoader classLoader) throws FileNotFoundException {  
         if (this.delegationInProgress.get() == null) {
             try {
                 this.delegationInProgress.set(DELEGATION_IN_PROGRESS_MARKER);
@@ -104,7 +102,7 @@
     /** 
      * {@inheritDoc}
      */
-    public Enumeration<URL> postFindResources(String name, BundleClassLoader classLoader, BundleData data) throws FileNotFoundException {
+    public Enumeration<URL> postFindResources(String name, ModuleClassLoader classLoader) throws FileNotFoundException {
         if (this.delegationInProgress.get() == null) {
             try {
                 this.delegationInProgress.set(DELEGATION_IN_PROGRESS_MARKER);
@@ -129,28 +127,28 @@
     /** 
      * {@inheritDoc}
      */
-    public Class<?> preFindClass(String name, BundleClassLoader classLoader, BundleData data) throws ClassNotFoundException {
+    public Class<?> preFindClass(String name, ModuleClassLoader classLoader) throws ClassNotFoundException {
         return null;
     }
 
     /** 
      * {@inheritDoc}
      */
-    public String preFindLibrary(String name, BundleClassLoader classLoader, BundleData data) throws FileNotFoundException {
+    public String preFindLibrary(String name, ModuleClassLoader classLoader) throws FileNotFoundException {
         return null;
     }
 
     /** 
      * {@inheritDoc}
      */
-    public URL preFindResource(String name, BundleClassLoader classLoader, BundleData data) throws FileNotFoundException {
+    public URL preFindResource(String name, ModuleClassLoader classLoader) throws FileNotFoundException {
         return null;
     }
 
     /** 
      * {@inheritDoc}
      */
-    public Enumeration<URL> preFindResources(String name, BundleClassLoader classLoader, BundleData data) throws FileNotFoundException {
+    public Enumeration<URL> preFindResources(String name, ModuleClassLoader classLoader) throws FileNotFoundException {
         return null;
     }
 
diff --git a/web/org.eclipse.virgo.web.enterprise.persistence.openejb.classloading.hook/src/main/java/org/eclipse/virgo/web/enterprise/persistence/openejb/classloading/hook/AppLoaderClasspathExtenderClassLoadingHook.java b/web/org.eclipse.virgo.web.enterprise.persistence.openejb.classloading.hook/src/main/java/org/eclipse/virgo/web/enterprise/persistence/openejb/classloading/hook/AppLoaderClasspathExtenderClassLoadingHook.java
index 1aeb3f6..af1dc41 100755
--- a/web/org.eclipse.virgo.web.enterprise.persistence.openejb.classloading.hook/src/main/java/org/eclipse/virgo/web/enterprise/persistence/openejb/classloading/hook/AppLoaderClasspathExtenderClassLoadingHook.java
+++ b/web/org.eclipse.virgo.web.enterprise.persistence.openejb.classloading.hook/src/main/java/org/eclipse/virgo/web/enterprise/persistence/openejb/classloading/hook/AppLoaderClasspathExtenderClassLoadingHook.java
@@ -13,165 +13,144 @@
 

 import java.io.File;

 import java.io.FilenameFilter;

-import java.security.ProtectionDomain;

 import java.util.ArrayList;

 import java.util.logging.Level;

 import java.util.logging.Logger;

 

-import org.eclipse.osgi.baseadaptor.BaseData;

-import org.eclipse.osgi.baseadaptor.HookConfigurator;

-import org.eclipse.osgi.baseadaptor.HookRegistry;

-import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;

-import org.eclipse.osgi.baseadaptor.hooks.ClassLoadingHook;

-import org.eclipse.osgi.baseadaptor.loader.BaseClassLoader;

-import org.eclipse.osgi.baseadaptor.loader.ClasspathEntry;

-import org.eclipse.osgi.baseadaptor.loader.ClasspathManager;

-import org.eclipse.osgi.framework.adaptor.BundleProtectionDomain;

-import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegate;

-import org.osgi.framework.BundleException;

+import org.eclipse.osgi.internal.hookregistry.ClassLoaderHook;

+import org.eclipse.osgi.internal.hookregistry.HookConfigurator;

+import org.eclipse.osgi.internal.hookregistry.HookRegistry;

+import org.eclipse.osgi.internal.loader.classpath.ClasspathEntry;

+import org.eclipse.osgi.internal.loader.classpath.ClasspathManager;

+import org.eclipse.osgi.storage.BundleInfo.Generation;

+import org.eclipse.osgi.storage.bundlefile.BundleEntry;

 

-public class AppLoaderClasspathExtenderClassLoadingHook implements ClassLoadingHook,

-		HookConfigurator {

+public class AppLoaderClasspathExtenderClassLoadingHook extends ClassLoaderHook implements HookConfigurator {

 

-	File persistenceIntegrationJar = null;

-	private static final String FILE_SCHEME = "file:";

-	private static final String WEB_CONTEXTPATH_HEADER = "Web-ContextPath";

-	private static final Logger logger = Logger

-			.getLogger("com.sap.core.service.accessor.persistence.classloading.hook.AppLoaderClasspathExtenderClassLoadingHook");

-	private static final String PERSISTENCE_INTEGRATION_JAR_PROP_NAME = "persistence.integration.jar.name";

-	private static final String PERSISTENCE_INTEGRATION_JAR = System.getProperty(PERSISTENCE_INTEGRATION_JAR_PROP_NAME);

-	private static final String CONFIG_AREA = "osgi.configuration.area";

-	private static final String LIB_DIR = "lib";

-	private static final String PERSISTENCE_DIR = "persistence";

-	

-	@Override

-	public void addHooks(HookRegistry registry) {

-		registry.addClassLoadingHook(this);

-	}

+    File persistenceIntegrationJar = null;

 

-	@Override

-	public boolean addClassPathEntry(ArrayList<ClasspathEntry> cpEntries, String cp, ClasspathManager hostmanager, BaseData sourcedata, ProtectionDomain sourcedomain) {

-		if (isAppBundle(sourcedata) && (shouldAdd(cpEntries))) {

-			ClasspathEntry persistenceIntegrationClasspathEntry = null;

-			try {

-				persistenceIntegrationClasspathEntry = determinePersistenceIntegrationPath(hostmanager, sourcedata, sourcedomain);

-			} catch (ClasspathExtenderClassLoadingHookException ex) {

-				logger.log(Level.SEVERE, ex.getMessage(), ex);

-			}

-			

-			if (persistenceIntegrationClasspathEntry != null) {

-				cpEntries.add(persistenceIntegrationClasspathEntry);

-				return true;

-			}

-		}

-		return false;

-	}

+    private static final String FILE_SCHEME = "file:";

 

-	boolean shouldAdd(ArrayList<ClasspathEntry> cpEntries) {

-		for (ClasspathEntry cpEntry : cpEntries) {

-			if (cpEntry.getBundleFile().getBaseFile().getName().startsWith(PERSISTENCE_INTEGRATION_JAR)) {

-				return false;

-			}

-		}

-		return true;

-	}

+    private static final String WEB_CONTEXTPATH_HEADER = "Web-ContextPath";

 

-	ClasspathEntry determinePersistenceIntegrationPath(ClasspathManager hostmanager, BaseData sourcedata, ProtectionDomain sourcedomain) throws ClasspathExtenderClassLoadingHookException{

-		if (persistenceIntegrationJar == null) {

-			findPersistenceIntegrationJar();

-		}

-		

-		ClasspathEntry cp = hostmanager.getExternalClassPath(persistenceIntegrationJar.getAbsolutePath(), sourcedata, sourcedomain);

-		if (cp == null) {

-			throw new ClasspathExtenderClassLoadingHookException("Failed to create classpath entry for file [" + PERSISTENCE_INTEGRATION_JAR + "]");

-		}

-		

-		return cp;

-	}

+    private static final Logger logger = Logger.getLogger(

+        "com.sap.core.service.accessor.persistence.classloading.hook.AppLoaderClasspathExtenderClassLoadingHook");

 

-	void findPersistenceIntegrationJar() throws ClasspathExtenderClassLoadingHookException{

-		String configurationPath = System.getProperty(CONFIG_AREA);

-		if (configurationPath == null) {

-			throw new ClasspathExtenderClassLoadingHookException("Property [" + CONFIG_AREA + "] is missing");

-		}

-		File configurationFile = new File(normalize(configurationPath));

-		File lib = new File(configurationFile.getParentFile(), LIB_DIR);

-		if (!lib.exists()) {

-			throw new ClasspathExtenderClassLoadingHookException("lib folder is missing");

-		}

-		

-		File persistenceLibDir = new File(lib, PERSISTENCE_DIR);

-		if (!persistenceLibDir.exists()) {

-			throw new ClasspathExtenderClassLoadingHookException("lib/persistence folder is missing");

-		}

-		

-		String[] libs = persistenceLibDir.list(new FilenameFilter() {	

-			@Override

-			public boolean accept(File dir, String name) {

-				if (name.startsWith(PERSISTENCE_INTEGRATION_JAR)) {

-					return true;

-				}

-				return false;

-			}

-		});

-		

-		if (libs.length == 0) {

-			throw new ClasspathExtenderClassLoadingHookException("No file with name starting with [" + PERSISTENCE_INTEGRATION_JAR + "] was found in lib/persistence folder");

-		}

-		

-		if (libs.length > 1) {

-			logger.log(Level.SEVERE, "Found " + libs.length + " files with name starting with [" + PERSISTENCE_INTEGRATION_JAR + "] was found in lib/persistence folder (one expected); choosing [" + libs[0] + "]");

-		}

-		

-		persistenceIntegrationJar = new File(persistenceLibDir, libs[0]);

-		

-	}

+    private static final String PERSISTENCE_INTEGRATION_JAR_PROP_NAME = "persistence.integration.jar.name";

 

-	String normalize(String filePath) {

-		if (filePath.startsWith(FILE_SCHEME)) {

-			return filePath.substring(FILE_SCHEME.length());

-		}

-		return filePath;

-	}

+    private static final String PERSISTENCE_INTEGRATION_JAR = System.getProperty(PERSISTENCE_INTEGRATION_JAR_PROP_NAME);

 

-	boolean isAppBundle(BaseData sourcedata) {

-		try {

-			if (sourcedata.getManifest().get(WEB_CONTEXTPATH_HEADER) != null) {

-				return true;

-			}

-		} catch (BundleException e) {

-			logger.log(Level.SEVERE, "Error checking if bundle [" + sourcedata

-					+ "] is application.", e);

-			return false;

-		}

-		return false;

-	}

+    private static final String CONFIG_AREA = "osgi.configuration.area";

 

-	@Override

-	public BaseClassLoader createClassLoader(ClassLoader parent,

-			ClassLoaderDelegate delegate, BundleProtectionDomain protectionDomain,

-			BaseData sourcedata, String[] classpath) {

-		return null;

-	}

+    private static final String LIB_DIR = "lib";

 

-	@Override

-	public String findLibrary(BaseData arg0, String arg1) {

-		return null;

-	}

+    private static final String PERSISTENCE_DIR = "persistence";

 

-	@Override

-	public ClassLoader getBundleClassLoaderParent() {

-		return null;

-	}

+    @Override

+    public void addHooks(HookRegistry registry) {

+        registry.addClassLoaderHook(this);

+    }

 

-	@Override

-	public void initializedClassLoader(BaseClassLoader arg0, BaseData arg1) {

-	}

+    @Override

+    public boolean addClassPathEntry(ArrayList<ClasspathEntry> cpEntries, String cp, ClasspathManager hostmanager, Generation sourceGeneration) {

+        if (isAppBundle(sourceGeneration) && (shouldAdd(cpEntries))) {

+            ClasspathEntry persistenceIntegrationClasspathEntry = null;

+            try {

+                persistenceIntegrationClasspathEntry = determinePersistenceIntegrationPath(hostmanager, sourceGeneration);

+            } catch (ClasspathExtenderClassLoadingHookException ex) {

+                logger.log(Level.SEVERE, ex.getMessage(), ex);

+            }

 

-	@Override

-	public byte[] processClass(String name, byte[] classbytes, ClasspathEntry classpathEntry,

-			BundleEntry entry, ClasspathManager classpathManager) {

-		return null;

-	}

+            if (persistenceIntegrationClasspathEntry != null) {

+                cpEntries.add(persistenceIntegrationClasspathEntry);

+                return true;

+            }

+        }

+        return false;

+    }

+

+    boolean shouldAdd(ArrayList<ClasspathEntry> cpEntries) {

+        for (ClasspathEntry cpEntry : cpEntries) {

+            if (cpEntry.getBundleFile().getBaseFile().getName().startsWith(PERSISTENCE_INTEGRATION_JAR)) {

+                return false;

+            }

+        }

+        return true;

+    }

+

+    ClasspathEntry determinePersistenceIntegrationPath(ClasspathManager hostmanager, Generation sourcedata)

+        throws ClasspathExtenderClassLoadingHookException {

+        if (persistenceIntegrationJar == null) {

+            findPersistenceIntegrationJar();

+        }

+

+        ClasspathEntry cp = hostmanager.getExternalClassPath(persistenceIntegrationJar.getAbsolutePath(), sourcedata);

+        if (cp == null) {

+            throw new ClasspathExtenderClassLoadingHookException("Failed to create classpath entry for file [" + PERSISTENCE_INTEGRATION_JAR + "]");

+        }

+

+        return cp;

+    }

+

+    void findPersistenceIntegrationJar() throws ClasspathExtenderClassLoadingHookException {

+        String configurationPath = System.getProperty(CONFIG_AREA);

+        if (configurationPath == null) {

+            throw new ClasspathExtenderClassLoadingHookException("Property [" + CONFIG_AREA + "] is missing");

+        }

+        File configurationFile = new File(normalize(configurationPath));

+        File lib = new File(configurationFile.getParentFile(), LIB_DIR);

+        if (!lib.exists()) {

+            throw new ClasspathExtenderClassLoadingHookException("lib folder is missing");

+        }

+

+        File persistenceLibDir = new File(lib, PERSISTENCE_DIR);

+        if (!persistenceLibDir.exists()) {

+            throw new ClasspathExtenderClassLoadingHookException("lib/persistence folder is missing");

+        }

+

+        String[] libs = persistenceLibDir.list(new FilenameFilter() {

+

+            @Override

+            public boolean accept(File dir, String name) {

+                if (name.startsWith(PERSISTENCE_INTEGRATION_JAR)) {

+                    return true;

+                }

+                return false;

+            }

+        });

+

+        if (libs.length == 0) {

+            throw new ClasspathExtenderClassLoadingHookException(

+                "No file with name starting with [" + PERSISTENCE_INTEGRATION_JAR + "] was found in lib/persistence folder");

+        }

+

+        if (libs.length > 1) {

+            logger.log(Level.SEVERE, "Found " + libs.length + " files with name starting with [" + PERSISTENCE_INTEGRATION_JAR

+                + "] was found in lib/persistence folder (one expected); choosing [" + libs[0] + "]");

+        }

+

+        persistenceIntegrationJar = new File(persistenceLibDir, libs[0]);

+

+    }

+

+    String normalize(String filePath) {

+        if (filePath.startsWith(FILE_SCHEME)) {

+            return filePath.substring(FILE_SCHEME.length());

+        }

+        return filePath;

+    }

+

+    boolean isAppBundle(Generation sourcedata) {

+        // TODO - review this change

+        if (sourcedata.getHeaders().get(WEB_CONTEXTPATH_HEADER) != null) {

+            return true;

+        }

+        return false;

+    }

+

+    @Override

+    public byte[] processClass(String name, byte[] classbytes, ClasspathEntry classpathEntry, BundleEntry entry, ClasspathManager classpathManager) {

+        return null;

+    }

 

 }

diff --git a/web/org.eclipse.virgo.web.enterprise.persistence.openejb.classloading.hook/src/main/java/org/eclipse/virgo/web/enterprise/persistence/openejb/classloading/hook/ClasspathExtenderClassLoadingHookException.java b/web/org.eclipse.virgo.web.enterprise.persistence.openejb.classloading.hook/src/main/java/org/eclipse/virgo/web/enterprise/persistence/openejb/classloading/hook/ClasspathExtenderClassLoadingHookException.java
index d5c5e07..36b2018 100755
--- a/web/org.eclipse.virgo.web.enterprise.persistence.openejb.classloading.hook/src/main/java/org/eclipse/virgo/web/enterprise/persistence/openejb/classloading/hook/ClasspathExtenderClassLoadingHookException.java
+++ b/web/org.eclipse.virgo.web.enterprise.persistence.openejb.classloading.hook/src/main/java/org/eclipse/virgo/web/enterprise/persistence/openejb/classloading/hook/ClasspathExtenderClassLoadingHookException.java
@@ -13,7 +13,9 @@
 

 public class ClasspathExtenderClassLoadingHookException extends Exception {

 

-	public ClasspathExtenderClassLoadingHookException(String message) {

+	private static final long serialVersionUID = 1L;

+

+    public ClasspathExtenderClassLoadingHookException(String message) {

 		super(message);

 	}

 	

diff --git a/web/org.eclipse.virgo.web.enterprise.security.openejb.classloading.hook/src/main/java/org/eclipse/virgo/web/enterprise/security/openejb/classloading/hook/OpenEjbEmptyProtectionDomainClassloadingHook.java b/web/org.eclipse.virgo.web.enterprise.security.openejb.classloading.hook/src/main/java/org/eclipse/virgo/web/enterprise/security/openejb/classloading/hook/OpenEjbEmptyProtectionDomainClassloadingHook.java
index 00328a7..79f05a2 100755
--- a/web/org.eclipse.virgo.web.enterprise.security.openejb.classloading.hook/src/main/java/org/eclipse/virgo/web/enterprise/security/openejb/classloading/hook/OpenEjbEmptyProtectionDomainClassloadingHook.java
+++ b/web/org.eclipse.virgo.web.enterprise.security.openejb.classloading.hook/src/main/java/org/eclipse/virgo/web/enterprise/security/openejb/classloading/hook/OpenEjbEmptyProtectionDomainClassloadingHook.java
@@ -16,66 +16,41 @@
 import java.security.ProtectionDomain;

 import java.util.ArrayList;

 

-import org.eclipse.osgi.baseadaptor.BaseData;

-import org.eclipse.osgi.baseadaptor.HookConfigurator;

-import org.eclipse.osgi.baseadaptor.HookRegistry;

-import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;

-import org.eclipse.osgi.baseadaptor.hooks.ClassLoadingHook;

-import org.eclipse.osgi.baseadaptor.loader.BaseClassLoader;

-import org.eclipse.osgi.baseadaptor.loader.ClasspathEntry;

-import org.eclipse.osgi.baseadaptor.loader.ClasspathManager;

-import org.eclipse.osgi.framework.adaptor.BundleProtectionDomain;

-import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegate;

-import org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader;

+import org.eclipse.osgi.internal.framework.EquinoxConfiguration;

+import org.eclipse.osgi.internal.hookregistry.ClassLoaderHook;

+import org.eclipse.osgi.internal.hookregistry.HookConfigurator;

+import org.eclipse.osgi.internal.hookregistry.HookRegistry;

+import org.eclipse.osgi.internal.loader.BundleLoader;

+import org.eclipse.osgi.internal.loader.EquinoxClassLoader;

+import org.eclipse.osgi.internal.loader.ModuleClassLoader;

+import org.eclipse.osgi.internal.loader.classpath.ClasspathEntry;

+import org.eclipse.osgi.internal.loader.classpath.ClasspathManager;

+import org.eclipse.osgi.storage.BundleInfo.Generation;

 

 //Applicable only for org.apache.openejb.core

-public class OpenEjbEmptyProtectionDomainClassloadingHook implements ClassLoadingHook, HookConfigurator {

-	//Equinox implicitly creates a ProtectionDomain for each bundle with all permissions.

-	//Openejb does security checks related to security manager with its own protection domain which is not the app protection domain in OSGi case

-	@Override

-	public BaseClassLoader createClassLoader(ClassLoader parent,

-			ClassLoaderDelegate delegate, BundleProtectionDomain domain,

-			BaseData data, String[] classpath) {

-		

-		ProtectionDomain processedProtectionDomain = domain;

-	   

-		if (processedProtectionDomain == null && data.getSymbolicName().equals("org.apache.openejb.core")) {		

-			PermissionCollection emptyPermissionCollection = (new AllPermission()).newPermissionCollection();

-			processedProtectionDomain = new ProtectionDomain(null, emptyPermissionCollection);			

-		}

-		return new DefaultClassLoader(parent, delegate, processedProtectionDomain, data, classpath);

-	}

+public class OpenEjbEmptyProtectionDomainClassloadingHook extends ClassLoaderHook implements HookConfigurator {

 

-	@Override

-	public boolean addClassPathEntry(ArrayList<ClasspathEntry> arg0,

-			String arg1, ClasspathManager arg2, BaseData arg3,

-			ProtectionDomain arg4) {

-		return false;

-	}

+    // Equinox implicitly creates a ProtectionDomain for each bundle with all permissions.

+    // Openejb does security checks related to security manager with its own protection domain which is not the app

+    // protection domain in OSGi case

+    @Override

+    public ModuleClassLoader createClassLoader(ClassLoader parent, EquinoxConfiguration configuration, BundleLoader delegate, Generation generation) {

+        ProtectionDomain processedProtectionDomain = generation.getDomain();

 

-	@Override

-	public String findLibrary(BaseData arg0, String arg1) {

-		return null;

-	}

+        if (processedProtectionDomain == null && generation.getRevision().getSymbolicName().equals("org.apache.openejb.core")) {

+            PermissionCollection emptyPermissionCollection = (new AllPermission()).newPermissionCollection();

+            processedProtectionDomain = new ProtectionDomain(null, emptyPermissionCollection);

+        }

+        return new EquinoxClassLoader(parent, configuration, delegate, generation);

+    }

 

-	@Override

-	public ClassLoader getBundleClassLoaderParent() {

-		return null;

-	}

+    @Override

+    public boolean addClassPathEntry(ArrayList<ClasspathEntry> cpEntries, String cp, ClasspathManager hostmanager, Generation sourceGeneration) {

+        return false;

+    }

 

-	@Override

-	public void initializedClassLoader(BaseClassLoader arg0, BaseData arg1) {

-	}

-

-	@Override

-	public byte[] processClass(String arg0, byte[] arg1, ClasspathEntry arg2,

-			BundleEntry arg3, ClasspathManager arg4) {

-		return null;

-	}

-

-	@Override

-	public void addHooks(HookRegistry hookRegistry) {

-		hookRegistry.addClassLoadingHook(this);

-		

-	}

+    @Override

+    public void addHooks(HookRegistry hookRegistry) {

+        hookRegistry.addClassLoaderHook(this);

+    }

 }

diff --git a/web/org.eclipse.virgo.web.enterprise.services.accessor/src/main/java/org/eclipse/virgo/web/enterprise/services/accessor/ClassLoaderJarScanner.java b/web/org.eclipse.virgo.web.enterprise.services.accessor/src/main/java/org/eclipse/virgo/web/enterprise/services/accessor/ClassLoaderJarScanner.java
index 809b02f..e3f85d0 100755
--- a/web/org.eclipse.virgo.web.enterprise.services.accessor/src/main/java/org/eclipse/virgo/web/enterprise/services/accessor/ClassLoaderJarScanner.java
+++ b/web/org.eclipse.virgo.web.enterprise.services.accessor/src/main/java/org/eclipse/virgo/web/enterprise/services/accessor/ClassLoaderJarScanner.java
@@ -30,10 +30,9 @@
 import org.apache.tomcat.JarScanner;

 import org.apache.tomcat.JarScannerCallback;

 import org.apache.tomcat.util.scan.JarFactory;

-import org.eclipse.osgi.baseadaptor.BaseData;

-import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;

-import org.eclipse.osgi.framework.adaptor.BundleData;

-import org.eclipse.osgi.framework.internal.core.BundleHost;

+import org.eclipse.osgi.internal.framework.EquinoxBundle;

+import org.eclipse.osgi.storage.BundleInfo.Generation;

+import org.eclipse.osgi.storage.bundlefile.BundleFile;

 import org.osgi.framework.Bundle;

 import org.slf4j.Logger;

 import org.slf4j.LoggerFactory;

@@ -159,12 +158,10 @@
     }

 

     private BundleFile getBundleFile(Bundle bundle) {

-        if (bundle instanceof BundleHost) {

-            BundleHost bh = (BundleHost) bundle;

-            BundleData bundleData = bh.getBundleData();

-            if (bundleData instanceof BaseData) {

-                return ((BaseData) bundleData).getBundleFile();

-            }

+        if (bundle instanceof EquinoxBundle) {

+            EquinoxBundle equinoxBundle = (EquinoxBundle) bundle;

+            Generation generation = (Generation) equinoxBundle.getModule().getCurrentRevision().getRevisionInfo();

+            return generation.getBundleFile();

         }

         return null;

     }

diff --git a/web/org.eclipse.virgo.web.enterprise.services.accessor/src/main/java/org/eclipse/virgo/web/enterprise/services/accessor/WebAppBundleClassLoaderDelegateHook.java b/web/org.eclipse.virgo.web.enterprise.services.accessor/src/main/java/org/eclipse/virgo/web/enterprise/services/accessor/WebAppBundleClassLoaderDelegateHook.java
index fbd9be3..800fc63 100755
--- a/web/org.eclipse.virgo.web.enterprise.services.accessor/src/main/java/org/eclipse/virgo/web/enterprise/services/accessor/WebAppBundleClassLoaderDelegateHook.java
+++ b/web/org.eclipse.virgo.web.enterprise.services.accessor/src/main/java/org/eclipse/virgo/web/enterprise/services/accessor/WebAppBundleClassLoaderDelegateHook.java
@@ -28,10 +28,9 @@
 import java.util.concurrent.CopyOnWriteArraySet;

 import java.util.concurrent.atomic.AtomicInteger;

 

-import org.eclipse.osgi.framework.adaptor.BundleClassLoader;

-import org.eclipse.osgi.framework.adaptor.BundleData;

-import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegateHook;

-import org.eclipse.osgi.framework.internal.core.BundleHost;

+import org.eclipse.osgi.container.ModuleWiring;

+import org.eclipse.osgi.internal.hookregistry.ClassLoaderHook;

+import org.eclipse.osgi.internal.loader.ModuleClassLoader;

 import org.osgi.framework.Bundle;

 import org.osgi.framework.BundleReference;

 import org.osgi.framework.FrameworkUtil;

@@ -42,7 +41,7 @@
 import org.slf4j.Logger;

 import org.slf4j.LoggerFactory;

 

-class WebAppBundleClassLoaderDelegateHook implements ClassLoaderDelegateHook {

+class WebAppBundleClassLoaderDelegateHook extends ClassLoaderHook {

 

     private static final String GEMINI_WEB_TOMCAT_SYMBOLIC_NAME = "org.eclipse.gemini.web.tomcat";

 

@@ -179,15 +178,14 @@
     }

 

     @Override

-    public Class<?> postFindClass(String name, BundleClassLoader bcl, BundleData bd) throws ClassNotFoundException {

+    public Class<?> postFindClass(String name, ModuleClassLoader classLoader) throws ClassNotFoundException {

     	if(matchesNegativeCache(name)) {

     		return null;

     	}

         if (shouldEnter(MAX_IMPL_SEARCH_DEPTH)) {

             try {

                 enter();

-

-                Bundle bundle = bd.getBundle();

+                Bundle bundle = classLoader.getBundle();

                 	

 				if (this.implBundles.contains(bundle)) {

                     ClassLoader tccl = Thread.currentThread().getContextClassLoader();

@@ -216,7 +214,7 @@
         if (shouldEnter(MAX_API_SEARCH_DEPTH)) {

         	try {

         		enter();

-        		Bundle bundle = bd.getBundle();

+        		Bundle bundle = classLoader.getBundle();

 

         		if (this.webAppBundles.containsKey(bundle)) {

         			for (Bundle postFindApiProvider : postFindApiBundles) {

@@ -251,18 +249,18 @@
     }

 

     @Override

-    public String postFindLibrary(String name, BundleClassLoader bcl, BundleData bd) {

+    public String postFindLibrary(String name, ModuleClassLoader classLoader) {

         // no-op

         return null;

     }

 

     @Override

-    public URL postFindResource(String name, BundleClassLoader bcl, BundleData bd) throws FileNotFoundException {

+    public URL postFindResource(String name, ModuleClassLoader classLoader) throws FileNotFoundException {

         if (shouldEnter(MAX_RESOURCE_SEARCH_DEPTH)) {

             try {

                 enter();

 

-                Bundle bundle = bd.getBundle();

+                Bundle bundle = classLoader.getBundle();

 

                 if (this.webAppBundles.containsKey(bundle)) {

                     return doFindApiResource(name);

@@ -315,12 +313,12 @@
     }

 

     @Override

-    public Enumeration<URL> postFindResources(String name, BundleClassLoader bcl, BundleData bd) throws FileNotFoundException {

+    public Enumeration<URL> postFindResources(String name, ModuleClassLoader classLoader) throws FileNotFoundException {

         if (shouldEnter(MAX_RESOURCE_SEARCH_DEPTH)) {

             try {

                 enter();

 

-                Bundle bundle = bd.getBundle();

+                Bundle bundle = classLoader.getBundle();

 

                 if (this.webAppBundles.containsKey(bundle)) {

                     return doFindApiResources(name);

@@ -347,7 +345,7 @@
     }

 

     @Override

-    public Class<?> preFindClass(String name, BundleClassLoader bcl, BundleData bd) throws ClassNotFoundException {

+    public Class<?> preFindClass(String name, ModuleClassLoader classLoader) throws ClassNotFoundException {

     	if(matchesNegativeCache(name)) {

     		return null;

     	}

@@ -355,7 +353,7 @@
             try {

                 enter();

 

-                Bundle bundle = bd.getBundle();

+                Bundle bundle = classLoader.getBundle();

 

                 if (this.webAppBundles.containsKey(bundle)) {

                     if (checkPackageInImport(name, this.webAppBundles.get(bundle))) {

@@ -381,19 +379,19 @@
     }

 

     @Override

-    public String preFindLibrary(String name, BundleClassLoader bcl, BundleData bd) throws FileNotFoundException {

+    public String preFindLibrary(String name, ModuleClassLoader classLoader) throws FileNotFoundException {

         // no-op

         return null;

     }

 

     @Override

-    public URL preFindResource(String name, BundleClassLoader bcl, BundleData bd) throws FileNotFoundException {

+    public URL preFindResource(String name, ModuleClassLoader classLoader) throws FileNotFoundException {

         // no-op

         return null;

     }

 

     @Override

-    public Enumeration<URL> preFindResources(String name, BundleClassLoader bcl, BundleData bd) throws FileNotFoundException {

+    public Enumeration<URL> preFindResources(String name, ModuleClassLoader classLoader) throws FileNotFoundException {

         // no-op

         return null;

     }

@@ -542,14 +540,17 @@
     }

 

     private ClassLoader getBundleClassloader(Bundle bundle) {

-        if (bundle instanceof BundleHost) {

-            return ((BundleHost) bundle).getClassLoader();

-        } else {

-            if (LOGGER.isDebugEnabled()) {

-                LOGGER.debug("Cannot obtain classloader for bundle " + bundle);

-            }

-            return null;

-        }

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

+        return moduleWiring.getClassLoader();

+        // TODO Think about fragments here?

+//        if (bundle instanceof BundleHost) {

+//            return ((BundleHost) bundle).getClassLoader();

+//        } else {

+//            if (LOGGER.isDebugEnabled()) {

+//                LOGGER.debug("Cannot obtain classloader for bundle " + bundle);

+//            }

+//            return null;

+//        }

     }

 

     Set<Bundle> getApiBundles() {

diff --git a/web/org.eclipse.virgo.web.enterprise.services.accessor/src/test/java/org/eclipse/virgo/web/enterprise/services/accessor/WebAppBundleClassLoaderDelegateHookTest.java b/web/org.eclipse.virgo.web.enterprise.services.accessor/src/test/java/org/eclipse/virgo/web/enterprise/services/accessor/WebAppBundleClassLoaderDelegateHookTest.java
index d7fde0f..de206f9 100755
--- a/web/org.eclipse.virgo.web.enterprise.services.accessor/src/test/java/org/eclipse/virgo/web/enterprise/services/accessor/WebAppBundleClassLoaderDelegateHookTest.java
+++ b/web/org.eclipse.virgo.web.enterprise.services.accessor/src/test/java/org/eclipse/virgo/web/enterprise/services/accessor/WebAppBundleClassLoaderDelegateHookTest.java
@@ -27,6 +27,7 @@
 

 import org.eclipse.osgi.framework.adaptor.BundleClassLoader;

 import org.eclipse.osgi.framework.adaptor.BundleData;

+import org.eclipse.osgi.internal.loader.ModuleClassLoader;

 import org.junit.Test;

 import org.osgi.framework.Bundle;

 import org.osgi.framework.wiring.BundleRevision;

@@ -39,7 +40,7 @@
     @Test

     public void testPostFindWithWAB() throws ClassNotFoundException, IOException {

         BundleData bd = createMock(BundleData.class);

-        BundleClassLoader bcl = createMock(BundleClassLoader.class);

+        ModuleClassLoader bcl = createMock(ModuleClassLoader.class);

         Bundle wab = createMock(Bundle.class);

         Bundle apiBundle = createMock(Bundle.class);

         BundleRevision bundleRevision = createMock(BundleRevision.class);

diff --git a/web/org.eclipse.virgo.web.enterprise.services.accessor/src/test/java/org/eclipse/virgo/web/enterprise/services/accessor/WebAppBundleClassloaderCustomizerTest.java b/web/org.eclipse.virgo.web.enterprise.services.accessor/src/test/java/org/eclipse/virgo/web/enterprise/services/accessor/WebAppBundleClassloaderCustomizerTest.java
index 73dfb85..45945df 100755
--- a/web/org.eclipse.virgo.web.enterprise.services.accessor/src/test/java/org/eclipse/virgo/web/enterprise/services/accessor/WebAppBundleClassloaderCustomizerTest.java
+++ b/web/org.eclipse.virgo.web.enterprise.services.accessor/src/test/java/org/eclipse/virgo/web/enterprise/services/accessor/WebAppBundleClassloaderCustomizerTest.java
@@ -27,7 +27,7 @@
 import java.util.Map;

 import java.util.Set;

 

-import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegateHook;

+import org.eclipse.osgi.internal.hookregistry.ClassLoaderHook;

 import org.eclipse.virgo.kernel.equinox.extensions.hooks.PluggableDelegatingClassLoaderDelegateHook;

 import org.junit.Test;

 import org.osgi.framework.Bundle;

@@ -91,7 +91,7 @@
 

         assertTrue(webAppBundleClassloaderCustomizer.getWebAppBundleClassLoaderDelegateHook().getApiBundles().contains(apiBundle));

         assertTrue(webAppBundleClassloaderCustomizer.getWebAppBundleClassLoaderDelegateHook().getImplBundles().contains(implBundle));

-        assertTrue(((List<ClassLoaderDelegateHook>) field.get(PluggableDelegatingClassLoaderDelegateHook.getInstance())).contains(webAppBundleClassloaderCustomizer.getWebAppBundleClassLoaderDelegateHook()));

+        assertTrue(((List<ClassLoaderHook>) field.get(PluggableDelegatingClassLoaderDelegateHook.getInstance())).contains(webAppBundleClassloaderCustomizer.getWebAppBundleClassLoaderDelegateHook()));

 

         assertTrue(webAppBundleClassloaderCustomizer.extendClassLoaderChain(webBundle).length == 0);

         assertTrue(webAppBundleClassloaderCustomizer.getWebAppBundleTrackerCustomizer().getExposeAdditionalApiBundles().isEmpty());

@@ -101,7 +101,7 @@
 

         assertTrue(webAppBundleClassloaderCustomizer.getWebAppBundleClassLoaderDelegateHook().getApiBundles().isEmpty());

         assertTrue(webAppBundleClassloaderCustomizer.getWebAppBundleClassLoaderDelegateHook().getImplBundles().isEmpty());

-        assertTrue(((List<ClassLoaderDelegateHook>) field.get(PluggableDelegatingClassLoaderDelegateHook.getInstance())).isEmpty());

+        assertTrue(((List<ClassLoaderHook>) field.get(PluggableDelegatingClassLoaderDelegateHook.getInstance())).isEmpty());

 

         verify(ctx, bundleContext, apiBundle, implBundle, webBundle, bundleRevision, bundleWiring);

     }

diff --git a/web/org.eclipse.virgo.web.war.deployer/src/main/java/org/eclipse/virgo/web/war/deployer/WARDeployer.java b/web/org.eclipse.virgo.web.war.deployer/src/main/java/org/eclipse/virgo/web/war/deployer/WARDeployer.java
index 02b1970..c593343 100644
--- a/web/org.eclipse.virgo.web.war.deployer/src/main/java/org/eclipse/virgo/web/war/deployer/WARDeployer.java
+++ b/web/org.eclipse.virgo.web.war.deployer/src/main/java/org/eclipse/virgo/web/war/deployer/WARDeployer.java
@@ -22,6 +22,7 @@
 import java.net.URISyntaxException;
 import java.net.URLDecoder;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.HashMap;
@@ -35,9 +36,7 @@
 
 import org.eclipse.gemini.web.core.InstallationOptions;
 import org.eclipse.gemini.web.core.WebBundleManifestTransformer;
-import org.eclipse.osgi.framework.adaptor.BundleClassLoader;
-import org.eclipse.osgi.framework.internal.core.BundleHost;
-import org.eclipse.osgi.framework.internal.core.PackageAdminImpl;
+import org.eclipse.osgi.internal.loader.ModuleClassLoader;
 import org.eclipse.virgo.medic.eventlog.EventLogger;
 import org.eclipse.virgo.nano.core.KernelConfig;
 import org.eclipse.virgo.nano.deployer.SimpleDeployer;
@@ -56,6 +55,8 @@
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
+import org.osgi.framework.wiring.BundleWiring;
+import org.osgi.framework.wiring.FrameworkWiring;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.event.Event;
 import org.osgi.service.event.EventConstants;
@@ -379,10 +380,15 @@
             	}
             	wabStates.put(bundle.getSymbolicName(), "");
             	bundle.stop();
-            	if (bundle instanceof BundleHost) {
-            		BundleClassLoader loader = (BundleClassLoader)((BundleHost) bundle).getClassLoader(); 
-            		loader.close();
-            	}
+            	BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
+            	// TODO filter fragment?
+            	// TODO add type check before cast?
+            	ModuleClassLoader loader = (ModuleClassLoader) bundleWiring.getClassLoader();
+            	loader.close();
+//            	if (bundle instanceof BundleHost) {
+//            		BundleClassLoader loader = (BundleClassLoader)((BundleHost) bundle).getClassLoader(); 
+//            		loader.close();
+//            	}
                 // Extract the war file to the webapps directory. Use always JarUtils.unpackToDestructive.
                 try {
                     JarUtils.unpackToDestructive(new PathReference(updatedFile), new PathReference(warDir));
@@ -398,8 +404,13 @@
                 transformUnpackedManifest(warDir, warName);
                 this.eventLogger.log(WARDeployerLogEvents.NANO_UPDATING, bundle.getSymbolicName(), bundle.getVersion());
                 bundle.update();
-                if (this.packageAdmin != null) {
-                    ((PackageAdminImpl)this.packageAdmin).refreshPackages(new Bundle[] { bundle }, true, null);
+                FrameworkWiring frameworkWiring = bundle.adapt(FrameworkWiring.class);
+                // TODO is this sanity check necessary ?!
+//                if (this.packageAdmin != null) {
+//                    ((PackageAdminImpl)this.packageAdmin).refreshPackages(new Bundle[] { bundle }, true, null);
+//                }
+                if (frameworkWiring != null) {
+                    frameworkWiring.refreshBundles(Collections.singletonList(bundle));
                     this.logger.info("Update of file with path [" + path + "] is successful.");
                 }
                 bundle.start();