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 2010/04/01 22:20:43 UTC
svn commit: r930073 - in
/myfaces/extensions/cdi/branches/sandbox_conversations:
core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/
core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/
core/api/src...
Author: gpetracek
Date: Thu Apr 1 20:20:43 2010
New Revision: 930073
URL: http://svn.apache.org/viewvc?rev=930073&view=rev
Log:
[intermediate result] first part of the first api draft
Added:
myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/
myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/
myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/Conversation.java
myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/ConversationContext.java
myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/ConversationContextConfig.java
myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/ConversationManager.java
myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/access/
myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/access/AccessScoped.java
myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/named/
myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/named/ConversationScoped.java
myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/window/
myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/window/WindowScoped.java
myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/
myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/
myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultConversationManager.java
myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/named/
myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/named/NamedConversationContextAdapter.java
myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/named/NamedConversationContextExtension.java
Modified:
myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/config/javax.enterprise.inject.spi.Extension
Added: myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/Conversation.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/Conversation.java?rev=930073&view=auto
==============================================================================
--- myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/Conversation.java (added)
+++ myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/Conversation.java Thu Apr 1 20:20:43 2010
@@ -0,0 +1,36 @@
+/*
+ * 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.core.api.scope.conversation;
+
+import java.io.Serializable;
+
+/**
+ * A conversation is started automatically with the first access
+ *
+ * @author Gerhard Petracek
+ */
+public interface Conversation extends Serializable
+{
+ void end();
+
+ //void end(CleanupType cleanupType);
+
+ void restart();
+}
+
Added: myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/ConversationContext.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/ConversationContext.java?rev=930073&view=auto
==============================================================================
--- myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/ConversationContext.java (added)
+++ myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/ConversationContext.java Thu Apr 1 20:20:43 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.myfaces.extensions.cdi.core.api.scope.conversation;
+
+/**
+ * @author Gerhard Petracek
+ */
+public interface ConversationContext
+{
+ /**
+ * @return the id of the conversation (unique for each window/tab)
+ */
+ Long getId();
+
+ /**
+ * invalidate conversations immediately
+ */
+ void invalidate();
+}
Added: myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/ConversationContextConfig.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/ConversationContextConfig.java?rev=930073&view=auto
==============================================================================
--- myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/ConversationContextConfig.java (added)
+++ myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/ConversationContextConfig.java Thu Apr 1 20:20:43 2010
@@ -0,0 +1,27 @@
+/*
+ * 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.core.api.scope.conversation;
+
+/**
+ * @author Gerhard Petracek
+ */
+public interface ConversationContextConfig
+{
+ Long getTimeout();
+}
Added: myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/ConversationManager.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/ConversationManager.java?rev=930073&view=auto
==============================================================================
--- myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/ConversationManager.java (added)
+++ myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/ConversationManager.java Thu Apr 1 20:20:43 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.myfaces.extensions.cdi.core.api.scope.conversation;
+
+/**
+ * @author Gerhard Petracek
+ */
+public interface ConversationManager
+{
+ String CONVERSATION_CONTEXT_ID_PARAMETER_KEY = "codiConversationContext";
+
+ ConversationContext getCurrentConversationContext();
+
+ ConversationContext getConversationContext(Long id);
+
+ void activateConversationContext(ConversationContext conversationContext);
+
+ void resetCurrentConversationContext();
+
+ void removeCurrentConversationContext(ConversationContext conversationContext);
+}
Added: myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/access/AccessScoped.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/access/AccessScoped.java?rev=930073&view=auto
==============================================================================
--- myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/access/AccessScoped.java (added)
+++ myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/access/AccessScoped.java Thu Apr 1 20:20:43 2010
@@ -0,0 +1,38 @@
+/*
+ * 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.core.api.scope.conversation.access;
+
+import javax.enterprise.context.NormalScope;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+
+/**
+ * @author Gerhard Petracek
+ */
+@Target({METHOD,TYPE,FIELD})
+@Retention(RUNTIME)
+@NormalScope
+@Inherited
+public @interface AccessScoped
+{
+}
Added: myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/named/ConversationScoped.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/named/ConversationScoped.java?rev=930073&view=auto
==============================================================================
--- myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/named/ConversationScoped.java (added)
+++ myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/named/ConversationScoped.java Thu Apr 1 20:20:43 2010
@@ -0,0 +1,38 @@
+/*
+ * 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.core.api.scope.conversation.named;
+
+import javax.enterprise.context.NormalScope;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+
+/**
+ * @author Gerhard Petracek
+ */
+@Target({METHOD,TYPE,FIELD})
+@Retention(RUNTIME)
+@NormalScope
+@Inherited
+public @interface ConversationScoped
+{
+}
Added: myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/window/WindowScoped.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/window/WindowScoped.java?rev=930073&view=auto
==============================================================================
--- myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/window/WindowScoped.java (added)
+++ myfaces/extensions/cdi/branches/sandbox_conversations/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/window/WindowScoped.java Thu Apr 1 20:20:43 2010
@@ -0,0 +1,38 @@
+/*
+ * 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.core.api.scope.conversation.window;
+
+import javax.enterprise.context.NormalScope;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+
+/**
+ * @author Gerhard Petracek
+ */
+@Target({METHOD,TYPE,FIELD})
+@Retention(RUNTIME)
+@NormalScope
+@Inherited
+public @interface WindowScoped
+{
+}
Modified: myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/config/javax.enterprise.inject.spi.Extension
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/config/javax.enterprise.inject.spi.Extension?rev=930073&r1=930072&r2=930073&view=diff
==============================================================================
--- myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/config/javax.enterprise.inject.spi.Extension (original)
+++ myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/config/javax.enterprise.inject.spi.Extension Thu Apr 1 20:20:43 2010
@@ -16,4 +16,5 @@
# specific language governing permissions and limitations
# under the License.
#####################################################################################
-org.apache.myfaces.extensions.cdi.javaee.jsf.impl.listener.phase.PhaseListenerExtension
\ No newline at end of file
+org.apache.myfaces.extensions.cdi.javaee.jsf.impl.listener.phase.PhaseListenerExtension
+org.apache.myfaces.extensions.cdi.javaee.jsf.impl.scope.conversation.named.NamedConversationContextExtension
\ No newline at end of file
Added: myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultConversationManager.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultConversationManager.java?rev=930073&view=auto
==============================================================================
--- myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultConversationManager.java (added)
+++ myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/DefaultConversationManager.java Thu Apr 1 20:20:43 2010
@@ -0,0 +1,54 @@
+/*
+ * 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.javaee.jsf.impl.scope.conversation;
+
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ConversationManager;
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ConversationContext;
+
+/**
+ * TODO
+ * @author Gerhard Petracek
+ */
+public class DefaultConversationManager implements ConversationManager
+{
+ public ConversationContext getCurrentConversationContext()
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ public ConversationContext getConversationContext(Long id)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ public void activateConversationContext(ConversationContext conversationContext)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ public void resetCurrentConversationContext()
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ public void removeCurrentConversationContext(ConversationContext conversationContext)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+}
Added: myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/named/NamedConversationContextAdapter.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/named/NamedConversationContextAdapter.java?rev=930073&view=auto
==============================================================================
--- myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/named/NamedConversationContextAdapter.java (added)
+++ myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/named/NamedConversationContextAdapter.java Thu Apr 1 20:20:43 2010
@@ -0,0 +1,164 @@
+/*
+ * 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.javaee.jsf.impl.scope.conversation.named;
+
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.named.ConversationScoped;
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ConversationManager;
+import org.apache.myfaces.extensions.cdi.core.api.tools.annotate.DefaultAnnotation;
+import org.apache.myfaces.extensions.cdi.javaee.jsf.api.qualifier.Jsf;
+
+import javax.enterprise.context.spi.Context;
+import javax.enterprise.context.spi.Contextual;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.faces.context.FacesContext;
+import java.lang.annotation.Annotation;
+import java.util.Set;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class NamedConversationContextAdapter implements Context
+{
+ private BeanManager beanManager;
+
+ public NamedConversationContextAdapter(BeanManager beanManager)
+ {
+ this.beanManager = beanManager;
+ }
+
+ /**
+ * @return annotation of the codi conversation scope
+ */
+ public Class<? extends Annotation> getScope()
+ {
+ return ConversationScoped.class;
+ }
+
+ /**
+ * @param component descriptor of the bean
+ * @param creationalContext context for creating a bean
+ * @return a scoped bean-instance
+ */
+ public <T> T get(Contextual<T> component, CreationalContext<T> creationalContext)
+ {
+ if (component instanceof Bean)
+ {
+ ConversationManager conversationManager = resolveConversationManager();
+
+ T beanInstance = component.create(creationalContext);
+ scopeBeanInstance((Bean<T>)component, beanInstance, conversationManager);
+ return beanInstance;
+ }
+
+ Class invalidComponentClass = component.create(creationalContext).getClass();
+ throw new IllegalStateException(invalidComponentClass + " is no valid conversation scoped bean");
+ }
+
+ /**
+ * @param component descriptor of the bean
+ * @return an instance of the requested bean if it already exists in the current
+ * {@link org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ConversationContext}
+ * null otherwise
+ */
+ public <T> T get(Contextual<T> component)
+ {
+ if (component instanceof Bean)
+ {
+ Bean<T> foundBean = ((Bean<T>) component);
+ ConversationManager conversationManager = resolveConversationManager();
+
+ return resolveBeanInstance(foundBean, conversationManager);
+ }
+ return null;
+ }
+
+ /**
+ * @return true as soon as JSF is active (the {@link org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ConversationContext}
+ * will be created automatically
+ */
+ public boolean isActive()
+ {
+ return FacesContext.getCurrentInstance() != null;
+ }
+
+ /**
+ * @return an instance of a custom (the default) {@link ConversationManager}
+ */
+ private ConversationManager resolveConversationManager()
+ {
+ Bean<ConversationManager> conversationManagerBean = resolveConversationManagerBean();
+ CreationalContext<ConversationManager> conversationManagerCreationalContext = this.beanManager.createCreationalContext(conversationManagerBean);
+ return conversationManagerBean.create(conversationManagerCreationalContext);
+ }
+
+ /**
+ * @return the descriptor of a custom {@link ConversationManager} with the qualifier {@link Jsf} or
+ * the descriptor of the default implementation provided by this module
+ */
+ private Bean<ConversationManager> resolveConversationManagerBean()
+ {
+ Set<?> conversationManagerBeans = this.beanManager.getBeans(ConversationManager.class, DefaultAnnotation.of(Jsf.class));
+
+ if(conversationManagerBeans.isEmpty())
+ {
+ conversationManagerBeans = getDefaultConversationManager();
+ }
+
+ if(conversationManagerBeans.size() != 1)
+ {
+ throw new IllegalStateException(conversationManagerBeans.size() + " conversation-managers were found");
+ }
+ //noinspection unchecked
+ return (Bean<ConversationManager>)conversationManagerBeans.iterator().next();
+ }
+
+ /**
+ * @return the descriptor of the default {@link ConversationManager}
+ */
+ private Set<Bean<?>> getDefaultConversationManager()
+ {
+ return this.beanManager.getBeans(ConversationManager.class);
+ }
+
+ /**
+ * @param beanDescriptor descriptor of the requested bean
+ * @param conversationManager the current {@link ConversationManager}
+ * @return the instance of the requested bean if it exists in the current {@link org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ConversationContext}
+ * null otherwise
+ */
+ private <T> T resolveBeanInstance(Bean<T> beanDescriptor, ConversationManager conversationManager)
+ {
+ //TODO
+ return null;
+ }
+
+ /**
+ * Store the given bean in the {@link org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ConversationContext}
+ *
+ * @param beanDescriptor descriptor of the current bean
+ * @param beanInstance bean to save in the current conversation
+ * @param conversationManager current {@link ConversationManager}
+ */
+ private <T> void scopeBeanInstance(Bean<T> beanDescriptor, T beanInstance, ConversationManager conversationManager)
+ {
+ //TODO
+ }
+}
Added: myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/named/NamedConversationContextExtension.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/named/NamedConversationContextExtension.java?rev=930073&view=auto
==============================================================================
--- myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/named/NamedConversationContextExtension.java (added)
+++ myfaces/extensions/cdi/branches/sandbox_conversations/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/scope/conversation/named/NamedConversationContextExtension.java Thu Apr 1 20:20:43 2010
@@ -0,0 +1,34 @@
+/*
+ * 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.javaee.jsf.impl.scope.conversation.named;
+
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.event.Observes;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class NamedConversationContextExtension implements Extension
+{
+ public void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager manager) {
+ event.addContext(new NamedConversationContextAdapter(manager));
+ }
+}