Author: nickarls
Date: 2008-12-02 17:26:39 -0500 (Tue, 02 Dec 2008)
New Revision: 390
Removed:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/TransactionObservationPhase.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EventBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/DeferredEventNotification.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java
Log:
refactorings in events
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2008-12-02
13:24:58 UTC (rev 389)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2008-12-02
22:26:39 UTC (rev 390)
@@ -29,6 +29,7 @@
import javax.webbeans.DefinitionException;
import javax.webbeans.Dependent;
import javax.webbeans.DeploymentType;
+import javax.webbeans.Event;
import javax.webbeans.Named;
import javax.webbeans.Production;
import javax.webbeans.ScopeType;
@@ -60,7 +61,7 @@
{
@SuppressWarnings("unchecked")
- private static Set<Class<?>> STANDARD_WEB_BEAN_CLASSES = new
HashSet<Class<?>>(Arrays.asList(DefaultEnterpriseBeanLookup.class));
+ private static Set<Class<?>> STANDARD_WEB_BEAN_CLASSES = new
HashSet<Class<?>>(Arrays.asList(DefaultEnterpriseBeanLookup.class,
Event.class));
/**
* Helper class for getting deployment type
@@ -387,7 +388,7 @@
}
else if (deploymentType.equals(Standard.class) &&
!STANDARD_WEB_BEAN_CLASSES.contains(getAnnotatedItem().getType()))
{
- throw new DefinitionException(getAnnotatedItem() + " cannot have deployment
type @Standard");
+ throw new DefinitionException(getAnnotatedItem().getName() + " cannot have
deployment type @Standard");
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EventBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EventBean.java 2008-12-02
13:24:58 UTC (rev 389)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EventBean.java 2008-12-02
22:26:39 UTC (rev 390)
@@ -18,8 +18,11 @@
package org.jboss.webbeans.bean;
import java.lang.reflect.Field;
+import java.lang.reflect.Type;
+import javax.webbeans.DefinitionException;
import javax.webbeans.Dependent;
+import javax.webbeans.Event;
import javax.webbeans.Standard;
import org.jboss.webbeans.ManagerImpl;
@@ -36,7 +39,7 @@
*
* @param <T>
*/
-public class EventBean<T> extends AbstractBean<EventImpl<T>, Field>
+public class EventBean<T> extends AbstractBean<Event<T>, Field>
{
private static LogProvider log = Logging.getLogProvider(EventBean.class);
@@ -44,7 +47,7 @@
// The debug location
private String location;
// The underlying annotated item
- private AnnotatedField<EventImpl<T>> annotatedItem;
+ private AnnotatedField<Event<T>> annotatedItem;
/**
* Constructor
@@ -57,7 +60,7 @@
public EventBean(AnnotatedField<T> field, ManagerImpl manager)
{
super(manager);
- this.annotatedItem = (AnnotatedField<EventImpl<T>>) field;
+ this.annotatedItem = (AnnotatedField<Event<T>>) field;
init();
}
@@ -77,7 +80,15 @@
*/
private void checkAnnotatedItem()
{
- // TODO: checks
+ Type[] actualTypeArguments = annotatedItem.getActualTypeArguments();
+ if (actualTypeArguments.length != 1)
+ {
+ throw new DefinitionException("Event must have type arguments");
+ }
+ if (!(actualTypeArguments[0] instanceof Class))
+ {
+ throw new DefinitionException("Event must have concrete type
argument");
+ }
}
/**
@@ -102,7 +113,7 @@
* @see org.jboss.webbeans.bean.AbstractBean#getAnnotatedItem()
*/
@Override
- protected AnnotatedItem<EventImpl<T>, Field> getAnnotatedItem()
+ protected AnnotatedItem<Event<T>, Field> getAnnotatedItem()
{
return annotatedItem;
}
@@ -154,7 +165,7 @@
* @see javax.webbeans.manager.Bean#create()
*/
@Override
- public EventImpl<T> create()
+ public Event<T> create()
{
return new EventImpl<T>(getManager(),
annotatedItem.getBindingTypesAsArray());
}
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/DeferredEventNotification.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/DeferredEventNotification.java 2008-12-02
13:24:58 UTC (rev 389)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/DeferredEventNotification.java 2008-12-02
22:26:39 UTC (rev 390)
@@ -21,6 +21,11 @@
import javax.transaction.Synchronization;
import javax.webbeans.Observer;
+import static
org.jboss.webbeans.event.EventManager.TransactionObservationPhase.AFTER_COMPLETION;
+import static
org.jboss.webbeans.event.EventManager.TransactionObservationPhase.AFTER_SUCCESS;
+import static
org.jboss.webbeans.event.EventManager.TransactionObservationPhase.AFTER_FAILURE;
+import static
org.jboss.webbeans.event.EventManager.TransactionObservationPhase.BEFORE_COMPLETION;
+
/**
* A synchronization object which will deliver the event to the observer after
* the JTA transaction currently in effect is committed.
@@ -69,20 +74,20 @@
*/
public void afterCompletion(int status)
{
- if
(observer.isInterestedInTransactionPhase(TransactionObservationPhase.AFTER_COMPLETION))
+ if (observer.isInterestedInTransactionPhase(AFTER_COMPLETION))
{
observer.notify(event);
}
switch (status)
{
case Status.STATUS_COMMITTED:
- if
(observer.isInterestedInTransactionPhase(TransactionObservationPhase.AFTER_SUCCESS))
+ if (observer.isInterestedInTransactionPhase(AFTER_SUCCESS))
{
observer.notify();
}
break;
case Status.STATUS_ROLLEDBACK:
- if
(observer.isInterestedInTransactionPhase(TransactionObservationPhase.AFTER_FAILURE))
+ if (observer.isInterestedInTransactionPhase(AFTER_FAILURE))
{
observer.notify();
}
@@ -98,7 +103,7 @@
*/
public void beforeCompletion()
{
- if
(observer.isInterestedInTransactionPhase(TransactionObservationPhase.BEFORE_COMPLETION))
+ if (observer.isInterestedInTransactionPhase(BEFORE_COMPLETION))
{
observer.notify(event);
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java 2008-12-02
13:24:58 UTC (rev 389)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java 2008-12-02
22:26:39 UTC (rev 390)
@@ -22,10 +22,12 @@
import java.util.Set;
import javax.webbeans.BindingType;
+import javax.webbeans.Dependent;
import javax.webbeans.DuplicateBindingTypeException;
import javax.webbeans.Event;
import javax.webbeans.Observable;
import javax.webbeans.Observer;
+import javax.webbeans.Standard;
import org.jboss.webbeans.ManagerImpl;
@@ -37,6 +39,8 @@
* @param <T>
* @see javax.webbeans.Event
*/
+@Standard
+@Dependent
public class EventImpl<T> implements Event<T>
{
// The set of binding types
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-12-02
13:24:58 UTC (rev 389)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-12-02
22:26:39 UTC (rev 390)
@@ -46,6 +46,15 @@
public class EventManager
{
/**
+ * The known transactional phases a transactional event observer can be
+ * interested in
+ */
+ protected enum TransactionObservationPhase
+ {
+ NONE, BEFORE_COMPLETION, AFTER_COMPLETION, AFTER_FAILURE, AFTER_SUCCESS
+ }
+
+ /**
* An event type -> observer list map
*/
private class RegisteredObserversMap extends ForwardingMap<Class<?>,
List<EventObserver<?>>>
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2008-12-02
13:24:58 UTC (rev 389)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2008-12-02
22:26:39 UTC (rev 390)
@@ -31,6 +31,13 @@
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.bean.EventBean;
+import org.jboss.webbeans.event.EventManager.TransactionObservationPhase;
+
+import static
org.jboss.webbeans.event.EventManager.TransactionObservationPhase.AFTER_COMPLETION;
+import static
org.jboss.webbeans.event.EventManager.TransactionObservationPhase.AFTER_FAILURE;
+import static
org.jboss.webbeans.event.EventManager.TransactionObservationPhase.AFTER_SUCCESS;
+import static
org.jboss.webbeans.event.EventManager.TransactionObservationPhase.BEFORE_COMPLETION;
+import static org.jboss.webbeans.event.EventManager.TransactionObservationPhase.NONE;
import org.jboss.webbeans.introspector.AnnotatedMethod;
/**
@@ -80,19 +87,19 @@
List<TransactionObservationPhase> observationPhases = new
ArrayList<TransactionObservationPhase>();
if
(observerMethod.getAnnotatedParameters(BeforeTransactionCompletion.class).isEmpty())
{
- observationPhases.add(TransactionObservationPhase.BEFORE_COMPLETION);
+ observationPhases.add(BEFORE_COMPLETION);
}
if
(observerMethod.getAnnotatedParameters(AfterTransactionCompletion.class).isEmpty())
{
- observationPhases.add(TransactionObservationPhase.AFTER_COMPLETION);
+ observationPhases.add(AFTER_COMPLETION);
}
if
(observerMethod.getAnnotatedParameters(AfterTransactionFailure.class).isEmpty())
{
- observationPhases.add(TransactionObservationPhase.AFTER_FAILURE);
+ observationPhases.add(AFTER_FAILURE);
}
if
(observerMethod.getAnnotatedParameters(AfterTransactionSuccess.class).isEmpty())
{
- observationPhases.add(TransactionObservationPhase.AFTER_SUCCESS);
+ observationPhases.add(AFTER_SUCCESS);
}
if (observationPhases.size() > 1)
{
@@ -104,7 +111,7 @@
}
else
{
- transactionObservationPhase = TransactionObservationPhase.NONE;
+ transactionObservationPhase = NONE;
}
}
Deleted:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/TransactionObservationPhase.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/TransactionObservationPhase.java 2008-12-02
13:24:58 UTC (rev 389)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/TransactionObservationPhase.java 2008-12-02
22:26:39 UTC (rev 390)
@@ -1,29 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jboss.webbeans.event;
-
-/**
- * The known transactional phases a transactional event observer can be
- * interested in
- *
- * @author Nicklas Karlsson
- */
-public enum TransactionObservationPhase
-{
- NONE, BEFORE_COMPLETION, AFTER_COMPLETION, AFTER_FAILURE, AFTER_SUCCESS
-}