Top Description Inners Fields Constructors Methods
com.sun.faces.config.manager.documents

public Class DocumentOrderingWrapper

extends Object
Class Inheritance
Imports
java.text.MessageFormat, java.util.ArrayList, .Arrays, .Collections, .Comparator, .HashMap, .HashSet, .LinkedHashMap, .LinkedList, .List, .Map, .Set, java.util.concurrent.CopyOnWriteArrayList, java.util.logging.Level, .Logger, org.w3c.dom.Element, .Node, .NodeList, com.sun.faces.config.ConfigurationException, com.sun.faces.util.FacesLogger, .Timer

This class is used by the config system to order faces-config documents found on the classpath or configured explicitly via the javax.faces.CONFIG_FILES context init parameter.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static final String
AFTER

Constant for the after element.

private String[]
afterIds

The wrapped Document's before IDs.

private static final String
BEFORE

Constant for the before element.

private String[]
beforeIds

The wrapped Document's before IDs.

private static Comparator<DocumentOrderingWrapper>
COMPARATOR

Comparator implementation to aid in sorting faces-config documents.

private static final int
DO_NOT_SWAP

Return code indicating that no swap needs to occur for the elements being compared.

private DocumentInfo
documentInfo

The wrapped Document.

private String
id

The wrapped Document's ID.

private static final Logger
LOGGER

Logger for this class.

private static final int
MAX_SORT_PASSED

This is the limit on the number of attempts made to sort the documents.

private static final String
NAME

Constant for the name element.

private static final String
ORDERING

Constant for the ordering element.

private static final String
OTHERS

Constant for the others element.

private static final String
OTHERS_KEY

Others keyword for sorting.

private static final int
SWAP

Return code indicating that element n is to be swapped with n + 1

Constructor Summary

AccessConstructor and Description
public
DocumentOrderingWrapper(DocumentInfo document)

Constructs a new DocumentOrderingWrapper for the specified Document.

Method Summary

Modifier and TypeMethod and Description
private void
checkDuplicates(String[] source, String[] searchTarget)

Ensure the IDs in source aren't present in searchTarget.

public static <K, V extends Comparable<? super V>> Map<K, V>
public static boolean
private static void
enhanceOrderingData(DocumentOrderingWrapper[] wrappers)

Update before/after knowledge of all nodes in the array.

private Set<String>
extractIds(Node n, String nodeName)

Extract and return a Set of IDs contained within the provided Node.

public String[]

Returns:

this Document's after IDs, if any
getAfterIds
()

public String[]

Returns:

this Document's before IDs, if any
getBeforeIds
()

public DocumentInfo

Returns:

the wrapped Document
getDocument
()

public static HashMap<String, DocumentOrderingWrapper>
public String

Returns:

this Document's ID, if any
getDocumentId
()

private String
getDocumentName(Element documentElement)

public static LinkedList<String>
private String
getNodeText(Node node)

Return the textual content, if any, of the provided Node.

private void
init()

Performs the initialization necessary to allow sorting of faces-config documents.

public static int
public boolean

Returns:

true if this document is after the specified id, otherwise false
isAfter
(String id)

public boolean

Returns:

true if any after IDs are present, otherwise, false
isAfterOrdered
()

public boolean

Returns:

true if this document is after others, otherwise false
isAfterOthers
()

public boolean

Returns:

true if this document is before the specified id, otherwise false
isBefore
(String id)

public boolean

Returns:

true if any before IDs are present, otherwise false
isBeforeOrdered
()

public boolean

Returns:

true if this document is before others, otherwise false
isBeforeOthers
()

public boolean

Returns:

true if this document has any before or after IDs, otherwise false
isOrdered
()

public static void
private static boolean

Returns:

true if ids contains id
search
(String[]
an array of IDs
ids
,
String
the ID to search for
id
)

Simple helper method around Arrays.binarySearch().

public static DocumentOrderingWrapper[]

Returns:

an array of DocumentOrderingWrappers that may be smaller than the input array of wrappers.
sort
(DocumentOrderingWrapper[]
Documents to sort
documents
,
List<String>
the absolute order as specified in the /WEB-INF/faces-config.xml
absoluteOrder
)

Sort the provided array of Documents per the order specified in the List represented by absoluteOrder.

public static void
sort(DocumentOrderingWrapper[] documents)

Sort the provided array of Documents per the requirements of the 2.0 specification.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

AFTERback to summary
private static final String AFTER

Constant for the after element.

afterIdsback to summary
private String[] afterIds

The wrapped Document's before IDs.

BEFOREback to summary
private static final String BEFORE

Constant for the before element.

beforeIdsback to summary
private String[] beforeIds

The wrapped Document's before IDs.

COMPARATORback to summary
private static Comparator<DocumentOrderingWrapper> COMPARATOR

Comparator implementation to aid in sorting faces-config documents.

DO_NOT_SWAPback to summary
private static final int DO_NOT_SWAP

Return code indicating that no swap needs to occur for the elements being compared.

documentInfoback to summary
private DocumentInfo documentInfo

The wrapped Document.

idback to summary
private String id

The wrapped Document's ID.

LOGGERback to summary
private static final Logger LOGGER

Logger for this class.

MAX_SORT_PASSEDback to summary
private static final int MAX_SORT_PASSED

This is the limit on the number of attempts made to sort the documents. Any attempt to exceed this limit will result in an Exception being thrown.

NAMEback to summary
private static final String NAME

Constant for the name element.

ORDERINGback to summary
private static final String ORDERING

Constant for the ordering element.

OTHERSback to summary
private static final String OTHERS

Constant for the others element.

OTHERS_KEYback to summary
private static final String OTHERS_KEY

Others keyword for sorting.

SWAPback to summary
private static final int SWAP

