1 16 package org.springframework.webflow.engine.builder.xml; 17 18 import java.util.Stack ; 19 20 import org.springframework.beans.BeansException; 21 import org.springframework.beans.factory.BeanFactory; 22 import org.springframework.binding.convert.ConversionService; 23 import org.springframework.binding.expression.ExpressionParser; 24 import org.springframework.core.io.ResourceLoader; 25 import org.springframework.webflow.action.BeanInvokingActionFactory; 26 import org.springframework.webflow.engine.Flow; 27 import org.springframework.webflow.engine.FlowAttributeMapper; 28 import org.springframework.webflow.engine.FlowExecutionExceptionHandler; 29 import org.springframework.webflow.engine.TargetStateResolver; 30 import org.springframework.webflow.engine.TransitionCriteria; 31 import org.springframework.webflow.engine.ViewSelector; 32 import org.springframework.webflow.engine.builder.FlowArtifactFactory; 33 import org.springframework.webflow.engine.builder.FlowArtifactLookupException; 34 import org.springframework.webflow.engine.builder.FlowServiceLocator; 35 import org.springframework.webflow.execution.Action; 36 37 48 class LocalFlowServiceLocator implements FlowServiceLocator { 49 50 53 private Stack localRegistries = new Stack (); 54 55 58 private FlowServiceLocator parent; 59 60 64 public LocalFlowServiceLocator(FlowServiceLocator parent) { 65 this.parent = parent; 66 } 67 68 72 public void push(LocalFlowServiceRegistry registry) { 73 registry.init(this, parent); 74 localRegistries.push(registry); 75 } 76 77 80 public LocalFlowServiceRegistry pop() { 81 return (LocalFlowServiceRegistry)localRegistries.pop(); 82 } 83 84 87 public void diposeOfAnyRegistries() { 88 while (!localRegistries.isEmpty()) { 89 pop(); 90 } 91 } 92 93 96 public LocalFlowServiceRegistry top() { 97 return (LocalFlowServiceRegistry)localRegistries.peek(); 98 } 99 100 103 public boolean isEmpty() { 104 return localRegistries.isEmpty(); 105 } 106 107 109 public Flow getSubflow(String id) throws FlowArtifactLookupException { 110 Flow currentFlow = getCurrentFlow(); 111 if (currentFlow.getId().equals(id)) { 113 return currentFlow; 114 } 115 if (currentFlow.containsInlineFlow(id)) { 117 return currentFlow.getInlineFlow(id); 118 } 119 return parent.getSubflow(id); 121 } 122 123 public Action getAction(String id) throws FlowArtifactLookupException { 124 if (containsBean(id)) { 125 return (Action)getBean(id, Action.class); 126 } 127 else { 128 return parent.getAction(id); 129 } 130 } 131 132 public FlowAttributeMapper getAttributeMapper(String id) throws FlowArtifactLookupException { 133 if (containsBean(id)) { 134 return (FlowAttributeMapper)getBean(id, FlowAttributeMapper.class); 135 } 136 else { 137 return parent.getAttributeMapper(id); 138 } 139 } 140 141 public TransitionCriteria getTransitionCriteria(String id) throws FlowArtifactLookupException { 142 if (containsBean(id)) { 143 return (TransitionCriteria)getBean(id, TransitionCriteria.class); 144 } 145 else { 146 return parent.getTransitionCriteria(id); 147 } 148 } 149 150 public TargetStateResolver getTargetStateResolver(String id) throws FlowArtifactLookupException { 151 if (containsBean(id)) { 152 return (TargetStateResolver)getBean(id, TargetStateResolver.class); 153 } 154 else { 155 return parent.getTargetStateResolver(id); 156 } 157 } 158 159 public ViewSelector getViewSelector(String id) throws FlowArtifactLookupException { 160 if (containsBean(id)) { 161 return (ViewSelector)getBean(id, ViewSelector.class); 162 } 163 else { 164 return parent.getViewSelector(id); 165 } 166 } 167 168 public FlowExecutionExceptionHandler getExceptionHandler(String id) throws FlowArtifactLookupException { 169 if (containsBean(id)) { 170 return (FlowExecutionExceptionHandler)getBean(id, FlowExecutionExceptionHandler.class); 171 } 172 else { 173 return parent.getExceptionHandler(id); 174 } 175 } 176 177 public FlowArtifactFactory getFlowArtifactFactory() { 178 return parent.getFlowArtifactFactory(); 179 } 180 181 public BeanInvokingActionFactory getBeanInvokingActionFactory() { 182 return parent.getBeanInvokingActionFactory(); 183 } 184 185 public BeanFactory getBeanFactory() { 186 return top().getContext(); 187 } 188 189 public ResourceLoader getResourceLoader() { 190 return parent.getResourceLoader(); 191 } 192 193 public ExpressionParser getExpressionParser() { 194 return parent.getExpressionParser(); 195 } 196 197 public ConversionService getConversionService() { 198 return parent.getConversionService(); 199 } 200 201 203 206 protected Flow getCurrentFlow() { 207 return top().getFlow(); 208 } 209 210 214 protected boolean containsBean(String id) { 215 if (localRegistries.isEmpty()) { 216 return false; 217 } 218 else { 219 return getBeanFactory().containsBean(id); 220 } 221 } 222 223 226 protected Object getBean(String id, Class artifactType) throws FlowArtifactLookupException { 227 try { 228 return getBeanFactory().getBean(id, artifactType); 229 } 230 catch (BeansException e) { 231 throw new FlowArtifactLookupException(id, artifactType, e); 232 } 233 } 234 } | Popular Tags |