@Test public void testGetPersistenceProvidersPositive() throws Exception { prepareServicesFile(new String[] {"org.eclipse.virgo.web.enterprise.javax.persistence.extension.TestPersistenceProvider"}); DefaultPersistenceProviderResolver resolver = new DefaultPersistenceProviderResolver(); List<PersistenceProvider> persistenceProviders = resolver.getPersistenceProviders(); Assert.assertEquals("Found Persistence Providers are not the correct number", 1, persistenceProviders.size()); Assert.assertEquals("Provider not Test Persistence Provider", persistenceProviders.get(0).getClass(), TestPersistenceProvider.class); }
@Override public List<PersistenceProvider> getPersistenceProviders() { ClassLoader loader = getContextClassLoader(); List<PersistenceProvider> loadedProviders = this.providers.get(loader); if (loadedProviders == null) { Collection<ProviderName> providerNames = getProviderNames(loader); loadedProviders = new ArrayList<PersistenceProvider>(); for (ProviderName providerName : providerNames) { try { PersistenceProvider provider = (PersistenceProvider) loader.loadClass(providerName.getName()).newInstance(); loadedProviders.add(provider); } catch (ClassNotFoundException cnfe) { log(Level.FINEST, cnfe + ": " + providerName); } catch (InstantiationException ie) { log(Level.FINEST, ie + ": " + providerName); } catch (IllegalAccessException iae) { log(Level.FINEST, iae + ": " + providerName); } catch (ClassCastException cce) { log(Level.FINEST, cce + ": " + providerName); } } if (loadedProviders.isEmpty() && !providerNames.isEmpty()) { log(Level.WARNING, "No valid providers found using:"); for (ProviderName name : providerNames) { log(Level.WARNING, name.toString()); } } this.providers.put(loader, loadedProviders); } return loadedProviders; }
DefaultPersistenceProviderResolver implements PersistenceProviderResolver { @Override public List<PersistenceProvider> getPersistenceProviders() { ClassLoader loader = getContextClassLoader(); List<PersistenceProvider> loadedProviders = this.providers.get(loader); if (loadedProviders == null) { Collection<ProviderName> providerNames = getProviderNames(loader); loadedProviders = new ArrayList<PersistenceProvider>(); for (ProviderName providerName : providerNames) { try { PersistenceProvider provider = (PersistenceProvider) loader.loadClass(providerName.getName()).newInstance(); loadedProviders.add(provider); } catch (ClassNotFoundException cnfe) { log(Level.FINEST, cnfe + ": " + providerName); } catch (InstantiationException ie) { log(Level.FINEST, ie + ": " + providerName); } catch (IllegalAccessException iae) { log(Level.FINEST, iae + ": " + providerName); } catch (ClassCastException cce) { log(Level.FINEST, cce + ": " + providerName); } } if (loadedProviders.isEmpty() && !providerNames.isEmpty()) { log(Level.WARNING, "No valid providers found using:"); for (ProviderName name : providerNames) { log(Level.WARNING, name.toString()); } } this.providers.put(loader, loadedProviders); } return loadedProviders; } }
DefaultPersistenceProviderResolver implements PersistenceProviderResolver { @Override public List<PersistenceProvider> getPersistenceProviders() { ClassLoader loader = getContextClassLoader(); List<PersistenceProvider> loadedProviders = this.providers.get(loader); if (loadedProviders == null) { Collection<ProviderName> providerNames = getProviderNames(loader); loadedProviders = new ArrayList<PersistenceProvider>(); for (ProviderName providerName : providerNames) { try { PersistenceProvider provider = (PersistenceProvider) loader.loadClass(providerName.getName()).newInstance(); loadedProviders.add(provider); } catch (ClassNotFoundException cnfe) { log(Level.FINEST, cnfe + ": " + providerName); } catch (InstantiationException ie) { log(Level.FINEST, ie + ": " + providerName); } catch (IllegalAccessException iae) { log(Level.FINEST, iae + ": " + providerName); } catch (ClassCastException cce) { log(Level.FINEST, cce + ": " + providerName); } } if (loadedProviders.isEmpty() && !providerNames.isEmpty()) { log(Level.WARNING, "No valid providers found using:"); for (ProviderName name : providerNames) { log(Level.WARNING, name.toString()); } } this.providers.put(loader, loadedProviders); } return loadedProviders; }  }
DefaultPersistenceProviderResolver implements PersistenceProviderResolver { @Override public List<PersistenceProvider> getPersistenceProviders() { ClassLoader loader = getContextClassLoader(); List<PersistenceProvider> loadedProviders = this.providers.get(loader); if (loadedProviders == null) { Collection<ProviderName> providerNames = getProviderNames(loader); loadedProviders = new ArrayList<PersistenceProvider>(); for (ProviderName providerName : providerNames) { try { PersistenceProvider provider = (PersistenceProvider) loader.loadClass(providerName.getName()).newInstance(); loadedProviders.add(provider); } catch (ClassNotFoundException cnfe) { log(Level.FINEST, cnfe + ": " + providerName); } catch (InstantiationException ie) { log(Level.FINEST, ie + ": " + providerName); } catch (IllegalAccessException iae) { log(Level.FINEST, iae + ": " + providerName); } catch (ClassCastException cce) { log(Level.FINEST, cce + ": " + providerName); } } if (loadedProviders.isEmpty() && !providerNames.isEmpty()) { log(Level.WARNING, "No valid providers found using:"); for (ProviderName name : providerNames) { log(Level.WARNING, name.toString()); } } this.providers.put(loader, loadedProviders); } return loadedProviders; }  @Override List<PersistenceProvider> getPersistenceProviders(); @Override void clearCachedProviders(); }
DefaultPersistenceProviderResolver implements PersistenceProviderResolver { @Override public List<PersistenceProvider> getPersistenceProviders() { ClassLoader loader = getContextClassLoader(); List<PersistenceProvider> loadedProviders = this.providers.get(loader); if (loadedProviders == null) { Collection<ProviderName> providerNames = getProviderNames(loader); loadedProviders = new ArrayList<PersistenceProvider>(); for (ProviderName providerName : providerNames) { try { PersistenceProvider provider = (PersistenceProvider) loader.loadClass(providerName.getName()).newInstance(); loadedProviders.add(provider); } catch (ClassNotFoundException cnfe) { log(Level.FINEST, cnfe + ": " + providerName); } catch (InstantiationException ie) { log(Level.FINEST, ie + ": " + providerName); } catch (IllegalAccessException iae) { log(Level.FINEST, iae + ": " + providerName); } catch (ClassCastException cce) { log(Level.FINEST, cce + ": " + providerName); } } if (loadedProviders.isEmpty() && !providerNames.isEmpty()) { log(Level.WARNING, "No valid providers found using:"); for (ProviderName name : providerNames) { log(Level.WARNING, name.toString()); } } this.providers.put(loader, loadedProviders); } return loadedProviders; }  @Override List<PersistenceProvider> getPersistenceProviders(); @Override void clearCachedProviders();  }