KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > engine > builder > DefaultFlowServiceLocator


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.springframework.webflow.engine.builder;
17
18 import org.springframework.beans.factory.BeanFactory;
19 import org.springframework.util.Assert;
20 import org.springframework.webflow.definition.registry.FlowDefinitionRegistry;
21 import org.springframework.webflow.definition.registry.NoSuchFlowDefinitionException;
22 import org.springframework.webflow.engine.Flow;
23
24 /**
25  * The default flow service locator implementation that obtains subflow
26  * definitions from a dedicated {@link FlowDefinitionRegistry} and obtains the
27  * remaining services from a generic Spring {@link BeanFactory}.
28  *
29  * @see FlowDefinitionRegistry
30  * @see FlowServiceLocator#getSubflow(String)
31  * @see BeanFactory
32  *
33  * @author Keith Donald
34  */

35 public class DefaultFlowServiceLocator extends BaseFlowServiceLocator {
36
37     /**
38      * The registry for locating subflows.
39      */

40     private FlowDefinitionRegistry subflowRegistry;
41
42     /**
43      * The Spring bean factory used.
44      */

45     private BeanFactory beanFactory;
46
47     /**
48      * Creates a flow service locator that retrieves subflows from the provided
49      * registry and additional artifacts from the provided bean factory.
50      * @param subflowRegistry The registry for loading subflows
51      * @param beanFactory The spring bean factory
52      */

53     public DefaultFlowServiceLocator(FlowDefinitionRegistry subflowRegistry, BeanFactory beanFactory) {
54         Assert.notNull(subflowRegistry, "The subflow registry is required");
55         Assert.notNull(beanFactory, "The beanFactory is required");
56         this.subflowRegistry = subflowRegistry;
57         this.beanFactory = beanFactory;
58     }
59
60     public Flow getSubflow(String JavaDoc id) throws FlowArtifactLookupException {
61         try {
62             return (Flow)subflowRegistry.getFlowDefinition(id);
63         }
64         catch (NoSuchFlowDefinitionException e) {
65             throw new FlowArtifactLookupException(id, Flow.class,
66                     "Could not locate subflow definition with id '" + id + "'", e);
67         }
68     }
69
70     public BeanFactory getBeanFactory() {
71         return beanFactory;
72     }
73
74     /**
75      * Returns the flow definition registry used to lookup subflows.
76      * @return the flow definition registry
77      */

78     protected FlowDefinitionRegistry getSubflowRegistry() {
79         return subflowRegistry;
80     }
81 }
Popular Tags