You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2009/10/23 19:32:26 UTC
svn commit: r829140 - in /incubator/openwebbeans/trunk/webbeans-impl/src:
main/java/org/apache/webbeans/event/ main/java/org/apache/webbeans/event/xml/
main/java/org/apache/webbeans/plugins/ main/java/org/apache/webbeans/util/
main/java/org/apache/webb...
Author: struberg
Date: Fri Oct 23 17:32:22 2009
New Revision: 829140
URL: http://svn.apache.org/viewvc?rev=829140&view=rev
Log:
OWB-140 rewrite the NotificationManager to utilise the functionality of ObserverMethod<X>
* By using the ObserverMethod#getObserverdQualifiers() we have been able to drop the ObserverWrapper
* fixed the @Default handling filterQualifier
* fixed the @Any handling in the filterQualifier
Added:
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
- copied, changed from r825456, incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/BeanObserverImpl.java
Removed:
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/BeanObserverImpl.java
Modified:
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventUtil.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/xml/BeanObserverXMLImpl.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansXMLConfigurator.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java
incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves1.java
incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/portable/events/MyExtension.java
incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/event/LoggedInObserver.java
incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/event/TypeArgumentInterfaceObserver.java
incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/event/TypeArgumentObserver.java
incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/servlet/TestContext.java
incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/EventTest.java
incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/component/ObserversComponentTest.java
incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/exception/EventExceptionTest.java
incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/portable/events/ExtensionTest.java
incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/xml/definition/XMLDefinitionTest.java
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventUtil.java?rev=829140&r1=829139&r2=829140&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventUtil.java Fri Oct 23 17:32:22 2009
@@ -17,6 +17,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
+import java.util.Set;
import javax.enterprise.event.Event;
import javax.enterprise.event.Observes;
@@ -48,6 +49,11 @@
}
}
+ public static void checkEventBindings(Set<Annotation> annotations)
+ {
+ AnnotationUtil.checkQualifierConditions(annotations);
+ }
+
public static void checkEventBindings(Annotation... annotations)
{
AnnotationUtil.checkQualifierConditions(annotations);
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java?rev=829140&r1=829139&r2=829140&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java Fri Oct 23 17:32:22 2009
@@ -1,15 +1,20 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You 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.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.event;
@@ -18,7 +23,6 @@
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@@ -27,6 +31,7 @@
import javax.enterprise.event.Observes;
import javax.enterprise.event.Reception;
import javax.enterprise.event.TransactionPhase;
+import javax.enterprise.inject.Any;
import javax.enterprise.inject.Default;
import javax.enterprise.inject.TypeLiteral;
import javax.enterprise.inject.spi.ObserverMethod;
@@ -34,6 +39,7 @@
import javax.transaction.Synchronization;
import javax.transaction.Transaction;
+import org.apache.webbeans.annotation.DefaultLiteral;
import org.apache.webbeans.component.InjectionTargetBean;
import org.apache.webbeans.container.BeanManagerImpl;
import org.apache.webbeans.container.activity.ActivityManager;
@@ -51,7 +57,7 @@
{
private static final WebBeansLogger logger = WebBeansLogger.getLogger(NotificationManager.class);
- private final Map<Type, Set<ObserverWrapper<?>>> observers = new ConcurrentHashMap<Type, Set<ObserverWrapper<?>>>();
+ private final Map<Type, Set<ObserverMethod<?>>> observers = new ConcurrentHashMap<Type, Set<ObserverMethod<?>>>();
private final TransactionService transactionService = ServiceLoader.getService(TransactionService.class);
@@ -67,25 +73,25 @@
return manager.getNotificationManager();
}
- public <T> void addObserver(ObserverMethod<T> observer, Type eventType, Annotation... annotations)
+ public <T> void addObserver(ObserverMethod<T> observer, Type eventType)
{
- EventUtil.checkEventBindings(annotations);
+ EventUtil.checkEventBindings(observer.getObservedQualifiers());
- Set<ObserverWrapper<?>> set = observers.get(eventType);
+ Set<ObserverMethod<?>> set = observers.get(eventType);
if (set == null)
{
- set = new HashSet<ObserverWrapper<?>>();
+ set = new HashSet<ObserverMethod<?>>();
observers.put(eventType, set);
}
- set.add(new ObserverWrapper<T>(observer, annotations));
+ set.add(observer);
}
- public <T> void addObserver(ObserverMethod<T> observer, TypeLiteral<T> typeLiteral, Annotation... annotations)
+ public <T> void addObserver(ObserverMethod<T> observer, TypeLiteral<T> typeLiteral)
{
EventUtil.checkEventType(typeLiteral.getRawType());
- addObserver(observer, typeLiteral.getRawType(), annotations);
+ addObserver(observer, typeLiteral.getRawType());
}
public <T> void removeObserver(ObserverMethod<T> observer, Class<T> eventType, Annotation... annotations)
@@ -95,18 +101,16 @@
if (observers.containsKey(eventType))
{
- Set<ObserverWrapper<?>> set = observers.get(eventType);
- for (ObserverWrapper<?> s : set)
+ Set<ObserverMethod<?>> set = observers.get(eventType);
+ for (ObserverMethod<?> ob : set)
{
- ObserverMethod<T> ob = (ObserverMethod<T>) s.getObserver();
-
- Set<Annotation> evenBindings = s.getQualifiers();
+ Set<Annotation> evenBindings = ob.getObservedQualifiers();
Annotation[] anns = new Annotation[evenBindings.size()];
anns = evenBindings.toArray(anns);
if (ob.equals(observer) && Arrays.equals(anns, annotations))
{
- set.remove(s);
+ set.remove(ob);
}
}
}
@@ -121,19 +125,21 @@
{
EventUtil.checkEventBindings(eventQualifiers);
+ Set<Annotation> qualifiers = toQualiferSet(eventQualifiers);
+
Class<T> eventType = (Class<T>) event.getClass();
//EventUtil.checkEventType(eventType);
- Set<ObserverWrapper<T>> wrappers = filterByType(eventType);
+ Set<ObserverMethod<T>> observers = filterByType(eventType);
- wrappers = filterByQualifiers(wrappers, eventQualifiers);
+ observers = filterByQualifiers(observers, qualifiers);
- return unwrap(wrappers);
+ return observers;
}
- private <T> Set<ObserverWrapper<T>> filterByType(Class<T> eventType)
+ private <T> Set<ObserverMethod<T>> filterByType(Class<T> eventType)
{
- Set<ObserverWrapper<T>> matching = new HashSet<ObserverWrapper<T>>();
+ Set<ObserverMethod<T>> matching = new HashSet<ObserverMethod<T>>();
Set<Type> types = new HashSet<Type>();
ClassUtil.setTypeHierarchy(types, eventType);
@@ -146,11 +152,11 @@
{
if (ClassUtil.isAssignable(check, type))
{
- Set<ObserverWrapper<?>> wrappers = this.observers.get(type);
+ Set<ObserverMethod<?>> wrappers = this.observers.get(type);
- for (ObserverWrapper<?> wrapper : wrappers)
+ for (ObserverMethod<?> wrapper : wrappers)
{
- matching.add((ObserverWrapper<T>) wrapper);
+ matching.add((ObserverMethod<T>) wrapper);
}
break;
}
@@ -159,15 +165,22 @@
return matching;
}
- private <T> Set<ObserverWrapper<T>> filterByQualifiers(Set<ObserverWrapper<T>> wrappers, Annotation... annotations)
+ /**
+ * filter out all {@code ObserverMethod}s which do not fit the given qualifiers.
+ */
+ private <T> Set<ObserverMethod<T>> filterByQualifiers(Set<ObserverMethod<T>> observers, Set<Annotation> eventQualifiers)
{
- Set<Annotation> eventQualifiers = toQualiferSet(annotations);
-
- Set<ObserverWrapper<T>> matching = new HashSet<ObserverWrapper<T>>();
-
- search: for (ObserverWrapper<T> wrapper : wrappers)
+ if (eventQualifiers.size() == 1 && eventQualifiers.iterator().next() instanceof Any)
+ {
+ return observers;
+ }
+
+ Set<ObserverMethod<T>> matching = new HashSet<ObserverMethod<T>>();
+
+ search:
+ for (ObserverMethod<T> ob : observers)
{
- Set<Annotation> qualifiers = wrapper.getQualifiers();
+ Set<Annotation> qualifiers = ob.getObservedQualifiers();
if (qualifiers.size() > eventQualifiers.size())
{
@@ -182,23 +195,11 @@
}
}
- matching.add(wrapper);
+ matching.add(ob);
}
return matching;
}
-
- private <T> Set<ObserverMethod<T>> unwrap(Set<ObserverWrapper<T>> wrappers)
- {
- Set<ObserverMethod<T>> observers = new HashSet<ObserverMethod<T>>();
-
- for (ObserverWrapper<T> wrapper : wrappers)
- {
- observers.add(wrapper.getObserver());
- }
-
- return observers;
- }
public void fireEvent(Object event, Annotation... qualifiers)
{
@@ -272,8 +273,6 @@
{
Observes observes = AnnotationUtil.getMethodFirstParameterAnnotation(observableMethod, Observes.class);
- Annotation[] qualifiers = AnnotationUtil.getMethodFirstParameterQualifierWithGivenAnnotation(observableMethod, Observes.class);
-
boolean ifExist = false;
if (observes.notifyObserver().equals(Reception.IF_EXISTS))
@@ -281,66 +280,31 @@
ifExist = true;
}
- //X TODO TransactionPhase phase = EventUtil.getObserverMethodTransactionType(observableMethod);
-
- BeanObserverImpl<T> observer = new BeanObserverImpl(component, observableMethod, ifExist);
+ ObserverMethodImpl<T> observer = new ObserverMethodImpl(component, observableMethod, ifExist);
Class<T> clazz = (Class<T>) AnnotationUtil.getMethodFirstParameterTypeClazzWithAnnotation(observableMethod, Observes.class);
- addObserver(observer, clazz, qualifiers);
+ addObserver(observer, clazz);
}
}
- private static Set<Annotation> toQualiferSet(Annotation... qualifiers)
- {
- Set<Annotation> set = ArrayUtil.asSet(qualifiers);
-
- return pruneDefault(set);
- }
-
- private static Set<Annotation> pruneDefault(Set<Annotation> set) {
- Iterator<Annotation> iterator = set.iterator();
- while (iterator.hasNext()) {
- if (iterator.next() instanceof Default)
- {
- iterator.remove();
- }
- }
- return set;
- }
-
/**
- * Wrapper around the {@link javax.enterprise.event.Observer} instance.
- *
- * @param <T> generic event type
+ * Converts the given qualifiers array to a Set.
+ * This function additionally fixes @Default and @Any conditions.
*/
- private static class ObserverWrapper<T>
+ private static Set<Annotation> toQualiferSet(Annotation... qualifiers)
{
- /** Event qualifiers appearing on the parameter */
- private final Set<Annotation> qualifiers;
-
- /**Wrapped observer instance*/
- private final ObserverMethod<T> observer;
-
- public ObserverWrapper(ObserverMethod<T> observer, Annotation... qualifiers)
- {
- this.qualifiers = toQualiferSet(qualifiers);
- this.qualifiers.remove(Default.class);
- this.observer = observer;
- }
-
- public Set<Annotation> getQualifiers()
- {
- return this.qualifiers;
- }
+ Set<Annotation> set = ArrayUtil.asSet(qualifiers);
- public ObserverMethod<T> getObserver()
+ if (qualifiers.length == 0)
{
- return observer;
+ set.add(new DefaultLiteral());
}
+
+ return set;
}
-
+
private static class AbstractSynchronization<T> implements Synchronization {
private final ObserverMethod<T> observer;
@@ -354,10 +318,12 @@
public void beforeCompletion()
{
+ // TODO
}
public void afterCompletion(int i)
{
+ // TODO
}
public void notifyObserver() {
Copied: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java (from r825456, incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/BeanObserverImpl.java)
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java?p2=incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java&p1=incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/BeanObserverImpl.java&r1=825456&r2=829140&rev=829140&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/BeanObserverImpl.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java Fri Oct 23 17:32:22 2009
@@ -1,15 +1,20 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You 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.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.event;
@@ -18,6 +23,7 @@
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -26,7 +32,6 @@
import javax.enterprise.event.Observes;
import javax.enterprise.event.Reception;
import javax.enterprise.event.TransactionPhase;
-import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.ObserverMethod;
import org.apache.webbeans.annotation.DefaultLiteral;
@@ -62,10 +67,10 @@
*
* @param <T> event type
*/
-public class BeanObserverImpl<T> implements ObserverMethod<T>
+public class ObserverMethodImpl<T> implements ObserverMethod<T>
{
/**Logger instance*/
- private static final WebBeansLogger logger = WebBeansLogger.getLogger(BeanObserverImpl.class);
+ private static final WebBeansLogger logger = WebBeansLogger.getLogger(ObserverMethodImpl.class);
/**Observer owner bean that defines observer method*/
private final InjectionTargetBean<?> bean;
@@ -75,7 +80,17 @@
/**Using existing bean instance or not*/
private final boolean ifExist;
-
+
+ /** the observed qualifiers */
+ private final Set<Annotation> observedQualifiers;
+
+ /** the type of the observed event */
+ private final Type observedEventType;
+
+ /** the transaction phase */
+ private final TransactionPhase phase;
+
+
/**
* Creates a new bean observer instance.
*
@@ -84,11 +99,48 @@
* @param ifExist if exist parameter
* @param type transaction type
*/
- public BeanObserverImpl(InjectionTargetBean<?> bean, Method observerMethod, boolean ifExist)
+ public ObserverMethodImpl(InjectionTargetBean<?> bean, Method observerMethod, boolean ifExist)
{
this.bean = bean;
this.observerMethod = observerMethod;
this.ifExist = ifExist;
+
+ Annotation[] qualifiers = AnnotationUtil.getMethodFirstParameterQualifierWithGivenAnnotation(observerMethod, Observes.class);
+ AnnotationUtil.checkQualifierConditions(qualifiers);
+ this.observedQualifiers = new HashSet<Annotation>(qualifiers.length);
+
+ for (Annotation qualifier : qualifiers)
+ {
+ observedQualifiers.add(qualifier);
+ }
+
+ this.observedEventType = null; //X TODO
+
+ this.phase = EventUtil.getObserverMethodTransactionType(observerMethod);
+ }
+
+ /**
+ * used if the qualifiers and event type are already known, e.g. from the XML.
+ * @param bean
+ * @param observerMethod
+ * @param ifExist
+ * @param observedQualifiers
+ * @param observedEventType
+ */
+ protected ObserverMethodImpl(InjectionTargetBean<?> bean, Method observerMethod, boolean ifExist,
+ Annotation[] qualifiers, Type observedEventType)
+ {
+ this.bean = bean;
+ this.observerMethod = observerMethod;
+ this.ifExist = ifExist;
+ this.observedQualifiers = new HashSet<Annotation>(qualifiers.length);
+ for (Annotation qualifier : qualifiers)
+ {
+ observedQualifiers.add(qualifier);
+ }
+ this.observedEventType = null; //X TODO
+ this.phase = EventUtil.getObserverMethodTransactionType(observerMethod); //X TODO might be overriden via XML?
+
}
/**
@@ -234,24 +286,30 @@
return bean.getClass();
}
- public Set<Annotation> getObservedQualifiers() {
- // TODO Auto-generated method stub
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public Set<Annotation> getObservedQualifiers()
+ {
+ return observedQualifiers;
}
-
+
+ /**
+ * {@inheritDoc}
+ */
public Type getObservedType() {
- // TODO Auto-generated method stub
- return null;
+ return observedEventType;
}
+ /**
+ * {@inheritDoc}
+ */
public Reception getReception() {
- // TODO Auto-generated method stub
- return null;
+ return ifExist ? Reception.IF_EXISTS : Reception.ALWAYS;
}
public TransactionPhase getTransactionPhase() {
- // TODO Auto-generated method stub
- return null;
+ return phase;
}
}
\ No newline at end of file
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/xml/BeanObserverXMLImpl.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/xml/BeanObserverXMLImpl.java?rev=829140&r1=829139&r2=829140&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/xml/BeanObserverXMLImpl.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/xml/BeanObserverXMLImpl.java Fri Oct 23 17:32:22 2009
@@ -1,20 +1,26 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You 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.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.event.xml;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
+import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -22,16 +28,17 @@
import org.apache.webbeans.component.InjectionTargetBean;
import org.apache.webbeans.container.BeanManagerImpl;
import org.apache.webbeans.container.InjectionResolver;
-import org.apache.webbeans.event.BeanObserverImpl;
+import org.apache.webbeans.event.ObserverMethodImpl;
import org.apache.webbeans.inject.xml.XMLInjectionPointModel;
-public class BeanObserverXMLImpl<T> extends BeanObserverImpl<T>
+public class BeanObserverXMLImpl<T> extends ObserverMethodImpl<T>
{
private List<XMLInjectionPointModel> observersParameters = new ArrayList<XMLInjectionPointModel>();
- public BeanObserverXMLImpl(InjectionTargetBean<?> bean, Method observerMethod, boolean ifExist)
+ public BeanObserverXMLImpl(InjectionTargetBean<?> bean, Method observerMethod, boolean ifExist,
+ Annotation[] observedQualifiers, Type observedType)
{
- super(bean, observerMethod, ifExist);
+ super(bean, observerMethod, ifExist, observedQualifiers, observedType);
}
/*
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java?rev=829140&r1=829139&r2=829140&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java Fri Oct 23 17:32:22 2009
@@ -146,9 +146,9 @@
}
/**
- * Gets ejb plugin
+ * Gets the JMS plugin
*
- * @return ejb plugin
+ * @return jms plugin
*/
public OpenWebBeansJmsPlugin getJmsPlugin()
{
@@ -164,7 +164,7 @@
}
/**
- * Gets ejb plugin
+ * Gets the EE resource plugin
*
* @return ejb plugin
*/
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java?rev=829140&r1=829139&r2=829140&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java Fri Oct 23 17:32:22 2009
@@ -728,46 +728,50 @@
public static void checkQualifierConditions(Annotation... qualifierAnnots)
{
- Annotation before = null;
+ Set<Annotation> annSet = ArrayUtil.asSet(qualifierAnnots);
+ //check for duplicate annotations
+ if (qualifierAnnots.length != annSet.size())
+ {
+ throw new IllegalArgumentException("Qualifier annotations can not contain duplicate qualifiers:" + qualifierAnnots);
+ }
+
+ checkQualifierConditions(annSet);
+ }
+
+ /**
+ * This function obviously cannot check for duplicate annotations.
+ * So this must have been done before!
+ * @param qualifierAnnots
+ */
+ public static void checkQualifierConditions(Set<Annotation> qualifierAnnots)
+ {
for (Annotation ann : qualifierAnnots)
{
- Method[] methods = ann.annotationType().getDeclaredMethods();
+ checkQualifierConditions(ann);
+ }
+ }
- for (Method method : methods)
- {
- Class<?> clazz = method.getReturnType();
- if (clazz.isArray() || clazz.isAnnotation())
- {
- if (!AnnotationUtil.hasAnnotation(method.getDeclaredAnnotations(), NonBinding.class))
- {
- throw new WebBeansConfigurationException("@Qualifier : " + ann.annotationType().getName() + " must have @NonBinding valued members for its array-valued and annotation valued members");
- }
- }
- }
-
-
- if (!AnnotationUtil.isQualifierAnnotation(ann.annotationType()))
- {
- throw new IllegalArgumentException("Qualifier annotations must be annotated with @Qualifier");
- }
+ private static void checkQualifierConditions(Annotation ann) {
+ Method[] methods = ann.annotationType().getDeclaredMethods();
- if (before == null)
- {
- before = ann;
- }
- else
+ for (Method method : methods)
+ {
+ Class<?> clazz = method.getReturnType();
+ if (clazz.isArray() || clazz.isAnnotation())
{
- if (before.equals(ann))
- {
- throw new IllegalArgumentException("Qualifier annotations can not contain duplicate qualifier : @" + before.annotationType().getName());
- }
- else
+ if (!AnnotationUtil.hasAnnotation(method.getDeclaredAnnotations(), NonBinding.class))
{
- before = ann;
+ throw new WebBeansConfigurationException("@Qualifier : " + ann.annotationType().getName() + " must have @NonBinding valued members for its array-valued and annotation valued members");
}
}
}
+
+
+ if (!AnnotationUtil.isQualifierAnnotation(ann.annotationType()))
+ {
+ throw new IllegalArgumentException("Qualifier annotations must be annotated with @Qualifier");
+ }
}
/**
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansXMLConfigurator.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansXMLConfigurator.java?rev=829140&r1=829139&r2=829140&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansXMLConfigurator.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansXMLConfigurator.java Fri Oct 23 17:32:22 2009
@@ -1334,6 +1334,7 @@
* <Initializes> = 0; <Produces> = 1; <Disposes> = 2; <Observes> = 3;
* <Destructor> = 4; InterceptorBindingType annotation on method = 5;
*/
+ //X TODO replace this with an enum or constants for better readability!
int type = 0;
/* Method parameters classes */
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java?rev=829140&r1=829139&r2=829140&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java Fri Oct 23 17:32:22 2009
@@ -700,6 +700,9 @@
}
}
+ /**
+ * TODO review the logic of this function. It is a bit unintuitive why the childElement loop exists
+ */
public static <T, K> void defineXMLObservesMethod(XMLManagedBean<T> component, Method observesMethod, Element observesMethodElement, String errorMessage)
{
component.addObservableMethod(observesMethod);
@@ -709,8 +712,8 @@
/* Other parameter elements other than @Observes */
List<Element> otherParameterElements = new ArrayList<Element>();
-
- BeanObserverXMLImpl<K> beanObserver = new BeanObserverXMLImpl<K>(component, observesMethod, false);
+
+ BeanObserverXMLImpl<K> beanObserver = null;
Class<K> eventType = null;
@@ -732,9 +735,12 @@
Annotation[] bindingAnns = new Annotation[bindingTypes.size()];
bindingAnns = bindingTypes.toArray(bindingAnns);
+ beanObserver = new BeanObserverXMLImpl<K>(component, observesMethod, false,
+ bindingAnns, null /** TODO Type! */);
+
beanObserver.addXMLInjectionObservesParameter(model);
- NotificationManager.getInstance().addObserver(beanObserver, eventType, bindingAnns);
+ NotificationManager.getInstance().addObserver(beanObserver, eventType);
}
/* Disposal method parameter other than @Disposes */
@@ -745,10 +751,13 @@
}// end of for childs
/* Add other params injection point models */
- for (Element otherElement : otherParameterElements)
+ if (beanObserver != null)
{
- XMLInjectionPointModel injectionPointParamModel = XMLUtil.getInjectionPointModel(otherElement, errorMessage);
- beanObserver.addXMLInjectionObservesParameter(injectionPointParamModel);
+ for (Element otherElement : otherParameterElements)
+ {
+ XMLInjectionPointModel injectionPointParamModel = XMLUtil.getInjectionPointModel(otherElement, errorMessage);
+ beanObserver.addXMLInjectionObservesParameter(injectionPointParamModel);
+ }
}
}
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves1.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves1.java?rev=829140&r1=829139&r2=829140&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves1.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves1.java Fri Oct 23 17:32:22 2009
@@ -16,15 +16,11 @@
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.Any;
-import javax.enterprise.inject.Default;
-import org.apache.webbeans.annotation.deployment.Production;
import org.apache.webbeans.test.annotation.binding.Check;
import org.apache.webbeans.test.event.LoggedInEvent;
-@Production
@RequestScoped
-@Default
public class ComponentWithObserves1
{
private String userName;
@@ -34,13 +30,11 @@
public void afterLoggedIn(@Observes @Any LoggedInEvent event)
{
this.userName = event.getUserName();
-
}
public void afterLoggedInWithMember(@Observes @Check(type = "CHECK") LoggedInEvent event)
{
this.userNameWithMember = event.getUserName();
-
}
public String getUserName()
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/portable/events/MyExtension.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/portable/events/MyExtension.java?rev=829140&r1=829139&r2=829140&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/portable/events/MyExtension.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/portable/events/MyExtension.java Fri Oct 23 17:32:22 2009
@@ -1,15 +1,20 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You 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.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.test.component.portable.events;
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/event/LoggedInObserver.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/event/LoggedInObserver.java?rev=829140&r1=829139&r2=829140&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/event/LoggedInObserver.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/event/LoggedInObserver.java Fri Oct 23 17:32:22 2009
@@ -1,15 +1,20 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You 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.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.test.event;
@@ -21,15 +26,23 @@
import javax.enterprise.event.TransactionPhase;
import javax.enterprise.inject.spi.ObserverMethod;
-
+/**
+ * Test mock ObserverMethod which observes a LoggedInEvent
+ */
public class LoggedInObserver implements ObserverMethod<LoggedInEvent>
{
private String result = null;
+ private final Set<Annotation> qualifiers;
+
+ public LoggedInObserver(Set<Annotation> anns)
+ {
+ this.qualifiers = anns;
+ }
+
public void notify(LoggedInEvent event)
{
result = "ok";
-
}
/**
@@ -50,32 +63,27 @@
@Override
public Class<?> getBeanClass() {
- // TODO Auto-generated method stub
return null;
}
@Override
public Set<Annotation> getObservedQualifiers() {
- // TODO Auto-generated method stub
- return null;
+ return qualifiers;
}
@Override
public Type getObservedType() {
- // TODO Auto-generated method stub
- return null;
+ return LoggedInEvent.class;
}
@Override
public Reception getReception() {
- // TODO Auto-generated method stub
- return null;
+ return Reception.ALWAYS;
}
@Override
public TransactionPhase getTransactionPhase() {
- // TODO Auto-generated method stub
- return null;
+ return TransactionPhase.IN_PROGRESS;
}
}
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/event/TypeArgumentInterfaceObserver.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/event/TypeArgumentInterfaceObserver.java?rev=829140&r1=829139&r2=829140&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/event/TypeArgumentInterfaceObserver.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/event/TypeArgumentInterfaceObserver.java Fri Oct 23 17:32:22 2009
@@ -1,15 +1,20 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You 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.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.test.event;
@@ -21,11 +26,20 @@
import javax.enterprise.event.TransactionPhase;
import javax.enterprise.inject.spi.ObserverMethod;
-
+/**
+ * Test mock ObserverMethod which observes instances of TypeArgumenEventInterface implementations.
+ */
public class TypeArgumentInterfaceObserver implements ObserverMethod<ITypeArgumentEventInterface>
{
private String result;
+ private final Set<Annotation> qualifiers;
+
+
+ public TypeArgumentInterfaceObserver(Set<Annotation> anns) {
+ this.qualifiers = anns;
+ }
+
public void notify(ITypeArgumentEventInterface event)
{
this.result = "ok";
@@ -44,8 +58,7 @@
@Override
public Set<Annotation> getObservedQualifiers() {
- // TODO Auto-generated method stub
- return null;
+ return qualifiers;
}
@Override
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/event/TypeArgumentObserver.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/event/TypeArgumentObserver.java?rev=829140&r1=829139&r2=829140&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/event/TypeArgumentObserver.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/event/TypeArgumentObserver.java Fri Oct 23 17:32:22 2009
@@ -1,15 +1,20 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You 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.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.test.event;
@@ -21,11 +26,20 @@
import javax.enterprise.event.TransactionPhase;
import javax.enterprise.inject.spi.ObserverMethod;
-
+/**
+ * Test mock ObserverMethod which observes a TypeArgumentBaseEvent
+ */
public class TypeArgumentObserver implements ObserverMethod<TypeArgumentBaseEvent>
{
private String result = null;
+ private final Set<Annotation> qualifiers;
+
+ public TypeArgumentObserver(Set<Annotation> anns)
+ {
+ this.qualifiers = anns;
+ }
+
public void notify(TypeArgumentBaseEvent event)
{
result = "ok";
@@ -45,8 +59,7 @@
@Override
public Set<Annotation> getObservedQualifiers() {
- // TODO Auto-generated method stub
- return null;
+ return qualifiers;
}
@Override
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/servlet/TestContext.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/servlet/TestContext.java?rev=829140&r1=829139&r2=829140&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/servlet/TestContext.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/servlet/TestContext.java Fri Oct 23 17:32:22 2009
@@ -625,7 +625,6 @@
*/
public void startTests(ServletContext ctx)
{
-
}
}
\ No newline at end of file
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/EventTest.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/EventTest.java?rev=829140&r1=829139&r2=829140&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/EventTest.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/EventTest.java Fri Oct 23 17:32:22 2009
@@ -14,7 +14,10 @@
package org.apache.webbeans.test.unittests.event;
import java.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.Set;
+import javax.enterprise.context.NormalScope;
import javax.enterprise.inject.AnnotationLiteral;
import javax.enterprise.inject.TypeLiteral;
import javax.servlet.ServletContext;
@@ -29,6 +32,7 @@
import org.apache.webbeans.test.event.TypeArgumentInterfaceObserver;
import org.apache.webbeans.test.event.TypeArgumentObserver;
import org.apache.webbeans.test.servlet.TestContext;
+import org.apache.webbeans.util.ArrayUtil;
import org.junit.Assert;
import org.junit.Test;
@@ -55,8 +59,8 @@
{
};
- LoggedInObserver observer = new LoggedInObserver();
- NotificationManager.getInstance().addObserver(observer, LoggedInEvent.class, anns);
+ LoggedInObserver observer = new LoggedInObserver(ArrayUtil.asSet(anns));
+ NotificationManager.getInstance().addObserver(observer, LoggedInEvent.class);
getManager().fireEvent(new LoggedInEvent(), anns);
@@ -71,12 +75,12 @@
{
};
- TypeArgumentObserver observer = new TypeArgumentObserver();
+ TypeArgumentObserver observer = new TypeArgumentObserver(ArrayUtil.asSet(anns));
TypeLiteral<TypeArgumentBaseEvent> tl = new TypeLiteral<TypeArgumentBaseEvent>()
{
};
- NotificationManager.getInstance().addObserver(observer, tl, anns);
+ NotificationManager.getInstance().addObserver(observer, tl);
getManager().fireEvent(new TypeArgumentEvent(), anns);
@@ -91,8 +95,8 @@
{
};
- TypeArgumentInterfaceObserver observer = new TypeArgumentInterfaceObserver();
- NotificationManager.getInstance().addObserver(observer, ITypeArgumentEventInterface.class, anns);
+ TypeArgumentInterfaceObserver observer = new TypeArgumentInterfaceObserver(ArrayUtil.asSet(anns));
+ NotificationManager.getInstance().addObserver(observer, ITypeArgumentEventInterface.class);
getManager().fireEvent(new TypeArgumentEvent(), anns);
Assert.assertEquals("ok", observer.getResult());
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/component/ObserversComponentTest.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/component/ObserversComponentTest.java?rev=829140&r1=829139&r2=829140&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/component/ObserversComponentTest.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/component/ObserversComponentTest.java Fri Oct 23 17:32:22 2009
@@ -119,6 +119,28 @@
}
@Test
+ public void testFireWithAtAnyQualifier()
+ {
+ clear();
+
+ AbstractBean<ComponentWithObserves1> component = defineSimpleWebBean(ComponentWithObserves1.class);
+ ContextFactory.initRequestContext(null);
+
+ LoggedInEvent event = new LoggedInEvent("Mark");
+
+ Annotation[] anns = new Annotation[1];
+ anns[0] = new AnyLiteral();
+
+ getManager().fireEvent(event, anns);
+
+ ComponentWithObserves1 instance = getManager().getInstance(component);
+
+ Assert.assertEquals("Mark", instance.getUserName());
+ Assert.assertEquals("Mark", instance.getUserNameWithMember());
+ }
+
+
+ @Test
public void testObservesWithBindingMember2()
{
clear();
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/exception/EventExceptionTest.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/exception/EventExceptionTest.java?rev=829140&r1=829139&r2=829140&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/exception/EventExceptionTest.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/exception/EventExceptionTest.java Fri Oct 23 17:32:22 2009
@@ -14,6 +14,8 @@
package org.apache.webbeans.test.unittests.event.exception;
import java.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.Set;
import javax.enterprise.context.NormalScope;
import javax.enterprise.inject.AnnotationLiteral;
@@ -25,6 +27,7 @@
import org.apache.webbeans.test.event.LoggedInObserver;
import org.apache.webbeans.test.event.broke.BrokenEvent;
import org.apache.webbeans.test.servlet.TestContext;
+import org.apache.webbeans.util.ArrayUtil;
import org.junit.Assert;
import org.junit.Test;
@@ -82,16 +85,13 @@
};
getManager().fireEvent(new BrokenEvent(), anns);
+ Assert.fail();
}
catch (Exception e)
{
- System.out.println(e.getMessage());
- exc = e;
+ // this is an expected exception!
}
-
- Assert.assertNotNull(exc);
-
}
@Test
@@ -109,8 +109,8 @@
{
};
- LoggedInObserver observer = new LoggedInObserver();
- NotificationManager.getInstance().addObserver(observer, LoggedInEvent.class, anns);
+ LoggedInObserver observer = new LoggedInObserver(ArrayUtil.asSet(anns));
+ NotificationManager.getInstance().addObserver(observer, LoggedInEvent.class);
getManager().fireEvent(new LoggedInEvent(), anns);
@@ -134,13 +134,13 @@
try
{
- Annotation[] anns = new Annotation[1];
+ Annotation[] anns = new Annotation[2];
anns[0] = new AnnotationLiteral<NormalScope>()
{
};
-
- LoggedInObserver observer = new LoggedInObserver();
- NotificationManager.getInstance().addObserver(observer, LoggedInEvent.class, anns);
+
+ LoggedInObserver observer = new LoggedInObserver(ArrayUtil.asSet(anns));
+ NotificationManager.getInstance().addObserver(observer, LoggedInEvent.class);
getManager().fireEvent(new LoggedInEvent(), anns);
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/portable/events/ExtensionTest.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/portable/events/ExtensionTest.java?rev=829140&r1=829139&r2=829140&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/portable/events/ExtensionTest.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/portable/events/ExtensionTest.java Fri Oct 23 17:32:22 2009
@@ -1,15 +1,20 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You 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.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.test.unittests.portable.events;
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/xml/definition/XMLDefinitionTest.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/xml/definition/XMLDefinitionTest.java?rev=829140&r1=829139&r2=829140&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/xml/definition/XMLDefinitionTest.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/xml/definition/XMLDefinitionTest.java Fri Oct 23 17:32:22 2009
@@ -19,12 +19,14 @@
import org.apache.webbeans.component.xml.XMLManagedBean;
import org.apache.webbeans.context.ContextFactory;
import org.apache.webbeans.context.creational.CreationalContextFactory;
+import org.apache.webbeans.plugins.PluginLoader;
import org.apache.webbeans.test.annotation.binding.Mock;
import org.apache.webbeans.test.servlet.TestContext;
import org.apache.webbeans.test.xml.definition.Definition1;
import org.apache.webbeans.test.xml.definition.Definition2;
import org.apache.webbeans.test.xml.definition.TstBeanConstructor;
import org.apache.webbeans.test.xml.definition.TstBeanUnnamed;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -42,8 +44,17 @@
initDefaultDeploymentTypes();
initializeDeploymentType(Mock.class, 2);
initDependentContext();
+
+ // initialize the plugin. There are no plugins, but we should not get any NPEs
+ PluginLoader.getInstance().startUp();
}
+ @After
+ public void shutDown()
+ {
+ PluginLoader.getInstance().shutDown();
+ }
+
@Test
public void testDefinition1()
{