? src/org/netbeans/modules/j2ee/deployment/devmodules/spi/InstanceListener.java Index: apichanges.xml =================================================================== RCS file: /cvs/j2eeserver/apichanges.xml,v retrieving revision 1.9 diff -u -r1.9 apichanges.xml --- apichanges.xml 21 Jan 2005 19:07:32 -0000 1.9 +++ apichanges.xml 25 Jan 2005 08:21:55 -0000 @@ -80,6 +80,26 @@ + + + Added InstanceListener. Added Deployment.getServerInstancesIDs methods for getting server instances based on some requirements. + + + + + +

+ Added InstanceListener that will allow listening to server instance changes (addition, + removal, etc.). Methods for InstanceListener registration were added to J2eeModuleProvider. + To the Deployment class were added getServerInstanceIDs methods for listing + registered server instances based on some requirements - supported module types, J2EE specification + versions and tools. +

+
+ + + +
StartServer.needsRestart tells j2eeserver a state of the server Index: src/org/netbeans/modules/j2ee/deployment/devmodules/api/Deployment.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/Deployment.java,v retrieving revision 1.17 diff -u -r1.17 Deployment.java --- src/org/netbeans/modules/j2ee/deployment/devmodules/api/Deployment.java 20 Jan 2005 15:18:34 -0000 1.17 +++ src/org/netbeans/modules/j2ee/deployment/devmodules/api/Deployment.java 25 Jan 2005 08:21:55 -0000 @@ -15,9 +15,12 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.List; import java.util.Map; +import java.util.Set; import java.util.WeakHashMap; import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; import org.netbeans.modules.j2ee.deployment.impl.*; @@ -167,6 +170,87 @@ public String [] getServerInstanceIDs () { return InstanceProperties.getInstanceList (); + } + + /** + * Return ServerInstanceIDs of all registered server instances that support + * specified module types. + * + * @param moduleTypes list of module types that the server instance must support. + * + * @return ServerInstanceIDs of all registered server instances that meet + * the specified requirements. + * @since 1.6 + */ + public String[] getServerInstanceIDs(Object[] moduleTypes) { + return getServerInstanceIDs(moduleTypes, null, null); + } + + /** + * Return ServerInstanceIDs of all registered server instances that support + * specified module types and J2EE specification versions. + * + * @param moduleTypes list of module types that the server instance must support. + * @param specVersions list of J2EE specification versions that the server instance + * must support. + * + * @return ServerInstanceIDs of all registered server instances that meet + * the specified requirements. + * @since 1.6 + */ + public String[] getServerInstanceIDs(Object[] moduleTypes, String[] specVersions) { + return getServerInstanceIDs(moduleTypes, specVersions, null); + } + + /** + * Return ServerInstanceIDs of all registered server instances that support + * specified module types, J2EE specification versions and tools. + * + * @param moduleTypes list of module types that the server instance must support. + * @param specVersions list of J2EE specification versions that the server instance + * must support. + * @param tools list of tools that the server instance must support. + * + * @return ServerInstanceIDs of all registered server instances that meet + * the specified requirements. + * @since 1.6 + */ + public String[] getServerInstanceIDs(Object[] moduleTypes, String[] specVersions, String[] tools) { + List result = new ArrayList(); + String[] serverInstanceIDs = getServerInstanceIDs(); + for (int i = 0; i < serverInstanceIDs.length; i++) { + J2eePlatform platform = getJ2eePlatform(serverInstanceIDs[i]); + if (platform != null) { + boolean isOk = true; + if (moduleTypes != null) { + Set platModuleTypes = platform.getSupportedModuleTypes(); + for (int j = 0; j < moduleTypes.length; j++) { + if (!platModuleTypes.contains(moduleTypes[j])) { + isOk = false; + } + } + } + if (isOk && specVersions != null) { + Set platSpecVers = platform.getSupportedSpecVersions(); + for (int j = 0; j < specVersions.length; j++) { + if (!platSpecVers.contains(specVersions[j])) { + isOk = false; + } + } + } + if (isOk && tools != null) { + for (int j = 0; j < tools.length; j++) { + if (!platform.isToolSupported(tools[j])) { + isOk = false; + } + } + } + if (isOk) { + result.add(serverInstanceIDs[i]); + } + } + } + return (String[])result.toArray(new String[result.size()]); } public String getServerInstanceDisplayName (String id) { Index: src/org/netbeans/modules/j2ee/deployment/devmodules/spi/J2eeModuleProvider.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/spi/J2eeModuleProvider.java,v retrieving revision 1.40 diff -u -r1.40 J2eeModuleProvider.java --- src/org/netbeans/modules/j2ee/deployment/devmodules/spi/J2eeModuleProvider.java 21 Jan 2005 19:10:24 -0000 1.40 +++ src/org/netbeans/modules/j2ee/deployment/devmodules/spi/J2eeModuleProvider.java 25 Jan 2005 08:21:55 -0000 @@ -58,7 +58,7 @@ */ public abstract class J2eeModuleProvider { - private ServerRegistry.InstanceListener il; + private InstanceListener il; private ConfigSupportImpl confSupp; List listeners = new ArrayList(); private ConfigFilesListener configFilesListener = null; @@ -67,8 +67,8 @@ public J2eeModuleProvider () { il = new IL (); ServerRegistry.getInstance ().addInstanceListener ( - (ServerRegistry.InstanceListener) WeakListeners.create( - ServerRegistry.InstanceListener.class, il, ServerRegistry.getInstance ())); + (InstanceListener) WeakListeners.create( + InstanceListener.class, il, ServerRegistry.getInstance ())); } public abstract J2eeModule getJ2eeModule (); @@ -323,6 +323,28 @@ listeners.remove(l); } + /** + * Register an instance listener that will listen to server instances changes. + * + * @l listener which should be added. + * + * @since 1.6 + */ + public final void addInstanceListener(InstanceListener l) { + ServerRegistry.getInstance ().addInstanceListener(l); + } + + /** + * Remove an instance listener which has been registered previously. + * + * @l listener which should be removed. + * + * @since 1.6 + */ + public final void removeInstanceListener(InstanceListener l) { + ServerRegistry.getInstance ().removeInstanceListener(l); + } + private void addCFL() { //already listen if (configFilesListener != null) @@ -330,9 +352,11 @@ configFilesListener = new ConfigFilesListener(this, listeners); } - private final class IL implements ServerRegistry.InstanceListener { + private final class IL implements InstanceListener { - public void changeDefaultInstance (ServerString oldInstance, ServerString newInstance) { + public void changeDefaultInstance (String oldInst, String newInst) { + ServerString oldInstance = new ServerString(ServerRegistry.getInstance().getServerInstance(oldInst)); + ServerString newInstance = new ServerString(ServerRegistry.getInstance().getServerInstance(newInst)); if (useDefaultServer () && oldInstance == null || ((newInstance != null) && (oldInstance.getPlugin() != newInstance.getPlugin()))) { if (J2eeModule.WAR.equals(getJ2eeModule().getModuleType())) { String oldCtxPath = getConfigSupportImpl().getWebContextRoot(); @@ -349,10 +373,10 @@ } } - public void instanceAdded (org.netbeans.modules.j2ee.deployment.impl.ServerString instance) { + public void instanceAdded (String instance) { } - public void instanceRemoved (org.netbeans.modules.j2ee.deployment.impl.ServerString instance) { + public void instanceRemoved (String instance) { } } Index: src/org/netbeans/modules/j2ee/deployment/impl/InstancePropertiesImpl.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/InstancePropertiesImpl.java,v retrieving revision 1.7 diff -u -r1.7 InstancePropertiesImpl.java --- src/org/netbeans/modules/j2ee/deployment/impl/InstancePropertiesImpl.java 23 Aug 2004 13:16:42 -0000 1.7 +++ src/org/netbeans/modules/j2ee/deployment/impl/InstancePropertiesImpl.java 25 Jan 2005 08:21:55 -0000 @@ -21,16 +21,16 @@ package org.netbeans.modules.j2ee.deployment.impl; import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; -import org.netbeans.modules.j2ee.deployment.impl.ServerInstance; import org.openide.filesystems.FileObject; import org.openide.util.NbBundle; import java.beans.PropertyChangeEvent; +import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener; /** * * @author nn136682 */ -public class InstancePropertiesImpl extends InstanceProperties implements ServerRegistry.InstanceListener { +public class InstancePropertiesImpl extends InstanceProperties implements InstanceListener { private final String url; private transient FileObject fo; @@ -59,13 +59,13 @@ return fo; } - // ServerRegistry.InstanceListener methods - public void instanceRemoved(ServerString instance) { - if (instance != null && url.equals(instance.getUrl())) + // InstanceListener methods + public void instanceRemoved(String instance) { + if (instance != null && url.equals(instance)) fo = null; } - public void instanceAdded(ServerString instance) {} - public void changeDefaultInstance(ServerString oldInstance, ServerString newInstance){ + public void instanceAdded(String instance) {} + public void changeDefaultInstance(String oldInstance, String newInstance){ } public String getProperty(String propname) throws IllegalStateException { Index: src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java,v retrieving revision 1.36 diff -u -r1.36 ServerRegistry.java --- src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java 15 Dec 2004 21:43:16 -0000 1.36 +++ src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java 25 Jan 2005 08:21:56 -0000 @@ -24,6 +24,8 @@ import java.util.*; import java.io.*; +import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; +import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener; import org.openide.modules.InstalledFileLocator; //import java.util.logging.*; @@ -213,12 +215,12 @@ ServerInstance instance = (ServerInstance) instancesMap().remove(url); if (instance != null) { - ServerString ss = new ServerString(instance); - fireInstanceListeners(ss, false); - removeInstanceFromFile(instance.getUrl()); + fireInstanceListeners(url, false); + removeInstanceFromFile(url); } ServerString newinst = getDefaultInstance(false); - fireDefaultInstance(def, newinst); + fireDefaultInstance(def != null ? def.getUrl() : null, + newinst != null ? newinst.getUrl() : null); } public ServerInstance[] getServerInstances() { @@ -321,7 +323,7 @@ writeInstanceToFile(url,username,password); if (displayName != null) instance.getInstanceProperties().setProperty( InstanceProperties.DISPLAY_NAME_ATTR, displayName); - fireInstanceListeners(str,true); + fireInstanceListeners(url, true); return true; } } @@ -371,7 +373,7 @@ configNamesByType = null; } - private void fireInstanceListeners(ServerString instance, boolean add) { + private void fireInstanceListeners(String instance, boolean add) { for(Iterator i = instanceListeners.iterator();i.hasNext();) { InstanceListener pl = (InstanceListener)i.next(); if(add) pl.instanceAdded(instance); @@ -379,7 +381,7 @@ } } - private void fireDefaultInstance(ServerString oldInstance, ServerString newInstance) { + private void fireDefaultInstance(String oldInstance, String newInstance) { for(Iterator i = instanceListeners.iterator();i.hasNext();) { InstanceListener pl = (InstanceListener)i.next(); pl.changeDefaultInstance(oldInstance, newInstance); @@ -395,12 +397,13 @@ removeDefaultInstanceFile(); ServerString oldValue = defaultInstance; defaultInstance = null; - fireDefaultInstance(oldValue, null); + fireDefaultInstance(oldValue != null ? oldValue.getUrl() : null, null); } else { if (ServerStringConverter.writeServerInstance(instance, DIR_INSTALLED_SERVERS, FILE_DEFAULT_INSTANCE)) { ServerString oldValue = defaultInstance; defaultInstance = instance; - fireDefaultInstance(oldValue, instance); + fireDefaultInstance(oldValue != null ? oldValue.getUrl() : null, + instance != null ? instance.getUrl() : null); } } } @@ -503,16 +506,6 @@ public void serverAdded(Server name); public void serverRemoved(Server name); - - } - - public interface InstanceListener extends EventListener { - - public void instanceAdded(ServerString instance); - - public void instanceRemoved(ServerString instance); - - public void changeDefaultInstance(ServerString oldInstance, ServerString newInstance); } Index: src/org/netbeans/modules/j2ee/deployment/impl/ui/ServerRegistryNode.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ui/ServerRegistryNode.java,v retrieving revision 1.19 diff -u -r1.19 ServerRegistryNode.java --- src/org/netbeans/modules/j2ee/deployment/impl/ui/ServerRegistryNode.java 15 Jan 2005 12:53:16 -0000 1.19 +++ src/org/netbeans/modules/j2ee/deployment/impl/ui/ServerRegistryNode.java 25 Jan 2005 08:21:56 -0000 @@ -29,6 +29,7 @@ import org.netbeans.modules.j2ee.deployment.impl.ui.actions.*; import org.netbeans.modules.j2ee.deployment.impl.*; import java.util.*; +import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener; /** * The server registry node is a node representing the registry in global options. @@ -37,7 +38,7 @@ */ public class ServerRegistryNode extends AbstractNode -implements ServerRegistry.PluginListener, ServerRegistry.InstanceListener { +implements ServerRegistry.PluginListener, InstanceListener { static final String REGISTRY_ICON_BASE = "org/netbeans/modules/j2ee/deployment/impl/ui/resources/ServerRegistry";//NOI18N @@ -72,14 +73,14 @@ serverNodes.clear(); } - public void instanceAdded(ServerString instance) { + public void instanceAdded(String instance) { updateKeys(); } - public void instanceRemoved(ServerString instance) { + public void instanceRemoved(String instance) { updateKeys(); } - public void changeDefaultInstance(ServerString oldInstance, ServerString instance) { - setDisplayNameWithDefaultServer(instance == null ? null : instance.getServerInstance()); + public void changeDefaultInstance(String oldInstance, String newInstance) { + setDisplayNameWithDefaultServer(newInstance == null ? null : ServerRegistry.getInstance().getServerInstance(newInstance)); } private void updateKeys() {