Return code indicating that element n is to be swapped with n + 1

Constructor Detail

DocumentOrderingWrapperback to summary
public DocumentOrderingWrapper(DocumentInfo document)

Constructs a new DocumentOrderingWrapper for the specified Document.

Method Detail

checkDuplicatesback to summary
private void checkDuplicates(String[] source, String[] searchTarget)

Ensure the IDs in source aren't present in searchTarget.

descendingByValueback to summary
public static <K, V extends Comparable<? super V>> Map<K, V> descendingByValue(Map<K, V> map)
doneback to summary
public static boolean done(DocumentOrderingWrapper[] documents, LinkedList<String> ids)
enhanceOrderingDataback to summary
private static void enhanceOrderingData(DocumentOrderingWrapper[] wrappers) throws CircularDependencyException

Update before/after knowledge of all nodes in the array. Consider the case of A after B, B after C, C after D, and D with no ordering characteristics. When the code below executes, the before/after of specific nodes will be updated so that in the case of the example above we'd have: A -> after B B -> before A, after C C -> before B, A after D D -> before C, B, A So when an attempt is made to sort [A, B, C, D] the end result is [D, C, B, A] No extra enhancement of after ID information is necessary outside of the single node information due to the way the algorithm processes the array. This method also performs cyclic detection. If, after updating the before/after information, the before/after information contains a reference to the document ID we're currently processing, throw an exception.

extractIdsback to summary
private Set<String> extractIds(Node n, String nodeName)

Extract and return a Set of IDs contained within the provided Node.

getAfterIdsback to summary
public String[] getAfterIds()
Returns:String[]

this Document's after IDs, if any

getBeforeIdsback to summary
public String[] getBeforeIds()
Returns:String[]

this Document's before IDs, if any

getDocumentback to summary
public DocumentInfo getDocument()
Returns:DocumentInfo

the wrapped Document

getDocumentHashMapback to summary
public static HashMap<String, DocumentOrderingWrapper> getDocumentHashMap(DocumentOrderingWrapper[] documents)
getDocumentIdback to summary
public String getDocumentId()
Returns:String

this Document's ID, if any

getDocumentNameback to summary
private String getDocumentName(Element documentElement)
getIdsback to summary
public static LinkedList<String> getIds(DocumentOrderingWrapper[] documents)
getNodeTextback to summary
private String getNodeText(Node node)

Return the textual content, if any, of the provided Node.

initback to summary
private void init()

Performs the initialization necessary to allow sorting of faces-config documents.

innerSortback to summary
public static int innerSort(DocumentOrderingWrapper[] documents)
isAfterback to summary
public boolean isAfter(String id)
Returns:boolean

true if this document is after the specified id, otherwise false

isAfterOrderedback to summary
public boolean isAfterOrdered()
Returns:boolean

true if any after IDs are present, otherwise, false

isAfterOthersback to summary
public boolean isAfterOthers()
Returns:boolean

true if this document is after others, otherwise false

isBeforeback to summary
public boolean isBefore(String id)
Returns:boolean

true if this document is before the specified id, otherwise false

isBeforeOrderedback to summary
public boolean isBeforeOrdered()
Returns:boolean

true if any before IDs are present, otherwise false

isBeforeOthersback to summary
public boolean isBeforeOthers()
Returns:boolean

true if this document is before others, otherwise false

isOrderedback to summary
public boolean isOrdered()
Returns:boolean

true if this document has any before or after IDs, otherwise false

preSortback to summary
public static void preSort(DocumentOrderingWrapper[] documents)
searchback to summary
private static boolean search(String[] ids, String id)

Simple helper method around Arrays.binarySearch().

Parameters
ids:String[]

an array of IDs

id:String

the ID to search for

Returns:boolean

true if ids contains id

sortback to summary
public static DocumentOrderingWrapper[] sort(DocumentOrderingWrapper[] documents, List<String> absoluteOrder)

Sort the provided array of Documents per the order specified in the List represented by absoluteOrder.

Parameters
documents:DocumentOrderingWrapper[]

Documents to sort

absoluteOrder:List<String>

the absolute order as specified in the /WEB-INF/faces-config.xml

Returns:DocumentOrderingWrapper[]

an array of DocumentOrderingWrappers that may be smaller than the input array of wrappers.

sortback to summary
public static void sort(DocumentOrderingWrapper[] documents)

Sort the provided array of Documents per the requirements of the 2.0 specification. Note, that this method only provides partial ordering and not absolute ordering.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
com.sun.faces.config.manager.documents back to summary

private final Class DocumentOrderingWrapper.CircularDependencyException

extends Exception
Class Inheritance
Annotations
@SuppressWarnings:serial

Constructor Summary

AccessConstructor and Description
public

Constructor Detail

CircularDependencyExceptionback to summary
public CircularDependencyException()
com.sun.faces.config.manager.documents back to summary

private final Class DocumentOrderingWrapper.DocumentOrderingComparator

extends Object
implements Comparator<DocumentOrderingWrapper>
Class Inheritance
  • java.lang.Object
  • com.sun.faces.config.manager.documents.DocumentOrderingWrapper.DocumentOrderingComparator
All Implemented Interfaces
java.util.Comparator

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public int
compare(DocumentOrderingWrapper
the first object to be compared.
wrapper1
,
DocumentOrderingWrapper
the second object to be compared.
wrapper2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

DocumentOrderingComparatorback to summary
private DocumentOrderingComparator()

Method Detail

compareback to summary
public int compare(DocumentOrderingWrapper wrapper1, DocumentOrderingWrapper wrapper2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
wrapper1:DocumentOrderingWrapper

the first object to be compared.

wrapper2:DocumentOrderingWrapper

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Annotations
@Override