1 23 24 package com.sun.enterprise.cli.commands; 25 26 import com.sun.enterprise.cli.framework.CommandValidationException; 27 import com.sun.enterprise.cli.framework.CommandException; 28 import com.sun.enterprise.cli.framework.CLILogger; 29 import com.sun.enterprise.admin.pluggable.ClientPluggableFeatureFactory; 30 import com.sun.enterprise.admin.servermgmt.DomainsManager; 31 import com.sun.enterprise.admin.servermgmt.DomainConfig; 32 import com.sun.enterprise.admin.servermgmt.InstancesManager; 33 import com.sun.enterprise.admin.common.Status; 34 35 39 public class StopDomainCommand extends BaseLifeCycleCommand { 40 41 48 public boolean validateOptions() throws CommandValidationException { 49 return super.validateOptions(); 50 } 51 52 public void stopDomain (String domainName) throws CommandException, CommandValidationException 53 { 54 try { 55 final ClientPluggableFeatureFactory fac = getFeatureFactory(); 56 final DomainsManager mgr = fac.getDomainsManager(); 57 final DomainConfig cfg = getDomainConfig(domainName); 58 final InstancesManager im = mgr.getInstancesManager(cfg); 59 final int state = im.getInstanceStatus(); 60 final String [] domains = mgr.listDomains(cfg); 61 boolean exists = false; 62 63 for(int i = 0; domains != null && i < domains.length; i++) 64 { 65 if(domains[i].equals(domainName)) 66 { 67 exists = true; 68 break; 69 } 70 } 71 72 if(!exists) 73 { 74 mgr.stopDomain(cfg); 77 } 78 79 else if (state == Status.kInstanceRunningCode) 81 { 82 mgr.stopDomain(cfg); 83 84 CLILogger.getInstance().printDetailMessage(getLocalizedString("DomainStopped", 85 new Object [] {domainName})); 86 } 87 else 88 { 89 93 throw new CommandException(getLocalizedString("CannotStopDomainAlreadyStopped", 94 new Object [] {domainName})); 95 } 96 } 97 catch(Exception e) { 98 CLILogger.getInstance().printDetailMessage(e.getLocalizedMessage()); 99 throw new CommandException(getLocalizedString("CannotStopDomain", 100 new Object [] {domainName} ), e); 101 } 102 } 103 108 public void runCommand() throws CommandException, CommandValidationException { 109 validateOptions(); 110 String domainName = null; 111 try { 112 domainName = getDomainName(); 113 } catch(Exception e) { 114 CLILogger.getInstance().printDetailMessage(e.getLocalizedMessage()); 115 domainName = domainName==null?getLocalizedString("Undefined"):domainName; 116 throw new CommandException(getLocalizedString("CannotStopDomain", 117 new Object [] {domainName} ), e); 118 } 119 stopDomain(domainName); 120 } 121 } 122 | Popular Tags |