Return-Path: X-Original-To: apmail-myfaces-commits-archive@www.apache.org Delivered-To: apmail-myfaces-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DC9276E17 for ; Sat, 23 Jul 2011 12:42:43 +0000 (UTC) Received: (qmail 98588 invoked by uid 500); 23 Jul 2011 12:42:43 -0000 Delivered-To: apmail-myfaces-commits-archive@myfaces.apache.org Received: (qmail 98524 invoked by uid 500); 23 Jul 2011 12:42:42 -0000 Mailing-List: contact commits-help@myfaces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "MyFaces Development" Delivered-To: mailing list commits@myfaces.apache.org Received: (qmail 98516 invoked by uid 99); 23 Jul 2011 12:42:42 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 23 Jul 2011 12:42:42 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 23 Jul 2011 12:42:39 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 63E5023889B2 for ; Sat, 23 Jul 2011 12:42:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1150097 - in /myfaces/extensions/cdi/trunk/core: api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/ api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/startup/ impl/src/main/java/org/apache/myfaces/extensions/... Date: Sat, 23 Jul 2011 12:42:19 -0000 To: commits@myfaces.apache.org From: gpetracek@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110723124219.63E5023889B2@eris.apache.org> Author: gpetracek Date: Sat Jul 23 12:42:17 2011 New Revision: 1150097 URL: http://svn.apache.org/viewvc?rev=1150097&view=rev Log: EXTCDI-198 and EXTCDI-209 optional simple service provider Added: myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/SimpleServiceProvider.java myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/SimpleServiceProviderContext.java myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/spi/ myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/spi/EditableServiceProviderContext.java Modified: myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/ServiceProviderContext.java myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/startup/CodiStartupBroadcaster.java myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/DefaultServiceProvider.java myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/DefaultServiceProviderContext.java myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/serviceloader/ServiceProviderTest.java Modified: myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/ServiceProviderContext.java URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/ServiceProviderContext.java?rev=1150097&r1=1150096&r2=1150097&view=diff ============================================================================== --- myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/ServiceProviderContext.java (original) +++ myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/ServiceProviderContext.java Sat Jul 23 12:42:17 2011 @@ -19,20 +19,16 @@ package org.apache.myfaces.extensions.cdi.core.api.provider; import javax.enterprise.inject.Typed; -import java.util.List; /** * @author Gerhard Petracek */ -//TODO @Typed() public abstract class ServiceProviderContext { + /** + * Allows to provide a custom {@link ClassLoader} + * @return the class-loader which should be used for the first try + */ public abstract ClassLoader getClassLoader(); - - public abstract T postConstruct(T instance); - - public abstract boolean filterService(Class serviceClass); - - public abstract void preInstallServices(List> foundServiceClasses); } Modified: myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/startup/CodiStartupBroadcaster.java URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/startup/CodiStartupBroadcaster.java?rev=1150097&r1=1150096&r2=1150097&view=diff ============================================================================== --- myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/startup/CodiStartupBroadcaster.java (original) +++ myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/startup/CodiStartupBroadcaster.java Sat Jul 23 12:42:17 2011 @@ -83,26 +83,6 @@ public abstract class CodiStartupBroadca { return classLoader; } - - @Override - public StartupEventBroadcaster postConstruct(StartupEventBroadcaster instance) - { - //do nothing - return instance; - } - - @Override - public boolean filterService(Class serviceClass) - { - //do nothing - return false; - } - - @Override - public void preInstallServices(List> foundServiceClasses) - { - //do nothing - } }); List> filter = broadcasterFilter.get(classLoader); Modified: myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/DefaultServiceProvider.java URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/DefaultServiceProvider.java?rev=1150097&r1=1150096&r2=1150097&view=diff ============================================================================== --- myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/DefaultServiceProvider.java (original) +++ myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/DefaultServiceProvider.java Sat Jul 23 12:42:17 2011 @@ -18,31 +18,25 @@ */ package org.apache.myfaces.extensions.cdi.core.impl.provider; -import org.apache.myfaces.extensions.cdi.core.api.UnhandledException; import org.apache.myfaces.extensions.cdi.core.api.provider.ServiceProviderContext; import org.apache.myfaces.extensions.cdi.core.api.util.ClassUtils; +import org.apache.myfaces.extensions.cdi.core.impl.provider.spi.EditableServiceProviderContext; import javax.enterprise.event.Observes; +import javax.enterprise.inject.Typed; import javax.enterprise.inject.spi.AfterDeploymentValidation; -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.lang.reflect.Constructor; -import java.net.URL; import java.util.ArrayList; -import java.util.Collections; -import java.util.Enumeration; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.apache.myfaces.extensions.cdi.core.api.provider.ServiceProvider; /** * @author Gerhard Petracek */ -public class DefaultServiceProvider extends ServiceProvider +@Typed() +@SuppressWarnings({"unchecked"}) +public class DefaultServiceProvider extends SimpleServiceProvider { - protected List> foundServiceClasses = new ArrayList>(); private static Map deploymentFinished = new ConcurrentHashMap(); private static Map, List>> serviceCache = new ConcurrentHashMap, List>>(); @@ -64,193 +58,63 @@ public class DefaultServiceProvider e { List> result = serviceCache.get(this.serviceType); - if(result == null) + if(result != null) { - result = resolveServiceImplementations(); - } - - if(result == null) - { - return Collections.emptyList(); - } - - List foundServices = new ArrayList(); - - for(Class serviceClass : result) - { - foundServices.add(createInstance(serviceClass)); - } - - return foundServices; - } - - private List> resolveServiceImplementations() - { - for (URL configFile : getConfigFileList()) - { - loadConfiguredServices(configFile); - } - - this.serviceProviderContext.preInstallServices(this.foundServiceClasses); - - serviceCache.put(this.serviceType, this.foundServiceClasses); - return this.foundServiceClasses; - } - - protected void activateInjectionSupport(@Observes AfterDeploymentValidation afterDeploymentValidation) - { - deploymentFinished.put(ClassUtils.getClassLoader(null), Boolean.TRUE); - } + List foundServices = new ArrayList(); - private List getConfigFileList() - { - List serviceFiles = new ArrayList(); - - try - { - Enumeration serviceFileEnumerator = - this.serviceProviderContext.getClassLoader().getResources(getConfigFileLocation()); - - while (serviceFileEnumerator.hasMoreElements()) + for(Class serviceClass : result) { - serviceFiles.add(serviceFileEnumerator.nextElement()); + foundServices.add(createInstance(serviceClass)); } + + return foundServices; } - catch (Exception e) - { - throw new UnhandledException( - "Failed to load " + this.serviceType.getName() + " configured in " + getConfigFileLocation(), e); - } - return serviceFiles; - } - private String getConfigFileLocation() - { - return SERVICE_CONFIG + this.serviceType.getName(); + return super.loadServiceImplementations(); } - private void loadConfiguredServices(URL serviceFile) + @Override + protected List> resolveServiceImplementations() { - InputStream inputStream = null; + super.resolveServiceImplementations(); - try - { - String serviceClassName; - inputStream = serviceFile.openStream(); - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, FILE_ENCODING)); - - while ((serviceClassName = bufferedReader.readLine()) != null) - { - serviceClassName = extractConfiguredServiceClassName(serviceClassName); - if (!"".equals(serviceClassName)) - { - loadService(serviceClassName); - } - } - } - catch (Exception e) + if(this.serviceProviderContext instanceof EditableServiceProviderContext) { - throw new UnhandledException("Failed to process service-config: " + serviceFile, e); + ((EditableServiceProviderContext)this.serviceProviderContext) + .preInstallServices(this.foundServiceClasses); } - finally - { - if (inputStream != null) - { - try - { - inputStream.close(); - } - catch (Exception e) - { - throw new UnhandledException("Failed to close " + serviceFile, e); - } - } - } - } - - private String extractConfiguredServiceClassName(String currentConfigLine) - { - int startOfComment = currentConfigLine.indexOf('#'); - if (startOfComment > -1) - { - currentConfigLine = currentConfigLine.substring(0, startOfComment); - } - return currentConfigLine.trim(); + serviceCache.put(this.serviceType, this.foundServiceClasses); + return this.foundServiceClasses; } - private void loadService(String serviceClassName) + protected boolean isServiceSupported(Class serviceClass) { - Class serviceClass = (Class) loadClass(serviceClassName); - - if (serviceClass != null && !this.foundServiceClasses.contains(serviceClass) && - !this.serviceProviderContext.filterService(serviceClass)) - { - this.foundServiceClasses.add(serviceClass); - } - else if(serviceClass == null) + //noinspection SimplifiableIfStatement + if(this.serviceProviderContext instanceof EditableServiceProviderContext) { - throw new IllegalStateException(serviceClassName + " couldn't be loaded. " + - "Please ensure that this class is in the classpath or remove the entry from " - + getConfigFileLocation() + ". Or mark it as optional."); + return !((EditableServiceProviderContext)this.serviceProviderContext) + .filterService(serviceClass); } + return true; } - private Class loadClass(String serviceClassName) + @Override + protected T createInstance(Class serviceClass) { - Class targetClass = ClassUtils.tryToLoadClassForName(serviceClassName); + T instance = super.createInstance(serviceClass); - if(targetClass == null) + if(this.serviceProviderContext instanceof EditableServiceProviderContext) { - targetClass = loadClassForName(serviceClassName, this.serviceProviderContext.getClassLoader()); - - if(targetClass == null) - { - targetClass = loadClassForName(serviceClassName, ClassUtils.getClassLoader(null)); - - if(targetClass == null) - { - return null; - } - } + return ((EditableServiceProviderContext)this.serviceProviderContext).postConstruct(instance); } - return targetClass.asSubclass(this.serviceType); + return instance; } - private static Class loadClassForName(String serviceClassName, ClassLoader classLoader) - { - if(classLoader == null) - { - return null; - } - - try - { - return classLoader.loadClass(serviceClassName); - } - catch (Exception e) - { - return loadClassForName(serviceClassName, classLoader.getParent()); - } - } - - private T createInstance(Class serviceClass) + protected void activateInjectionSupport(@Observes AfterDeploymentValidation afterDeploymentValidation) { - try - { - Constructor constructor = serviceClass.getDeclaredConstructor(); - constructor.setAccessible(true); - T instance = (T)constructor.newInstance(); - - this.serviceProviderContext.postConstruct(instance); - - return instance; - } - catch (Exception e) - { - return null; - } + deploymentFinished.put(ClassUtils.getClassLoader(null), Boolean.TRUE); } //deactivated by default - register this class as cdi extension to activate it @@ -264,13 +128,4 @@ public class DefaultServiceProvider e foundServiceClasses.clear(); serviceCache.clear(); } - - /** - * {@inheritDoc} - */ - @Override - public String toString() - { - return "Config file: " + getConfigFileLocation(); - } } Modified: myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/DefaultServiceProviderContext.java URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/DefaultServiceProviderContext.java?rev=1150097&r1=1150096&r2=1150097&view=diff ============================================================================== --- myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/DefaultServiceProviderContext.java (original) +++ myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/DefaultServiceProviderContext.java Sat Jul 23 12:42:17 2011 @@ -20,6 +20,7 @@ package org.apache.myfaces.extensions.cd import org.apache.myfaces.extensions.cdi.core.api.tools.InvocationOrderComparator; import org.apache.myfaces.extensions.cdi.core.api.util.ClassUtils; +import org.apache.myfaces.extensions.cdi.core.impl.provider.spi.EditableServiceProviderContext; import org.apache.myfaces.extensions.cdi.core.impl.util.ActivationUtils; import org.apache.myfaces.extensions.cdi.core.impl.util.CodiUtils; @@ -33,7 +34,8 @@ import javax.enterprise.inject.Typed; * @author Gerhard Petracek */ @Typed -public class DefaultServiceProviderContext extends ServiceProviderContext +public class DefaultServiceProviderContext + extends ServiceProviderContext implements EditableServiceProviderContext { protected boolean deploymentFinished = false; @@ -49,7 +51,6 @@ public class DefaultServiceProviderConte /** * {@inheritDoc} */ - @Override public T postConstruct(T instance) { if(this.deploymentFinished) @@ -63,7 +64,6 @@ public class DefaultServiceProviderConte /** * {@inheritDoc} */ - @Override public boolean filterService(Class serviceClass) { return !ActivationUtils.isActivated(serviceClass, SystemPropertyExpressionInterpreter.class); @@ -73,7 +73,6 @@ public class DefaultServiceProviderConte * {@inheritDoc} */ //TODO remove all usages of InvocationOrderComparator which aren't needed any more - @Override public void preInstallServices(List> foundServiceClasses) { if(foundServiceClasses != null && !foundServiceClasses.isEmpty()) Added: myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/SimpleServiceProvider.java URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/SimpleServiceProvider.java?rev=1150097&view=auto ============================================================================== --- myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/SimpleServiceProvider.java (added) +++ myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/SimpleServiceProvider.java Sat Jul 23 12:42:17 2011 @@ -0,0 +1,243 @@ +/* + * 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.impl.provider; + +import org.apache.myfaces.extensions.cdi.core.api.UnhandledException; +import org.apache.myfaces.extensions.cdi.core.api.provider.ServiceProvider; +import org.apache.myfaces.extensions.cdi.core.api.provider.ServiceProviderContext; +import org.apache.myfaces.extensions.cdi.core.api.util.ClassUtils; + +import javax.enterprise.inject.Typed; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.reflect.Constructor; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Enumeration; +import java.util.List; + +/** + * @author Gerhard Petracek + */ +@Typed() +public class SimpleServiceProvider extends ServiceProvider +{ + protected List> foundServiceClasses = new ArrayList>(); + + protected SimpleServiceProvider(Class serviceType, ServiceProviderContext serviceProviderContext) + { + super(serviceType, serviceProviderContext); + } + + /** + * {@inheritDoc} + */ + protected List loadServiceImplementations() + { + List> result = resolveServiceImplementations(); + + if(result == null) + { + return Collections.emptyList(); + } + + List foundServices = new ArrayList(); + + for(Class serviceClass : result) + { + foundServices.add(createInstance(serviceClass)); + } + + return foundServices; + } + + protected List> resolveServiceImplementations() + { + for (URL configFile : getConfigFileList()) + { + loadConfiguredServices(configFile); + } + + return this.foundServiceClasses; + } + + protected List getConfigFileList() + { + List serviceFiles = new ArrayList(); + + try + { + Enumeration serviceFileEnumerator = + this.serviceProviderContext.getClassLoader().getResources(getConfigFileLocation()); + + while (serviceFileEnumerator.hasMoreElements()) + { + serviceFiles.add(serviceFileEnumerator.nextElement()); + } + } + catch (Exception e) + { + throw new UnhandledException( + "Failed to load " + this.serviceType.getName() + " configured in " + getConfigFileLocation(), e); + } + return serviceFiles; + } + + protected String getConfigFileLocation() + { + return SERVICE_CONFIG + this.serviceType.getName(); + } + + protected void loadConfiguredServices(URL serviceFile) + { + InputStream inputStream = null; + + try + { + String serviceClassName; + inputStream = serviceFile.openStream(); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, FILE_ENCODING)); + + while ((serviceClassName = bufferedReader.readLine()) != null) + { + serviceClassName = extractConfiguredServiceClassName(serviceClassName); + if (!"".equals(serviceClassName)) + { + loadService(serviceClassName); + } + } + } + catch (Exception e) + { + throw new UnhandledException("Failed to process service-config: " + serviceFile, e); + } + finally + { + if (inputStream != null) + { + try + { + inputStream.close(); + } + catch (Exception e) + { + throw new UnhandledException("Failed to close " + serviceFile, e); + } + } + } + } + + protected String extractConfiguredServiceClassName(String currentConfigLine) + { + int startOfComment = currentConfigLine.indexOf('#'); + + if (startOfComment > -1) + { + currentConfigLine = currentConfigLine.substring(0, startOfComment); + } + return currentConfigLine.trim(); + } + + protected void loadService(String serviceClassName) + { + Class serviceClass = (Class) loadClass(serviceClassName); + + if (serviceClass != null && + !this.foundServiceClasses.contains(serviceClass) && + isServiceSupported(serviceClass)) + { + this.foundServiceClasses.add(serviceClass); + } + else if(serviceClass == null) + { + throw new IllegalStateException(serviceClassName + " couldn't be loaded. " + + "Please ensure that this class is in the classpath or remove the entry from " + + getConfigFileLocation() + ". Or mark it as optional."); + } + } + + protected boolean isServiceSupported(Class serviceClass) + { + return true; //TODO + } + + protected Class loadClass(String serviceClassName) + { + Class targetClass = ClassUtils.tryToLoadClassForName(serviceClassName); + + if(targetClass == null) + { + targetClass = loadClassForName(serviceClassName, this.serviceProviderContext.getClassLoader()); + + if(targetClass == null) + { + targetClass = loadClassForName(serviceClassName, ClassUtils.getClassLoader(null)); + + if(targetClass == null) + { + return null; + } + } + } + + return targetClass.asSubclass(this.serviceType); + } + + protected static Class loadClassForName(String serviceClassName, ClassLoader classLoader) + { + if(classLoader == null) + { + return null; + } + + try + { + return classLoader.loadClass(serviceClassName); + } + catch (Exception e) + { + return loadClassForName(serviceClassName, classLoader.getParent()); + } + } + + protected T createInstance(Class serviceClass) + { + try + { + Constructor constructor = serviceClass.getDeclaredConstructor(); + constructor.setAccessible(true); + return (T)constructor.newInstance(); + } + catch (Exception e) + { + return null; + } + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() + { + return "Config file: " + getConfigFileLocation(); + } +} Added: myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/SimpleServiceProviderContext.java URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/SimpleServiceProviderContext.java?rev=1150097&view=auto ============================================================================== --- myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/SimpleServiceProviderContext.java (added) +++ myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/SimpleServiceProviderContext.java Sat Jul 23 12:42:17 2011 @@ -0,0 +1,39 @@ +/* + * 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.impl.provider; + +import org.apache.myfaces.extensions.cdi.core.api.provider.ServiceProviderContext; +import org.apache.myfaces.extensions.cdi.core.api.util.ClassUtils; + +import javax.enterprise.inject.Typed; + +/** + * @author Gerhard Petracek + */ +@Typed() +public class SimpleServiceProviderContext extends ServiceProviderContext +{ + /** + * {@inheritDoc} + */ + public ClassLoader getClassLoader() + { + return ClassUtils.getClassLoader(null); + } +} Added: myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/spi/EditableServiceProviderContext.java URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/spi/EditableServiceProviderContext.java?rev=1150097&view=auto ============================================================================== --- myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/spi/EditableServiceProviderContext.java (added) +++ myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/provider/spi/EditableServiceProviderContext.java Sat Jul 23 12:42:17 2011 @@ -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.impl.provider.spi; + +import javax.enterprise.inject.Typed; +import java.util.List; + +/** + * @author Gerhard Petracek + */ +@Typed() +//TODO +public interface EditableServiceProviderContext +{ + T postConstruct(T instance); + + boolean filterService(Class serviceClass); + + void preInstallServices(List> foundServiceClasses); +} Modified: myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/serviceloader/ServiceProviderTest.java URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/serviceloader/ServiceProviderTest.java?rev=1150097&r1=1150096&r2=1150097&view=diff ============================================================================== --- myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/serviceloader/ServiceProviderTest.java (original) +++ myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/serviceloader/ServiceProviderTest.java Sat Jul 23 12:42:17 2011 @@ -28,6 +28,8 @@ import org.apache.myfaces.extensions.cdi import org.apache.myfaces.extensions.cdi.core.impl.config.PropertyFileResolver; import org.apache.myfaces.extensions.cdi.core.impl.config.ServiceLoaderResolver; import org.apache.myfaces.extensions.cdi.core.impl.config.SystemPropertyResolver; +import org.apache.myfaces.extensions.cdi.core.impl.provider.SimpleServiceProvider; +import org.apache.myfaces.extensions.cdi.core.impl.provider.SimpleServiceProviderContext; import org.apache.myfaces.extensions.cdi.core.test.impl.config.TestConfiguredValueResolver; import org.apache.myfaces.extensions.cdi.core.test.impl.config.TestInterface; import org.testng.Assert; @@ -40,7 +42,8 @@ import java.util.List; public class ServiceProviderTest { @Test - public void testExtensions() + @SuppressWarnings({"unchecked"}) + public void testExtensionsWithDefaultServiceProvider() { List extensionList = ServiceProvider.loadServices(Extension.class); Assert.assertEquals(extensionList.size(), 3); @@ -62,6 +65,59 @@ public class ServiceProviderTest } @Test + @SuppressWarnings({"unchecked"}) + public void testExtensionsWithDefaultServiceProviderWithSimple() + { + List extensionList = + ServiceProvider.loadServices(Extension.class, new SimpleServiceProviderContext()); + Assert.assertEquals(extensionList.size(), 3); + + Iterator iterator = extensionList.iterator(); + + Extension extension; + while (iterator.hasNext()) + { + extension = iterator.next(); + Assert.assertTrue(extension instanceof ActivationExtension || + extension instanceof BeanManagerProvider || + extension instanceof CodiDeactivatorExtension); + + iterator.remove(); + } + + Assert.assertEquals(extensionList.size(), 0); + } + + @Test + @SuppressWarnings({"unchecked"}) + public void testExtensionsWithSimpleServiceProvider() + { + List extensionList = new SimpleServiceProvider(Extension.class, new SimpleServiceProviderContext()) { + @Override + public List loadServiceImplementations() + { + return super.loadServiceImplementations(); + } + }.loadServiceImplementations(); + Assert.assertEquals(extensionList.size(), 3); + + Iterator iterator = extensionList.iterator(); + + Extension extension; + while (iterator.hasNext()) + { + extension = iterator.next(); + Assert.assertTrue(extension instanceof ActivationExtension || + extension instanceof BeanManagerProvider || + extension instanceof CodiDeactivatorExtension); + + iterator.remove(); + } + + Assert.assertEquals(extensionList.size(), 0); + } + + @Test public void testDeactivatedImplementationConditionalExtensions() { System.setProperty("env", "test"); @@ -101,6 +157,10 @@ public class ServiceProviderTest Assert.assertNotNull(ClassUtils.tryToLoadClassForName( "org.apache.myfaces.extensions.cdi.core.impl.provider.DefaultServiceProvider")); Assert.assertNotNull(ClassUtils.tryToLoadClassForName( + "org.apache.myfaces.extensions.cdi.core.impl.provider.SimpleServiceProvider")); + Assert.assertNotNull(ClassUtils.tryToLoadClassForName( "org.apache.myfaces.extensions.cdi.core.impl.provider.DefaultServiceProviderContext")); + Assert.assertNotNull(ClassUtils.tryToLoadClassForName( + "org.apache.myfaces.extensions.cdi.core.impl.provider.SimpleServiceProviderContext")); } }