org.milyn.cdr
Class SmooksResourceConfigurationSortComparator
java.lang.Object
org.milyn.cdr.SmooksResourceConfigurationSortComparator
- All Implemented Interfaces:
- Comparator
public class SmooksResourceConfigurationSortComparator
- extends Object
- implements Comparator
Sort Comparator for SmooksResourceConfiguration Objects based on their "specificity".
Before reading this be sure to read the SmooksResourceConfiguration class Javadoc.
As Smooks applies ContentHandlers (DOMElementVisitors and
SerializationUnits) it may discover that in a given case more than 1 ContentHandler
can be applied. How does Smooks decide on the order in which these ContentHandlers are to be applied to the content?
At the moment, Smooks uses this class to calculate a "specificity" rating for each Content Delivery Resource based on its
<smooks-resource> configuration, and sorts them in decreasing order of specificity.
The following outlines how this specificity value is calculated at present.
// Get the combined specificity of all the profile targeting expressions.
ProfileTargetingExpression[] profileTargetingExpressions = resourceConfig.getProfileTargetingExpressions();
for(int i = 0; i < profileTargetingExpressions.length; i++) {
specificity += profileTargetingExpressions[i].getSpecificity(profileSet);
}
// Check the 'selector' attribute value.
if(resourceConfig.isXmlDef()) {
specificity += 10;
} else if(resourceConfig.getselector().equals("*")) {
specificity += 5;
} else {
// Explicit selector listed
specificity += 100;
// If the selector is contextual it's, therefore more specific so
// account for that. Subtract 1 because that "1" is already accounted
// for by the addition of 100 - it's the extra we're accounting for here...
if(resourceConfig.isSelectorContextual()) {
int contextSpecificity = resourceConfig.getContextualSelector().length;
specificity += (10 * (contextSpecificity - 1));
}
}
// Check the 'namespace' attribute.
if(resourceConfig.getSelectorNamespaceURI() != null) {
specificity += 10;
}
For more details on this please refer to the code in this class.
- Author:
- tfennelly
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SmooksResourceConfigurationSortComparator
public SmooksResourceConfigurationSortComparator(ProfileSet profileSet)
- Private constructor.
- Parameters:
profileSet - Profile set used to evaluate specificity.
compare
public int compare(Object configObj1,
Object configObj2)
- Specified by:
compare in interface Comparator
getSpecificity
protected double getSpecificity(SmooksResourceConfiguration resourceConfig)
- Get the specificity of the SmooksResourceConfiguration.
The "specificity" is evaluated based on the selector and target-profile values.
- Parameters:
resourceConfig - Resource configuration.
- Returns:
- Configuration specificity.
Copyright © 2008. All Rights Reserved.