@Override
  public void validate(final FacesContext context) {
    context
        .getApplication()
        .publishEvent(context, PreValidateEvent.class, UIValidateForm.class, this);
    BeanManager manager = BeanManagerAccessor.getBeanManager();
    manager.fireEvent(this, BEFORE);

    Validator validator = context.getApplication().createValidator(validatorId);
    if (validator == null) {
      throw new IllegalArgumentException(
          "Could not create Validator with id: [" + validatorId + "]");
    }

    try {
      UIComponent parent = this.getParent();
      validator.validate(context, parent, components);
    } catch (ValidatorException e) {
      setValid(false);
      for (UIInput comp : components.values()) {
        comp.setValid(false);
        // TODO Put this back when attributes can control it
        // context.addMessage(comp.getClientId(), e.getFacesMessage());
      }
      context.addMessage(null, e.getFacesMessage());
    }

    manager.fireEvent(this, AFTER);
    context
        .getApplication()
        .publishEvent(context, PostValidateEvent.class, UIValidateForm.class, this);
  }
  @Test
  public void test() throws Exception {
    final Orange orange = new Orange();
    beanManager.fireEvent(orange);

    final Green green = new Green();
    beanManager.fireEvent(green);

    Assert.assertEquals(2, painter.getObserved().size());
    Assert.assertSame(orange, painter.getObserved().get(0));
    Assert.assertSame(green, painter.getObserved().get(1));
  }
  @Test
  public void testRoomObservers() {
    beanManager.fireEvent(new CleanEvent());

    Assert.assertTrue(hall.isClean());
    Assert.assertTrue(pit.isClean());
  }
 public void configure() {
   Set<Bean<?>> beans = beanManager.getBeans(Object.class);
   for (Bean<?> bean : beans) {
     Annotation qualifier = tryToFindAStereotypeQualifier(bean);
     if (qualifier != null) {
       beanManager.fireEvent(new DefaultBeanClass(bean.getBeanClass()), qualifier);
     }
   }
   interceptorsCache.init();
 }
Beispiel #5
0
 public void login() {
   AuthenticationResult result =
       this.cm.validateCredentials(new UserPasswordCredentialSet(this.loginName, this.password));
   if (result.getResult()) {
     UserPasswordCredentialSet set =
         (UserPasswordCredentialSet) result.getValidatedCredentialSet();
     this.activeAccount = set.getAccount();
     bm.fireEvent(new PostLoggedInEvent(activeAccount));
     this.loggedIn = true;
     this.loginName = null;
     this.password = null;
   } else {
     addMsg("Login failed.", FacesMessage.SEVERITY_ERROR);
   }
 }
 @Override
 public void handle() throws FacesException {
   Iterator<ExceptionQueuedEvent> it = getUnhandledExceptionQueuedEvents().iterator();
   while (it.hasNext()) {
     try {
       ExceptionQueuedEvent evt = it.next();
       // Fires the Event with the Exception (with expected Qualifier) to
       // be handled
       ExceptionToCatchEvent etce =
           new ExceptionToCatchEvent(
               evt.getContext().getException(), FacesRequestLiteral.INSTANCE);
       beanManager.fireEvent(etce);
     } finally {
       it.remove();
     }
   }
   getWrapped().handle();
 }
