Detect changes in parent flow definitions

Issue: SWF-1662
This commit is contained in:
Rossen Stoyanchev
2015-06-04 22:04:19 -04:00
parent 3438a65378
commit 61291fbdab
3 changed files with 74 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2004-2012 the original author or authors.
* Copyright 2004-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package org.springframework.webflow.engine.model.builder.xml;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
@@ -52,6 +53,8 @@ import org.springframework.webflow.engine.model.VarModel;
import org.springframework.webflow.engine.model.ViewStateModel;
import org.springframework.webflow.engine.model.builder.FlowModelBuilder;
import org.springframework.webflow.engine.model.builder.FlowModelBuilderException;
import org.springframework.webflow.engine.model.registry.FlowModelHolder;
import org.springframework.webflow.engine.model.registry.FlowModelHolderLocator;
import org.springframework.webflow.engine.model.registry.FlowModelLocator;
import org.springframework.webflow.engine.model.registry.NoSuchFlowModelException;
import org.w3c.dom.Document;
@@ -63,6 +66,7 @@ import org.xml.sax.SAXException;
*
* @author Keith Donald
* @author Scott Andrews
* @author Rossen Stoyanchev
*/
public class XmlFlowModelBuilder implements FlowModelBuilder {
@@ -78,6 +82,8 @@ public class XmlFlowModelBuilder implements FlowModelBuilder {
private FlowModel flowModel;
private final List<FlowModelHolder> parentHolders = new ArrayList<FlowModelHolder>(4);
/**
* Create a new XML flow model builder that will parse the XML document at the specified resource location and use
* the provided locator to access parent flow models.
@@ -157,6 +163,11 @@ public class XmlFlowModelBuilder implements FlowModelBuilder {
if (lastModified > lastModifiedTimestamp) {
return true;
} else {
for (FlowModelHolder parent : this.parentHolders) {
if (parent.hasFlowModelChanged()) {
return true;
}
}
return false;
}
} catch (IOException e) {
@@ -635,6 +646,14 @@ public class XmlFlowModelBuilder implements FlowModelBuilder {
throw new FlowModelBuilderException("Unable to find flow '" + parentFlowId
+ "' to inherit from", e);
}
try {
if (this.modelLocator instanceof FlowModelHolderLocator) {
FlowModelHolderLocator locator = (FlowModelHolderLocator) this.modelLocator;
this.parentHolders.add(locator.getFlowModelHolder(parentFlowId));
}
} catch (NoSuchFlowModelException e) {
// Ignore
}
}
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2004-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.webflow.engine.model.registry;
/**
* A companion to {@link FlowModelLocator} for access to the FlowModelHolder
* wrapping the FlowModel.
*
* @author Rossen Stoyanchev
* @since 2.4.2
*/
public interface FlowModelHolderLocator {
/**
* Lookup the FlowModelHolder with the specified id.
* @param id the flow model identifier
* @return the flow model holder
* @throws NoSuchFlowModelException when the flow model with the specified
* id does not exist
*/
public FlowModelHolder getFlowModelHolder(String id) throws NoSuchFlowModelException;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2004-2012 the original author or authors.
* Copyright 2004-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,8 +27,9 @@ import org.springframework.webflow.engine.model.FlowModel;
*
* @author Keith Donald
* @author Scott Andrews
* @author Rossen Stoyanchev
*/
public class FlowModelRegistryImpl implements FlowModelRegistry {
public class FlowModelRegistryImpl implements FlowModelRegistry, FlowModelHolderLocator {
/**
* The map of loaded Flow models maintained in this registry.
@@ -48,7 +49,7 @@ public class FlowModelRegistryImpl implements FlowModelRegistry {
public FlowModel getFlowModel(String id) throws NoSuchFlowModelException {
try {
return getFlowModelHolder(id).getFlowModel();
return getLocalFlowModelHolder(id).getFlowModel();
} catch (NoSuchFlowModelException e) {
if (parent != null) {
// try parent
@@ -69,12 +70,25 @@ public class FlowModelRegistryImpl implements FlowModelRegistry {
flowModels.put(id, modelHolder);
}
// implementing FlowModelHolderLocator
public FlowModelHolder getFlowModelHolder(String id) throws NoSuchFlowModelException {
try {
return getLocalFlowModelHolder(id);
} catch (NoSuchFlowModelException e) {
if (parent != null && parent instanceof FlowModelHolderLocator) {
return ((FlowModelHolderLocator) parent).getFlowModelHolder(id);
}
throw e;
}
}
// internal helpers
/**
* Returns the identified flow model holder. Throws an exception if it cannot be found.
*/
private FlowModelHolder getFlowModelHolder(String id) throws NoSuchFlowModelException {
private FlowModelHolder getLocalFlowModelHolder(String id) throws NoSuchFlowModelException {
FlowModelHolder holder = flowModels.get(id);
if (holder == null) {
throw new NoSuchFlowModelException(id);