You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gp...@apache.org on 2011/03/16 02:21:24 UTC
svn commit: r1082024 -
/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/
Author: gpetracek
Date: Wed Mar 16 01:21:23 2011
New Revision: 1082024
URL: http://svn.apache.org/viewvc?rev=1082024&view=rev
Log:
EXTCDI-152 bean serialization workaround for weld
Added:
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/AbstractConversationBeanEntry.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/PassivationAwareConversationBeanEntry.java
Modified:
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ConversationBeanEntry.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/DefaultBeanEntryFactory.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/DefaultWindowHandler.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/GroupedConversationContext.java
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/AbstractConversationBeanEntry.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/AbstractConversationBeanEntry.java?rev=1082024&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/AbstractConversationBeanEntry.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/AbstractConversationBeanEntry.java Wed Mar 16 01:21:23 2011
@@ -0,0 +1,156 @@
+/*
+ * 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.myfaces.extensions.cdi.jsf.impl.scope.conversation;
+
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.event.AccessBeanEvent;
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.event.ScopeBeanEvent;
+import org.apache.myfaces.extensions.cdi.core.impl.scope.conversation.spi.BeanEntry;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.BeanManager;
+import java.io.Serializable;
+
+import static org.apache.myfaces.extensions.cdi.core.impl.util.CodiUtils.createNewInstanceOfBean;
+
+/**
+ * @author Gerhard Petracek
+ */
+abstract class AbstractConversationBeanEntry<T> implements BeanEntry<T>
+{
+ //all implementations will be serializable
+ protected CreationalContext<T> creationalContext;
+
+ protected T currentBeanInstance;
+
+ //all implementations will be serializable
+ protected BeanManager beanManager;
+
+ protected boolean scopeBeanEventEnable;
+
+ protected boolean accessBeanEventEnable;
+
+ protected boolean unscopeBeanEventEnable;
+
+ protected AbstractConversationBeanEntry()
+ {
+ }
+
+ AbstractConversationBeanEntry(CreationalContext<T> creationalContext,
+ BeanManager beanManager,
+ boolean scopeBeanEventEnable,
+ boolean accessBeanEventEnable,
+ boolean unscopeBeanEventEnable)
+ {
+ this.creationalContext = creationalContext;
+ this.beanManager = beanManager;
+
+ this.scopeBeanEventEnable = scopeBeanEventEnable;
+ this.accessBeanEventEnable = accessBeanEventEnable;
+ this.unscopeBeanEventEnable = unscopeBeanEventEnable;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public CreationalContext<T> getCreationalContext()
+ {
+ return creationalContext;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T getBeanInstance()
+ {
+ if (this.currentBeanInstance == null)
+ {
+ //in case of a reset
+ createNewBeanInstance();
+ }
+
+ if(this.accessBeanEventEnable)
+ {
+ //we don't have to check the implementation of Serializable - cdi already checked it
+ this.beanManager.fireEvent(new AccessBeanEvent((Serializable)this.currentBeanInstance));
+ }
+
+ return this.currentBeanInstance;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T resetBeanInstance()
+ {
+ T oldBeanInstance = this.currentBeanInstance;
+
+ this.currentBeanInstance = null;
+
+ return oldBeanInstance;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isScopeBeanEventEnabled()
+ {
+ return this.scopeBeanEventEnable;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isAccessBeanEventEnabled()
+ {
+ return this.accessBeanEventEnable;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isUnscopeBeanEventEnabled()
+ {
+ return this.unscopeBeanEventEnable;
+ }
+
+ protected synchronized void createNewBeanInstance()
+ {
+ if(this.currentBeanInstance != null)
+ {
+ return;
+ }
+
+ this.currentBeanInstance = createNewInstanceOfBean(this.creationalContext, getBean());
+
+ if(this.scopeBeanEventEnable)
+ {
+ //we don't have to check the implementation of Serializable - cdi already checked it
+ this.beanManager.fireEvent(new ScopeBeanEvent((Serializable)this.currentBeanInstance));
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString()
+ {
+ return this.getBean().toString();
+ }
+}
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ConversationBeanEntry.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ConversationBeanEntry.java?rev=1082024&r1=1082023&r2=1082024&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ConversationBeanEntry.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ConversationBeanEntry.java Wed Mar 16 01:21:23 2011
@@ -18,39 +18,19 @@
*/
package org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation;
-import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.event.AccessBeanEvent;
-import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.event.ScopeBeanEvent;
-import org.apache.myfaces.extensions.cdi.core.impl.scope.conversation.spi.BeanEntry;
-
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
-import java.io.Serializable;
-
-import static org.apache.myfaces.extensions.cdi.core.impl.util.CodiUtils.createNewInstanceOfBean;
/**
* @author Gerhard Petracek
*/
-class ConversationBeanEntry<T> implements BeanEntry<T>
+class ConversationBeanEntry<T> extends AbstractConversationBeanEntry<T>
{
private static final long serialVersionUID = -4756851133555458294L;
private final Bean<T> bean;
- private T currentBeanInstance;
-
- private CreationalContext<T> creationalContext;
-
- //all implementations will be serializable
- private BeanManager beanManager;
-
- private final boolean scopeBeanEventEnable;
-
- private final boolean accessBeanEventEnable;
-
- private final boolean unscopeBeanEventEnable;
-
ConversationBeanEntry(CreationalContext<T> creationalContext,
Bean<T> bean,
BeanManager beanManager,
@@ -58,13 +38,8 @@ class ConversationBeanEntry<T> implement
boolean accessBeanEventEnable,
boolean unscopeBeanEventEnable)
{
+ super(creationalContext, beanManager, scopeBeanEventEnable, accessBeanEventEnable, unscopeBeanEventEnable);
this.bean = bean;
- this.creationalContext = creationalContext;
- this.beanManager = beanManager;
-
- this.scopeBeanEventEnable = scopeBeanEventEnable;
- this.accessBeanEventEnable = accessBeanEventEnable;
- this.unscopeBeanEventEnable = unscopeBeanEventEnable;
}
/**
@@ -74,93 +49,4 @@ class ConversationBeanEntry<T> implement
{
return this.bean;
}
-
- /**
- * {@inheritDoc}
- */
- public CreationalContext<T> getCreationalContext()
- {
- return creationalContext;
- }
-
- /**
- * {@inheritDoc}
- */
- public T getBeanInstance()
- {
- if (this.currentBeanInstance == null)
- {
- //in case of a reset
- createNewBeanInstance();
- }
-
- if(this.accessBeanEventEnable)
- {
- //we don't have to check the implementation of Serializable - cdi already checked it
- this.beanManager.fireEvent(new AccessBeanEvent((Serializable)this.currentBeanInstance));
- }
-
- return this.currentBeanInstance;
- }
-
- /**
- * {@inheritDoc}
- */
- public T resetBeanInstance()
- {
- T oldBeanInstance = this.currentBeanInstance;
-
- this.currentBeanInstance = null;
-
- return oldBeanInstance;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isScopeBeanEventEnabled()
- {
- return this.scopeBeanEventEnable;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isAccessBeanEventEnabled()
- {
- return this.accessBeanEventEnable;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isUnscopeBeanEventEnabled()
- {
- return this.unscopeBeanEventEnable;
- }
-
- private synchronized void createNewBeanInstance()
- {
- if(this.currentBeanInstance != null)
- {
- return;
- }
-
- this.currentBeanInstance = createNewInstanceOfBean(this.creationalContext, this.bean);
-
- if(this.scopeBeanEventEnable)
- {
- //we don't have to check the implementation of Serializable - cdi already checked it
- this.beanManager.fireEvent(new ScopeBeanEvent((Serializable)this.currentBeanInstance));
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString()
- {
- return this.bean.toString();
- }
}
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/DefaultBeanEntryFactory.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/DefaultBeanEntryFactory.java?rev=1082024&r1=1082023&r2=1082024&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/DefaultBeanEntryFactory.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/DefaultBeanEntryFactory.java Wed Mar 16 01:21:23 2011
@@ -25,7 +25,11 @@ import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.spi.PassivationCapable;
import javax.inject.Inject;
+import java.io.Serializable;
+import java.util.logging.Level;
+import java.util.logging.Logger;
/**
* @author Gerhard Petracek
@@ -45,6 +49,36 @@ class DefaultBeanEntryFactory implements
boolean accessBeanEventEnabled,
boolean unscopeBeanEventEnabled)
{
+ if(Serializable.class.isAssignableFrom(bean.getBeanClass()))
+ {
+ return new ConversationBeanEntry<T>(creationalContext,
+ bean,
+ this.beanManager,
+ scopeBeanEventEnabled,
+ accessBeanEventEnabled,
+ unscopeBeanEventEnabled);
+ }
+
+ if(PassivationCapable.class.isAssignableFrom(bean.getClass()))
+ {
+ return new PassivationAwareConversationBeanEntry<T>(creationalContext,
+ bean,
+ ((PassivationCapable)bean).getId(),
+ this.beanManager,
+ scopeBeanEventEnabled,
+ accessBeanEventEnabled,
+ unscopeBeanEventEnabled);
+ }
+
+ //should never occur
+ Logger logger = Logger.getLogger(DefaultBeanEntryFactory.class.getName());
+ if(logger.isLoggable(Level.WARNING))
+ {
+ logger.warning("the bean-implementation: " + bean.getClass() + " doesn't implement " +
+ Serializable.class.getName() + " or " + PassivationCapable.class.getName() +
+ " -> mechanisms like session serialization won't work.");
+ }
+
return new ConversationBeanEntry<T>(creationalContext,
bean,
this.beanManager,
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/DefaultWindowHandler.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/DefaultWindowHandler.java?rev=1082024&r1=1082023&r2=1082024&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/DefaultWindowHandler.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/DefaultWindowHandler.java Wed Mar 16 01:21:23 2011
@@ -172,6 +172,7 @@ public class DefaultWindowHandler implem
//don't use {@link RequestCache} here directly - due to the redirect it was cleared
protected String getCurrentWindowId()
{
+ //TODO
return RequestCache.getWindowContextManager().getCurrentWindowContext().getId();
}
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/GroupedConversationContext.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/GroupedConversationContext.java?rev=1082024&r1=1082023&r2=1082024&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/GroupedConversationContext.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/GroupedConversationContext.java Wed Mar 16 01:21:23 2011
@@ -134,6 +134,7 @@ class GroupedConversationContext extends
if(editableWindowContext == null)
{
editableWindowContext = (EditableWindowContext)windowContextManager.getCurrentWindowContext();
+ //also done by the default implementation but this also ensures that custom impls are fast
RequestCache.setCurrentWindowContext(editableWindowContext);
}
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/PassivationAwareConversationBeanEntry.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/PassivationAwareConversationBeanEntry.java?rev=1082024&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/PassivationAwareConversationBeanEntry.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/PassivationAwareConversationBeanEntry.java Wed Mar 16 01:21:23 2011
@@ -0,0 +1,63 @@
+/*
+ * 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.myfaces.extensions.cdi.jsf.impl.scope.conversation;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+
+/**
+ * Fallback e.g. for Weld
+ *
+ * @author Gerhard Petracek
+ */
+class PassivationAwareConversationBeanEntry<T> extends AbstractConversationBeanEntry<T>
+{
+ private static final long serialVersionUID = 5461280883272018770L;
+
+ private String beanId;
+
+ private transient Bean<T> bean;
+
+ PassivationAwareConversationBeanEntry(CreationalContext<T> creationalContext,
+ Bean<T> bean,
+ String beanId,
+ BeanManager beanManager,
+ boolean scopeBeanEventEnable,
+ boolean accessBeanEventEnable,
+ boolean unscopeBeanEventEnable)
+ {
+ super(creationalContext, beanManager, scopeBeanEventEnable, accessBeanEventEnable, unscopeBeanEventEnable);
+ this.bean = bean;
+ this.beanId = beanId;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Bean<T> getBean()
+ {
+ if(this.bean == null)
+ {
+ this.bean = (Bean<T>) this.beanManager.getPassivationCapableBean(this.beanId);
+ }
+
+ return bean;
+ }
+}