[webbeans-commits] Webbeans SVN: r3661 - ri/trunk/impl/src/main/java/org/jboss/webbeans/bean and 5 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Mon Sep 14 11:46:43 EDT 2009
Author: pete.muir at jboss.org
Date: 2009-09-14 11:46:43 -0400 (Mon, 14 Sep 2009)
New Revision: 3661
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ee/
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ee/EEResourceProducerField.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ee/PersistenceContextProducerField.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/ws/
ri/trunk/impl/src/main/java/org/jboss/webbeans/ws/WSApiAbstraction.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ProducerField.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AbstractBeanDeployer.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/PersistenceContextInjectionTest.java
tck/trunk/impl/src/main/resources/tck-audit-cdi.xml
Log:
WBRI-377
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ProducerField.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ProducerField.java 2009-09-14 15:42:41 UTC (rev 3660)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ProducerField.java 2009-09-14 15:46:43 UTC (rev 3661)
@@ -29,7 +29,7 @@
import org.jboss.webbeans.util.Names;
/**
- * Represents a producer field bean
+ * Represents a producer field
*
* @author Pete Muir
*
@@ -42,12 +42,12 @@
private final String id;
/**
- * Creates a producer field Web Bean
+ * Creates a producer field
*
* @param field The underlying method abstraction
* @param declaringBean The declaring bean abstraction
* @param manager the current manager
- * @return A producer Web Bean
+ * @return A producer field
*/
public static <T> ProducerField<T> of(WBField<T, ?> field, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
{
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ee/EEResourceProducerField.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ee/EEResourceProducerField.java (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ee/EEResourceProducerField.java 2009-09-14 15:46:43 UTC (rev 3661)
@@ -0,0 +1,74 @@
+/*
+ * 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.bean.ee;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.bean.AbstractClassBean;
+import org.jboss.webbeans.bean.ProducerField;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
+import org.jboss.webbeans.ejb.EJBApiAbstraction;
+import org.jboss.webbeans.introspector.WBField;
+import org.jboss.webbeans.persistence.PersistenceApiAbstraction;
+import org.jboss.webbeans.ws.WSApiAbstraction;
+
+/**
+ * @author pmuir
+ *
+ */
+public class EEResourceProducerField<T> extends ProducerField<T>
+{
+
+ /**
+ * Creates an EE resource producer field
+ *
+ * @param field The underlying method abstraction
+ * @param declaringBean The declaring bean abstraction
+ * @param manager the current manager
+ * @return A producer field
+ */
+ public static <T> EEResourceProducerField<T> of(WBField<T, ?> field, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
+ {
+ return new EEResourceProducerField<T>(field, declaringBean, manager);
+ }
+
+ protected EEResourceProducerField(WBField<T, ?> field, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
+ {
+ super(field, declaringBean, manager);
+ }
+
+ @Override
+ public void initialize(BeanDeployerEnvironment environment)
+ {
+ if (!isInitialized())
+ {
+ super.initialize(environment);
+ checkEEResource();
+ }
+ }
+
+ protected void checkEEResource()
+ {
+ EJBApiAbstraction ejbApiAbstraction = manager.getServices().get(EJBApiAbstraction.class);
+ PersistenceApiAbstraction persistenceApiAbstraction = manager.getServices().get(PersistenceApiAbstraction.class);
+ WSApiAbstraction wsApiAbstraction = manager.getServices().get(WSApiAbstraction.class);
+ if (!(getAnnotatedItem().isAnnotationPresent(ejbApiAbstraction.RESOURCE_ANNOTATION_CLASS) || getAnnotatedItem().isAnnotationPresent(persistenceApiAbstraction.PERSISTENCE_CONTEXT_ANNOTATION_CLASS) || getAnnotatedItem().isAnnotationPresent(persistenceApiAbstraction.PERSISTENCE_UNIT_ANNOTATION_CLASS) || getAnnotatedItem().isAnnotationPresent(ejbApiAbstraction.EJB_ANNOTATION_CLASS)) || getAnnotatedItem().isAnnotationPresent(wsApiAbstraction.WEB_SERVICE_REF_ANNOTATION_CLASS))
+ {
+ throw new IllegalStateException("Tried to create an EEResourceProducerField, but no @Resource, @PersistenceContext, @PersistenceUnit, @WebServiceRef or @EJB is present " + getAnnotatedItem());
+ }
+ }
+
+}
Property changes on: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ee/EEResourceProducerField.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ee/PersistenceContextProducerField.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ee/PersistenceContextProducerField.java (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ee/PersistenceContextProducerField.java 2009-09-14 15:46:43 UTC (rev 3661)
@@ -0,0 +1,60 @@
+/*
+ * 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.bean.ee;
+
+import javax.persistence.EntityManager;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.bean.AbstractClassBean;
+import org.jboss.webbeans.introspector.WBField;
+
+/**
+ * @author pmuir
+ *
+ */
+public class PersistenceContextProducerField<T extends EntityManager> extends EEResourceProducerField<T>
+{
+
+ /**
+ * Creates an EE resource producer field
+ *
+ * @param field The underlying method abstraction
+ * @param declaringBean The declaring bean abstraction
+ * @param manager the current manager
+ * @return A producer field
+ */
+ public static <T extends EntityManager> EEResourceProducerField<T> of(WBField<T, ?> field, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
+ {
+ return new PersistenceContextProducerField<T>(field, declaringBean, manager);
+ }
+
+ /**
+ * @param field
+ * @param declaringBean
+ * @param manager
+ */
+ protected PersistenceContextProducerField(WBField<T, ?> field, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
+ {
+ super(field, declaringBean, manager);
+ }
+
+ public void dispose(T instance)
+ {
+ instance.close();
+ }
+
+}
Property changes on: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ee/PersistenceContextProducerField.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AbstractBeanDeployer.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AbstractBeanDeployer.java 2009-09-14 15:42:41 UTC (rev 3660)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AbstractBeanDeployer.java 2009-09-14 15:46:43 UTC (rev 3661)
@@ -32,13 +32,15 @@
import org.jboss.webbeans.bean.AbstractClassBean;
import org.jboss.webbeans.bean.DecoratorImpl;
import org.jboss.webbeans.bean.DisposalMethod;
-import org.jboss.webbeans.bean.SessionBean;
+import org.jboss.webbeans.bean.ManagedBean;
+import org.jboss.webbeans.bean.NewManagedBean;
import org.jboss.webbeans.bean.NewSessionBean;
-import org.jboss.webbeans.bean.NewManagedBean;
import org.jboss.webbeans.bean.ProducerField;
import org.jboss.webbeans.bean.ProducerMethod;
import org.jboss.webbeans.bean.RIBean;
-import org.jboss.webbeans.bean.ManagedBean;
+import org.jboss.webbeans.bean.SessionBean;
+import org.jboss.webbeans.bean.ee.EEResourceProducerField;
+import org.jboss.webbeans.bean.ee.PersistenceContextProducerField;
import org.jboss.webbeans.ejb.EJBApiAbstraction;
import org.jboss.webbeans.ejb.InternalEjbDescriptor;
import org.jboss.webbeans.event.ObserverFactory;
@@ -49,8 +51,10 @@
import org.jboss.webbeans.jsf.JsfApiAbstraction;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.persistence.PersistenceApiAbstraction;
import org.jboss.webbeans.servlet.ServletApiAbstraction;
import org.jboss.webbeans.util.Reflections;
+import org.jboss.webbeans.ws.WSApiAbstraction;
public class AbstractBeanDeployer
{
@@ -147,7 +151,19 @@
protected <T> void createProducerField(AbstractClassBean<?> declaringBean, WBField<T, ?> field)
{
- ProducerField<T> bean = ProducerField.of(field, declaringBean, manager);
+ ProducerField<T> bean;
+ if (isPersistenceContextProducerField(field))
+ {
+ bean = PersistenceContextProducerField.of(field, declaringBean, manager);
+ }
+ else if (isEEResourceProducerField(field))
+ {
+ bean = EEResourceProducerField.of(field, declaringBean, manager);
+ }
+ else
+ {
+ bean = ProducerField.of(field, declaringBean, manager);
+ }
getEnvironment().addBean(bean);
}
@@ -228,6 +244,20 @@
hasSimpleWebBeanConstructor(clazz);
}
+ protected boolean isEEResourceProducerField(WBField<?, ?> field)
+ {
+ EJBApiAbstraction ejbApiAbstraction = manager.getServices().get(EJBApiAbstraction.class);
+ PersistenceApiAbstraction persistenceApiAbstraction = manager.getServices().get(PersistenceApiAbstraction.class);
+ WSApiAbstraction wsApiAbstraction = manager.getServices().get(WSApiAbstraction.class);
+ return field.isAnnotationPresent(ejbApiAbstraction.EJB_ANNOTATION_CLASS) || field.isAnnotationPresent(ejbApiAbstraction.RESOURCE_ANNOTATION_CLASS) || field.isAnnotationPresent(persistenceApiAbstraction.PERSISTENCE_UNIT_ANNOTATION_CLASS) || field.isAnnotationPresent(wsApiAbstraction.WEB_SERVICE_REF_ANNOTATION_CLASS);
+ }
+
+ protected boolean isPersistenceContextProducerField(WBField<?, ?> field)
+ {
+ PersistenceApiAbstraction persistenceApiAbstraction = manager.getServices().get(PersistenceApiAbstraction.class);
+ return field.isAnnotationPresent(persistenceApiAbstraction.PERSISTENCE_CONTEXT_ANNOTATION_CLASS);
+ }
+
private static boolean hasSimpleWebBeanConstructor(WBClass<?> type)
{
return type.getNoArgsWBConstructor() != null || type.getAnnotatedWBConstructors(Inject.class).size() > 0;
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-09-14 15:42:41 UTC (rev 3660)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-09-14 15:46:43 UTC (rev 3661)
@@ -62,6 +62,7 @@
import org.jboss.webbeans.servlet.ServletApiAbstraction;
import org.jboss.webbeans.transaction.spi.TransactionServices;
import org.jboss.webbeans.util.serviceProvider.ServiceLoader;
+import org.jboss.webbeans.ws.WSApiAbstraction;
/**
* Common bootstrapping functionality that is run at application startup and
@@ -212,6 +213,7 @@
services.add(EJBApiAbstraction.class, new EJBApiAbstraction(resourceLoader));
services.add(JsfApiAbstraction.class, new JsfApiAbstraction(resourceLoader));
services.add(PersistenceApiAbstraction.class, new PersistenceApiAbstraction(resourceLoader));
+ services.add(WSApiAbstraction.class, new WSApiAbstraction(resourceLoader));
services.add(ServletApiAbstraction.class, new ServletApiAbstraction(resourceLoader));
// Temporary workaround to provide context for building annotated class
// TODO expose AnnotatedClass on SPI and allow container to provide impl of this via ResourceLoader
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/ws/WSApiAbstraction.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/ws/WSApiAbstraction.java (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/ws/WSApiAbstraction.java 2009-09-14 15:46:43 UTC (rev 3661)
@@ -0,0 +1,41 @@
+/*
+ * 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.ws;
+
+import java.lang.annotation.Annotation;
+
+import org.jboss.webbeans.bootstrap.api.Service;
+import org.jboss.webbeans.resources.spi.ResourceLoader;
+import org.jboss.webbeans.util.ApiAbstraction;
+
+public class WSApiAbstraction extends ApiAbstraction implements Service
+{
+
+ public final Class<? extends Annotation> WEB_SERVICE_REF_ANNOTATION_CLASS;
+
+ /**
+ * @param resourceLoader
+ */
+ public WSApiAbstraction(ResourceLoader resourceLoader)
+ {
+ super(resourceLoader);
+ WEB_SERVICE_REF_ANNOTATION_CLASS = annotationTypeForName("javax.xml.ws.WebServiceRef");
+ }
+
+ public void cleanup() {}
+
+}
\ No newline at end of file
Property changes on: ri/trunk/impl/src/main/java/org/jboss/webbeans/ws/WSApiAbstraction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/PersistenceContextInjectionTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/PersistenceContextInjectionTest.java 2009-09-14 15:42:41 UTC (rev 3660)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/PersistenceContextInjectionTest.java 2009-09-14 15:46:43 UTC (rev 3661)
@@ -78,6 +78,21 @@
@Test(groups = { "beanLifecycle", "commonAnnotations", "integration" })
@SpecAssertions( {
+ @SpecAssertion(section="7.3.6", id="nb")
+ })
+ public void testDestructionOfPersistenceContext() throws Exception
+ {
+ Bean<ManagedBean> managedBean = getBeans(ManagedBean.class).iterator().next();
+ CreationalContext<ManagedBean> creationalContext = getCurrentManager().createCreationalContext(managedBean);
+ ManagedBean instance = managedBean.create(creationalContext);
+ EntityManager em = instance.getPersistenceContext();
+ assert em.isOpen();
+ managedBean.destroy(instance, creationalContext);
+ assert !em.isOpen();
+ }
+
+ @Test(groups = { "beanLifecycle", "commonAnnotations", "integration" })
+ @SpecAssertions( {
@SpecAssertion(section="7.3.6", id="lc"),
@SpecAssertion(section="7.3.6", id="mf")
})
Modified: tck/trunk/impl/src/main/resources/tck-audit-cdi.xml
===================================================================
--- tck/trunk/impl/src/main/resources/tck-audit-cdi.xml 2009-09-14 15:42:41 UTC (rev 3660)
+++ tck/trunk/impl/src/main/resources/tck-audit-cdi.xml 2009-09-14 15:46:43 UTC (rev 3661)
@@ -3703,24 +3703,28 @@
<group>
<text>When the |destroy()| method is called, the container discards this internal reference. For certain kinds of resource, for example persistence contexts, the container eventually performs additional cleanup to destroy state associated with the client or transaction, as required by the Java EE platform specification.</text>
- <assertion id="na">
- <text>Check Java EE component environment resource</text>
+ <assertion id="na" testable="false">
+ <text>Check Java EE component environment resource</text>
+ <note>No behavior specified by platform spec</note>
</assertion>
<assertion id="nb">
<text>Check Entity Manager</text>
</assertion>
- <assertion id="nc">
- <text>Check Entity Manager Factory</text>
+ <assertion id="nc" testable="false">
+ <text>Check Entity Manager Factory</text>
+ <note>No behavior specified by platform spec</note>
</assertion>
- <assertion id="nd">
- <text>Check Remote EJB instance</text>
+ <assertion id="nd" testable="false">
+ <text>Check Remote EJB instance</text>
+ <note>No behavior specified by platform spec</note>
</assertion>
- <assertion id="ne">
- <text>Check Web Service Reference</text>
+ <assertion id="ne" testable="false">
+ <text>Check Web Service Reference</text>
+ <note>No behavior specified by platform spec</note>
</assertion>
</group>
More information about the weld-commits
mailing list