Skip to content

Commit

Permalink
Implement support for retrieving context param value via @FacesConfig
Browse files Browse the repository at this point in the history
annotation attribute, if any
  • Loading branch information
BalusC committed Oct 14, 2023
1 parent e87d7d3 commit 9cddd35
Show file tree
Hide file tree
Showing 2 changed files with 323 additions and 276 deletions.
27 changes: 27 additions & 0 deletions impl/src/main/java/com/sun/faces/cdi/CdiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand All @@ -35,6 +36,7 @@
import com.sun.faces.util.FacesLogger;
import com.sun.faces.util.Util;

import jakarta.annotation.Priority;
import jakarta.enterprise.context.ContextNotActiveException;
import jakarta.enterprise.context.spi.Context;
import jakarta.enterprise.context.spi.CreationalContext;
Expand All @@ -60,6 +62,31 @@
*/
public final class CdiUtils {

/**
* This does unfortunately not exist in cdi spec: https://stackoverflow.com/a/63653513
*
* This basically sorts descending by priority with fallback to FQN.
* Highest priority first.
* Priotityless bean last.
* Same priorities ordered by FQN (for now?)
*/
public static final Comparator<Object> BEAN_PRIORITY_COMPARATOR = (left, right) -> {
Priority leftPriority = left.getClass().getAnnotation(Priority.class);
Priority rightPriority = right.getClass().getAnnotation(Priority.class);

int compare = leftPriority != null && rightPriority != null ? Integer.compare(leftPriority.value(), rightPriority.value())
: leftPriority != null ? -1
: rightPriority != null ? 1
: 0;

if (compare == 0) {
return left.getClass().getName().compareTo(right.getClass().getName());
}

return compare;
};


/**
* Stores the logger.
*/
Expand Down
Loading

0 comments on commit 9cddd35

Please sign in to comment.