1 16 package org.springframework.webflow.engine; 17 18 import org.springframework.core.style.ToStringCreator; 19 import org.springframework.util.Assert; 20 import org.springframework.util.StringUtils; 21 import org.springframework.webflow.core.collection.AttributeMap; 22 import org.springframework.webflow.execution.Action; 23 import org.springframework.webflow.execution.Event; 24 import org.springframework.webflow.execution.RequestContext; 25 26 39 public class AnnotatedAction extends AnnotatedObject implements Action { 40 41 43 51 public static final String NAME_ATTRIBUTE = "name"; 52 53 61 public static final String METHOD_ATTRIBUTE = "method"; 62 63 66 private Action targetAction; 67 68 73 public AnnotatedAction(Action targetAction) { 74 setTargetAction(targetAction); 75 } 76 77 81 public Action getTargetAction() { 82 return targetAction; 83 } 84 85 88 public void setTargetAction(Action targetAction) { 89 Assert.notNull(targetAction, "The targetAction to annotate is required"); 90 this.targetAction = targetAction; 91 } 92 93 99 public String getName() { 100 return getAttributeMap().getString(NAME_ATTRIBUTE); 101 } 102 103 108 public void setName(String name) { 109 getAttributeMap().put(NAME_ATTRIBUTE, name); 110 } 111 112 117 public boolean isNamed() { 118 return StringUtils.hasText(getName()); 119 } 120 121 125 public String getMethod() { 126 return getAttributeMap().getString(METHOD_ATTRIBUTE); 127 } 128 129 134 public void setMethod(String method) { 135 getAttributeMap().put(METHOD_ATTRIBUTE, method); 136 } 137 138 public Event execute(RequestContext context) throws Exception { 139 AttributeMap originalAttributes = getAttributeMap(); 140 try { 141 context.setAttributes(getAttributeMap()); 142 Event result = getTargetAction().execute(context); 143 return postProcessResult(result); 144 } 145 finally { 146 context.setAttributes(originalAttributes); 148 } 149 } 150 151 159 protected Event postProcessResult(Event resultEvent) { 160 if (resultEvent == null) { 161 return null; 162 } 163 if (isNamed()) { 164 String qualifiedId = getName() + "." + resultEvent.getId(); 166 resultEvent = new Event(resultEvent.getSource(), qualifiedId, resultEvent.getAttributes()); 167 } 168 return resultEvent; 169 } 170 171 public String toString() { 172 return new ToStringCreator(this).append("targetAction", getTargetAction()) 173 .append("attributes", getAttributeMap()).toString(); 174 } 175 } | Popular Tags |