1 23 24 package com.sun.enterprise.cli.commands; 25 26 import java.util.Iterator ; 27 import java.util.Vector ; 28 import com.sun.enterprise.cli.framework.*; 29 30 31 35 public class UnsetCommand extends S1ASCommand 36 { 37 38 private final static String ENVIRONMENT_PREFIX = "AS_ADMIN_"; 39 private final static String ENVIRONMENT_DELIMITER = "="; 40 41 private CommandEnvironment commandEnvironment = CommandEnvironment.getInstance(); 42 43 44 public UnsetCommand() 45 { 46 } 47 48 52 public boolean validateOptions() throws CommandValidationException 53 { 54 return super.validateOptions(); 55 } 56 57 61 public void runCommand() throws CommandException, CommandValidationException 62 { 63 validateOptions(); 64 65 for (int ii = 0; ii < operands.size(); ii++) 66 { 67 updateEnvironment((String )operands.elementAt(ii)); 68 } 69 } 70 71 72 76 private String checkForPrefix(String name) throws CommandException 77 { 78 String envName = null; 79 if (name.regionMatches(true, 0, ENVIRONMENT_PREFIX, 0, 81 ENVIRONMENT_PREFIX.length())) 82 { 83 envName = name.substring(ENVIRONMENT_PREFIX.length()); 85 } 86 else 87 { 88 throw new CommandException(getLocalizedString("CouldNotUnsetVariable", 89 new Object [] {name})); 90 } 91 return envName.toLowerCase(); 92 } 93 94 95 101 private void updateEnvironment(String nameStr) 102 throws CommandException 103 { 104 final String envName = checkForPrefix(nameStr); 105 if (envName.equals("*")) 106 { 107 removeAllEnvironments(); 108 } 109 else 110 { 111 if (commandEnvironment.removeEnvironment(envName) == null) 112 throw new CommandException(getLocalizedString("UnableToRemoveEnv", 113 new Object [] {nameStr})); 114 } 115 } 116 117 118 122 private void removeAllEnvironments() 123 { 124 final java.util.HashMap envMap = new 125 java.util.HashMap (commandEnvironment.getEnvironments()); 126 final java.util.Iterator envIter = envMap.keySet().iterator(); 127 128 while (envIter.hasNext()) 129 { 130 final String envName = (String )envIter.next(); 131 if (commandEnvironment.removeEnvironment(envName) == null) 132 CLILogger.getInstance().printWarning(getLocalizedString( 133 "UnableToRemoveEnv", 134 new Object [] {envName})); 135 } 136 } 137 138 } 139 | Popular Tags |