Author: shane.bryzak(a)jboss.com
Date: 2010-08-31 09:40:20 -0400 (Tue, 31 Aug 2010)
New Revision: 13678
Added:
modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/EntityManagerProducer.java
Modified:
modules/remoting/trunk/core/pom.xml
modules/remoting/trunk/core/src/main/java/org/jboss/seam/remoting/Call.java
modules/remoting/trunk/core/src/main/java/org/jboss/seam/remoting/ExecutionHandler.java
modules/remoting/trunk/core/src/main/java/org/jboss/seam/remoting/NonInjectionRemoting.java
modules/remoting/trunk/core/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
modules/remoting/trunk/core/src/main/java/org/jboss/seam/remoting/wrapper/BagWrapper.java
modules/remoting/trunk/examples/model/pom.xml
modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/PersonAction.java
modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/PersonSearch.java
modules/remoting/trunk/pom.xml
Log:
fix compiler/deployment/runtime exceptions, code cleanup
Modified: modules/remoting/trunk/core/pom.xml
===================================================================
--- modules/remoting/trunk/core/pom.xml 2010-08-31 12:53:46 UTC (rev 13677)
+++ modules/remoting/trunk/core/pom.xml 2010-08-31 13:40:20 UTC (rev 13678)
@@ -20,6 +20,7 @@
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
+ <optional>true</optional>
</dependency>
<dependency>
Modified: modules/remoting/trunk/core/src/main/java/org/jboss/seam/remoting/Call.java
===================================================================
--- modules/remoting/trunk/core/src/main/java/org/jboss/seam/remoting/Call.java 2010-08-31
12:53:46 UTC (rev 13677)
+++ modules/remoting/trunk/core/src/main/java/org/jboss/seam/remoting/Call.java 2010-08-31
13:40:20 UTC (rev 13678)
@@ -156,10 +156,9 @@
*
* @throws Exception
*/
- @SuppressWarnings("unchecked")
public void execute() throws Exception
{
- CreationalContext ctx = beanManager.createCreationalContext(targetBean);
+ CreationalContext<?> ctx = beanManager.createCreationalContext(targetBean);
// Get an instance of the component
Object instance = beanManager.getReference(targetBean, targetBean.getBeanClass(),
ctx);;
Modified:
modules/remoting/trunk/core/src/main/java/org/jboss/seam/remoting/ExecutionHandler.java
===================================================================
---
modules/remoting/trunk/core/src/main/java/org/jboss/seam/remoting/ExecutionHandler.java 2010-08-31
12:53:46 UTC (rev 13677)
+++
modules/remoting/trunk/core/src/main/java/org/jboss/seam/remoting/ExecutionHandler.java 2010-08-31
13:40:20 UTC (rev 13678)
@@ -18,7 +18,8 @@
import org.dom4j.io.SAXReader;
import org.jboss.seam.remoting.util.Strings;
import org.jboss.seam.remoting.wrapper.Wrapper;
-import org.jboss.weld.conversation.ConversationManager;
+import org.jboss.weld.conversation.ConversationManager2;
+import org.jboss.weld.servlet.BeanProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -33,7 +34,6 @@
private static final Logger log = LoggerFactory.getLogger(ExecutionHandler.class);
@Inject BeanManager beanManager;
- @Inject ConversationManager conversationManager;
@Inject Conversation conversation;
/**
@@ -69,10 +69,12 @@
final Element env = doc.getRootElement();
final RequestContext ctx = new RequestContext(env.element("header"));
+ ConversationManager2 conversationManager =
BeanProvider.conversationManager(request.getServletContext());
+
if (ctx.getConversationId() != null &&
!Strings.isEmpty(ctx.getConversationId()))
{
// this is non portable ;/
- conversationManager.beginOrRestoreConversation(ctx.getConversationId());
+ conversationManager.setupConversation(ctx.getConversationId());
}
// Extract the calls from the request
@@ -82,7 +84,7 @@
// Store the conversation ID in the outgoing context
try
{
- ctx.setConversationId(conversation.getId());
+ ctx.setConversationId(conversation.isTransient() ? null :
conversation.getId());
}
catch (ContextNotActiveException ex)
{
@@ -118,11 +120,10 @@
// First reconstruct all the references
Element refsNode = callElement.element("refs");
- Iterator iter = refsNode.elementIterator("ref");
+ Iterator<Element> iter = refsNode.elementIterator("ref");
while (iter.hasNext())
{
- call.getContext()
- .createWrapperFromElement((Element) iter.next());
+ call.getContext().createWrapperFromElement(iter.next());
}
// Now unmarshal the ref values
Modified:
modules/remoting/trunk/core/src/main/java/org/jboss/seam/remoting/NonInjectionRemoting.java
===================================================================
---
modules/remoting/trunk/core/src/main/java/org/jboss/seam/remoting/NonInjectionRemoting.java 2010-08-31
12:53:46 UTC (rev 13677)
+++
modules/remoting/trunk/core/src/main/java/org/jboss/seam/remoting/NonInjectionRemoting.java 2010-08-31
13:40:20 UTC (rev 13678)
@@ -13,7 +13,7 @@
import org.jboss.seam.remoting.model.ModelHandler;
import org.jboss.weld.Container;
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
-import org.jboss.weld.exceptions.ForbiddenStateException;
+import org.jboss.weld.exceptions.IllegalStateException;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.servlet.api.ServletServices;
@@ -26,16 +26,17 @@
BeanDeploymentArchive war =
Container.instance().services().get(ServletServices.class).getBeanDeploymentArchive(ctx);
if (war == null)
{
- throw new ForbiddenStateException(BEAN_DEPLOYMENT_ARCHIVE_MISSING, ctx);
+ throw new IllegalStateException(BEAN_DEPLOYMENT_ARCHIVE_MISSING, ctx);
}
BeanManagerImpl beanManager =
Container.instance().beanDeploymentArchives().get(war);
if (beanManager == null)
{
- throw new ForbiddenStateException(BEAN_MANAGER_FOR_ARCHIVE_NOT_FOUND, ctx,
war);
+ throw new IllegalStateException(BEAN_MANAGER_FOR_ARCHIVE_NOT_FOUND, ctx, war);
}
return beanManager;
}
+ @SuppressWarnings("unchecked")
@Override
protected ExecutionHandler getExecutionHandler()
{
@@ -45,6 +46,7 @@
return bean.create(beanManager.createCreationalContext(bean));
}
+ @SuppressWarnings("unchecked")
@Override
protected InterfaceGenerator getInterfaceHandler()
{
@@ -54,6 +56,7 @@
return bean.create(beanManager.createCreationalContext(bean));
}
+ @SuppressWarnings("unchecked")
@Override
protected ModelHandler getModelHandler()
{
Modified:
modules/remoting/trunk/core/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
===================================================================
---
modules/remoting/trunk/core/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java 2010-08-31
12:53:46 UTC (rev 13677)
+++
modules/remoting/trunk/core/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java 2010-08-31
13:40:20 UTC (rev 13678)
@@ -29,11 +29,8 @@
import org.jboss.seam.remoting.wrapper.BeanWrapper;
import org.jboss.seam.remoting.wrapper.MapWrapper;
import org.jboss.seam.remoting.wrapper.Wrapper;
-import org.jboss.weld.Container;
-import org.jboss.weld.context.ContextLifecycle;
-import org.jboss.weld.context.ConversationContext;
-import org.jboss.weld.conversation.ConversationManager;
-import org.jboss.weld.servlet.ConversationBeanStore;
+import org.jboss.weld.conversation.ConversationManager2;
+import org.jboss.weld.servlet.BeanProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,7 +44,6 @@
private static final Logger log = LoggerFactory.getLogger(ModelHandler.class);
@Inject BeanManager beanManager;
- @Inject ConversationManager conversationManager;
@Inject ModelRegistry registry;
@Inject Conversation conversation;
@@ -74,75 +70,49 @@
final Element env = doc.getRootElement();
final RequestContext ctx = new RequestContext(env.element("header"));
- ConversationContext conversationContext = null;
- try
- {
- // Initialize the conversation context
- // TODO - this is non-portable, we should at least use the new
ConversationManager API once Nik has
- // written it, and non-portable code should be abstracted out
- conversationContext =
Container.instance().services().get(ContextLifecycle.class).getConversationContext();
-
- if (ctx.getConversationId() != null &&
!Strings.isEmpty(ctx.getConversationId()))
- {
- conversationContext.setBeanStore(new ConversationBeanStore(
- request.getSession(), false, ctx.getConversationId()));
- conversationContext.setActive(true);
- conversationManager.beginOrRestoreConversation(ctx.getConversationId());
- }
- else
+ ConversationManager2 conversationManager =
BeanProvider.conversationManager(request.getServletContext());
+
+ if (ctx.getConversationId() != null &&
!Strings.isEmpty(ctx.getConversationId()))
+ {
+ conversationManager.setupConversation(ctx.getConversationId());
+ }
+
+ Element modelElement = env.element("body").element("model");
+ String operation = modelElement.attributeValue("operation");
+
+ if ("expand".equals(operation))
+ {
+ processExpandRequest(modelElement, ctx, response.getOutputStream());
+ }
+ else
+ {
+ Model model = null;
+ if ("fetch".equals(operation))
{
- conversationContext.setBeanStore(new ConversationBeanStore(
- request.getSession(), false,
- ((org.jboss.weld.conversation.ConversationImpl)
conversation).getUnderlyingId()));
- conversationContext.setActive(true);
+ model = processFetchRequest(modelElement);
}
-
- Element modelElement =
env.element("body").element("model");
- String operation = modelElement.attributeValue("operation");
-
- if ("expand".equals(operation))
+ else if ("apply".equals(operation))
{
- processExpandRequest(modelElement, ctx, response.getOutputStream());
+ model = processApplyRequest(modelElement);
}
- else
+
+ if (model.getAction() != null && model.getAction().getException() !=
null)
{
- Model model = null;
- if ("fetch".equals(operation))
- {
- model = processFetchRequest(modelElement);
- }
- else if ("apply".equals(operation))
- {
- model = processApplyRequest(modelElement);
- }
-
- if (model.getAction() != null && model.getAction().getException() !=
null)
- {
- response.getOutputStream().write(ENVELOPE_TAG_OPEN);
- response.getOutputStream().write(BODY_TAG_OPEN);
- MarshalUtils.marshalException(model.getAction().getException(),
- model.getAction().getContext(), response.getOutputStream());
- response.getOutputStream().write(BODY_TAG_CLOSE);
- response.getOutputStream().write(ENVELOPE_TAG_CLOSE);
- response.getOutputStream().flush();
- return;
- }
-
- model.evaluate();
-
- ctx.setConversationId(conversation.isTransient() ? null :
conversation.getId());
- marshalResponse(model, ctx, response.getOutputStream());
+ response.getOutputStream().write(ENVELOPE_TAG_OPEN);
+ response.getOutputStream().write(BODY_TAG_OPEN);
+ MarshalUtils.marshalException(model.getAction().getException(),
+ model.getAction().getContext(), response.getOutputStream());
+ response.getOutputStream().write(BODY_TAG_CLOSE);
+ response.getOutputStream().write(ENVELOPE_TAG_CLOSE);
+ response.getOutputStream().flush();
+ return;
}
+
+ model.evaluate();
+
+ ctx.setConversationId(conversation.isTransient() ? null :
conversation.getId());
+ marshalResponse(model, ctx, response.getOutputStream());
}
- finally
- {
- conversationManager.cleanupConversation();
- if (conversationContext != null)
- {
- conversationContext.setBeanStore(null);
- conversationContext.setActive(false);
- }
- }
}
@SuppressWarnings({ "unchecked" })
Modified:
modules/remoting/trunk/core/src/main/java/org/jboss/seam/remoting/wrapper/BagWrapper.java
===================================================================
---
modules/remoting/trunk/core/src/main/java/org/jboss/seam/remoting/wrapper/BagWrapper.java 2010-08-31
12:53:46 UTC (rev 13677)
+++
modules/remoting/trunk/core/src/main/java/org/jboss/seam/remoting/wrapper/BagWrapper.java 2010-08-31
13:40:20 UTC (rev 13678)
@@ -51,7 +51,7 @@
{
try
{
- Class cls =
Class.forName("org.hibernate.collection.PersistentCollection");
+ Class<?> cls =
Class.forName("org.hibernate.collection.PersistentCollection");
// Fix to prevent uninitialized lazy loading in Hibernate
if (cls.isInstance(value) && !loadLazy)
@@ -116,9 +116,9 @@
vals.add(context.createWrapperFromElement((Element) e.elements().get(0)));
}
- if (type instanceof Class && ((Class) type).isArray())
+ if (type instanceof Class && ((Class<?>) type).isArray())
{
- Class arrayType = ((Class) type).getComponentType();
+ Class<?> arrayType = ((Class<?>) type).getComponentType();
value = Array.newInstance(arrayType, vals.size()); // Fix this
for (int i = 0; i < vals.size(); i++)
{
@@ -126,11 +126,11 @@
}
}
else if (type instanceof Class &&
- Collection.class.isAssignableFrom((Class) type))
+ Collection.class.isAssignableFrom((Class<?>) type))
{
try
{
- value = getConcreteClass((Class) type).newInstance();
+ value = getConcreteClass((Class<?>) type).newInstance();
}
catch (Exception ex)
{
@@ -144,9 +144,9 @@
}
}
else if (type instanceof ParameterizedType &&
- Collection.class.isAssignableFrom((Class) ((ParameterizedType)
type).getRawType()))
+ Collection.class.isAssignableFrom((Class<?>) ((ParameterizedType)
type).getRawType()))
{
- Class rawType = (Class) ((ParameterizedType) type).getRawType();
+ Class<?> rawType = (Class<?>) ((ParameterizedType)
type).getRawType();
Type genType = Object.class;
for (Type t : ((ParameterizedType) type).getActualTypeArguments())
Modified: modules/remoting/trunk/examples/model/pom.xml
===================================================================
--- modules/remoting/trunk/examples/model/pom.xml 2010-08-31 12:53:46 UTC (rev 13677)
+++ modules/remoting/trunk/examples/model/pom.xml 2010-08-31 13:40:20 UTC (rev 13678)
@@ -31,6 +31,24 @@
</dependency>
<dependency>
+ <groupId>org.jboss.seam.persistence</groupId>
+ <artifactId>seam-persistence-impl</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>junit</artifactId>
+ <groupId>junit</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-extensions</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<scope>provided</scope>
Added:
modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/EntityManagerProducer.java
===================================================================
---
modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/EntityManagerProducer.java
(rev 0)
+++
modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/EntityManagerProducer.java 2010-08-31
13:40:20 UTC (rev 13678)
@@ -0,0 +1,17 @@
+package org.jboss.seam.remoting.examples.model;
+
+import javax.enterprise.context.ConversationScoped;
+import javax.enterprise.inject.Produces;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceUnit;
+
+import org.jboss.seam.persistence.SeamManaged;
+
+public class EntityManagerProducer
+{
+ @PersistenceUnit
+ @ConversationScoped
+ @Produces
+ @SeamManaged
+ EntityManagerFactory emf;
+}
Modified:
modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/PersonAction.java
===================================================================
---
modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/PersonAction.java 2010-08-31
12:53:46 UTC (rev 13677)
+++
modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/PersonAction.java 2010-08-31
13:40:20 UTC (rev 13678)
@@ -7,16 +7,16 @@
import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
+import org.jboss.seam.persistence.transaction.Transactional;
import org.jboss.seam.remoting.annotations.WebRemote;
-@ConversationScoped
-public class PersonAction implements Serializable
+
+public @ConversationScoped @Transactional class PersonAction implements Serializable
{
private static final long serialVersionUID = -1923705862231821692L;
- @PersistenceContext EntityManager entityManager;
+ @Inject EntityManager entityManager;
@Inject Conversation conversation;
private Person person;
@@ -46,6 +46,10 @@
else
{
person = entityManager.merge(person);
+ for (Address address : person.getAddresses())
+ {
+ entityManager.merge(address);
+ }
}
conversation.end();
Modified:
modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/PersonSearch.java
===================================================================
---
modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/PersonSearch.java 2010-08-31
12:53:46 UTC (rev 13677)
+++
modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/PersonSearch.java 2010-08-31
13:40:20 UTC (rev 13678)
@@ -2,9 +2,9 @@
import java.util.List;
-import javax.inject.Named;
+import javax.enterprise.inject.Model;
+import javax.inject.Inject;
import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
import org.jboss.seam.remoting.annotations.WebRemote;
@@ -13,10 +13,9 @@
*
* @author Shane Bryzak
*/
-@Named("personSearch")
-public class PersonSearch
+public @Model class PersonSearch
{
- @PersistenceContext EntityManager entityManager;
+ @Inject EntityManager entityManager;
@WebRemote @SuppressWarnings("unchecked")
public List<Person> listPeople()
Modified: modules/remoting/trunk/pom.xml
===================================================================
--- modules/remoting/trunk/pom.xml 2010-08-31 12:53:46 UTC (rev 13677)
+++ modules/remoting/trunk/pom.xml 2010-08-31 13:40:20 UTC (rev 13678)
@@ -5,7 +5,7 @@
<parent>
<artifactId>seam-parent</artifactId>
<groupId>org.jboss.seam</groupId>
- <version>1</version>
+ <version>3-SNAPSHOT</version>
</parent>
<groupId>org.jboss.seam.remoting</groupId>
@@ -46,6 +46,12 @@
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-core</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ </dependency>
+
</dependencies>
</dependencyManagement>