1 29 30 package nextapp.echo2.app.update; 31 32 import java.io.Serializable ; 33 import java.util.HashMap ; 34 import java.util.Iterator ; 35 import java.util.Map ; 36 37 import nextapp.echo2.app.ApplicationInstance; 38 import nextapp.echo2.app.Component; 39 40 46 public class ClientUpdateManager 47 implements Serializable { 48 49 private Map clientComponentUpdateMap = new HashMap (); 50 private Map applicationUpdateMap = new HashMap (); 51 private Component actionComponent; 52 private String actionName; 53 private Object actionValue; 54 private ApplicationInstance applicationInstance; 55 56 61 ClientUpdateManager(ApplicationInstance applicationInstance) { 62 this.applicationInstance = applicationInstance; 63 } 64 65 73 ClientComponentUpdate getComponentUpdate(Component component) { 74 return (ClientComponentUpdate) clientComponentUpdateMap.get(component); 75 } 76 77 84 Object getApplicationUpdatePropertyValue(String propertyName) { 85 return applicationUpdateMap.get(propertyName); 86 } 87 88 94 void process() { 95 Iterator applicationUpdateIt = applicationUpdateMap.keySet().iterator(); 97 while (applicationUpdateIt.hasNext()) { 98 String propertyName = (String ) applicationUpdateIt.next(); 99 Object propertyValue = applicationUpdateMap.get(propertyName); 100 applicationInstance.processInput(propertyName, propertyValue); 101 } 102 103 Iterator componentUpdateIt = clientComponentUpdateMap.values().iterator(); 105 while (componentUpdateIt.hasNext()) { 106 ClientComponentUpdate update = (ClientComponentUpdate) componentUpdateIt.next(); 107 Iterator inputNameIt = update.getInputNames(); 108 while (inputNameIt.hasNext()) { 109 String inputName = (String ) inputNameIt.next(); 110 update.getComponent().processInput(inputName, update.getInputValue(inputName)); 111 } 112 } 113 114 if (actionComponent != null) { 116 actionComponent.processInput(actionName, actionValue); 117 } 118 } 119 120 123 void purge() { 124 clientComponentUpdateMap.clear(); 125 applicationUpdateMap.clear(); 126 actionComponent = null; 127 actionName = null; 128 actionValue = null; 129 } 130 131 137 public void setApplicationProperty(String propertyName, Object propertyValue) { 138 applicationUpdateMap.put(propertyName, propertyValue); 139 } 140 141 151 public void setComponentAction(Component actionComponent, String actionName, Object actionValue) { 152 if (!actionComponent.verifyInput(actionName, actionValue)) { 153 return; 155 } 156 157 this.actionComponent = actionComponent; 158 this.actionName = actionName; 159 this.actionValue = actionValue; 160 } 161 162 169 public void setComponentProperty(Component component, String inputName, Object inputValue) { 170 if (!component.verifyInput(inputName, inputValue)) { 171 return; 173 } 174 175 ClientComponentUpdate clientUpdate = (ClientComponentUpdate) clientComponentUpdateMap.get(component); 176 if (clientUpdate == null) { 177 clientUpdate = new ClientComponentUpdate(component); 178 clientComponentUpdateMap.put(component, clientUpdate); 179 } 180 clientUpdate.addInput(inputName, inputValue); 181 } 182 183 } 184 | Popular Tags |