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 2010/01/12 18:09:45 UTC
svn commit: r898422 - in /openwebbeans/trunk/webbeans-impl/src:
main/java/org/apache/webbeans/config/
main/java/org/apache/webbeans/container/
main/java/org/apache/webbeans/portable/events/discovery/
main/java/org/apache/webbeans/util/ test/java/org/ap...
Author: struberg
Date: Tue Jan 12 17:09:44 2010
New Revision: 898422
URL: http://svn.apache.org/viewvc?rev=898422&view=rev
Log:
OWB-225 implement functionality for adding additional Scopes and Qualifiers via a CDI Extension
Added:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefaultAnnotation.java (with props)
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ExternalScope.java (with props)
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/ExtensionTest.java (with props)
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScopeContext.java (with props)
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScopeExtension.java (with props)
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScoped.java (with props)
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScopedBean.java (with props)
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/BeforeBeanDiscoveryImpl.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefaultAnnotation.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefaultAnnotation.java?rev=898422&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefaultAnnotation.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefaultAnnotation.java Tue Jan 12 17:09:44 2010
@@ -0,0 +1,41 @@
+/*
+ * 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.config;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+/**
+ * A small helper class to create a Annotation instance of the given annotation class
+ * via {@link java.lang.reflect.Proxy}.
+ * The annotation literal gets filled with the default values.
+ */
+public class DefaultAnnotation implements InvocationHandler{
+ public static Annotation of(Class<? extends Annotation> annotation)
+ {
+ return (Annotation) Proxy.newProxyInstance(annotation.getClassLoader(), new Class[] {annotation}, new DefaultAnnotation());
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+ {
+ return method.getDefaultValue();
+ }
+}
Propchange: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefaultAnnotation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefaultAnnotation.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java?rev=898422&r1=898421&r2=898422&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java Tue Jan 12 17:09:44 2010
@@ -57,6 +57,8 @@
import org.apache.webbeans.component.ProducerFieldBean;
import org.apache.webbeans.component.ProducerMethodBean;
import org.apache.webbeans.config.inheritance.IBeanInheritedMetaData;
+import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.container.ExternalScope;
import org.apache.webbeans.container.InjectionResolver;
import org.apache.webbeans.event.EventUtil;
import org.apache.webbeans.event.NotificationManager;
@@ -211,7 +213,8 @@
{
Class<? extends Annotation> type = annotation.annotationType();
- if (AnnotationUtil.isQualifierAnnotation(type))
+ if (AnnotationUtil.isQualifierAnnotation(type) ||
+ BeanManagerImpl.getManager().getAdditionalQualifiers().contains(type))
{
Method[] methods = type.getDeclaredMethods();
@@ -294,12 +297,38 @@
{
boolean found = false;
+ List<ExternalScope> additionalScopes = BeanManagerImpl.getManager().getAdditionalScopes();
+
for (Annotation annotation : annotations)
{
+ Class<? extends Annotation> annotationType = annotation.annotationType();
+
/*Normal scope*/
- Annotation var = annotation.annotationType().getAnnotation(NormalScope.class);
+ Annotation var = annotationType.getAnnotation(NormalScope.class);
/*Pseudo scope*/
- Annotation pseudo = annotation.annotationType().getAnnotation(Scope.class);
+ Annotation pseudo = annotationType.getAnnotation(Scope.class);
+
+ if (var == null && pseudo == null)
+ {
+ // check for additional scopes registered via a CDI Extension
+ for (ExternalScope additionalScope : additionalScopes)
+ {
+ if (annotationType.equals(additionalScope.getScope()))
+ {
+ // create a proxy which implements the given annotation
+ Annotation scopeAnnotation = additionalScope.getScopeAnnotation();
+
+ if (additionalScope.isNormal())
+ {
+ var = scopeAnnotation;
+ }
+ else
+ {
+ pseudo = scopeAnnotation;
+ }
+ }
+ }
+ }
if (var != null)
{
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java?rev=898422&r1=898421&r2=898422&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java Tue Jan 12 17:09:44 2010
@@ -45,6 +45,7 @@
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.BeforeBeanDiscovery;
import javax.enterprise.inject.spi.Decorator;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.InjectionTarget;
@@ -129,6 +130,19 @@
private WebBeansXMLConfigurator xmlConfigurator = null;
/**
+ * This list contains additional qualifiers which got set via the {@link BeforeBeanDiscovery#addQualifier(Class)}
+ * event function.
+ */
+ private List<Class<? extends Annotation>> additionalQualifiers = Collections.synchronizedList(new ArrayList<Class<? extends Annotation>>());
+
+ /**
+ * This list contains additional scopes which got set via the
+ * {@link BeforeBeanDiscovery#addScope(Class, boolean, boolean)} event function.
+ */
+ private List<ExternalScope> additionalScopes = Collections.synchronizedList(new ArrayList<ExternalScope>());
+
+
+ /**
* The parent Manager this child is depending from.
*/
private BeanManagerImpl parent;
@@ -900,5 +914,29 @@
return null;
}
+ public void addAdditionalQualifier(Class<? extends Annotation> qualifier)
+ {
+ if (!additionalQualifiers.contains(qualifier))
+ {
+ additionalQualifiers.add(qualifier);
+ }
+ }
+ public List<Class<? extends Annotation>> getAdditionalQualifiers()
+ {
+ return additionalQualifiers;
+ }
+
+ public void addAdditionalScope(ExternalScope additionalScope)
+ {
+ if (!additionalScopes.contains(additionalScope))
+ {
+ additionalScopes.add(additionalScope);
+ }
+ }
+
+ public List<ExternalScope> getAdditionalScopes()
+ {
+ return additionalScopes;
+ }
}
\ No newline at end of file
Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ExternalScope.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ExternalScope.java?rev=898422&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ExternalScope.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ExternalScope.java Tue Jan 12 17:09:44 2010
@@ -0,0 +1,70 @@
+/*
+ * 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.container;
+
+
+import java.lang.annotation.Annotation;
+import javax.enterprise.inject.spi.BeforeBeanDiscovery;
+
+import org.apache.webbeans.config.DefaultAnnotation;
+
+
+/**
+ * A wrapper for an external scope which can be added by
+ * {@link BeforeBeanDiscovery#addScope(Class, boolean, boolean)}.
+ */
+public class ExternalScope {
+
+ private Class<? extends Annotation> scope;
+ private boolean normal;
+ private boolean passivating;
+ private Annotation scopeAnnotation;
+
+ public ExternalScope(Class<? extends Annotation> scope, boolean normal, boolean passivating)
+ {
+ this.scope = scope;
+ this.normal = normal;
+ this.passivating = passivating;
+ this.scopeAnnotation = DefaultAnnotation.of(scope);
+ }
+
+ public Class<? extends Annotation> getScope()
+ {
+ return scope;
+ }
+
+ public boolean isNormal()
+ {
+ return normal;
+ }
+
+ public boolean isPassivating()
+ {
+ return passivating;
+ }
+
+ /**
+ * @return an instance of the annotation class we got set
+ * in {@link BeforeBeanDiscovery#addScope(Class, boolean, boolean)}
+ */
+ public Annotation getScopeAnnotation()
+ {
+ return scopeAnnotation;
+ }
+}
Propchange: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ExternalScope.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ExternalScope.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java?rev=898422&r1=898421&r2=898422&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java Tue Jan 12 17:09:44 2010
@@ -65,6 +65,8 @@
@Override
public void addDefinitionError(Throwable t)
{
+ // TODO and where do we evaluate and log those errors? ;)
+ // -> OWB-227
this.errors.add(t);
}
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/BeforeBeanDiscoveryImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/BeforeBeanDiscoveryImpl.java?rev=898422&r1=898421&r2=898422&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/BeforeBeanDiscoveryImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/BeforeBeanDiscoveryImpl.java Tue Jan 12 17:09:44 2010
@@ -18,6 +18,9 @@
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.BeforeBeanDiscovery;
+import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.container.ExternalScope;
+
/**
* Events that is fired before container starts to discover beans.
*
@@ -27,6 +30,13 @@
public class BeforeBeanDiscoveryImpl implements BeforeBeanDiscovery
{
+ private BeanManagerImpl beanManager = null;
+
+ public BeforeBeanDiscoveryImpl()
+ {
+ beanManager = BeanManagerImpl.getManager();
+ }
+
/**
* {@inheritDoc}
*/
@@ -43,7 +53,7 @@
@Override
public void addQualifier(Class<? extends Annotation> qualifier)
{
- // TODO Auto-generated method stub
+ beanManager.addAdditionalQualifier(qualifier);
}
@@ -63,8 +73,8 @@
@Override
public void addScope(Class<? extends Annotation> scope, boolean normal, boolean passivating)
{
- // TODO Auto-generated method stub
-
+ ExternalScope additionalScope = new ExternalScope(scope, normal, passivating);
+ beanManager.addAdditionalScope(additionalScope);
}
/**
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=898422&r1=898421&r2=898422&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java Tue Jan 12 17:09:44 2010
@@ -98,6 +98,7 @@
import org.apache.webbeans.config.EJBWebBeansConfigurator;
import org.apache.webbeans.config.ManagedBeanConfigurator;
import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.container.ExternalScope;
import org.apache.webbeans.conversation.ConversationImpl;
import org.apache.webbeans.decorator.DecoratorUtil;
import org.apache.webbeans.decorator.DecoratorsManager;
@@ -1767,14 +1768,23 @@
{
return true;
}
- else if(scopeType.isAnnotationPresent(Scope.class))
+
+ if(scopeType.isAnnotationPresent(Scope.class))
{
return false;
}
- else
+
+ List<ExternalScope> additionalScopes = BeanManagerImpl.getManager().getAdditionalScopes();
+ for (ExternalScope additionalScope : additionalScopes)
{
- throw new IllegalArgumentException("scopeType argument must be annotated with @Scope or @NormalScope");
+ if (additionalScope.getScope().equals(scopeType))
+ {
+ return additionalScope.isNormal();
+ }
}
+
+ // no scopetype found so far -> kawumms
+ throw new IllegalArgumentException("scopeType argument must be annotated with @Scope or @NormalScope");
}
public static void checkNullInstance(Object instance,Class<?> scopeType, String errorMessage)
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/ExtensionTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/ExtensionTest.java?rev=898422&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/ExtensionTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/ExtensionTest.java Tue Jan 12 17:09:44 2010
@@ -0,0 +1,80 @@
+/*
+ * 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.newtests.portable;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.enterprise.inject.spi.Bean;
+
+import junit.framework.Assert;
+
+import org.apache.webbeans.annotation.DefaultLiteral;
+import org.apache.webbeans.context.ContextFactory;
+import org.apache.webbeans.lifecycle.test.MockServletContext;
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.apache.webbeans.newtests.portable.scopeextension.ExternalTestScopeExtension;
+import org.apache.webbeans.newtests.portable.scopeextension.ExternalTestScopedBean;
+import org.apache.webbeans.portable.events.ExtensionLoader;
+import org.apache.webbeans.portable.events.discovery.BeforeShutdownImpl;
+import org.junit.Test;
+
+/**
+ * This test checks if an extension gets loaded correctly and
+ * if all specified events get fired.
+ */
+public class ExtensionTest extends AbstractUnitTest
+{
+ public ExtensionTest()
+ {
+ }
+
+
+ /**
+ * This test adds a scope and tests if the lifecycle works
+ */
+ @Test
+ public void testScopeExtension()
+ {
+ Collection<Class<?>> classes = new ArrayList<Class<?>>();
+ classes.add(ExternalTestScopedBean.class);
+ addExtension(new ExternalTestScopeExtension());
+ startContainer(classes);
+
+ MockServletContext servletContext = new MockServletContext();
+ ContextFactory.initApplicationContext(servletContext);
+
+ @SuppressWarnings("unchecked")
+ Bean<ExternalTestScopedBean> bean = (Bean<ExternalTestScopedBean>) getBeanManager().getBeans(ExternalTestScopedBean.class,
+ new DefaultLiteral()).iterator().next();
+
+ ExternalTestScopedBean instance = (ExternalTestScopedBean) getBeanManager().getReference(bean, ExternalTestScopedBean.class,
+ getBeanManager().createCreationalContext(bean));
+
+ Assert.assertNotNull(instance);
+
+
+ //Fire shut down
+ getBeanManager().fireEvent(new BeforeShutdownImpl(), new Annotation[0]);
+
+ ContextFactory.destroyApplicationContext(servletContext);
+ }
+
+}
Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/ExtensionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/ExtensionTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScopeContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScopeContext.java?rev=898422&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScopeContext.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScopeContext.java Tue Jan 12 17:09:44 2010
@@ -0,0 +1,73 @@
+/*
+ * 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.newtests.portable.scopeextension;
+
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.enterprise.context.spi.Context;
+import javax.enterprise.context.spi.Contextual;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.BeforeShutdown;
+import javax.enterprise.event.Observes;
+
+public class ExternalTestScopeContext implements Context
+{
+ private static final Map<Contextual<?>, Object> instances = new HashMap<Contextual<?>, Object>();
+
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T get(Contextual<T> component)
+ {
+
+ return (T) instances.get(component);
+ }
+
+ @Override
+ public <T> T get(Contextual<T> component, CreationalContext<T> creationalContext)
+ {
+ @SuppressWarnings("unchecked")
+ T instance = (T) instances.get(component);
+ if (instance == null)
+ {
+ component.create(creationalContext);
+ }
+ return null;
+ }
+
+ @Override
+ public Class<? extends Annotation> getScope()
+ {
+ return ExternalTestScoped.class;
+ }
+
+ @Override
+ public boolean isActive()
+ {
+ return true;
+ }
+
+ public void endContext(@Observes BeforeShutdown beforeShutdown)
+ {
+ // a real world extension would destroy all contextual instances here
+ }
+
+}
Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScopeContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScopeContext.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScopeExtension.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScopeExtension.java?rev=898422&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScopeExtension.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScopeExtension.java Tue Jan 12 17:09:44 2010
@@ -0,0 +1,39 @@
+/*
+ * 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.newtests.portable.scopeextension;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.BeforeBeanDiscovery;
+import javax.enterprise.inject.spi.Extension;
+
+
+public class ExternalTestScopeExtension implements Extension
+{
+
+ public void addViewScoped(@Observes BeforeBeanDiscovery beforeBeanDiscovery)
+ {
+ beforeBeanDiscovery.addScope(ExternalTestScoped.class, true, true);
+ }
+
+ public void registerViewContext(@Observes AfterBeanDiscovery afterBeanDiscovery)
+ {
+ afterBeanDiscovery.addContext(new ExternalTestScopeContext());
+ }
+}
Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScopeExtension.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScopeExtension.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScoped.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScoped.java?rev=898422&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScoped.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScoped.java Tue Jan 12 17:09:44 2010
@@ -0,0 +1,37 @@
+/*
+ * 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.newtests.portable.scopeextension;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Test scope which is not @NormalScoped and not JSR-330 @Scope,
+ * which means it will not get autodetected.
+ */
+@Documented
+@Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+@Inherited
+public @interface ExternalTestScoped {
+
+}
Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScoped.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScoped.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScopedBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScopedBean.java?rev=898422&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScopedBean.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScopedBean.java Tue Jan 12 17:09:44 2010
@@ -0,0 +1,35 @@
+/*
+ * 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.newtests.portable.scopeextension;
+
+@ExternalTestScoped
+public class ExternalTestScopedBean {
+
+ public int i = 0;
+
+ public int getI() {
+ return i;
+ }
+
+ public void setI(int i) {
+ this.i = i;
+ }
+
+
+}
Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScopedBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/scopeextension/ExternalTestScopedBean.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision