You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2009/06/18 06:07:13 UTC
svn commit: r785893 - in
/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces:
config/NamedEventManager.java config/annotation/AnnotationConfigurator.java
view/facelets/tag/jsf/core/EventHandler.java
Author: lu4242
Date: Thu Jun 18 04:07:13 2009
New Revision: 785893
URL: http://svn.apache.org/viewvc?rev=785893&view=rev
Log:
checkstyle convert tabs to spaces
Modified:
myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/NamedEventManager.java
myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/annotation/AnnotationConfigurator.java
myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/EventHandler.java
Modified: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/NamedEventManager.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/NamedEventManager.java?rev=785893&r1=785892&r2=785893&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/NamedEventManager.java (original)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/NamedEventManager.java Thu Jun 18 04:07:13 2009
@@ -34,103 +34,103 @@
*/
public class NamedEventManager {
- private static final NamedEventManager instance = new NamedEventManager();
-
- private HashMap<String, Collection<Class<? extends ComponentSystemEvent>>> events;
-
- private NamedEventManager ()
- {
- events = new HashMap<String, Collection<Class<? extends ComponentSystemEvent>>>();
-
- // Special spec-defined values.
-
- addNamedEvent ("postAddToView", PostAddToViewEvent.class);
- addNamedEvent ("preRenderComponent", PreRenderComponentEvent.class);
- addNamedEvent ("preValidate", PreValidateEvent.class);
- addNamedEvent ("postValidate", PostValidateEvent.class);
- }
-
- public static NamedEventManager getInstance ()
- {
- return instance;
- }
-
- /**
- * Registers a named event.
- *
- * @param shortName a String containing the short name for the event, from the @NamedEvent.shortName()
- * attribute.
- * @param cls the event class to register.
- */
-
- public void addNamedEvent (String shortName, Class<? extends ComponentSystemEvent> cls)
- {
- String key = shortName;
- Collection<Class<? extends ComponentSystemEvent>> eventList;
-
- // Per the spec, if the short name is missing, generate one.
-
- if (shortName == null) {
- key = getFixedName (cls);
- }
-
- eventList = events.get (key);
-
- if (eventList == null) {
- // First event registered to this short name.
-
- eventList = new LinkedList<Class<? extends ComponentSystemEvent>>();
-
- events.put (key, eventList);
- }
-
- eventList.add (cls);
- }
-
- /**
- * Retrieves a collection of system event classes based on their short name.
- *
- * @param shortName the short name to look up.
- * @return a Collection of Class objects containing the system event classes registered to
- * the given short name.
- */
-
- public Collection<Class<? extends ComponentSystemEvent>> getNamedEvent (String shortName)
- {
- return events.get (shortName);
- }
-
- /**
- * Retrieves the short name for an event class, according to spec rules.
- *
- * @param cls the class to find the short name for.
- * @return a String containing the short name for the given class.
- */
-
- private String getFixedName (Class<? extends ComponentSystemEvent> cls)
- {
- StringBuilder result = new StringBuilder();
- String className;
-
- // Get the unqualified class name.
-
- className = cls.getSimpleName();
-
- // Strip the trailing "event" off the class name if present.
-
- if (className.toLowerCase().endsWith ("event")) {
- className = className.substring (0, result.length() - 5);
- }
-
- // Prepend the package name.
-
- if (cls.getPackage() != null) {
- result.append (cls.getPackage().getName());
- result.append ('.');
- }
-
- result.append (className);
-
- return result.toString();
- }
+ private static final NamedEventManager instance = new NamedEventManager();
+
+ private HashMap<String, Collection<Class<? extends ComponentSystemEvent>>> events;
+
+ private NamedEventManager ()
+ {
+ events = new HashMap<String, Collection<Class<? extends ComponentSystemEvent>>>();
+
+ // Special spec-defined values.
+
+ addNamedEvent ("postAddToView", PostAddToViewEvent.class);
+ addNamedEvent ("preRenderComponent", PreRenderComponentEvent.class);
+ addNamedEvent ("preValidate", PreValidateEvent.class);
+ addNamedEvent ("postValidate", PostValidateEvent.class);
+ }
+
+ public static NamedEventManager getInstance ()
+ {
+ return instance;
+ }
+
+ /**
+ * Registers a named event.
+ *
+ * @param shortName a String containing the short name for the event, from the @NamedEvent.shortName()
+ * attribute.
+ * @param cls the event class to register.
+ */
+
+ public void addNamedEvent (String shortName, Class<? extends ComponentSystemEvent> cls)
+ {
+ String key = shortName;
+ Collection<Class<? extends ComponentSystemEvent>> eventList;
+
+ // Per the spec, if the short name is missing, generate one.
+
+ if (shortName == null) {
+ key = getFixedName (cls);
+ }
+
+ eventList = events.get (key);
+
+ if (eventList == null) {
+ // First event registered to this short name.
+
+ eventList = new LinkedList<Class<? extends ComponentSystemEvent>>();
+
+ events.put (key, eventList);
+ }
+
+ eventList.add (cls);
+ }
+
+ /**
+ * Retrieves a collection of system event classes based on their short name.
+ *
+ * @param shortName the short name to look up.
+ * @return a Collection of Class objects containing the system event classes registered to
+ * the given short name.
+ */
+
+ public Collection<Class<? extends ComponentSystemEvent>> getNamedEvent (String shortName)
+ {
+ return events.get (shortName);
+ }
+
+ /**
+ * Retrieves the short name for an event class, according to spec rules.
+ *
+ * @param cls the class to find the short name for.
+ * @return a String containing the short name for the given class.
+ */
+
+ private String getFixedName (Class<? extends ComponentSystemEvent> cls)
+ {
+ StringBuilder result = new StringBuilder();
+ String className;
+
+ // Get the unqualified class name.
+
+ className = cls.getSimpleName();
+
+ // Strip the trailing "event" off the class name if present.
+
+ if (className.toLowerCase().endsWith ("event")) {
+ className = className.substring (0, result.length() - 5);
+ }
+
+ // Prepend the package name.
+
+ if (cls.getPackage() != null) {
+ result.append (cls.getPackage().getName());
+ result.append ('.');
+ }
+
+ result.append (className);
+
+ return result.toString();
+ }
}
Modified: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/annotation/AnnotationConfigurator.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/annotation/AnnotationConfigurator.java?rev=785893&r1=785892&r2=785893&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/annotation/AnnotationConfigurator.java (original)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/annotation/AnnotationConfigurator.java Thu Jun 18 04:07:13 2009
@@ -857,25 +857,25 @@
NamedEvent namedEvent = (NamedEvent) clazz.getAnnotation (NamedEvent.class);
if (namedEvent != null) {
- // Can only apply @NamedEvent to ComponentSystemEvent subclasses.
-
- if (!ComponentSystemEvent.class.isAssignableFrom (clazz)) {
- // Just log this. We'll catch it later in the runtime.
-
- if (log.isWarnEnabled()) {
- log.warn (clazz.getName() + " is annotated with @javax.faces.event.NamedEvent, but does " +
- "not extend javax.faces.event.ComponentSystemEvent");
- }
-
- return;
- }
-
- // Have to register @NamedEvent annotations with the NamedEventManager class since
- // we need to get access to this info later and can't from the dispenser (it's not a
- // singleton).
-
- NamedEventManager.getInstance().addNamedEvent (namedEvent.shortName(),
- (Class<? extends ComponentSystemEvent>) clazz);
+ // Can only apply @NamedEvent to ComponentSystemEvent subclasses.
+
+ if (!ComponentSystemEvent.class.isAssignableFrom (clazz)) {
+ // Just log this. We'll catch it later in the runtime.
+
+ if (log.isWarnEnabled()) {
+ log.warn (clazz.getName() + " is annotated with @javax.faces.event.NamedEvent, but does " +
+ "not extend javax.faces.event.ComponentSystemEvent");
+ }
+
+ return;
+ }
+
+ // Have to register @NamedEvent annotations with the NamedEventManager class since
+ // we need to get access to this info later and can't from the dispenser (it's not a
+ // singleton).
+
+ NamedEventManager.getInstance().addNamedEvent (namedEvent.shortName(),
+ (Class<? extends ComponentSystemEvent>) clazz);
}
// TODO: All annotations scanned at startup must be configured here!
Modified: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/EventHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/EventHandler.java?rev=785893&r1=785892&r2=785893&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/EventHandler.java (original)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/EventHandler.java Thu Jun 18 04:07:13 2009
@@ -46,131 +46,131 @@
*/
public final class EventHandler extends TagHandler {
- private TagAttribute listener;
- private TagAttribute name;
- private TagAttribute type;
-
- public EventHandler (TagConfig tagConfig)
- {
- super (tagConfig);
-
- listener = getRequiredAttribute ("listener");
- name = getAttribute ("name");
- type = getAttribute ("type");
-
- // TODO: is this right? The spec isn't entirely clear, but it seems to me that one or the other
- // attribute must be defined, despite the fact that the docs say "name" is required.
-
- if ((name == null) && (type == null)) {
- throw new TagException (this.tag, "One of the 'name' or 'type' attributes must be defined");
- }
-
- else if ((name != null) && (type != null)) {
- throw new TagException (this.tag, "Both the 'name' and 'type' attributes cannot be defined");
- }
- }
-
- @Override
- public void apply (FaceletContext ctx, UIComponent parent) throws ELException, FacesException, FaceletException, IOException
- {
- Class<? extends ComponentSystemEvent> eventClass = getEventClass (ctx);
- MethodExpression methodExp = listener.getMethodExpression(ctx, void.class, new Class<?>[] {
- ComponentSystemEvent.class });
-
- // Simply register the event on the component.
-
- parent.subscribeToEvent (eventClass, new Listener (ctx.getFacesContext().getELContext(), methodExp));
- }
-
- /**
- * Gets the event class defined by the tag (either in the "name" or "type" attribute).
- *
- * @param context the Facelet context
- * @return a Class containing the event class defined by the tag.
- */
-
- @SuppressWarnings("unchecked")
- private Class<? extends ComponentSystemEvent> getEventClass (FaceletContext context)
- {
- Class<?> eventClass = null;
- ValueExpression valueExp = ((name != null) ? name.getValueExpression (context, String.class) :
- type.getValueExpression (context, String.class));
- String value = (String) valueExp.getValue (context.getFacesContext().getELContext());
-
- if (name != null) {
- Collection<Class<? extends ComponentSystemEvent>> events;
-
- // We can look up the event class by name in the NamedEventManager.
-
- events = NamedEventManager.getInstance().getNamedEvent (value);
-
- if (events.size() > 1) {
- StringBuilder classNames = new StringBuilder ("[");
- Iterator<Class<? extends ComponentSystemEvent>> eventIterator = events.iterator();
-
- // TODO: The spec is somewhat vague, but I think we're supposed to throw an exception
- // here. The @NamedEvent javadocs say that if a short name is registered to more than one
- // event class that we must throw an exception listing the short name and the classes in
- // the list _when the application makes reference to it_. I believe processing this tag
- // qualifies as the application "making reference" to the short name. Why the exception
- // isn't thrown when processing the @NamedEvent annotation, I don't know. Perhaps follow
- // up with the EG to see if this is correct.
-
- while (eventIterator.hasNext()) {
- classNames.append (eventIterator.next().getName());
-
- if (eventIterator.hasNext()) {
- classNames.append (", ");
- }
-
- else {
- classNames.append ("]");
- }
- }
-
- throw new FacesException ("The event name '" + value + "' is mapped to more than one " +
- " event class: " + classNames.toString());
- }
-
- else {
- eventClass = events.iterator().next();
- }
- }
-
- else {
- // Must have been defined via the "type" attribute, so instantiate the class.
-
- try {
- eventClass = ReflectionUtil.forName (value);
- }
-
- catch (Throwable e) {
- throw new TagAttributeException ((name != null) ? name : type, "Couldn't create event class", e);
- }
- }
-
- if (!ComponentSystemEvent.class.isAssignableFrom (eventClass)) {
- throw new TagAttributeException ((name != null) ? name : type, "Event class " + eventClass.getName() +
- " is not of type javax.faces.event.ComponentSystemEvent");
- }
-
- return (Class<? extends ComponentSystemEvent>) eventClass;
- }
-
- private class Listener implements ComponentSystemEventListener {
- private ELContext elContext;
- private MethodExpression methodExp;
-
- private Listener (ELContext elContext, MethodExpression methodExp)
- {
- this.elContext = elContext;
- this.methodExp = methodExp;
- }
-
- @Override
- public void processEvent (ComponentSystemEvent event)
- {
- this.methodExp.invoke(elContext, new Object[] { event });
- }
- }
+ private TagAttribute listener;
+ private TagAttribute name;
+ private TagAttribute type;
+
+ public EventHandler (TagConfig tagConfig)
+ {
+ super (tagConfig);
+
+ listener = getRequiredAttribute ("listener");
+ name = getAttribute ("name");
+ type = getAttribute ("type");
+
+ // TODO: is this right? The spec isn't entirely clear, but it seems to me that one or the other
+ // attribute must be defined, despite the fact that the docs say "name" is required.
+
+ if ((name == null) && (type == null)) {
+ throw new TagException (this.tag, "One of the 'name' or 'type' attributes must be defined");
+ }
+
+ else if ((name != null) && (type != null)) {
+ throw new TagException (this.tag, "Both the 'name' and 'type' attributes cannot be defined");
+ }
+ }
+
+ @Override
+ public void apply (FaceletContext ctx, UIComponent parent) throws ELException, FacesException, FaceletException, IOException
+ {
+ Class<? extends ComponentSystemEvent> eventClass = getEventClass (ctx);
+ MethodExpression methodExp = listener.getMethodExpression(ctx, void.class, new Class<?>[] {
+ ComponentSystemEvent.class });
+
+ // Simply register the event on the component.
+
+ parent.subscribeToEvent (eventClass, new Listener (ctx.getFacesContext().getELContext(), methodExp));
+ }
+
+ /**
+ * Gets the event class defined by the tag (either in the "name" or "type" attribute).
+ *
+ * @param context the Facelet context
+ * @return a Class containing the event class defined by the tag.
+ */
+
+ @SuppressWarnings("unchecked")
+ private Class<? extends ComponentSystemEvent> getEventClass (FaceletContext context)
+ {
+ Class<?> eventClass = null;
+ ValueExpression valueExp = ((name != null) ? name.getValueExpression (context, String.class) :
+ type.getValueExpression (context, String.class));
+ String value = (String) valueExp.getValue (context.getFacesContext().getELContext());
+
+ if (name != null) {
+ Collection<Class<? extends ComponentSystemEvent>> events;
+
+ // We can look up the event class by name in the NamedEventManager.
+
+ events = NamedEventManager.getInstance().getNamedEvent (value);
+
+ if (events.size() > 1) {
+ StringBuilder classNames = new StringBuilder ("[");
+ Iterator<Class<? extends ComponentSystemEvent>> eventIterator = events.iterator();
+
+ // TODO: The spec is somewhat vague, but I think we're supposed to throw an exception
+ // here. The @NamedEvent javadocs say that if a short name is registered to more than one
+ // event class that we must throw an exception listing the short name and the classes in
+ // the list _when the application makes reference to it_. I believe processing this tag
+ // qualifies as the application "making reference" to the short name. Why the exception
+ // isn't thrown when processing the @NamedEvent annotation, I don't know. Perhaps follow
+ // up with the EG to see if this is correct.
+
+ while (eventIterator.hasNext()) {
+ classNames.append (eventIterator.next().getName());
+
+ if (eventIterator.hasNext()) {
+ classNames.append (", ");
+ }
+
+ else {
+ classNames.append ("]");
+ }
+ }
+
+ throw new FacesException ("The event name '" + value + "' is mapped to more than one " +
+ " event class: " + classNames.toString());
+ }
+
+ else {
+ eventClass = events.iterator().next();
+ }
+ }
+
+ else {
+ // Must have been defined via the "type" attribute, so instantiate the class.
+
+ try {
+ eventClass = ReflectionUtil.forName (value);
+ }
+
+ catch (Throwable e) {
+ throw new TagAttributeException ((name != null) ? name : type, "Couldn't create event class", e);
+ }
+ }
+
+ if (!ComponentSystemEvent.class.isAssignableFrom (eventClass)) {
+ throw new TagAttributeException ((name != null) ? name : type, "Event class " + eventClass.getName() +
+ " is not of type javax.faces.event.ComponentSystemEvent");
+ }
+
+ return (Class<? extends ComponentSystemEvent>) eventClass;
+ }
+
+ private class Listener implements ComponentSystemEventListener {
+ private ELContext elContext;
+ private MethodExpression methodExp;
+
+ private Listener (ELContext elContext, MethodExpression methodExp)
+ {
+ this.elContext = elContext;
+ this.methodExp = methodExp;
+ }
+
+ @Override
+ public void processEvent (ComponentSystemEvent event)
+ {
+ this.methodExp.invoke(elContext, new Object[] { event });
+ }
+ }
}