Skip to content

Commit

Permalink
WBRI-377
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@3661 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Sep 14, 2009
1 parent f544697 commit 370f0a5
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 7 deletions.
6 changes: 3 additions & 3 deletions impl/src/main/java/org/jboss/webbeans/bean/ProducerField.java
Expand Up @@ -29,7 +29,7 @@
import org.jboss.webbeans.util.Names;

/**
* Represents a producer field bean
* Represents a producer field
*
* @author Pete Muir
*
Expand All @@ -42,12 +42,12 @@ public class ProducerField<T> extends AbstractProducerBean<T, Field>
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)
{
Expand Down
@@ -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());
}
}

}
@@ -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();
}

}
Expand Up @@ -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.NewSessionBean;
import org.jboss.webbeans.bean.ManagedBean;
import org.jboss.webbeans.bean.NewManagedBean;
import org.jboss.webbeans.bean.NewSessionBean;
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;
Expand All @@ -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
{
Expand Down Expand Up @@ -147,7 +151,19 @@ protected <T> void createProducerMethod(AbstractClassBean<?> declaringBean, WBMe

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);
}

Expand Down Expand Up @@ -228,6 +244,20 @@ protected boolean isTypeManagedBeanOrDecorator(WBClass<?> clazz)
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;
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -212,6 +213,7 @@ private ServiceRegistry getImplementationServices(ResourceLoader resourceLoader)
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
Expand Down
41 changes: 41 additions & 0 deletions impl/src/main/java/org/jboss/webbeans/ws/WSApiAbstraction.java
@@ -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() {}

}

0 comments on commit 370f0a5

Please sign in to comment.