예제 #1
0
 /**
  * Inspect an annotation to see if it specifies a view in which it should be. Fall back on default
  * view otherwise.
  *
  * @param annotation
  * @param currentPhase
  * @param defaultPhases
  * @return true if the annotation is applicable to this view and phase, false otherwise
  */
 public boolean isAnnotationApplicableToPhase(
     Annotation annotation, PhaseIdType currentPhase, PhaseIdType[] defaultPhases) {
   Method restrictAtViewMethod = getRestrictAtViewMethod(annotation);
   PhaseIdType[] phasedIds = null;
   if (restrictAtViewMethod != null) {
     log.warnf(
         "Annotation %s is using the restrictAtViewMethod. Use a @RestrictAtPhase qualifier on the annotation instead.");
     phasedIds = getRestrictedPhaseIds(restrictAtViewMethod, annotation);
   }
   RestrictAtPhase restrictAtPhaseQualifier =
       AnnotationInspector.getAnnotation(
           annotation.annotationType(), RestrictAtPhase.class, beanManager);
   if (restrictAtPhaseQualifier != null) {
     log.debug("Using Phases found in @RestrictAtView qualifier on the annotation.");
     phasedIds = restrictAtPhaseQualifier.value();
   }
   if (phasedIds == null) {
     log.debug("Falling back on default phase ids");
     phasedIds = defaultPhases;
   }
   if (Arrays.binarySearch(phasedIds, currentPhase) >= 0) {
     return true;
   }
   return false;
 }
예제 #2
0
 /**
  * Get the default phases at which restrictions should be applied, by looking for
  * a @RestrictAtPhase on a matching @ViewPattern, falling back on global defaults if none are
  * found
  *
  * @param viewId
  * @return default phases for a view
  */
 public PhaseIdType[] getDefaultPhases(String viewId) {
   PhaseIdType[] defaultPhases = null;
   RestrictAtPhase restrictAtPhase =
       viewConfigStore.getAnnotationData(viewId, RestrictAtPhase.class);
   if (restrictAtPhase != null) {
     defaultPhases = restrictAtPhase.value();
   }
   if (defaultPhases == null) {
     defaultPhases = RestrictAtPhaseDefault.DEFAULT_PHASES;
   }
   return defaultPhases;
 }