diff -r df2fd46b18ec j2eeserver/apichanges.xml --- a/j2eeserver/apichanges.xml Mon May 19 17:03:51 2008 +0200 +++ b/j2eeserver/apichanges.xml Wed May 21 12:51:06 2008 +0200 @@ -111,6 +111,27 @@ is the proper place. + + + + There should be server instance representation in the API. + + + + + + +

+ API server instance in the API with clear indication that + instance was removed should be used in favor of Deployment + facade. +

+
+ + + + +
diff -r df2fd46b18ec j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/Deployment.java --- a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/Deployment.java Mon May 19 17:03:51 2008 +0200 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/Deployment.java Wed May 21 12:51:06 2008 +0200 @@ -294,11 +294,32 @@ public final class Deployment { } return (String[])result.toArray(new String[result.size()]); } - + + /** + * Returns the display name of the instance identified by the given id. + * + * @param id id of the instance + * @return the display name of the instance, null if the + * instance does not exist or not defined + * @deprecated use getServerInstance(serverInstanceID).getDisplayName() + */ public String getServerInstanceDisplayName (String id) { - return ServerRegistry.getInstance ().getServerInstance (id).getDisplayName (); + ServerInstance si = ServerRegistry.getInstance().getServerInstance(id); + if (si != null) { + return si.getDisplayName(); + } + return null; } - + + /** + * Returns the id of the server to which the instance represented + * by the id belongs to. + * + * @param instanceId id of the instance + * @return the id of the server, null if the + * instance does not exist + * @deprecated use getServerInstance(serverInstanceID).getServerID() + */ public String getServerID (String instanceId) { ServerInstance si = ServerRegistry.getInstance().getServerInstance(instanceId); if (si != null) { @@ -360,7 +381,19 @@ public final class Deployment { } return new String[0]; } - + + /** + * Returns the server instance allowing client to query its properties + * and/or status. + * + * @param serverInstanceId id of the server instance + * @return server instance + * @since 1.45 + */ + public org.netbeans.modules.j2ee.deployment.devmodules.api.ServerInstance getServerInstance(String serverInstanceId) { + return new org.netbeans.modules.j2ee.deployment.devmodules.api.ServerInstance(serverInstanceId); + } + public String [] getServerIDs () { Collection c = ServerRegistry.getInstance ().getServers (); String ids [] = new String [c.size ()]; @@ -379,6 +412,7 @@ public final class Deployment { * @return J2eePlatform for the given server instance, null if * server instance of the specified ID does not exist. * @since 1.5 + * @deprecated use getServerInstance(serverInstanceID).getJ2eePlatform() */ public J2eePlatform getJ2eePlatform(String serverInstanceID) { ServerInstance serInst = ServerRegistry.getInstance().getServerInstance(serverInstanceID); @@ -386,6 +420,16 @@ public final class Deployment { return J2eePlatform.create(serInst); } + /** + * Returns the display name of the server with given id. + *

+ * Client is usually searching for the display name of the server for particular + * instance. For this use getServerInstance(serverInstanceID).getServerDisplyName(). + * + * @param id id of the server + * @return the display name of the server with given id, null + * if the server does not exist + */ public String getServerDisplayName(String id) { Server server = ServerRegistry.getInstance ().getServer(id); if (server == null) { // probably uninstalled @@ -409,6 +453,7 @@ public final class Deployment { * @throws NullPointerException if serverInstanceID is null. * * @since 1.32 + * @deprecated use getServerInstance(serverInstanceID).isRunning() */ public boolean isRunning(String serverInstanceID) { Parameters.notNull("serverInstanceID", serverInstanceID); // NOI18N diff -r df2fd46b18ec j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/InstanceRemovedException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/InstanceRemovedException.java Wed May 21 12:51:06 2008 +0200 @@ -0,0 +1,61 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.j2ee.deployment.devmodules.api; + +/** + * Thrown when the instance of the server does not exist anymore. + * + * @author Petr Hejl + */ +public class InstanceRemovedException extends Exception { + + public InstanceRemovedException(Throwable cause) { + super(cause); + } + + public InstanceRemovedException(String message, Throwable cause) { + super(message, cause); + } + + public InstanceRemovedException(String message) { + super(message); + } + +} diff -r df2fd46b18ec j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/ServerInstance.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/ServerInstance.java Wed May 21 12:51:06 2008 +0200 @@ -0,0 +1,150 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.j2ee.deployment.devmodules.api; + +import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry; + +/** + * The class allowing the client to query the instance identified by + * the instance ID. Because corresponding instance can be removed anytime + * each method can throw {@link InstanceRemovedException}. + * + * @author Petr Hejl + * @since 1.45 + */ +public final class ServerInstance { + + /* + * There is bit wider synchronization on ServerRegistry in following + * methods. This is because even getters on instance implementation + * are backed by other objects that can disappear asynchronously. + * To avoid this we are doing this synchronization (remove is using registry). + */ + + private final String serverInstanceId; + + ServerInstance(String serverInstanceId) { + this.serverInstanceId = serverInstanceId; + } + + /** + * Returns the display name of this instance. + * + * @return the display name of this instance + * @throws InstanceRemovedException if the instance is not available anymore + */ + public String getDisplayName() throws InstanceRemovedException { + final ServerRegistry registry = ServerRegistry.getInstance(); + // see comment at the beginning of the class + synchronized (registry) { + org.netbeans.modules.j2ee.deployment.impl.ServerInstance inst = + getInstanceFromRegistry(registry); + return inst.getDisplayName(); + } + } + + /** + * Returns the display name of the server. + * + * @return the display name of the server + * @throws InstanceRemovedException if the instance is not available anymore + */ + public String getServerDisplayName() throws InstanceRemovedException { + final ServerRegistry registry = ServerRegistry.getInstance(); + // see comment at the beginning of the class + synchronized (registry) { + org.netbeans.modules.j2ee.deployment.impl.ServerInstance inst = getInstanceFromRegistry(registry); + return inst.getServer().getDisplayName(); + } + } + + /** + * Returns the ID of the server associated with this instance. + * + * @return the ID of the server associated with this instance + * @throws InstanceRemovedException if the instance is not available anymore + */ + public String getServerID() throws InstanceRemovedException { + final ServerRegistry registry = ServerRegistry.getInstance(); + // see comment at the beginning of the class + synchronized (registry) { + org.netbeans.modules.j2ee.deployment.impl.ServerInstance inst = getInstanceFromRegistry(registry); + return inst.getServer().getShortName(); + } + } + + /** + * Returns true if this instance is running, false + * otherwise. + * + * @return true if this instance is running, false + * otherwise + * @throws InstanceRemovedException if the instance is not available anymore + */ + public boolean isRunning() throws InstanceRemovedException { + final org.netbeans.modules.j2ee.deployment.impl.ServerInstance inst = + getInstanceFromRegistry(ServerRegistry.getInstance()); + + return (inst.isReallyRunning() || inst.isSuspended()); + } + + /** + * Returns the platform for this instance. + * + * @return the platform for this instance + * @throws InstanceRemovedException if the instance is not available anymore + */ + public J2eePlatform getJ2eePlatform() throws InstanceRemovedException { + return J2eePlatform.create(getInstanceFromRegistry(ServerRegistry.getInstance())); + } + + private org.netbeans.modules.j2ee.deployment.impl.ServerInstance getInstanceFromRegistry(ServerRegistry registry) + throws InstanceRemovedException { + + synchronized (registry) { + org.netbeans.modules.j2ee.deployment.impl.ServerInstance inst = + registry.getServerInstance(serverInstanceId); + if (inst == null) { + throw new InstanceRemovedException(serverInstanceId); + } + return inst; + } + } +} diff -r df2fd46b18ec j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/projects/DeploymentTargetImpl.java --- a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/projects/DeploymentTargetImpl.java Mon May 19 17:03:51 2008 +0200 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/projects/DeploymentTargetImpl.java Wed May 21 12:51:06 2008 +0200 @@ -42,18 +42,17 @@ package org.netbeans.modules.j2ee.deploy package org.netbeans.modules.j2ee.deployment.impl.projects; import org.netbeans.modules.j2ee.deployment.execution.*; -import org.netbeans.modules.j2ee.deployment.plugins.api.*; import org.netbeans.modules.j2ee.deployment.impl.*; import org.netbeans.modules.j2ee.deployment.devmodules.spi.*; import org.netbeans.modules.j2ee.deployment.devmodules.api.*; import javax.enterprise.deploy.spi.TargetModuleID; import javax.enterprise.deploy.shared.ModuleType; import org.openide.filesystems.FileUtil; -import java.util.*; import java.io.*; import java.util.logging.Level; import java.util.logging.Logger; import org.netbeans.modules.j2ee.deployment.config.*; +import org.netbeans.modules.j2ee.deployment.impl.ServerInstance; import org.netbeans.modules.j2ee.deployment.plugins.spi.IncrementalDeployment; import org.openide.util.NbBundle; diff -r df2fd46b18ec j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/devmodules/spi/DeploymentTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/devmodules/spi/DeploymentTest.java Wed May 21 12:51:06 2008 +0200 @@ -0,0 +1,103 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.j2ee.deployment.devmodules.spi; + +import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; +import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry; +import org.netbeans.modules.j2ee.deployment.impl.ServerRegistryTestBase; + +/** + * + * @author Petr Hejl + */ +public class DeploymentTest extends ServerRegistryTestBase { + + private static final String URL = "fooservice:testInstance"; // NOI18N + + public DeploymentTest(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + ServerRegistry registry = ServerRegistry.getInstance(); + registry.addInstance(URL, "user", "password", "TestInstance", true, null); // NOI18N + } + + @Override + protected void tearDown() throws Exception { + ServerRegistry registry = ServerRegistry.getInstance(); + registry.removeServerInstance(URL); + super.tearDown(); + } + + public void testGetDisplayName() { + assertEquals("TestInstance", Deployment.getDefault().getServerInstanceDisplayName(URL)); + ServerRegistry.getInstance().removeServerInstance(URL); + assertNull(Deployment.getDefault().getServerInstanceDisplayName(URL)); + } + + public void testGetServerID() { + Deployment deployment = Deployment.getDefault(); + assertEquals("Test", deployment.getServerID(URL)); + ServerRegistry.getInstance().removeServerInstance(URL); + assertNull(deployment.getServerID(URL)); + } + + public void testIsRunning() { + // TODO missing test for running state + assertFalse(Deployment.getDefault().isRunning(URL)); + ServerRegistry.getInstance().removeServerInstance(URL); + assertFalse(Deployment.getDefault().isRunning(URL)); + } + + public void testGetJ2eePlatform() { + assertNotNull(Deployment.getDefault().getJ2eePlatform(URL)); + ServerRegistry.getInstance().removeServerInstance(URL); + assertNull(Deployment.getDefault().getJ2eePlatform(URL)); + } + + public void testGetServerDisplayName() { + assertEquals("Sample JSR88 plugin", Deployment.getDefault().getServerDisplayName("Test")); + ServerRegistry.getInstance().removeServerInstance(URL); + assertEquals("Sample JSR88 plugin", Deployment.getDefault().getServerDisplayName("Test")); + } +} diff -r df2fd46b18ec j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/devmodules/spi/ServerInstanceTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/devmodules/spi/ServerInstanceTest.java Wed May 21 12:51:06 2008 +0200 @@ -0,0 +1,133 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.j2ee.deployment.devmodules.spi; + +import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; +import org.netbeans.modules.j2ee.deployment.devmodules.api.InstanceRemovedException; +import org.netbeans.modules.j2ee.deployment.devmodules.api.ServerInstance; +import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry; +import org.netbeans.modules.j2ee.deployment.impl.ServerRegistryTestBase; + +/** + * + * @author Petr Hejl + */ +public class ServerInstanceTest extends ServerRegistryTestBase { + + private static final String URL = "fooservice:testInstance"; // NOI18N + + public ServerInstanceTest(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + ServerRegistry registry = ServerRegistry.getInstance(); + registry.addInstance(URL, "user", "password", "TestInstance", true, null); // NOI18N + } + + @Override + protected void tearDown() throws Exception { + ServerRegistry registry = ServerRegistry.getInstance(); + registry.removeServerInstance(URL); + super.tearDown(); + } + + public void testGetDisplayName() throws InstanceRemovedException { + ServerInstance instance = Deployment.getDefault().getServerInstance(URL); + assertEquals("TestInstance", instance.getDisplayName()); + ServerRegistry.getInstance().removeServerInstance(URL); + try { + instance.getDisplayName(); + fail("Does not throw InstanceRemovedException"); + } catch (InstanceRemovedException ex) { + // expected + } + } + + public void testGetServerDisplayName() throws InstanceRemovedException { + ServerInstance instance = Deployment.getDefault().getServerInstance(URL); + assertEquals("Sample JSR88 plugin", instance.getServerDisplayName()); + ServerRegistry.getInstance().removeServerInstance(URL); + try { + instance.getServerDisplayName(); + fail("Does not throw InstanceRemovedException"); + } catch (InstanceRemovedException ex) { + // expected + } + } + + public void testGetServerID() throws InstanceRemovedException { + ServerInstance instance = Deployment.getDefault().getServerInstance(URL); + assertEquals("Test", instance.getServerID()); + ServerRegistry.getInstance().removeServerInstance(URL); + try { + instance.getServerID(); + fail("Does not throw InstanceRemovedException"); + } catch (InstanceRemovedException ex) { + // expected + } + } + + public void testIsRunning() throws InstanceRemovedException { + ServerInstance instance = Deployment.getDefault().getServerInstance(URL); + assertFalse(instance.isRunning()); + ServerRegistry.getInstance().removeServerInstance(URL); + try { + instance.isRunning(); + fail("Does not throw InstanceRemovedException"); + } catch (InstanceRemovedException ex) { + // expected + } + } + + public void testGetJ2eePlatform() throws InstanceRemovedException { + ServerInstance instance = Deployment.getDefault().getServerInstance(URL); + assertNotNull(instance.getJ2eePlatform()); + ServerRegistry.getInstance().removeServerInstance(URL); + try { + instance.getJ2eePlatform(); + fail("Does not throw InstanceRemovedException"); + } catch (InstanceRemovedException ex) { + // expected + } + } +}