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/09/30 00:54:11 UTC
svn commit: r1002884 - in
/myfaces/extensions/cdi/trunk/jee-modules/jsf-module:
api/src/main/java/org/apache/myfaces/extensions/cdi/jsf/api/config/view/
impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/
impl/src/main/java/org/a...
Author: gpetracek
Date: Wed Sep 29 22:54:11 2010
New Revision: 1002884
URL: http://svn.apache.org/viewvc?rev=1002884&view=rev
Log:
EXTCDI-68 first draft
Added:
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/jsf/api/config/view/PreRenderView.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/jsf/api/config/view/PreViewAction.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/security/ViewControllerActionListener.java
Modified:
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/PageBeanConfigEntry.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/PhasesLifecycleCallbackPhaseListener.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigEntry.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/security/SecurityViolationAwareActionListener.java
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/jsf/api/config/view/PreRenderView.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/jsf/api/config/view/PreRenderView.java?rev=1002884&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/jsf/api/config/view/PreRenderView.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/jsf/api/config/view/PreRenderView.java Wed Sep 29 22:54:11 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.jsf.api.config.view;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static java.lang.annotation.ElementType.METHOD;
+
+/**
+ * @author Gerhard Petracek
+ */
+@Target(METHOD)
+@Retention(RUNTIME)
+@Documented
+public @interface PreRenderView
+{
+}
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/jsf/api/config/view/PreViewAction.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/jsf/api/config/view/PreViewAction.java?rev=1002884&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/jsf/api/config/view/PreViewAction.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/jsf/api/config/view/PreViewAction.java Wed Sep 29 22:54:11 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.jsf.api.config.view;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static java.lang.annotation.ElementType.METHOD;
+
+/**
+ * @author Gerhard Petracek
+ */
+@Target(METHOD)
+@Retention(RUNTIME)
+@Documented
+public @interface PreViewAction
+{
+}
\ No newline at end of file
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/PageBeanConfigEntry.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/config/view/PageBeanConfigEntry.java?rev=1002884&r1=1002883&r2=1002884&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/PageBeanConfigEntry.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/PageBeanConfigEntry.java Wed Sep 29 22:54:11 2010
@@ -20,6 +20,8 @@ package org.apache.myfaces.extensions.cd
import org.apache.myfaces.extensions.cdi.jsf.api.listener.phase.BeforePhase;
import org.apache.myfaces.extensions.cdi.jsf.api.listener.phase.AfterPhase;
+import org.apache.myfaces.extensions.cdi.jsf.api.config.view.PreViewAction;
+import org.apache.myfaces.extensions.cdi.jsf.api.config.view.PreRenderView;
import static org.apache.myfaces.extensions.cdi.jsf.impl.util.ExceptionUtils.unsupportedPhasesLifecycleCallback;
import javax.faces.event.PhaseId;
@@ -29,6 +31,7 @@ import java.util.Map;
import java.util.HashMap;
import java.util.Collections;
import java.util.List;
+import java.util.ArrayList;
/**
* @author Gerhard Petracek
@@ -41,6 +44,9 @@ class PageBeanConfigEntry
private final Map<PhaseId, PhasesLifecycleCallbackEntry> phasesLifecycleCallbacks;
+ private List<Method> preViewActionMethods = new ArrayList<Method>();
+ private List<Method> preRenderViewMethods = new ArrayList<Method>();
+
PageBeanConfigEntry(String beanName, Class beanClass)
{
this.beanName = beanName;
@@ -63,6 +69,17 @@ class PageBeanConfigEntry
return phasesLifecycleCallbacks.get(phaseId);
}
+
+ List<Method> getPreViewActionMethods()
+ {
+ return this.preViewActionMethods;
+ }
+
+ List<Method> getPreRenderViewMethods()
+ {
+ return this.preRenderViewMethods;
+ }
+
private Map<PhaseId, PhasesLifecycleCallbackEntry> findCallbackDefinitions(Class beanClass)
{
Class currentClass = beanClass;
@@ -84,6 +101,14 @@ class PageBeanConfigEntry
afterCallbackEntryHelper.add(
currentMethod.getAnnotation(AfterPhase.class).value(), currentMethod);
}
+ else if(currentMethod.isAnnotationPresent(PreViewAction.class))
+ {
+ this.preViewActionMethods.add(currentMethod);
+ }
+ else if(currentMethod.isAnnotationPresent(PreRenderView.class))
+ {
+ this.preRenderViewMethods.add(currentMethod);
+ }
}
currentClass = currentClass.getSuperclass();
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/PhasesLifecycleCallbackPhaseListener.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/config/view/PhasesLifecycleCallbackPhaseListener.java?rev=1002884&r1=1002883&r2=1002884&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/PhasesLifecycleCallbackPhaseListener.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/PhasesLifecycleCallbackPhaseListener.java Wed Sep 29 22:54:11 2010
@@ -24,6 +24,7 @@ import org.apache.myfaces.extensions.cdi
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseListener;
+import javax.faces.event.PhaseId;
import javax.faces.component.UIViewRoot;
import java.util.List;
import java.lang.reflect.Method;
@@ -57,6 +58,7 @@ public final class PhasesLifecycleCallba
{
try
{
+ processPreRenderView(event);
processPhaseCallbacks(event, true);
}
catch (Exception e)
@@ -69,6 +71,24 @@ public final class PhasesLifecycleCallba
}
}
+ private void processPreRenderView(PhaseEvent event)
+ {
+ if (event.getPhaseId().equals(PhaseId.RENDER_RESPONSE))
+ {
+ processPreRenderView(event.getFacesContext().getViewRoot().getViewId());
+ }
+ }
+
+ private void processPreRenderView(String viewId)
+ {
+ ViewConfigEntry viewDefinitionEntry = ViewConfigCache.getViewDefinition(viewId);
+
+ if (viewDefinitionEntry != null)
+ {
+ viewDefinitionEntry.invokePreRenderViewMethods();
+ }
+ }
+
public javax.faces.event.PhaseId getPhaseId()
{
return javax.faces.event.PhaseId.ANY_PHASE;
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigEntry.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/config/view/ViewConfigEntry.java?rev=1002884&r1=1002883&r2=1002884&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigEntry.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigEntry.java Wed Sep 29 22:54:11 2010
@@ -21,6 +21,7 @@ package org.apache.myfaces.extensions.cd
import org.apache.myfaces.extensions.cdi.core.api.config.view.ViewConfig;
import org.apache.myfaces.extensions.cdi.core.api.security.AccessDecisionVoter;
import org.apache.myfaces.extensions.cdi.core.api.security.DefaultErrorView;
+import org.apache.myfaces.extensions.cdi.core.impl.utils.CodiUtils;
import org.apache.myfaces.extensions.cdi.jsf.api.config.view.NavigationMode;
import org.apache.myfaces.extensions.cdi.jsf.api.config.view.PageBean;
@@ -30,6 +31,7 @@ import java.util.Collections;
import java.util.ArrayList;
import java.beans.Introspector;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
/**
* @author Gerhard Petracek
@@ -97,6 +99,55 @@ public class ViewConfigEntry
return beanDefinition;
}
+ public void invokePreViewActionMethods()
+ {
+ for(PageBeanConfigEntry beanEntry : getBeanDefinitions())
+ {
+ processCallbacks(beanEntry, beanEntry.getPreViewActionMethods());
+ }
+ }
+
+ void invokePreRenderViewMethods()
+ {
+ for(PageBeanConfigEntry beanEntry : getBeanDefinitions())
+ {
+ processCallbacks(beanEntry, beanEntry.getPreRenderViewMethods());
+ }
+ }
+
+ private void processCallbacks(PageBeanConfigEntry beanEntry, List<Method> methodList)
+ {
+ Object bean;
+ if (!methodList.isEmpty())
+ {
+ //TODO provide a detailed error message in case of a missing bean
+ bean = CodiUtils.getOrCreateScopedInstanceOfBeanByName(beanEntry.getBeanName(), Object.class);
+
+ if (bean == null)
+ {
+ return;
+ }
+
+ for (Method callbackMethod : methodList)
+ {
+ invokeMethod(bean, callbackMethod);
+ }
+ }
+ }
+
+ private void invokeMethod(Object bean, Method preProcessMethod)
+ {
+ try
+ {
+ preProcessMethod.setAccessible(true);
+ preProcessMethod.invoke(bean);
+ }
+ catch (Exception e)
+ {
+ throw new IllegalStateException(e);
+ }
+ }
+
public Class<? extends AccessDecisionVoter>[] getAccessDecisionVoters()
{
return accessDecisionVoters;
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/security/SecurityViolationAwareActionListener.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/security/SecurityViolationAwareActionListener.java?rev=1002884&r1=1002883&r2=1002884&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/security/SecurityViolationAwareActionListener.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/security/SecurityViolationAwareActionListener.java Wed Sep 29 22:54:11 2010
@@ -46,6 +46,9 @@ public class SecurityViolationAwareActio
{
try
{
+ //TODO
+ new ViewControllerActionListener().processAction(actionEvent);
+
this.wrapped.processAction(actionEvent);
}
catch (FacesException facesException)
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/security/ViewControllerActionListener.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/security/ViewControllerActionListener.java?rev=1002884&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/security/ViewControllerActionListener.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/security/ViewControllerActionListener.java Wed Sep 29 22:54:11 2010
@@ -0,0 +1,76 @@
+/*
+ * 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.security;
+
+import org.apache.myfaces.extensions.cdi.core.api.Deactivatable;
+import org.apache.myfaces.extensions.cdi.core.api.util.ClassUtils;
+import org.apache.myfaces.extensions.cdi.jsf.impl.config.view.ViewConfigEntry;
+import org.apache.myfaces.extensions.cdi.jsf.impl.config.view.ViewConfigCache;
+
+import javax.faces.event.ActionListener;
+import javax.faces.event.ActionEvent;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class ViewControllerActionListener implements ActionListener, Deactivatable
+{
+ private ActionListener wrapped;
+
+ private final boolean deactivated;
+
+ ViewControllerActionListener()
+ {
+ this.deactivated = !isActivated();
+ }
+
+ public ViewControllerActionListener(ActionListener wrapped)
+ {
+ this();
+ this.wrapped = wrapped;
+ }
+
+ public void processAction(ActionEvent actionEvent) throws AbortProcessingException
+ {
+ if(this.deactivated)
+ {
+ return;
+ }
+
+ ViewConfigEntry viewConfigEntry =
+ ViewConfigCache.getViewDefinition(FacesContext.getCurrentInstance().getViewRoot().getViewId());
+
+ if(viewConfigEntry != null)
+ {
+ viewConfigEntry.invokePreViewActionMethods();
+ }
+
+ if(this.wrapped != null)
+ {
+ this.wrapped.processAction(actionEvent);
+ }
+ }
+
+ public boolean isActivated()
+ {
+ return ClassUtils.isClassActivated(getClass());
+ }
+}