1 17 18 19 20 package org.apache.lenya.cms.task; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import java.util.Map ; 25 26 import org.apache.avalon.framework.parameters.Parameters; 27 import org.apache.lenya.util.NamespaceMap; 28 import org.apache.log4j.Category; 29 30 public abstract class ParameterWrapper { 31 32 private static Category log = Category.getInstance(ParameterWrapper.class); 33 private NamespaceMap parameters; 34 35 39 public Map getMap() { 40 return parameters.getMap(); 41 } 42 43 47 public ParameterWrapper(Map prefixedParameters) { 48 parameters = new NamespaceMap(prefixedParameters, getPrefix()); 49 } 50 51 55 public abstract String getPrefix(); 56 57 62 public void put(String key, String value) { 63 if (value != null) { 64 log.debug("Setting parameter: [" + key + "] = [" + value + "]"); 65 parameters.put(key, value); 66 } 67 else { 68 log.debug("Not setting parameter: [" + key + "] = [" + value + "]"); 69 } 70 } 71 72 77 public String get(String key) { 78 return (String ) parameters.get(key); 79 } 80 81 85 protected abstract String [] getRequiredKeys(); 86 87 91 public boolean isComplete() { 92 boolean complete = true; 93 Map parameterMap = getMap(); 94 String [] requiredKeys = getRequiredKeys(); 95 int i = 0; 96 while (complete && i < requiredKeys.length) { 97 log.debug("Checking parameter: [" + requiredKeys[i] + "]"); 98 complete = complete && parameterMap.containsKey(requiredKeys[i]); 99 log.debug("OK: [" + complete + "]"); 100 i++; 101 } 102 return complete; 103 } 104 105 109 public String [] getMissingKeys() { 110 String [] requiredKeys = getRequiredKeys(); 111 Map parameterMap = getMap(); 112 List keyList = new ArrayList (); 113 for (int i = 0; i < requiredKeys.length; i++) { 114 if (!parameterMap.containsKey(requiredKeys[i])) { 115 keyList.add(requiredKeys[i]); 116 } 117 } 118 return (String []) keyList.toArray(new String [keyList.size()]); 119 } 120 121 125 public void parameterize(Parameters parameters) { 126 String [] keys = parameters.getNames(); 127 for (int i = 0; i < keys.length; i++) { 128 put(keys[i], parameters.getParameter(keys[i], null)); 129 } 130 } 131 132 } 133 | Popular Tags |