1 19 20 package org.netbeans.modules.web.project; 21 22 import java.util.ArrayList ; 23 import java.util.Collections ; 24 import java.util.List ; 25 import java.util.Set ; 26 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 27 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 28 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; 29 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 30 import org.netbeans.modules.j2ee.persistence.provider.Provider; 31 import org.netbeans.modules.j2ee.persistence.provider.ProviderUtil; 32 import org.netbeans.modules.j2ee.persistence.spi.provider.PersistenceProviderSupplier; 33 34 39 public class WebPersistenceProviderSupplier implements PersistenceProviderSupplier{ 40 41 private final WebProject project; 42 43 44 public WebPersistenceProviderSupplier(WebProject project) { 45 this.project = project; 46 } 47 48 public List <Provider> getSupportedProviders() { 49 J2eeModuleProvider j2eeModuleProvider = (J2eeModuleProvider) project.getLookup().lookup(J2eeModuleProvider.class); 53 J2eePlatform platform = Deployment.getDefault().getJ2eePlatform(j2eeModuleProvider.getServerInstanceID()); 54 55 if (platform == null){ 56 return Collections.<Provider>emptyList(); 57 } 58 List <Provider> result = new ArrayList <Provider>(); 59 60 addPersistenceProvider(ProviderUtil.HIBERNATE_PROVIDER, "hibernatePersistenceProviderIsDefault", platform, result); addPersistenceProvider(ProviderUtil.TOPLINK_PROVIDER, "toplinkPersistenceProviderIsDefault", platform, result); addPersistenceProvider(ProviderUtil.KODO_PROVIDER, "kodoPersistenceProviderIsDefault", platform, result); 64 return result; 65 } 66 67 private void addPersistenceProvider(Provider provider, String defaultProvider, J2eePlatform platform, List <Provider> providers){ 68 if (platform.isToolSupported(provider.getProviderClass())){ 70 if (platform.isToolSupported(defaultProvider)){ 71 providers.add(0, provider); 72 } else { 73 providers.add(provider); 74 } 75 } 76 } 77 78 public boolean supportsDefaultProvider() { 79 80 J2eeModuleProvider j2eeModuleProvider = (J2eeModuleProvider) project.getLookup().lookup(J2eeModuleProvider.class); 81 J2eePlatform platform = Deployment.getDefault().getJ2eePlatform(j2eeModuleProvider.getServerInstanceID()); 82 83 if (platform == null){ 84 return false; 86 } 87 88 Set <String > supportedVersions = platform.getSupportedSpecVersions(j2eeModuleProvider.getJ2eeModule().getModuleType()); 89 90 return supportedVersions.contains(J2eeModule.JAVA_EE_5); 91 } 92 93 94 } 95 | Popular Tags |