All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.faces.application.annotation.NamedEventConfigHandler Maven / Gradle / Ivy

Go to download

Jakarta Faces defines an MVC framework for building user interfaces for web applications, including UI components, state management, event handing, input validation, page navigation, and support for internationalization and accessibility.

There is a newer version: 4.1.2
Show newest version
/*
 * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0, which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 *
 * This Source Code may also be made available under the following Secondary
 * Licenses when the conditions for such availability set forth in the
 * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
 * version 2 with the GNU Classpath Exception, which is available at
 * https://www.gnu.org/software/classpath/license.html.
 *
 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
 */

package com.sun.faces.application.annotation;

import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sun.faces.application.ApplicationAssociate;
import com.sun.faces.application.NamedEventManager;

import jakarta.faces.context.FacesContext;
import jakarta.faces.event.NamedEvent;
import jakarta.faces.event.SystemEvent;

/**
 * This class handles the processing the NamedEvent annotation. For each class with this annotation, the following logic
 * is applied:
 * 
    *
  1. Get the unqualified class name (e.g., UserLoginEvent)
  2. *
  3. Strip off the trailing "Event", if present (e.g., UserLogin)
  4. *
  5. Convert the first character to lower-case (e.g., userLogin)
  6. *
  7. Prepend the package name to the lower-cased name
  8. *
  9. If the shortName attribute is specified, register the event by that name as well.
  10. *
*/ public class NamedEventConfigHandler implements ConfigAnnotationHandler { private static final Collection> HANDLES = List.of(NamedEvent.class); private Map, Annotation> namedEvents; @Override public Collection> getHandledAnnotations() { return HANDLES; } @Override public void collect(Class target, Annotation annotation) { if (namedEvents == null) { namedEvents = new HashMap<>(); } namedEvents.put(target, annotation); } @Override public void push(FacesContext ctx) { if (namedEvents != null) { ApplicationAssociate associate = ApplicationAssociate.getInstance(ctx.getExternalContext()); if (associate != null) { NamedEventManager nem = associate.getNamedEventManager(); for (Map.Entry, Annotation> entry : namedEvents.entrySet()) { process(nem, entry.getKey(), entry.getValue()); } } } } // --------------------------------------------------------- Private Methods /* */ private void process(NamedEventManager nem, Class annotatedClass, Annotation annotation) { String name = annotatedClass.getSimpleName(); int index = name.lastIndexOf("Event"); if (index > -1) { name = name.substring(0, index); } name = annotatedClass.getPackage().getName() + '.' + Character.toLowerCase(name.charAt(0)) + name.substring(1); nem.addNamedEvent(name, (Class) annotatedClass); String shortName = ((NamedEvent) annotation).shortName(); if ( !shortName.isEmpty() ) { if (nem.isDuplicateNamedEvent(shortName)) { nem.addDuplicateName(shortName, (Class) annotatedClass); } else { nem.addNamedEvent(shortName, (Class) annotatedClass); } } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy