diff -r 2ec36469c044 glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/Hk2OptionalFactory.java --- a/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/Hk2OptionalFactory.java Thu Jul 24 11:04:01 2008 -0700 +++ b/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/Hk2OptionalFactory.java Thu Jul 24 17:17:51 2008 -0700 @@ -50,6 +50,7 @@ import org.netbeans.modules.glassfish.javaee.db.Hk2DatasourceManager; import org.netbeans.modules.glassfish.javaee.ide.FastDeploy; import org.netbeans.modules.glassfish.spi.ServerUtilities; +import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceCreationException; import org.netbeans.modules.j2ee.deployment.plugins.spi.AntDeploymentProvider; import org.netbeans.modules.j2ee.deployment.plugins.spi.DatasourceManager; import org.netbeans.modules.j2ee.deployment.plugins.spi.FindJSPServlet; @@ -61,6 +62,7 @@ import org.openide.WizardDescriptor.InstantiatingIterator; import org.openide.WizardDescriptor.Panel; import org.openide.util.Lookup; +import org.openide.util.NbPreferences; /** @@ -212,4 +214,14 @@ } } + + @Override + public boolean registerDefaultInstance() throws InstanceCreationException { + final boolean needToRegisterDefaultServer = + !NbPreferences.forModule(this.getClass()).getBoolean(ServerUtilities.PROP_FIRST_RUN, false); + if (needToRegisterDefaultServer) { + ServerUtilities.getServerProvider(); + } + return needToRegisterDefaultServer; + } } diff -r 2ec36469c044 j2eeserver/apichanges.xml --- a/j2eeserver/apichanges.xml Thu Jul 24 11:04:01 2008 -0700 +++ b/j2eeserver/apichanges.xml Thu Jul 24 17:17:51 2008 -0700 @@ -106,11 +106,53 @@ J2EE Server Common API J2EE Server Common API + + Server Integration Plugin SPI Support + + + + Provide a way for a plugin to register a "default instance" + without deep knowledge of the serverRegistry implementation. + + + + + + +

+ OptionalDeploymentManagerFactory gets a new stub, that plugin + implementations would override. The Plugin author can assume + that the ServerRegistry is initialized to the point where it + can support the creation on instances. +

+
+ + +
+ + + + LookupProvider support for J2eePlatform lookup. + + + + + + +

+ Server plugins will use this static method in J2eePlatformImpl.getLookup() + method to enable registration of additional Lookup Providers in layer.xml files. +

+
+ + + +
diff -r 2ec36469c044 j2eeserver/nbproject/project.properties --- a/j2eeserver/nbproject/project.properties Thu Jul 24 11:04:01 2008 -0700 +++ b/j2eeserver/nbproject/project.properties Thu Jul 24 17:17:51 2008 -0700 @@ -39,7 +39,7 @@ is.autoload=true javac.source=1.5 -spec.version.base=1.49.0 +spec.version.base=1.51.0 javadoc.overview=${basedir}/api/doc/overview.html javadoc.arch=${basedir}/arch.xml diff -r 2ec36469c044 j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java --- a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java Thu Jul 24 11:04:01 2008 -0700 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java Thu Jul 24 17:17:51 2008 -0700 @@ -66,6 +66,7 @@ import java.util.Set; import java.util.logging.Level; import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener; +import org.netbeans.modules.j2ee.deployment.plugins.spi.OptionalDeploymentManagerFactory; import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler; import org.openide.filesystems.FileAttributeEvent; import org.openide.filesystems.FileChangeListener; @@ -105,7 +106,7 @@ public synchronized static boolean wasInitialized () { return instance != null && instance.servers != null && instance.instances != null; } - private transient Map servers = null; + private transient Map servers = null; private transient Map instances = null; private transient Collection pluginListeners = new HashSet(); private transient Collection instanceListeners = new ArrayList(); @@ -134,6 +135,24 @@ for (int i = 0; i < ch.length; i++) { addPlugin(ch[i]); } + LOGGER.log(Level.FINE, "Initializing default instances"); // NOI18N + for (String s : serversMap().keySet()) { + Server server = serversMap().get(s); + OptionalDeploymentManagerFactory odmf = server.getOptionalFactory(); + if (null != odmf) { + try { + if (odmf.registerDefaultInstance()) { + LOGGER.log(Level.FINE, "Registered default instance for "+server.getDisplayName()); // NOI18N + } else { + LOGGER.log(Level.FINE, "Default instance already registered for "+server.getDisplayName()); // NOI18N + } + } catch (InstanceCreationException ice) { + LOGGER.log(Level.WARNING, + server.getDisplayName() + " did not initialize its default instance.", // NOI18N + ice); + } + } + } LOGGER.log(Level.FINE, "Loading server instances"); // NOI18N dir = rep.getDefaultFileSystem().findResource(DIR_INSTALLED_SERVERS); dir.addFileChangeListener(new InstanceInstallListener()); @@ -146,7 +165,7 @@ } } - private Map serversMap() { + private Map serversMap() { init(); return servers; } diff -r 2ec36469c044 j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/OptionalDeploymentManagerFactory.java --- a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/OptionalDeploymentManagerFactory.java Thu Jul 24 11:04:01 2008 -0700 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/OptionalDeploymentManagerFactory.java Thu Jul 24 17:17:51 2008 -0700 @@ -43,6 +43,7 @@ package org.netbeans.modules.j2ee.deployment.plugins.spi; import javax.enterprise.deploy.spi.DeploymentManager; +import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceCreationException; import org.openide.WizardDescriptor; /** @@ -167,4 +168,17 @@ return null; } + /** + * Allows a plugin to insert an initial "instance" in the server registry, + * after the registry has completed initialization. + * + * @return false if the default instance was already registered. + * @thows InstanceCreationException if there was an actual failure to create + * a default instance. + * @since 1.51 + */ + public boolean registerDefaultInstance() throws InstanceCreationException { + return false; + } + } diff -r 2ec36469c044 j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistryTest.java --- a/j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistryTest.java Thu Jul 24 11:04:01 2008 -0700 +++ b/j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistryTest.java Thu Jul 24 17:17:51 2008 -0700 @@ -118,4 +118,34 @@ } } + public void testOptionalfactoryImpl() { + ServerRegistry registry = ServerRegistry.getInstance(); + System.out.println ("registry:" + registry); + Server testPlugin = registry.getServer("Test"); + if (testPlugin == null || ! testPlugin.getShortName().equals("Test")) + fail("Could not get testPlugin: "+testPlugin); + + + OptionalDeploymentManagerFactory optionalFactory = testPlugin.getOptionalFactory(); + boolean firstCall; + boolean firstCallFailed = false; + try { + firstCall = optionalFactory.registerDefaultInstance(); + } catch (InstanceCreationException ice) { + firstCallFailed = true; + } + boolean secondCall = false; + try { + secondCall = optionalFactory.registerDefaultInstance(); + if (firstCallFailed) + fail("a second call to registerDefaultInstance should fail if the first call also failed and the factory has not been modified"); + } catch (InstanceCreationException ice) { + if (!firstCallFailed) + fail("a second call to registerDefaultInstance should return false... not throw an exception"); + } + + if (secondCall) + fail("second call registered a default instance"); + } + }