You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2013/10/24 21:26:41 UTC
svn commit: r1535505 - in /myfaces/core/trunk/impl/src/main:
java/org/apache/myfaces/spi/impl/ resources/META-INF/services/
Author: lu4242
Date: Thu Oct 24 19:26:41 2013
New Revision: 1535505
URL: http://svn.apache.org/r1535505
Log:
MYFACES-3786: Web Container injection support should be provided for additional lifecycle artifacts (not just managed beans)
Added:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/CDIAnnotationDelegateInjectionProvider.java (with props)
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultInjectionProviderFactory.java
myfaces/core/trunk/impl/src/main/resources/META-INF/services/org.apache.myfaces.spi.InjectionProvider
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/CDIAnnotationDelegateInjectionProvider.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/CDIAnnotationDelegateInjectionProvider.java?rev=1535505&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/CDIAnnotationDelegateInjectionProvider.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/CDIAnnotationDelegateInjectionProvider.java Thu Oct 24 19:26:41 2013
@@ -0,0 +1,87 @@
+/*
+ * 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.spi.impl;
+
+import javax.faces.context.ExternalContext;
+import org.apache.myfaces.shared.util.ClassUtils;
+import org.apache.myfaces.spi.InjectionProvider;
+import org.apache.myfaces.spi.InjectionProviderException;
+import org.apache.myfaces.util.ExternalSpecifications;
+
+/**
+ * Delegation pattern to avoid direct instantiation
+ */
+public class CDIAnnotationDelegateInjectionProvider extends InjectionProvider
+{
+ private InjectionProvider delegate;
+ private final boolean available;
+
+ public CDIAnnotationDelegateInjectionProvider(ExternalContext externalContext)
+ {
+ if (ExternalSpecifications.isCDIAvailable(externalContext))
+ {
+ try
+ {
+ Class clazz = ClassUtils.simpleClassForName(
+ "org.apache.myfaces.cdi.impl.CDIAnnotationInjectionProvider");
+ delegate = (InjectionProvider) clazz.getConstructor(
+ ExternalContext.class).newInstance(externalContext);
+ }
+ catch(Exception e)
+ {
+ //Ignore
+ }
+ }
+ available = (delegate != null);
+ }
+
+ @Override
+ public Object inject(Object instance) throws InjectionProviderException
+ {
+ if (available)
+ {
+ return delegate.inject(instance);
+ }
+ return null;
+ }
+
+ @Override
+ public void postConstruct(Object instance, Object creationMetaData) throws InjectionProviderException
+ {
+ if (available)
+ {
+ delegate.postConstruct(instance, creationMetaData);
+ }
+ }
+
+ @Override
+ public void preDestroy(Object instance, Object creationMetaData) throws InjectionProviderException
+ {
+ if (available)
+ {
+ delegate.preDestroy(instance, creationMetaData);
+ }
+ }
+
+ @Override
+ public boolean isAvailable()
+ {
+ return available;
+ }
+}
Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/CDIAnnotationDelegateInjectionProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultInjectionProviderFactory.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultInjectionProviderFactory.java?rev=1535505&r1=1535504&r2=1535505&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultInjectionProviderFactory.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultInjectionProviderFactory.java Thu Oct 24 19:26:41 2013
@@ -269,6 +269,8 @@ public class DefaultInjectionProviderFac
private InjectionProvider resolveFallbackInjectionProvider(ExternalContext externalContext)
{
+ /* Added entry in META-INF/services/org.apache.myfaces.spi.InjectionProvider to
+ * give precedence to CDI integration instead server integration.
if (ExternalSpecifications.isCDIAvailable(externalContext))
{
try
@@ -283,6 +285,7 @@ public class DefaultInjectionProviderFac
//Ignore
}
}
+ */
try
{
Modified: myfaces/core/trunk/impl/src/main/resources/META-INF/services/org.apache.myfaces.spi.InjectionProvider
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/resources/META-INF/services/org.apache.myfaces.spi.InjectionProvider?rev=1535505&r1=1535504&r2=1535505&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/resources/META-INF/services/org.apache.myfaces.spi.InjectionProvider (original)
+++ myfaces/core/trunk/impl/src/main/resources/META-INF/services/org.apache.myfaces.spi.InjectionProvider Thu Oct 24 19:26:41 2013
@@ -1,2 +1,3 @@
+org.apache.myfaces.spi.impl.CDIAnnotationDelegateInjectionProvider
org.apache.myfaces.spi.impl.TomcatAnnotationInjectionProvider
org.apache.myfaces.spi.impl.Tomcat7AnnotationInjectionProvider
\ No newline at end of file