Beispiel #7
0
  @SuppressWarnings("unchecked")
  public void callback(final Message message) {
    /** If the message didn't not come from a remote, we don't handle it. */
    if (!message.isFlagSet(RoutingFlag.FromRemote)) return;

    try {
      ScopeUtil.associateRequestContext(message);

      final LocalContext localContext = LocalContext.get(message);

      switch (CDICommands.valueOf(message.getCommandType())) {
        case RemoteSubscribe:
          if (afterBeanDiscovery != null) {
            final String signature = getSignatureFromMessage(message);
            final String typeName = message.get(String.class, CDIProtocol.BeanType);
            final Class<?> type = Class.forName(typeName);
            final Set<String> annotationTypes = message.get(Set.class, CDIProtocol.Qualifiers);

            if (!activeObserverSignatures.contains(signature)) {

              if (type == null || !EnvUtil.isPortableType(type)) {
                log.warn("client tried to register a non-portable type: " + type);
                return;
              }

              final DynamicEventObserverMethod observerMethod =
                  new DynamicEventObserverMethod(
                      eventRoutingTable, messagebus, type, annotationTypes);

              if (!activeObserverMethods.contains(observerMethod)) {
                afterBeanDiscovery.addObserverMethod(observerMethod);
                activeObserverMethods.add(observerMethod);
              }

              activeObserverSignatures.add(signature);
            }

            eventRoutingTable.activateRoute(
                typeName, annotationTypes, message.getResource(QueueSession.class, "Session"));
          }
          break;

        case RemoteUnsubscribe:
          final String typeName = message.get(String.class, CDIProtocol.BeanType);
          final Set<String> annotationTypes = message.get(Set.class, CDIProtocol.Qualifiers);

          eventRoutingTable.deactivateRoute(
              typeName, annotationTypes, message.getResource(QueueSession.class, "Session"));
          break;

        case CDIEvent:
          if (!isRoutable(localContext, message)) {
            return;
          }

          final Object o = message.get(Object.class, CDIProtocol.BeanReference);
          EventConversationContext.activate(o, CDIServerUtil.getSession(message));
          try {
            @SuppressWarnings("unchecked")
            final Set<String> qualifierNames = message.get(Set.class, CDIProtocol.Qualifiers);
            List<Annotation> qualifiers = null;
            if (qualifierNames != null) {
              for (final String qualifierName : qualifierNames) {
                if (qualifiers == null) {
                  qualifiers = new ArrayList<Annotation>();
                }
                final Annotation qualifier = allQualifiers.get(qualifierName);
                if (qualifier != null) {
                  qualifiers.add(qualifier);
                }
              }
            }

            if (qualifiers != null) {
              beanManager.fireEvent(o, qualifiers.toArray(new Annotation[qualifiers.size()]));
            } else {
              beanManager.fireEvent(o);
            }
          } finally {
            EventConversationContext.deactivate();
          }

          break;

        case AttachRemote:
          if (observedEvents.size() > 0) {
            MessageBuilder.createConversation(message)
                .toSubject(CDI.CLIENT_DISPATCHER_SUBJECT)
                .command(CDICommands.AttachRemote)
                .with(MessageParts.RemoteServices, getEventTypes())
                .done()
                .reply();
          } else {
            MessageBuilder.createConversation(message)
                .toSubject(CDI.CLIENT_DISPATCHER_SUBJECT)
                .command(CDICommands.AttachRemote)
                .with(MessageParts.RemoteServices, "")
                .done()
                .reply();
          }

          localContext.setAttribute(CDI_EVENT_CHANNEL_OPEN, "1");
          break;

        default:
          throw new IllegalArgumentException("Unknown command type " + message.getCommandType());
      }
    } catch (Exception e) {
      throw new RuntimeException("Failed to dispatch CDI Event", e);
    }
  }
Beispiel #8
0
 public void fireWithUpdatedQualifierViaManager() {
   manager.fireEvent("", new AnnotationLiteral<Updated>() {});
 }
Beispiel #9
0
 public void fireWithNoQualifiersViaManager() {
   manager.fireEvent("");
 }
 @Override
 public void rewrite(Rewrite event) {
   manager.fireEvent(event);
 }
 @Override
 public void init(ServletContext context) {
   manager.fireEvent(context);
 }
Beispiel #12
0
 public void logout() {
   this.loggedIn = false;
   this.activeAccount = null;
   bm.fireEvent(new PostLoggedOutEvent(activeAccount));
   FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
 }
 @Test
 public void assertEventWithQualifiersIsCreatedCorrectly() {
   bm.fireEvent(
       new ExceptionToCatchEvent(new NullPointerException(), new EventQualifierLiteral()));
 }
 @Test
 public void assertEventIsCreatedCorrectly() {
   bm.fireEvent(new ExceptionToCatchEvent(new NullPointerException()));
 }