Interface ResourceConfigSortComparator

  • All Superinterfaces:
    Comparator<ResourceConfig>
    All Known Implementing Classes:
    DefaultResourceConfigSortComparator

    public interface ResourceConfigSortComparator
    extends Comparator<ResourceConfig>
    Sort Comparator for ResourceConfig Objects based on their "specificity".

    Before reading this be sure to read the ResourceConfig 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.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