change Service.create to take ServiceConfig arg

This commit is contained in:
Doug MacEachern 2005-06-26 02:53:54 +00:00
parent 7e3f7cce07
commit 72e7b88512
2 changed files with 27 additions and 43 deletions

View File

@ -119,55 +119,37 @@ public class Service extends Win32 {
} }
} }
public static Service create(String serviceName, public static Service create(ServiceConfig config)
String displayName,
String description,
String path)
throws Win32Exception throws Win32Exception
{ {
return create(serviceName, displayName, description, if (config.getName() == null) {
ServiceConfig.TYPE_WIN32_OWN_PROCESS, throw new IllegalArgumentException("name=null");
ServiceConfig.START_AUTO,
ServiceConfig.ERROR_NORMAL,
path, null, null, "");
}
public static Service create(String serviceName, String displayName,
String description, int serviceType,
int startType, int errorControl,
String path, String[] dependencies,
String startName, String password)
throws Win32Exception
{
if (serviceName == null) {
throw new IllegalArgumentException("serviceName=null");
} }
if (path == null) { if (config.getPath() == null) {
throw new IllegalArgumentException("path=null"); throw new IllegalArgumentException("path=null");
} }
if (displayName == null) {
displayName = serviceName;
}
Service service = new Service(); Service service = new Service();
service.service = CreateService(service.manager, service.service =
serviceName, CreateService(service.manager,
displayName, config.getName(),
serviceType, config.getDisplayName(),
startType, config.getType(),
errorControl, config.getStartType(),
path, config.getErrorControl(),
dependencies, config.getPath(),
startName, config.getDependencies(),
password); config.getServiceStartName(),
config.getPassword());
if (service.service == 0) { if (service.service == 0) {
throw getLastErrorException(); throw getLastErrorException();
} }
service.setDescription(description); if (config.getDescription() != null) {
service.setDescription(config.getDescription());
}
return service; return service;
} }

View File

@ -2,6 +2,7 @@ package net.hyperic.sigar.win32.test;
import junit.framework.TestCase; import junit.framework.TestCase;
import net.hyperic.sigar.win32.Service; import net.hyperic.sigar.win32.Service;
import net.hyperic.sigar.win32.ServiceConfig;
public class TestService extends TestCase { public class TestService extends TestCase {
@ -20,11 +21,12 @@ public class TestService extends TestCase {
if (!TEST_CREATE) { if (!TEST_CREATE) {
return; return;
} }
Service service = ServiceConfig config = new ServiceConfig("MyTestService");
Service.create("MyTestService", config.setDisplayName("My Test Service");
"My Test Service", config.setDescription("A Description of " + config.getDisplayName());
"This is a great service.", config.setPath("C:\\Program Files\\My Test 1.0\\mytest.exe");
"C:\\oracle\\ora90\\bin\\agntsrvc.exe");
Service.create(config);
} }
public void testDeleteService() throws Exception { public void testDeleteService() throws Exception {