├── .gitignore ├── README ├── beancontainer ├── api │ ├── README │ ├── pom.xml │ └── src │ │ ├── META-INF │ │ └── MANIFEST.MF │ │ ├── main │ │ ├── java │ │ │ ├── META-INF │ │ │ │ └── MANIFEST.MF │ │ │ └── org │ │ │ │ └── cdisource │ │ │ │ ├── beancontainer │ │ │ │ ├── AbstractBeanContainer.java │ │ │ │ ├── BeanContainer.java │ │ │ │ ├── BeanContainerExtention.java │ │ │ │ ├── BeanContainerImpl.java │ │ │ │ ├── BeanContainerInitializationException.java │ │ │ │ ├── BeanContainerManager.java │ │ │ │ ├── BeanManagerLocator.java │ │ │ │ ├── BeanNotFoundException.java │ │ │ │ ├── ScopeController.java │ │ │ │ ├── ScopeManager.java │ │ │ │ └── namespace │ │ │ │ │ └── BeanNamespace.java │ │ │ │ └── logging │ │ │ │ ├── JDKLogger.java │ │ │ │ ├── JDKLoggerFactory.java │ │ │ │ ├── LogFactory.java │ │ │ │ ├── LogFactoryManager.java │ │ │ │ ├── LogLevel.java │ │ │ │ ├── Logger.java │ │ │ │ ├── SystemOutLogger.java │ │ │ │ └── SystemOutLoggerFactory.java │ │ └── resources │ │ │ └── META-INF │ │ │ ├── beans.xml │ │ │ └── services │ │ │ ├── javax.enterprise.inject.spi.Extension │ │ │ └── org.cdisource.logging.LogFactory │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── cdisource │ │ │ └── beancontainer │ │ │ └── namespace │ │ │ └── BeanNamespaceTest.java │ │ └── resource │ │ └── META-INF │ │ └── beans.xml ├── jndi-impl │ ├── README │ ├── pom.xml │ └── src │ │ ├── META-INF │ │ └── MANIFEST.MF │ │ ├── main │ │ ├── java │ │ │ ├── META-INF │ │ │ │ └── MANIFEST.MF │ │ │ └── org │ │ │ │ └── cdisource │ │ │ │ └── beancontainer │ │ │ │ └── JndiBeanContainer.java │ │ └── resources │ │ │ └── META-INF │ │ │ └── services │ │ │ └── org.cdisource.beancontainer.BeanContainer │ │ └── test │ │ └── resource │ │ └── META-INF │ │ └── beans.xml ├── openwebbeans-impl │ ├── README │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ ├── META-INF │ │ │ │ └── MANIFEST.MF │ │ │ └── org │ │ │ │ └── cdisource │ │ │ │ └── beancontainer │ │ │ │ └── OpenWebBeansBeanContainer.java │ │ └── resources │ │ │ └── META-INF │ │ │ └── services │ │ │ └── org.cdisource.beancontainer.BeanContainer │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── cdisource │ │ │ └── beancontainer │ │ │ └── OpenWebBeansBeanContainerTest.java │ │ └── resource │ │ └── META-INF │ │ └── beans.xml ├── resin-impl │ ├── README │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ ├── META-INF │ │ │ │ └── MANIFEST.MF │ │ │ └── org │ │ │ │ └── cdisource │ │ │ │ └── beancontainer │ │ │ │ └── ResinBeanContainer.java │ │ └── resources │ │ │ └── META-INF │ │ │ └── services │ │ │ └── org.cdisource.beancontainer.BeanContainer │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── cdisource │ │ │ └── beancontainer │ │ │ └── ResinBeanContainerTest.java │ │ └── resource │ │ └── META-INF │ │ └── beans.xml ├── testing │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── cdisource │ │ │ └── testing │ │ │ ├── AbstractBeanContainerTest.java │ │ │ ├── BeanUsingBeanContainer.java │ │ │ ├── InjectedBean.java │ │ │ ├── InjectedBeanFactory.java │ │ │ ├── NamedBean.java │ │ │ ├── SimpleBean.java │ │ │ ├── SingletonBean.java │ │ │ ├── SomeOtherQualifier.java │ │ │ ├── SomeOtherQualifierQualifier.java │ │ │ └── SomeQualifier.java │ │ └── resources │ │ └── META-INF │ │ └── beans.xml └── weld-impl │ ├── README │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── cdisource │ │ │ └── beancontainer │ │ │ └── WeldBeanContainer.java │ └── resources │ │ └── META-INF │ │ └── services │ │ └── org.cdisource.beancontainer.BeanContainer │ └── test │ ├── java │ └── org │ │ └── cdisource │ │ └── beancontainer │ │ └── WeldBeanContainerTest.java │ └── resource │ └── META-INF │ └── beans.xml ├── cdsource-eclipse-formatter.xml ├── parent ├── README └── pom.xml ├── pom.xml ├── spring ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── cdisource │ │ │ └── springintegration │ │ │ ├── BeanManagerLocationUtil.java │ │ │ ├── CdiApplicationContext.java │ │ │ ├── CdiBeanFactory.java │ │ │ ├── CdiBeanFactoryPostProcessor.java │ │ │ ├── CdiFactoryBean.java │ │ │ ├── Spring.java │ │ │ ├── SpringBridge.java │ │ │ ├── SpringIntegrationExtention.java │ │ │ ├── SpringLookup.java │ │ │ ├── servletsupport │ │ │ └── ApplicationContextFinderServletContextListener.java │ │ │ └── springsupport │ │ │ ├── ApplicationContextLocator.java │ │ │ ├── ApplicationContextLocatorImpl.java │ │ │ └── ApplicationContextLocatorManager.java │ └── resources │ │ └── META-INF │ │ └── web-fragment.xml │ └── test │ ├── java │ └── org │ │ └── cdisource │ │ └── springintegration │ │ ├── CdiBean.java │ │ ├── CdiBean2.java │ │ ├── CdiBeanThatHasSpringInjection.java │ │ ├── CdiBeanThatHasSpringInjection2.java │ │ ├── CdiBeanThatHasSpringLookupInjection.java │ │ ├── ClassWithInjectionPoints.java │ │ ├── FooSpringBean.java │ │ ├── FooSpringBean2.java │ │ ├── FooSpringBean2Impl.java │ │ ├── NamedCdiBean.java │ │ ├── SpringBeanUsingAutoWired.java │ │ ├── SpringBeanUsingStandardInjection.java │ │ ├── SpringBridgeTest.java │ │ ├── SpringIntegrationExtentionTest.java │ │ └── SpringIntegrationUsingLookupExtentionTest.java │ └── resources │ ├── META-INF │ ├── beans.xml │ └── services │ │ ├── javax.enterprise.inject.spi.Extension │ │ └── org.cdisource.logging.LogFactory │ ├── applicationContext.xml │ └── springIntoCdiApplicationContext.xml ├── testing └── junit │ ├── pom.xml │ └── src │ ├── main │ └── java │ │ ├── META-INF │ │ └── MANIFEST.MF │ │ └── org │ │ └── cdisource │ │ └── testing │ │ └── junit │ │ ├── CdiTestRunner.java │ │ └── RunConfig.java │ └── test │ ├── java │ └── org │ │ └── cdisource │ │ └── testing │ │ └── junit │ │ ├── Calculator.java │ │ ├── CdiTestRunnerTest.java │ │ └── MessageBean.java │ └── resources │ └── META-INF │ └── beans.xml └── web ├── pom.xml └── src ├── main └── java │ └── org │ └── cdisource │ └── web │ ├── CDIExpressionResolver.java │ └── CDIServletContextListener.java └── test └── java └── org └── cdisource └── web └── CDIExpressionResolverTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | pom.xml~ 2 | .project 3 | .classpath 4 | .settings/ 5 | target/ 6 | release.properties 7 | *.releaseBackup 8 | *.versionsBackup 9 | 10 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This is CDI Advocate repository. 2 | Currently it hosts CDI beanContainer. 3 | CDI beanContainer is a small wrapper around Caucho Resin Candi and JBoss Seam Weld. 4 | It should be the basis of adding unit tests framework that works with all CDI implementations. 5 | 6 | Apache OpenWebBean support is planned. 7 | We are looking for someone to do the OpenWebBeans work. 8 | 9 | To learn more about this project go here: 10 | * Main website http://sites.google.com/site/cdipojo/ 11 | * Google project code http://code.google.com/p/jee6-cdi/ 12 | * Comprehensive CDI tutorial http://code.google.com/p/jee6-cdi/wiki/DependencyInjectionAnIntroductoryTutorial 13 | * Google Group for email support for examples http://groups.google.com/group/cdiadvocate4j?pli=1 -------------------------------------------------------------------------------- /beancontainer/api/README: -------------------------------------------------------------------------------- 1 | This is CDI Advocate repository. 2 | Currently it hosts CDI beanContainer. 3 | CDI beanContainer is a small wrapper around Caucho Resin Candi and JBoss Seam Weld. 4 | It should be the basis of adding unit tests framework that works with all CDI implementations. 5 | 6 | Apache OpenWebBean support is planned. 7 | We are looking for someone to do the OpenWebBeans work. 8 | 9 | To learn more about this project go here: 10 | * Main website http://sites.google.com/site/cdipojo/ 11 | * Google project code http://code.google.com/p/jee6-cdi/ 12 | * Comprehensive CDI tutorial http://code.google.com/p/jee6-cdi/wiki/DependencyInjectionAnIntroductoryTutorial 13 | * Google Group for email support for examples http://groups.google.com/group/cdiadvocate4j?pli=1 -------------------------------------------------------------------------------- /beancontainer/api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | org.cdisource.beancontainer 4 | beancontainer-api 5 | jar 6 | BeanContainer API 7 | 1.0-SNAPSHOT 8 | 9 | 10 | org.cdisource 11 | cdisource-parent 12 | 1.0-SNAPSHOT 13 | ../../parent 14 | 15 | 16 | 17 | 3.0 18 | 19 | 20 | 21 | 22 | Base API for common bean container 23 | 24 | 25 | javax.enterprise 26 | cdi-api 27 | 1.0-SP1 28 | jar 29 | compile 30 | 31 | 32 | junit 33 | junit 34 | 4.8.2 35 | jar 36 | test 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /beancontainer/api/src/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /beancontainer/api/src/main/java/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /beancontainer/api/src/main/java/org/cdisource/beancontainer/AbstractBeanContainer.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.beancontainer; 2 | 3 | import java.lang.annotation.Annotation; 4 | import java.util.Set; 5 | 6 | import javax.enterprise.context.spi.CreationalContext; 7 | import javax.enterprise.inject.spi.Bean; 8 | import javax.enterprise.inject.spi.BeanManager; 9 | 10 | import org.cdisource.beancontainer.namespace.BeanNamespace; 11 | 12 | /** 13 | * Abstract implementation of the {@link BeanContainer} interface that 14 | * implements the common lookup code once the container is initialized. 15 | *

16 | * Subclasses must implement the methods to actually startup and shutdown the 17 | * container as well as locating an instance of the {@link BeanManager}. 18 | *

19 | * This class also handles exceptions for when an attempt is made to call a 20 | * method on an inititialized container. 21 | * 22 | * @author Andy Gibson 23 | * @author Rick Hightower 24 | * 25 | */ 26 | public abstract class AbstractBeanContainer implements BeanContainer, BeanManagerLocator { 27 | 28 | private BeanNamespace beanNamespace; 29 | 30 | public boolean containsBeanWithName(String name) { 31 | checkForInitialization(); 32 | if (name == null) { 33 | throw new IllegalArgumentException("CDI Bean name cannot be null"); 34 | } 35 | 36 | BeanManager beanManager = locateBeanManager(); 37 | Set> beans = beanManager.getBeans(name); 38 | return beans.isEmpty(); 39 | 40 | } 41 | 42 | 43 | 44 | @Override 45 | public Object getBeanByName(String name) { 46 | checkForInitialization(); 47 | if (name == null) { 48 | throw new IllegalArgumentException("CDI Bean name cannot be null"); 49 | } 50 | 51 | BeanManager beanManager = locateBeanManager(); 52 | Set> beans = beanManager.getBeans(name); 53 | if (beans.isEmpty()) { 54 | throw new BeanNotFoundException( 55 | "Could not locate a bean with name " + name); 56 | } 57 | Bean bean = beanManager.resolve(beans); 58 | CreationalContext context = beanManager 59 | .createCreationalContext(bean); 60 | return beanManager.getReference(bean, bean.getBeanClass(), context); 61 | } 62 | 63 | @Override 64 | public T getBeanByName(Class type, String name) { 65 | @SuppressWarnings("unchecked") 66 | T beanByName = (T) this.getBeanByName(name); 67 | return beanByName; 68 | } 69 | 70 | @Override 71 | public T getBeanByType(Class type, Annotation... qualifiers) { 72 | checkForInitialization(); 73 | if (type == null) { 74 | throw new IllegalArgumentException("CDI Bean type cannot be null"); 75 | } 76 | 77 | BeanManager beanManager = locateBeanManager(); 78 | Set> beans = beanManager.getBeans(type, qualifiers); 79 | if (beans.isEmpty()) { 80 | throw new BeanNotFoundException("Could not locate a bean of type " 81 | + type.getName()); 82 | } 83 | Bean bean = beanManager.resolve(beans); 84 | CreationalContext context = beanManager 85 | .createCreationalContext(bean); 86 | @SuppressWarnings("unchecked") 87 | T result = (T) beanManager.getReference(bean, bean.getBeanClass(), 88 | context); 89 | return result; 90 | } 91 | 92 | /** 93 | * Checks to see if the container is initialized and if not, throws an 94 | * exception for the user. 95 | */ 96 | protected void checkForInitialization() { 97 | if (!isInitialized()) { 98 | throw new IllegalStateException( 99 | "CDI environment has not been initialized through a call to start()"); 100 | } 101 | } 102 | 103 | /** 104 | * Returns an instance of the {@link BeanManager}. Override this method to 105 | * check for initialization which will vary from implementation to 106 | * implementation. 107 | * 108 | * @return The bean manager instance 109 | */ 110 | protected abstract BeanManager locateBeanManager(); 111 | 112 | @Override 113 | public BeanManager getBeanManager() { 114 | return locateBeanManager(); 115 | } 116 | 117 | /** 118 | * Returns true if and only if the CDI environment has been initialized and 119 | * the {@link BeanContainer} is able to return a {@link BeanManager} 120 | * instance. Override this method to determine whether the particular 121 | * {@link BeanContainer} environment has been initialized. 122 | * 123 | * @return Indicates whether the CDI environment has been initialized 124 | */ 125 | protected abstract boolean isInitialized(); 126 | 127 | @Override 128 | public void start() { 129 | if (isInitialized()) { 130 | throw new IllegalStateException( 131 | "CDI Environment has already been initialized"); 132 | } 133 | try { 134 | doStart(); 135 | } catch (Exception e) { 136 | throw new BeanContainerInitializationException( 137 | "Unable to start BeanContainer : " + e.getMessage(), e); 138 | } 139 | 140 | } 141 | 142 | @Override 143 | public void stop() { 144 | if (!isInitialized()) { 145 | throw new IllegalStateException( 146 | "CDI Environment has not been initialized"); 147 | } 148 | doStop(); 149 | } 150 | 151 | @Override 152 | public BeanNamespace getBeanNamespace() { 153 | if (beanNamespace == null) { 154 | synchronized (this) { 155 | if (beanNamespace == null) { 156 | beanNamespace = buildNamespaceLookup(); 157 | } 158 | } 159 | } 160 | 161 | return beanNamespace; 162 | } 163 | 164 | protected BeanNamespace buildNamespaceLookup() { 165 | BeanNamespace namespace = new BeanNamespace(); 166 | BeanManager bm = locateBeanManager(); 167 | for (Bean bean : bm.getBeans(Object.class)) { 168 | String name = bean.getName(); 169 | if (name != null && name.length() != 0) { 170 | namespace.addObject(name, bean); 171 | } 172 | } 173 | return namespace; 174 | } 175 | 176 | /** 177 | * Performs the initialization of the CDI environment. This method can 178 | * assume that it has not already been initialized. Override to implement 179 | * the initialization for a particular CDI implementation. 180 | */ 181 | protected abstract void doStart() throws Exception; 182 | 183 | /** 184 | * Performs the shutdown of the CDI environment. This method can assume that 185 | * it has already been initialized. Override to implement the shutdown for a 186 | * particular CDI implementation. 187 | */ 188 | protected abstract void doStop(); 189 | 190 | @Override 191 | public void startScope(Class scope) { 192 | } 193 | 194 | @Override 195 | public void stopScope(Class scope) { 196 | } 197 | 198 | } 199 | -------------------------------------------------------------------------------- /beancontainer/api/src/main/java/org/cdisource/beancontainer/BeanContainer.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.beancontainer; 2 | 3 | import java.lang.annotation.Annotation; 4 | 5 | import javax.enterprise.inject.spi.Bean; 6 | 7 | import org.cdisource.beancontainer.namespace.BeanNamespace; 8 | 9 | 10 | /** 11 | * BeanContainer interface that defines a common interface to CDI 12 | * implementations. This small abstraction allows us to easily plugin different 13 | * CDI implementations for unit testing and for Java SE applications. 14 | * 15 | * 16 | * @author Rick Hightower 17 | * 18 | */ 19 | public interface BeanContainer { 20 | 21 | /** 22 | * Look up a bean by name. You should really consider using, getBeanByType 23 | * since this is the type safe version. 24 | * 25 | * @param name 26 | * The name of the bean you want to look up. 27 | * @return The bean you looked up. 28 | */ 29 | public Object getBeanByName(String name); 30 | 31 | /** 32 | * Look up a bean by name and pass its type to avoid casting. You should 33 | * really consider using, getBeanByType since this is the type safe version. 34 | * 35 | * @param name 36 | * The name of the bean you want to look up. 37 | * @return The bean you looked up. 38 | */ 39 | public T getBeanByName(Class type, String name); 40 | 41 | /** 42 | * Look up a bean its type and a list of annotations. This is the preferred 43 | * way to look up a bean. 44 | * 45 | * @param type 46 | * The bean type, can be a interface or a super class. 47 | * @param qualifiers 48 | * List of annotation qualifiers to perform the search. 49 | * @return The bean you looked up. 50 | */ 51 | public T getBeanByType(Class type, Annotation... qualifiers); 52 | 53 | /** 54 | * Start the bean container. Gives the container a chance to scan the 55 | * classpath looking for ./META-INF/beans.xml and setting up the beans to be 56 | * vended. 57 | *

58 | * Throws a {@link BeanContainerInitializationException} if there is a 59 | * problem initializing. 60 | * */ 61 | public void start(); 62 | 63 | /** 64 | * Stops the bean container. Allows it to do clean up and call any needed 65 | * callback methods, i.e., 66 | * 67 | * @PostConstruct on singletons 68 | */ 69 | public void stop(); 70 | 71 | /** 72 | * Returns the root instance of the {@link BeanNamespaceNotNeeded} object that can be 73 | * used to look up {@link Bean} instances by name. Used for looking up beans 74 | * that have longer namespaces such as "org.domain.project.name". 75 | * Particularly useful for expression lookups when you only get the 76 | * expression piece by piece. 77 | * 78 | * @return A {@link BeanNamespaceNotNeeded} instance that can be used to lookup 79 | * beans. 80 | */ 81 | public BeanNamespace getBeanNamespace(); 82 | 83 | 84 | public void startScope(Class scope); 85 | public void stopScope(Class scope); 86 | 87 | 88 | 89 | } 90 | -------------------------------------------------------------------------------- /beancontainer/api/src/main/java/org/cdisource/beancontainer/BeanContainerExtention.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.beancontainer; 2 | 3 | import javax.enterprise.event.Observes; 4 | import javax.enterprise.inject.spi.BeforeBeanDiscovery; 5 | import javax.enterprise.inject.spi.Extension; 6 | 7 | public class BeanContainerExtention implements Extension { 8 | void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd) { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /beancontainer/api/src/main/java/org/cdisource/beancontainer/BeanContainerImpl.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.beancontainer; 2 | 3 | import javax.enterprise.inject.spi.BeanManager; 4 | import javax.inject.Inject; 5 | 6 | public class BeanContainerImpl extends AbstractBeanContainer { 7 | @Inject protected BeanManager manager; 8 | 9 | public BeanContainerImpl() { 10 | 11 | } 12 | 13 | public BeanContainerImpl(BeanManager manager) { 14 | this.manager = manager; 15 | } 16 | 17 | @Override 18 | protected BeanManager locateBeanManager() { 19 | return manager; 20 | } 21 | 22 | @Override 23 | protected boolean isInitialized() { 24 | return manager != null; 25 | } 26 | 27 | @Override 28 | protected void doStart() throws Exception { 29 | } 30 | 31 | @Override 32 | protected void doStop() { 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /beancontainer/api/src/main/java/org/cdisource/beancontainer/BeanContainerInitializationException.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.beancontainer; 2 | 3 | /** 4 | * Exception class thrown when the {@link BeanContainer} fails to initialize 5 | * 6 | * @author Andy Gibson 7 | * 8 | */ 9 | public class BeanContainerInitializationException extends RuntimeException { 10 | 11 | private static final long serialVersionUID = -8787336526656793438L; 12 | 13 | public BeanContainerInitializationException(String message) { 14 | super(message); 15 | } 16 | 17 | public BeanContainerInitializationException(String message, Throwable cause) { 18 | super(message, cause); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /beancontainer/api/src/main/java/org/cdisource/beancontainer/BeanContainerManager.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.beancontainer; 2 | 3 | import java.io.PrintWriter; 4 | import java.io.StringWriter; 5 | import java.lang.ref.WeakReference; 6 | import java.util.Collections; 7 | import java.util.Map; 8 | import java.util.Properties; 9 | import java.util.ServiceLoader; 10 | import java.util.WeakHashMap; 11 | 12 | import org.cdisource.logging.Logger; 13 | 14 | 15 | import static org.cdisource.logging.LogFactoryManager.logger; 16 | 17 | 18 | /** 19 | * Thread safe Bean Container Manager that provides access to the CDI 20 | * implementation on the classpath by returning an instance of the 21 | * {@link BeanContainer} that represents that implementation. 22 | *

23 | * You can swap out the BeanContainer just by including the BeanContainer jar 24 | * file for a specific implementation in your project. 25 | *

26 | *

27 | * We look for a file under classpath/META-INF/services called 28 | * org.cdisource.beancontainer.BeanContainer. 29 | *

30 | * This file has one of three values: 31 | *
    32 | *
  1. org.cdisource.beancontainer.ResinBeanContainer
  2. 33 | *
  3. org.cdisource.beancontainer.OpenWebBeansBeanContainer
  4. 34 | *
  5. org.cdisource.beancontainer.WeldBeanContainer
  6. 35 | *
36 | * 37 | * 38 | *

39 | * You can also override which container is used using a System property 40 | * 41 | *

42 | * 43 | * $ java -Dorg.cdisource.beancontainer.BeanContainer=org.cdisource.beancontainer.ResinBeanContainer 44 | * 45 | *

46 | *

47 | * 48 | * @see java.util.ServiceLoader. 49 | * 50 | * @author Rick Hightower 51 | * @author Andy Gibson 52 | * 53 | */ 54 | public class BeanContainerManager { 55 | 56 | /** Logger */ 57 | private static Logger log = logger(BeanContainerManager.class); 58 | 59 | /** Property name that we use to look up the bean container override. */ 60 | public static String PROP_NAME = "org.cdisource.beancontainer.BeanContainer"; 61 | 62 | private static Map> map = Collections 63 | .synchronizedMap(new WeakHashMap>()); 64 | 65 | private static boolean useStatic = false; 66 | private static BeanContainer beanContainer; 67 | 68 | public static void testEnv() { 69 | useStatic=true; 70 | } 71 | 72 | /** 73 | * Thread safe method to create and initialize the {@link BeanContainer} 74 | * implementation on the classpath. 75 | * 76 | */ 77 | public static void initialize() { 78 | log.trace("initialize() called using system properties"); 79 | initialize(System.getProperties()); 80 | } 81 | 82 | /** 83 | * Thread safe method to create and initialize the {@link BeanContainer} 84 | * implementation on the classpath. 85 | * 86 | * @param properties 87 | * Properties to use for initialization 88 | */ 89 | public synchronized static void initialize(Properties properties) { 90 | log.trace("initialize(properties)"); 91 | startUpInstance(properties); 92 | 93 | } 94 | 95 | /** 96 | * Get the bean container instance using system properties. If this method 97 | * is called before one of the initialize methods is called, then the 98 | * manager creates and initializes a {@link BeanContainer} instance to 99 | * return. This is good for calling from unit tests and/or standalone applications. 100 | * It is not a good idea to use this from a web application due to classloader issues. 101 | *

102 | * Auto initializing this way means that we can call the getter from 103 | * anywhere without being totally concerned about who or where the container 104 | * is initialized. 105 | * 106 | * @see BeanContainerManager.PROP_NAME 107 | * @see {@link BeanContainerManager#initialize()} 108 | * */ 109 | public static BeanContainer getInstance() { 110 | 111 | if (useStatic && beanContainer!=null) { 112 | return beanContainer; 113 | } 114 | log.trace("getInstance() called"); 115 | synchronized (map) { 116 | WeakReference weakReference = map.get(Thread.currentThread().getContextClassLoader()); 117 | if (weakReference==null || weakReference.get()==null) { 118 | log.debug("getInstance():: instance was null"); 119 | initialize(); 120 | } 121 | return beanContainer(); 122 | } 123 | } 124 | 125 | private static BeanContainer beanContainer() { 126 | if (useStatic && beanContainer!=null) { 127 | return beanContainer; 128 | } 129 | WeakReference weakReference = map.get(Thread.currentThread().getContextClassLoader()); 130 | if (weakReference== null || weakReference.get() == null) { 131 | throw new IllegalStateException("WeakReference is not set"); 132 | } 133 | return weakReference.get(); 134 | } 135 | 136 | 137 | /** 138 | * Create the bean container instance using system properties. If this method 139 | * is called before one of the initialize methods is called, then the 140 | * manager creates and initializes a {@link BeanContainer} instance to 141 | * return. This is good for calling from unit tests and/or standalone applications. 142 | * It is not a good idea to use this from a web application due to classloader issues. 143 | *

144 | * Auto initializing this way means that we can call the getter from 145 | * anywhere without being totally concerned about who or where the container 146 | * is initialized. 147 | * 148 | * @see BeanContainerManager.PROP_NAME 149 | * @see {@link BeanContainerManager#initialize()} 150 | * */ 151 | public static BeanContainer createInstance() { 152 | log.trace("createInstance() called"); 153 | BeanContainer beanContainer = generateInstance(System.getProperties()); 154 | log.debug("createInstance():: instance is null? %s", beanContainer == null ? "yes" : "no"); 155 | return beanContainer; 156 | } 157 | /** 158 | * Thread safe method to create a new instance of a {@link BeanContainer} 159 | * and start it up and make it available through the 160 | * getInstance() method. 161 | * 162 | * @param properties 163 | * Properties to use for initialization 164 | */ 165 | private synchronized static void startUpInstance(Properties properties) { 166 | log.trace("startUpInstance(properties)"); 167 | BeanContainer instance = generateInstance(properties); 168 | if (instance != null) { 169 | instance.start(); 170 | } 171 | 172 | if (useStatic) { 173 | beanContainer= instance; 174 | } else { 175 | map.put(Thread.currentThread().getContextClassLoader(), new WeakReference(instance)); 176 | } 177 | } 178 | 179 | /** 180 | * Internal method to create a new instance of a {@link BeanContainer} 181 | * implementation. The returned container would not have been initialized 182 | * yet. 183 | * 184 | * @param properties 185 | * Properties to use for initialization 186 | * @return new instance of a {@link BeanContainer} implementation which has 187 | * not yet been started. 188 | */ 189 | private static BeanContainer generateInstance(Properties properties) { 190 | try { 191 | /* The property should override the ServiceLoader if found. */ 192 | String beanContainerClassName = properties.getProperty(PROP_NAME); 193 | 194 | /* If the property was not found, use the service loader. */ 195 | if (beanContainerClassName == null) { 196 | ServiceLoader instances = ServiceLoader.load(BeanContainer.class); 197 | if (instances.iterator().hasNext()) { 198 | return instances.iterator().next(); 199 | 200 | } 201 | } 202 | 203 | if (beanContainerClassName == null) { 204 | StringWriter stringWriter = new StringWriter(); 205 | PrintWriter out = new PrintWriter(stringWriter); 206 | out.println("Unable to find a BeanContainer on your classpath"); 207 | out 208 | .println("Expecting to find beancontainer-weld-impl.jar that has org.cdisource.beancontainer.WeldBeanContainer."); 209 | out 210 | .println("OR, Expecting to find beancontainer-resin-impl.jar that has org.cdisource.beancontainer.ResinBeanContainer."); 211 | out 212 | .println("OR, Expecting to find beancontainer-openwebbeans-impl.jar that has org.cdisource.beancontainer.OpenWebBeansBeanContainer."); 213 | out 214 | .println("OR, Expecting to find some class that implements org.cdisource.beancontainer.BeanContainer on the classpath"); 215 | out 216 | .println("with a META-INF/services/org.cdisource.beancontainer.BeanContainer file that has a single line which is the implementation."); 217 | out 218 | .println(" If this error message does not make sense refer to the JavaDoc for org.cdisource.beancontainer.BeanContainerManager."); 219 | throw new IllegalStateException(stringWriter.toString()); 220 | } 221 | 222 | /* 223 | * Get the classloader associated with the current webapp and not 224 | * the global classloader 225 | */ 226 | ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); 227 | Class clazz = Class.forName(beanContainerClassName, true, contextClassLoader); 228 | return (BeanContainer) clazz.newInstance(); 229 | 230 | } catch (Exception ex) { 231 | throw new RuntimeException(ex); 232 | } 233 | } 234 | 235 | /** 236 | * Thread safe method to shutdown the {@link BeanContainer} instance and 237 | * invalidate it. Further calls to get an instance or initialize will create 238 | * a new instance. 239 | */ 240 | public static synchronized void shutdown() { 241 | BeanContainer beanContainer = beanContainer(); 242 | if (beanContainer!=null) { 243 | beanContainer.stop(); 244 | } 245 | } 246 | } 247 | -------------------------------------------------------------------------------- /beancontainer/api/src/main/java/org/cdisource/beancontainer/BeanManagerLocator.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.beancontainer; 2 | 3 | import javax.enterprise.inject.spi.BeanManager; 4 | 5 | public interface BeanManagerLocator { 6 | /** 7 | * Returns the underlying {@link BeanManager} instance for this 8 | * implementation of CDI. 9 | * 10 | * @return Instance of the {@link BeanManager} implemented by this CDI 11 | * implementation. 12 | */ 13 | BeanManager getBeanManager(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /beancontainer/api/src/main/java/org/cdisource/beancontainer/BeanNotFoundException.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.beancontainer; 2 | 3 | 4 | /** 5 | * Exception thrown when a bean cannot be located 6 | * 7 | * @author Andy Gibson 8 | * 9 | */ 10 | public class BeanNotFoundException extends RuntimeException { 11 | 12 | private static final long serialVersionUID = -1122296335536887240L; 13 | 14 | public BeanNotFoundException(final String message) { 15 | super(message); 16 | } 17 | 18 | public BeanNotFoundException(final String message, Throwable cause) { 19 | super(message, cause); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /beancontainer/api/src/main/java/org/cdisource/beancontainer/ScopeController.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.beancontainer; 2 | 3 | public interface ScopeController { 4 | public void stop(); 5 | public void start(); 6 | } 7 | -------------------------------------------------------------------------------- /beancontainer/api/src/main/java/org/cdisource/beancontainer/ScopeManager.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.beancontainer; 2 | 3 | import java.lang.annotation.Annotation; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import javax.enterprise.context.spi.Context; 8 | import javax.enterprise.inject.spi.AfterBeanDiscovery; 9 | 10 | public class ScopeManager { 11 | private static ScopeManager instance = new ScopeManager(); 12 | 13 | private Map, ScopeController> map = new HashMap, ScopeController>(7); 14 | 15 | public void stop(Class scopeType) { 16 | ScopeController control = map.get(scopeType); 17 | if (control!=null) { 18 | control.stop(); 19 | } 20 | } 21 | public static void startScope(Class scopeType) { 22 | instance.start(scopeType); 23 | } 24 | public static void stopScope(Class scopeType) { 25 | instance.stop(scopeType); 26 | } 27 | 28 | 29 | public void start(Class scopeType) { 30 | ScopeController control = map.get(scopeType); 31 | if (control!=null) { 32 | control.start(); 33 | } 34 | } 35 | 36 | // public void register(ScopeController control, Context context) { 37 | // BeanContainerManager.getInstance().registerContext(context, true); 38 | // map.put(context.getScope(), control); 39 | // } 40 | 41 | public void register(AfterBeanDiscovery abd, ScopeController control, Context context) { 42 | abd.addContext(context); 43 | map.put(context.getScope(), control); 44 | } 45 | 46 | public static ScopeManager getInstance() { 47 | return instance; 48 | } 49 | public static void reset() { 50 | instance.map.clear(); 51 | instance = new ScopeManager(); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /beancontainer/api/src/main/java/org/cdisource/beancontainer/namespace/BeanNamespace.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.beancontainer.namespace; 2 | 3 | import java.util.Map; 4 | import java.util.TreeMap; 5 | 6 | /** 7 | * 8 | * @author Rick Hightower 9 | * @author Andy Gibson 10 | * 11 | */ 12 | public class BeanNamespace{ 13 | 14 | private final Map children = new TreeMap(); 15 | 16 | protected String[] splitName(final String name) { 17 | if (name == null) { 18 | throw new IllegalArgumentException("Object name cannot be null"); 19 | } 20 | 21 | if (name.length() == 0) { 22 | throw new IllegalArgumentException( 23 | "Cannot add bean with a name of zero length"); 24 | } 25 | String[] result = null; 26 | if (name.contains(".")) { 27 | result = name.split("\\."); 28 | } else { 29 | result = new String[] { name }; 30 | } 31 | return result; 32 | } 33 | 34 | /** 35 | * Add named object to the tree. Assumes the last element in the name, or 36 | * the only element in the name if it is a single name, is the actual name 37 | * with anything preceeding it is the namespace. 38 | * 39 | * @param name 40 | * @param object 41 | */ 42 | public void addObject(String name, Object object) { 43 | if (name == null) { 44 | throw new IllegalArgumentException("Object name cannot be null"); 45 | } 46 | String[] path = splitName(name); 47 | BeanNamespace node = this; 48 | // locate the next to last namespace node 49 | for (int i = 0; i < path.length - 1; i++) { 50 | 51 | String key = path[i]; 52 | Object next = node.children.get(key); 53 | // no node exists so create one 54 | if (next == null) { 55 | BeanNamespace newNode = new BeanNamespace(); 56 | node.children.put(key, newNode); 57 | node = newNode; 58 | } else { 59 | // if this is not a graph node, we have an error because some 60 | // object lives on our path. 61 | if (!(next instanceof BeanNamespace)) { 62 | String error = "Invalid namespace clash when inserting " 63 | + name + " - found instance of " + next.getClass(); 64 | throw new IllegalArgumentException(error); 65 | } else { 66 | // move down to the next graph node 67 | node = (BeanNamespace) next; 68 | } 69 | } 70 | } 71 | if (node != null) { 72 | node.children.put(path[path.length - 1], object); 73 | } 74 | } 75 | 76 | /** 77 | * Walks the graph and returns the first non-BeanGraphNode object it finds 78 | * on the expression path. If no non-Node objects are found then we return 79 | * null 80 | * 81 | * @param expression 82 | * Expression used to locate the node. 83 | * 84 | * @return 85 | */ 86 | public Object findObject(String expression) { 87 | String[] path = splitName(expression); 88 | BeanNamespace node = this; 89 | for (String s : path) { 90 | Object o = node.children.get(s); 91 | if (o instanceof BeanNamespace) { 92 | node = (BeanNamespace) o; 93 | } else { 94 | return o; 95 | } 96 | } 97 | return node!=this ? node : null; 98 | } 99 | 100 | public void dump() { 101 | dump(" "); 102 | } 103 | 104 | public void dump(String indent) { 105 | for (String k : children.keySet()) { 106 | Object v = children.get(k); 107 | System.out.println(indent + k + " - " + v); 108 | if (v instanceof BeanNamespace) { 109 | BeanNamespace bn = (BeanNamespace) v; 110 | bn.dump(indent + " "); 111 | } 112 | 113 | } 114 | } 115 | 116 | public boolean contains(final String name) { 117 | return children.containsKey(name); 118 | } 119 | 120 | public String toString() { 121 | return children.keySet().toString(); 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /beancontainer/api/src/main/java/org/cdisource/logging/JDKLogger.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.logging; 2 | 3 | import java.io.Serializable; 4 | import java.util.logging.Level; 5 | 6 | /** 7 | * This is our default logger, it uses JDK logging underneath. 8 | * 9 | * @author Rick Hightower 10 | * 11 | */ 12 | public class JDKLogger implements Logger, Serializable{ 13 | java.util.logging.Logger delegate; 14 | 15 | public JDKLogger() { 16 | 17 | } 18 | 19 | public JDKLogger(java.util.logging.Logger logger){ 20 | this.delegate = logger; 21 | if (delegate==null) { 22 | throw new IllegalStateException("delegate is null"); 23 | } 24 | } 25 | 26 | /** 27 | * 28 | */ 29 | private static final long serialVersionUID = 1L; 30 | 31 | @Override 32 | public void severe(String msg, Object... args) { 33 | if (delegate.isLoggable(Level.SEVERE)) { 34 | delegate.severe(String.format(msg, args)); 35 | } 36 | } 37 | 38 | @Override 39 | public void warning(String msg, Object... args) { 40 | if (delegate.isLoggable(Level.WARNING)) { 41 | delegate.warning(String.format(msg, args)); 42 | } 43 | } 44 | 45 | @Override 46 | public void info(String msg, Object... args) { 47 | if (delegate.isLoggable(Level.INFO)) { 48 | delegate.info(String.format(msg, args)); 49 | } 50 | } 51 | 52 | @Override 53 | public void config(String msg, Object... args) { 54 | if (delegate.isLoggable(Level.CONFIG)) { 55 | delegate.config(String.format(msg, args)); 56 | } 57 | } 58 | 59 | @Override 60 | public void debug(String msg, Object... args) { 61 | if (delegate.isLoggable(Level.FINE)) { 62 | delegate.fine(String.format(msg, args)); 63 | } 64 | 65 | } 66 | 67 | @Override 68 | public void trace(String msg, Object... args) { 69 | if (delegate.isLoggable(Level.FINER)) { 70 | delegate.finer(String.format(msg, args)); 71 | } 72 | } 73 | 74 | @Override 75 | public void finest(String msg, Object... args) { 76 | if (delegate.isLoggable(Level.FINEST)) { 77 | delegate.finest(String.format(msg, args)); 78 | } 79 | } 80 | 81 | public boolean isLevel(LogLevel level) { 82 | switch (level) { 83 | case SEVERE: 84 | return delegate.isLoggable(Level.SEVERE); 85 | case WARNING: 86 | return delegate.isLoggable(Level.WARNING); 87 | case INFO: 88 | return delegate.isLoggable(Level.INFO); 89 | case CONFIG: 90 | return delegate.isLoggable(Level.CONFIG); 91 | case DEBUG: 92 | return delegate.isLoggable(Level.FINE); 93 | case TRACE: 94 | return delegate.isLoggable(Level.FINER); 95 | case FINEST: 96 | return delegate.isLoggable(Level.FINEST); 97 | default: 98 | throw new IllegalStateException("Unknown log level"); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /beancontainer/api/src/main/java/org/cdisource/logging/JDKLoggerFactory.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.logging; 2 | 3 | /** 4 | * This is our default log factory. It uses the JDK logging. 5 | * @author Rick Hightower. 6 | * 7 | */ 8 | public class JDKLoggerFactory implements LogFactory { 9 | 10 | @Override 11 | public Logger getLogger(String name) { 12 | return new JDKLogger(java.util.logging.Logger.getLogger(name)); 13 | } 14 | 15 | @Override 16 | public Logger getLogger(Class clazz) { 17 | return new JDKLogger(java.util.logging.Logger.getLogger(clazz.getName())); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /beancontainer/api/src/main/java/org/cdisource/logging/LogFactory.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.logging; 2 | 3 | /** 4 | * LogFactory loads a logger. 5 | * @author Rick Hightower 6 | * 7 | */ 8 | public interface LogFactory { 9 | Logger getLogger(String string); 10 | Logger getLogger(Class clazz); 11 | } 12 | -------------------------------------------------------------------------------- /beancontainer/api/src/main/java/org/cdisource/logging/LogFactoryManager.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.logging; 2 | import java.util.Properties; 3 | import java.util.ServiceLoader; 4 | 5 | import org.cdisource.beancontainer.BeanContainer; 6 | 7 | /** 8 | * Our very own logging fetish. 9 | * 10 | * @author Rick Hightower 11 | * 12 | */ 13 | public class LogFactoryManager { 14 | public static String PROP_NAME = "org.cdisource.logging.LogFactory"; 15 | 16 | private static LogFactory logFactory; 17 | 18 | /** 19 | * Get the log factory instance using system properties. If this method 20 | * is called before one of the initialize methods is called, then the 21 | * manager creates and initializes a {@link LogFactory} instance to 22 | * return. 23 | *

24 | * Auto initializing this way means that we can call the getter from 25 | * anywhere without being totally concerned about who or where the container 26 | * is initialized. 27 | * 28 | * @see LogFactoryManager.PROP_NAME 29 | * @see {@link LogFactoryManager#initialize()} 30 | * */ 31 | public static LogFactory getInstance() { 32 | if (logFactory == null) { 33 | initialize(); 34 | } 35 | return logFactory; 36 | } 37 | 38 | /** Helper methods to look up the logger. 39 | * 40 | * @param name name of the logger 41 | * @return the logger 42 | */ 43 | public static Logger logger(String name) { 44 | return getInstance().getLogger(name); 45 | } 46 | 47 | /** 48 | * Helper method to look up the logger for a class 49 | * @param clazz class associated with the logger 50 | * @return the logger 51 | */ 52 | public static Logger logger(Class clazz) { 53 | return getInstance().getLogger(clazz); 54 | } 55 | 56 | /** 57 | * Thread safe method to create and initialize the {@link LogFactory} 58 | * implementation on the classpath. 59 | * 60 | */ 61 | public static void initialize() { 62 | initialize(System.getProperties()); 63 | } 64 | 65 | 66 | /** 67 | * Thread safe method to create and initialize the {@link LogFactory} 68 | * implementation on the classpath. 69 | * 70 | * @param properties 71 | * Properties to use for initialization 72 | */ 73 | public synchronized static void initialize(Properties properties) { 74 | if (logFactory != null) { 75 | return; 76 | } 77 | startUpInstance(properties); 78 | 79 | } 80 | 81 | /** 82 | * Thread safe method to create a new instance of a {@link LogFactory} 83 | * and start it up and make it available through the 84 | * getInstance() method. 85 | * 86 | * @param properties 87 | * Properties to use for initialization 88 | */ 89 | private synchronized static void startUpInstance(Properties properties) { 90 | // double check that the instance is null, someone might have created 91 | // it while we were entering this method. 92 | if (logFactory != null) { 93 | return; 94 | } 95 | logFactory = generateInstance(properties); 96 | } 97 | 98 | /** 99 | * Internal method to create a new instance of a {@link LogFactory} 100 | * implementation. The returned container would not have been initialized 101 | * yet. 102 | * 103 | * @param properties 104 | * Properties to use for initialization 105 | * @return new instance of a {@link BeanContainer} implementation which has 106 | * not yet been started. 107 | */ 108 | private static LogFactory generateInstance(Properties properties) { 109 | try { 110 | /* The property should override the ServiceLoader if found. */ 111 | String logFactoryClassname = properties.getProperty(PROP_NAME); 112 | 113 | /* If the property was not found, use the service loader. */ 114 | if (logFactoryClassname == null) { 115 | ServiceLoader instances = ServiceLoader.load(LogFactory.class); 116 | if (instances.iterator().hasNext()) { 117 | return instances.iterator().next(); 118 | } 119 | } 120 | 121 | if (logFactoryClassname == null) { 122 | throw new IllegalStateException("Unable to find the logfactory," + 123 | " this should never happen because we always ship with a log factory"); 124 | } 125 | 126 | /* 127 | * Get the classloader associated with the current webapp and not 128 | * the global classloader 129 | */ 130 | ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); 131 | Class clazz = Class.forName(logFactoryClassname, true, contextClassLoader); 132 | return (LogFactory) clazz.newInstance(); 133 | 134 | } catch (Exception ex) { 135 | throw new RuntimeException(ex); 136 | } 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /beancontainer/api/src/main/java/org/cdisource/logging/LogLevel.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.logging; 2 | 3 | /** 4 | * Our very own log levels. 5 | * @author Rick Hightower 6 | * 7 | */ 8 | public enum LogLevel { 9 | SEVERE, WARNING, INFO, CONFIG, DEBUG, TRACE, FINEST; 10 | } 11 | -------------------------------------------------------------------------------- /beancontainer/api/src/main/java/org/cdisource/logging/Logger.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.logging; 2 | 3 | /** 4 | * Our logging interface. Simple and direct. 5 | * @author Rick Hightower 6 | * 7 | */ 8 | public interface Logger { 9 | void severe (String msg, Object... args); 10 | void warning (String msg, Object... args); 11 | void info (String msg, Object... args); 12 | void config(String msg, Object... args); 13 | void debug(String msg, Object... args); 14 | void trace(String msg, Object... args); 15 | void finest(String msg, Object... args); 16 | boolean isLevel(LogLevel level); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /beancontainer/api/src/main/java/org/cdisource/logging/SystemOutLogger.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.logging; 2 | 3 | import java.io.Serializable; 4 | 5 | import static org.cdisource.logging.LogLevel.*; 6 | 7 | /** 8 | * Useful for when debugging. Sometimes getting log config to do what you want is hard. 9 | * This is as easy as putting the following two props on your command line: 10 | *

11 | *

12 | * 13 | * -Dorg.cdisource.logging.LogLevel=DEBUG -Dorg.cdisource.logging.LogFactory=org.cdisource.logging.SystemOutLoggerFactory 14 | *

15 | * The above is to set the level to DEBUG. The level defaults to INFO. 16 | *

17 | * @see LogLevel 18 | * @author Rick Hightower 19 | * 20 | */ 21 | public class SystemOutLogger implements Logger, Serializable { 22 | 23 | private String name; 24 | /** 25 | * 26 | */ 27 | private static final long serialVersionUID = 1L; 28 | 29 | 30 | public SystemOutLogger(String name) { 31 | this.name = name; 32 | } 33 | 34 | private LogLevel level() { 35 | String level = System.getProperty("org.cdisource.logging.LogLevel", "INFO"); 36 | LogLevel logLevel = LogLevel.valueOf(level); 37 | return logLevel; 38 | } 39 | 40 | private void printMessage(LogLevel msgLevel, String msg, Object... args) { 41 | int level = level().ordinal(); 42 | if (level >= msgLevel.ordinal()) { 43 | String message = String.format("%s %s %s", this.name, msgLevel.name(), String.format(msg, args)); 44 | System.out.println(message); 45 | } 46 | 47 | } 48 | 49 | @Override 50 | public void severe(String msg, Object... args) { 51 | printMessage(SEVERE, msg, args); 52 | } 53 | 54 | @Override 55 | public void warning(String msg, Object... args) { 56 | printMessage(WARNING, msg, args); 57 | } 58 | 59 | @Override 60 | public void info(String msg, Object... args) { 61 | printMessage(INFO, msg, args); 62 | } 63 | 64 | 65 | @Override 66 | public void config(String msg, Object... args) { 67 | printMessage(CONFIG, msg, args); 68 | } 69 | 70 | @Override 71 | public void debug(String msg, Object... args) { 72 | printMessage(DEBUG, msg, args); 73 | } 74 | 75 | @Override 76 | public void trace(String msg, Object... args) { 77 | printMessage(TRACE, msg, args); 78 | } 79 | 80 | @Override 81 | public void finest(String msg, Object... args) { 82 | printMessage(FINEST, msg, args); 83 | } 84 | 85 | @Override 86 | public boolean isLevel(LogLevel level) { 87 | return level == level(); 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /beancontainer/api/src/main/java/org/cdisource/logging/SystemOutLoggerFactory.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.logging; 2 | 3 | /** 4 | * Simple logger for using System.out without worrying about logging configuration. 5 | * @author Rick Hightower 6 | * 7 | *@see SystemOutLoggerFactory 8 | */ 9 | public class SystemOutLoggerFactory implements LogFactory { 10 | 11 | @Override 12 | public Logger getLogger(String name) { 13 | return new SystemOutLogger(name); 14 | } 15 | 16 | @Override 17 | public Logger getLogger(Class clazz) { 18 | return new SystemOutLogger(clazz.getName()); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /beancontainer/api/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | -------------------------------------------------------------------------------- /beancontainer/api/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | org.cdisource.beancontainer.BeanContainerExtention -------------------------------------------------------------------------------- /beancontainer/api/src/main/resources/META-INF/services/org.cdisource.logging.LogFactory: -------------------------------------------------------------------------------- 1 | org.cdisource.logging.JDKLoggerFactory 2 | -------------------------------------------------------------------------------- /beancontainer/api/src/test/java/org/cdisource/beancontainer/namespace/BeanNamespaceTest.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.beancontainer.namespace; 2 | 3 | import static junit.framework.Assert.assertEquals; 4 | import static junit.framework.Assert.assertNotNull; 5 | import static junit.framework.Assert.assertNotSame; 6 | import static junit.framework.Assert.assertNull; 7 | import static junit.framework.Assert.assertTrue; 8 | 9 | import org.junit.Before; 10 | import org.junit.Test; 11 | 12 | public class BeanNamespaceTest { 13 | 14 | private BeanNamespace root; 15 | 16 | @Before 17 | public void beforeTest() { 18 | root = new BeanNamespace(); 19 | } 20 | 21 | @Test 22 | public void testEmptyNamespaces() { 23 | Object result = root.findObject("Some.item"); 24 | assertNull(result); 25 | result = root.findObject("item"); 26 | assertNull(result); 27 | } 28 | 29 | @Test 30 | public void testSplitFunctionWithSingleValue() { 31 | String[] value = root.splitName("Single"); 32 | assertNotNull(value); 33 | assertEquals(1, value.length); 34 | 35 | } 36 | 37 | @Test(expected = IllegalArgumentException.class) 38 | public void testSplitFunctionWithNoValue() { 39 | root.splitName(""); 40 | } 41 | 42 | @Test(expected = IllegalArgumentException.class) 43 | public void testSplitFunctionWithNullValue() { 44 | root.splitName(null); 45 | } 46 | 47 | @Test 48 | public void testSplitFunctionWithMultiLevelName() { 49 | String[] value = root.splitName("Level1.Level2"); 50 | assertNotNull(value); 51 | assertEquals(2, value.length); 52 | assertEquals("Level1", value[0]); 53 | assertEquals("Level2", value[1]); 54 | 55 | } 56 | 57 | @Test 58 | public void testTopLevelInsert() { 59 | Integer value = new Integer(23); 60 | root.addObject("number", value); 61 | Object result = root.findObject("number"); 62 | Object nonResult = root.findObject("missing"); 63 | assertNotNull(result); 64 | assertEquals(value, result); 65 | assertNull(nonResult); 66 | } 67 | 68 | public void testMultiLevelInsert() { 69 | Integer value = new Integer(23); 70 | root.addObject("number.23", value); 71 | Object graphNode = root.findObject("number"); 72 | // test we got a graph node back 73 | assertNotNull(graphNode); 74 | assertTrue(graphNode.getClass().equals(BeanNamespace.class)); 75 | 76 | // now look for our value 77 | Object number = root.findObject("number.23"); 78 | assertEquals(value, number); 79 | 80 | // check we can't find 23 81 | Object nonResult = root.findObject("23"); 82 | assertNull(nonResult); 83 | } 84 | 85 | @Test 86 | public void testAddingToExistingPath() { 87 | root.addObject("one.two", new Integer(12)); 88 | root.addObject("one.three", new Integer(13)); 89 | 90 | } 91 | 92 | @Test 93 | public void testMultipleObjects() { 94 | for (int i = 900; i < 1000; i++) { 95 | 96 | String text = numberToNamespace(i); 97 | root.addObject(text, new Integer(i)); 98 | } 99 | Object result = root.findObject("9.5.6"); 100 | assertNotNull(result); 101 | assertEquals(new Integer(956), result); 102 | } 103 | 104 | @Test 105 | public void testSimilarPathsNamespace() { 106 | // special case where the insert code doesn't move on and 995 -> 9.5 so 107 | // looking for 9.5.6 ends up with the integer at 9.5 108 | root.addObject("9.5.6", new Integer(956)); 109 | root.addObject("9.9.5", new Integer(995)); 110 | Object v1 = root.findObject("9.5.6"); 111 | Object v2 = root.findObject("9.9.5"); 112 | assertEquals(956, v1); 113 | assertEquals(995, v2); 114 | 115 | } 116 | 117 | @Test 118 | public void testNumberToNamespace() { 119 | String v1 = numberToNamespace(3382); 120 | assertEquals("3.3.8.2", v1); 121 | 122 | String v2 = numberToNamespace(4); 123 | assertEquals("4", v2); 124 | 125 | } 126 | 127 | private String numberToNamespace(int number) { 128 | String result = ""; 129 | 130 | while (number > 0) { 131 | int digit = number % 10; 132 | String text = String.valueOf(digit); 133 | if (result.length() != 0) { 134 | result = "." + result; 135 | } 136 | result = text + result; 137 | number = number / 10; 138 | } 139 | return result; 140 | } 141 | 142 | @Test 143 | public void testCaseInsensitivity() { 144 | root.addObject("A", new Integer(1)); 145 | root.addObject("a", new Integer(2)); 146 | Object va = root.findObject("a"); 147 | Object vA = root.findObject("A"); 148 | assertNotSame(va,vA); 149 | } 150 | 151 | @Test 152 | public void testCaseInsensitivityInPath() { 153 | String name1 = "org.some.Object"; 154 | String name2 = "org.SOME.Object"; 155 | root.addObject(name1, new Integer(1)); 156 | root.addObject(name2, new Integer(2)); 157 | Object o1 = root.findObject(name1); 158 | Object o2 = root.findObject(name2); 159 | assertNotSame(o1,o2); 160 | assertEquals(o1, 1); 161 | assertEquals(o2, 2); 162 | } 163 | 164 | } 165 | 166 | -------------------------------------------------------------------------------- /beancontainer/api/src/test/resource/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | -------------------------------------------------------------------------------- /beancontainer/jndi-impl/README: -------------------------------------------------------------------------------- 1 | This is CDI Advocate repository. 2 | Currently it hosts CDI beanContainer. 3 | CDI beanContainer is a small wrapper around Caucho Resin Candi and JBoss Seam Weld. 4 | It should be the basis of adding unit tests framework that works with all CDI implementations. 5 | 6 | Apache OpenWebBean support is planned. 7 | We are looking for someone to do the OpenWebBeans work. 8 | 9 | To learn more about this project go here: 10 | * Main website http://sites.google.com/site/cdipojo/ 11 | * Google project code http://code.google.com/p/jee6-cdi/ 12 | * Comprehensive CDI tutorial http://code.google.com/p/jee6-cdi/wiki/DependencyInjectionAnIntroductoryTutorial 13 | * Google Group for email support for examples http://groups.google.com/group/cdiadvocate4j?pli=1 -------------------------------------------------------------------------------- /beancontainer/jndi-impl/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | org.cdisource.beancontainer 4 | beancontainer-jndi-impl 5 | jar 6 | 1.0-SNAPSHOT 7 | 8 | 9 | org.cdisource 10 | cdisource-parent 11 | 1.0-SNAPSHOT 12 | ../../parent 13 | 14 | 15 | 16 | 3.0 17 | 18 | 19 | JNDI Bean Container Implementation 20 | 21 | 22 | BeanContainer API Impl accessing a Java EE 6 container managed CDI implementation 23 | 24 | 25 | 26 | org.cdisource.beancontainer 27 | beancontainer-api 28 | 1.0-SNAPSHOT 29 | 30 | 31 | junit 32 | junit 33 | 4.8.2 34 | jar 35 | test 36 | 37 | 38 | org.cdisource.beancontainer 39 | beancontainer-test 40 | 1.0-SNAPSHOT 41 | jar 42 | test 43 | 44 | 45 | 46 | 47 | 48 | repository.jboss.org 49 | JBoss Repository 50 | http://repository.jboss.org/nexus/content/groups/public-jboss/ 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /beancontainer/jndi-impl/src/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /beancontainer/jndi-impl/src/main/java/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /beancontainer/jndi-impl/src/main/java/org/cdisource/beancontainer/JndiBeanContainer.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.beancontainer; 2 | 3 | //import javax.enterprise.context.spi.Context; 4 | import javax.enterprise.inject.spi.BeanManager; 5 | import javax.naming.InitialContext; 6 | 7 | public class JndiBeanContainer extends AbstractBeanContainer { 8 | 9 | 10 | private BeanManager beanManager; 11 | 12 | private final String BEAN_MANAGER_LOCATION = "java:comp/BeanManager"; 13 | 14 | @Override 15 | protected BeanManager locateBeanManager() { 16 | return beanManager; 17 | } 18 | 19 | @Override 20 | protected boolean isInitialized() { 21 | return beanManager != null; 22 | } 23 | 24 | @Override 25 | protected void doStart() throws Exception { 26 | // lookup the bean manager from jndi 27 | InitialContext ic = new InitialContext(); 28 | Object bean = null; 29 | try { 30 | bean = ic.lookup(BEAN_MANAGER_LOCATION); 31 | } catch (Exception e) { 32 | throw new BeanContainerInitializationException("Unable to lookup BeanManager instance in JNDI", e); 33 | } 34 | if (bean == null) { 35 | throw new BeanContainerInitializationException( 36 | "Null value returned when looking up the BeanManager from JNDI"); 37 | } 38 | if (bean instanceof BeanManager) { 39 | beanManager = (BeanManager) bean; 40 | } else { 41 | String msg = "Looked up JNDI Bean is not a BeanManager instance, bean type is " + bean.getClass().getName(); 42 | throw new BeanContainerInitializationException(msg); 43 | } 44 | } 45 | 46 | @Override 47 | protected void doStop() { 48 | beanManager = null; 49 | } 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /beancontainer/jndi-impl/src/main/resources/META-INF/services/org.cdisource.beancontainer.BeanContainer: -------------------------------------------------------------------------------- 1 | org.cdisource.beancontainer.JndiBeanContainer 2 | -------------------------------------------------------------------------------- /beancontainer/jndi-impl/src/test/resource/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | -------------------------------------------------------------------------------- /beancontainer/openwebbeans-impl/README: -------------------------------------------------------------------------------- 1 | This is CDI Advocate repository. 2 | Currently it hosts CDI beanContainer. 3 | CDI beanContainer is a small wrapper around Caucho Resin Candi and JBoss Seam Weld. 4 | It should be the basis of adding unit tests framework that works with all CDI implementations. 5 | 6 | Apache OpenWebBean support is planned. 7 | We are looking for someone to do the OpenWebBeans work. 8 | 9 | To learn more about this project go here: 10 | * Main website http://sites.google.com/site/cdipojo/ 11 | * Google project code http://code.google.com/p/jee6-cdi/ 12 | * Comprehensive CDI tutorial http://code.google.com/p/jee6-cdi/wiki/DependencyInjectionAnIntroductoryTutorial 13 | * Google Group for email support for examples http://groups.google.com/group/cdiadvocate4j?pli=1 -------------------------------------------------------------------------------- /beancontainer/openwebbeans-impl/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | org.cdisource.beancontainer 4 | beancontainer-openwebbeans-impl 5 | jar 6 | 1.0-SNAPSHOT 7 | 8 | 9 | org.cdisource 10 | cdisource-parent 11 | 1.0-SNAPSHOT 12 | ../../parent 13 | 14 | 15 | 16 | 17 | 1.1.1-SNAPSHOT 18 | 19 | 20 | 21 | 3.0 22 | 23 | 24 | OpenWebBeans Bean Container Implementation 25 | 26 | 27 | API Impl for Apache OpenWebBeans 28 | 29 | 30 | 31 | 32 | 33 | org.cdisource.beancontainer 34 | beancontainer-api 35 | 1.0-SNAPSHOT 36 | 37 | 38 | org.apache.openwebbeans 39 | openwebbeans-impl 40 | ${openwebbeans.version} 41 | 42 | 43 | org.apache.openwebbeans 44 | openwebbeans-spi 45 | ${openwebbeans.version} 46 | 47 | 48 | 49 | org.apache.geronimo.specs 50 | geronimo-jcdi_1.0_spec 51 | 1.0 52 | 53 | 54 | 55 | org.cdisource.beancontainer 56 | beancontainer-test 57 | 1.0-SNAPSHOT 58 | jar 59 | test 60 | 61 | 62 | 63 | org.apache.geronimo.specs 64 | geronimo-interceptor_1.1_spec 65 | 1.0 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | apachesnapshots 74 | http://repository.apache.org/snapshots 75 | 76 | true 77 | 78 | 79 | true 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /beancontainer/openwebbeans-impl/src/main/java/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /beancontainer/openwebbeans-impl/src/main/java/org/cdisource/beancontainer/OpenWebBeansBeanContainer.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.beancontainer; 2 | 3 | import javax.enterprise.inject.spi.BeanManager; 4 | 5 | import org.apache.webbeans.spi.ContainerLifecycle; 6 | 7 | import org.apache.webbeans.config.WebBeansContext; 8 | 9 | public class OpenWebBeansBeanContainer extends AbstractBeanContainer { 10 | 11 | private ContainerLifecycle lifecycle; 12 | private BeanManager beanManager; 13 | 14 | @Override 15 | protected BeanManager locateBeanManager() { 16 | return beanManager; 17 | } 18 | 19 | @Override 20 | protected boolean isInitialized() { 21 | return (lifecycle != null && beanManager != null); 22 | } 23 | 24 | @Override 25 | protected void doStart() throws Exception { 26 | lifecycle = WebBeansContext.getInstance().getService(ContainerLifecycle.class); 27 | lifecycle.startApplication(null); 28 | beanManager = lifecycle.getBeanManager(); 29 | } 30 | 31 | @Override 32 | protected void doStop() { 33 | lifecycle.stopApplication(null); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /beancontainer/openwebbeans-impl/src/main/resources/META-INF/services/org.cdisource.beancontainer.BeanContainer: -------------------------------------------------------------------------------- 1 | org.cdisource.beancontainer.OpenWebBeansBeanContainer 2 | -------------------------------------------------------------------------------- /beancontainer/openwebbeans-impl/src/test/java/org/cdisource/beancontainer/OpenWebBeansBeanContainerTest.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.beancontainer; 2 | import org.cdisource.testing.AbstractBeanContainerTest; 3 | import org.junit.Test; 4 | 5 | /** 6 | * Extends the {@link AbstractBeanContainerTest} to implement testing for the 7 | * OpenWebBeans {@link BeanContainer} implementation. 8 | * 9 | * @author Andy Gibson 10 | * 11 | */ 12 | public class OpenWebBeansBeanContainerTest extends AbstractBeanContainerTest { 13 | 14 | 15 | @Test 16 | public void testLookupProducer() { 17 | //this test fails for open web beans. 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /beancontainer/openwebbeans-impl/src/test/resource/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | -------------------------------------------------------------------------------- /beancontainer/resin-impl/README: -------------------------------------------------------------------------------- 1 | This is CDI Advocate repository. 2 | Currently it hosts CDI beanContainer. 3 | CDI beanContainer is a small wrapper around Caucho Resin Candi and JBoss Seam Weld. 4 | It should be the basis of adding unit tests framework that works with all CDI implementations. 5 | 6 | Apache OpenWebBean support is planned. 7 | We are looking for someone to do the OpenWebBeans work. 8 | 9 | To learn more about this project go here: 10 | * Main website http://sites.google.com/site/cdipojo/ 11 | * Google project code http://code.google.com/p/jee6-cdi/ 12 | * Comprehensive CDI tutorial http://code.google.com/p/jee6-cdi/wiki/DependencyInjectionAnIntroductoryTutorial 13 | * Google Group for email support for examples http://groups.google.com/group/cdiadvocate4j?pli=1 -------------------------------------------------------------------------------- /beancontainer/resin-impl/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | org.cdisource.beancontainer 4 | beancontainer-resin-impl 5 | jar 6 | 1.0-SNAPSHOT 7 | 8 | 9 | org.cdisource 10 | cdisource-parent 11 | 1.0-SNAPSHOT 12 | ../../parent 13 | 14 | 15 | 16 | 3.0 17 | 18 | 19 | Resin Bean Container Implementation 20 | 21 | 22 | Base API for common bean container 23 | 24 | 25 | 26 | 27 | 28 | 29 | com.caucho 30 | resin 31 | 4.0.17 32 | 33 | 34 | 35 | com.caucho 36 | resin-hessian 37 | 38 | 39 | 40 | org.osgi 41 | osgi_R4_core 42 | 43 | 44 | 45 | javax.mail 46 | mail 47 | 48 | 49 | 50 | javax.activation 51 | activation 52 | 53 | 54 | 55 | 56 | 57 | 58 | org.cdisource.beancontainer 59 | beancontainer-api 60 | 1.0-SNAPSHOT 61 | 62 | 63 | javax.validation 64 | validation-api 65 | 1.0.0.GA 66 | 67 | 68 | org.cdisource.beancontainer 69 | beancontainer-test 70 | 1.0-SNAPSHOT 71 | jar 72 | test 73 | 74 | 75 | 76 | 77 | 78 | caucho.maven.repo 79 | Caucho Repository 80 | http://caucho.com/m2 81 | 82 | 83 | caucho.maven.repo.snapshot 84 | Caucho Repository 85 | http://caucho.com/m2-snapshot 86 | 87 | 88 | 89 | 90 | 91 | 92 | org.apache.maven.plugins 93 | maven-surefire-plugin 94 | 2.8 95 | 96 | true 97 | false 98 | 99 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /beancontainer/resin-impl/src/main/java/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /beancontainer/resin-impl/src/main/java/org/cdisource/beancontainer/ResinBeanContainer.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.beancontainer; 2 | 3 | import java.lang.annotation.Annotation; 4 | 5 | import javax.enterprise.context.RequestScoped; 6 | import javax.enterprise.context.spi.Context; 7 | import javax.enterprise.inject.spi.BeanManager; 8 | 9 | import com.caucho.resin.BeanContainerRequest; 10 | 11 | public class ResinBeanContainer extends AbstractBeanContainer { 12 | 13 | public Context getContextByScope(Class scopeType){ 14 | return delegate.getCdiManager().getContext(scopeType); 15 | } 16 | 17 | com.caucho.resin.ResinBeanContainer delegate; 18 | 19 | @Override 20 | protected BeanManager locateBeanManager() { 21 | return delegate.getCdiManager(); 22 | } 23 | 24 | @Override 25 | protected boolean isInitialized() { 26 | return delegate != null; 27 | } 28 | 29 | @Override 30 | protected void doStart() throws Exception { 31 | delegate = new com.caucho.resin.ResinBeanContainer(); 32 | String resinConf = System.getProperty("org.cdisource.beancontainer.ResinBeanContainer.resinConf"); 33 | if (resinConf!=null) { 34 | delegate.addBeansXml(resinConf); 35 | } 36 | delegate.start(); 37 | } 38 | 39 | @Override 40 | protected void doStop() { 41 | delegate.close(); 42 | } 43 | 44 | ThreadLocal requestScopeHolder = new ThreadLocal(); 45 | @Override 46 | public void startScope(Class scope) { 47 | if (scope == RequestScoped.class) { 48 | BeanContainerRequest beginRequest = delegate.beginRequest(); 49 | requestScopeHolder.set(beginRequest); 50 | }else { 51 | //... 52 | } 53 | } 54 | 55 | @Override 56 | public void stopScope(Class scope) { 57 | if (scope == RequestScoped.class) { 58 | requestScopeHolder.set(null); 59 | } else { 60 | //... 61 | } 62 | 63 | } 64 | 65 | 66 | } 67 | -------------------------------------------------------------------------------- /beancontainer/resin-impl/src/main/resources/META-INF/services/org.cdisource.beancontainer.BeanContainer: -------------------------------------------------------------------------------- 1 | org.cdisource.beancontainer.ResinBeanContainer -------------------------------------------------------------------------------- /beancontainer/resin-impl/src/test/java/org/cdisource/beancontainer/ResinBeanContainerTest.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.beancontainer; 2 | 3 | import org.cdisource.testing.AbstractBeanContainerTest; 4 | 5 | public class ResinBeanContainerTest extends AbstractBeanContainerTest { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /beancontainer/resin-impl/src/test/resource/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | -------------------------------------------------------------------------------- /beancontainer/testing/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | org.cdisource 5 | cdisource-parent 6 | 1.0-SNAPSHOT 7 | ../../parent 8 | 9 | org.cdisource.beancontainer 10 | beancontainer-test 11 | Beancontainer testing harness 12 | 1.0-SNAPSHOT 13 | 14 | 15 | junit 16 | junit 17 | 4.8.2 18 | jar 19 | compile 20 | 21 | 22 | org.cdisource.beancontainer 23 | beancontainer-api 24 | 1.0-SNAPSHOT 25 | jar 26 | compile 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /beancontainer/testing/src/main/java/org/cdisource/testing/AbstractBeanContainerTest.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.testing; 2 | 3 | import static junit.framework.Assert.assertEquals; 4 | import static junit.framework.Assert.assertNotNull; 5 | import static junit.framework.Assert.assertTrue; 6 | 7 | import org.cdisource.beancontainer.BeanContainer; 8 | import org.cdisource.beancontainer.BeanContainerManager; 9 | import org.cdisource.beancontainer.BeanNotFoundException; 10 | import org.junit.After; 11 | import org.junit.Before; 12 | import org.junit.Test; 13 | 14 | /** 15 | * Abstract container test that can be used to perform initial tests on a 16 | * {@link BeanContainer} implementation. To use, just create a test case that 17 | * extends this class and make sure an implementation is also in the project so 18 | * it can load the {@link BeanContainer} instance. 19 | * 20 | * @author Andy Gibson 21 | * @author Rick Hightower 22 | * 23 | */ 24 | public class AbstractBeanContainerTest { 25 | 26 | private static BeanContainer beanContainer; 27 | 28 | public BeanContainer getBeanContainer() { 29 | return beanContainer; 30 | } 31 | 32 | @Before 33 | public void doBefore() { 34 | BeanContainerManager.initialize(); 35 | beanContainer = BeanContainerManager.getInstance(); 36 | } 37 | 38 | @After 39 | public void doAfter() { 40 | BeanContainerManager.shutdown(); 41 | } 42 | 43 | @Test 44 | public void shouldInitContainer() { 45 | assertNotNull("Bean container is not initialized", beanContainer); 46 | } 47 | 48 | @Test 49 | public void shouldGetBeanInstance() { 50 | assertNotNull(beanContainer); 51 | SimpleBean bean = beanContainer.getBeanByType(SimpleBean.class); 52 | assertNotNull("Could not locate bean instance by type", bean); 53 | assertNotNull("Bean hasn't had InjectedBean injected into it", bean.getInjectedBean()); 54 | } 55 | 56 | @Test 57 | public void shouldGetBeanByName() { 58 | assertNotNull(beanContainer); 59 | SimpleBean bean = (SimpleBean) beanContainer.getBeanByName("simpleBean"); 60 | assertNotNull("Could not locate bean instance by name", bean); 61 | } 62 | 63 | @Test 64 | public void shouldGetBeanByNameNoCast() { 65 | assertNotNull(beanContainer); 66 | SimpleBean bean = beanContainer.getBeanByName(SimpleBean.class, "simpleBean"); 67 | assertNotNull("Could not locate bean instance by name", bean); 68 | } 69 | 70 | @Test(expected = IllegalStateException.class) 71 | public void shouldThrowExceptionOnSecondStartup() { 72 | beanContainer.start(); 73 | } 74 | 75 | @Test(expected = BeanNotFoundException.class) 76 | public void shouldThrowExceptionOnMissignBeanByName() { 77 | beanContainer.getBeanByName("missing_bean_name"); 78 | } 79 | 80 | @Test(expected = BeanNotFoundException.class) 81 | public void shouldThrowExceptionOnMissignBeanByType() { 82 | beanContainer.getBeanByType(String.class); 83 | } 84 | 85 | @Test 86 | public void shouldHaveSingletonItem() { 87 | SimpleBean bean = beanContainer.getBeanByType(SimpleBean.class); 88 | assertNotNull("Named bean not found", bean); 89 | SingletonBean singleton = beanContainer.getBeanByType(SingletonBean.class); 90 | assertEquals("Found non-equal instances of a singleton bean", bean.getSingletonBean(), singleton); 91 | } 92 | 93 | @Test 94 | public void testSimpleNameSpaces() { 95 | Object bean = beanContainer.getBeanNamespace().findObject("simpleBean"); 96 | assertNotNull(bean); 97 | assertTrue("Cannot locate simpleBean ", beanContainer.getBeanNamespace().contains("simpleBean")); 98 | } 99 | 100 | @Test 101 | public void testLookupProducer() { 102 | InjectedBean beanByType = beanContainer.getBeanByType(InjectedBean.class, new SomeOtherQualifierQualifier()); 103 | assertNotNull(beanByType); 104 | } 105 | 106 | @Test public void testBeanContainerInjections() { 107 | assertEquals ("foo", beanContainer.getBeanByType(BeanUsingBeanContainer.class).foo()); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /beancontainer/testing/src/main/java/org/cdisource/testing/BeanUsingBeanContainer.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.testing; 2 | 3 | import javax.inject.Inject; 4 | 5 | import org.cdisource.beancontainer.BeanContainer; 6 | 7 | public class BeanUsingBeanContainer { 8 | @Inject BeanContainer container; 9 | 10 | public String foo () { 11 | return container.getBeanByType(InjectedBean.class).foo(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /beancontainer/testing/src/main/java/org/cdisource/testing/InjectedBean.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.testing; 2 | 3 | /** 4 | * Dummy bean for simple test cases. 5 | * 6 | * @author Andy Gibson 7 | * @author Rick Hightower 8 | * 9 | */ 10 | public class InjectedBean { 11 | 12 | public String foo () { 13 | return "foo"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /beancontainer/testing/src/main/java/org/cdisource/testing/InjectedBeanFactory.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.testing; 2 | 3 | import javax.enterprise.inject.Produces; 4 | 5 | @SomeOtherQualifier 6 | public class InjectedBeanFactory { 7 | @Produces @SomeOtherQualifier InjectedBean createTransport() { 8 | return new InjectedBean(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /beancontainer/testing/src/main/java/org/cdisource/testing/NamedBean.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.testing; 2 | 3 | import javax.inject.Named; 4 | 5 | @Named("org.long.Name") 6 | public class NamedBean { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /beancontainer/testing/src/main/java/org/cdisource/testing/SimpleBean.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.testing; 2 | 3 | import javax.inject.Inject; 4 | import javax.inject.Named; 5 | 6 | /** 7 | * Simple named bean for testing 8 | * 9 | * @author Andy Gibson 10 | * 11 | */ 12 | @Named("simpleBean") 13 | public class SimpleBean { 14 | 15 | @Inject 16 | private InjectedBean injectedBean; 17 | 18 | @Inject @SomeOtherQualifier 19 | private InjectedBean otherInjectedBean; 20 | 21 | 22 | 23 | @Inject 24 | private SingletonBean singletonBean; 25 | 26 | 27 | public InjectedBean getInjectedBean() { 28 | return injectedBean; 29 | } 30 | 31 | public InjectedBean getOtherInjectedBean() { 32 | return otherInjectedBean; 33 | } 34 | 35 | public SingletonBean getSingletonBean() { 36 | return singletonBean; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /beancontainer/testing/src/main/java/org/cdisource/testing/SingletonBean.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.testing; 2 | 3 | import javax.inject.Singleton; 4 | /** 5 | * Singleton bean for testing CDI 6 | * 7 | * @author Andy Gibson 8 | * 9 | */ 10 | @Singleton 11 | public class SingletonBean { 12 | 13 | private int counter; 14 | 15 | public int getCounter() { 16 | return counter; 17 | } 18 | 19 | public synchronized void incrementCount() { 20 | counter++; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /beancontainer/testing/src/main/java/org/cdisource/testing/SomeOtherQualifier.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.testing; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.Target; 6 | 7 | import javax.inject.Qualifier; 8 | 9 | import static java.lang.annotation.ElementType.FIELD; 10 | import static java.lang.annotation.ElementType.METHOD; 11 | import static java.lang.annotation.ElementType.PARAMETER; 12 | import static java.lang.annotation.ElementType.TYPE; 13 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 14 | 15 | @Qualifier 16 | @Target({ TYPE, METHOD, PARAMETER, FIELD }) 17 | @Retention(RUNTIME) 18 | @Documented 19 | public @interface SomeOtherQualifier { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /beancontainer/testing/src/main/java/org/cdisource/testing/SomeOtherQualifierQualifier.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.testing; 2 | 3 | import javax.enterprise.util.AnnotationLiteral; 4 | 5 | @SuppressWarnings("all") 6 | public class SomeOtherQualifierQualifier extends AnnotationLiteral implements SomeOtherQualifier { 7 | 8 | /** 9 | * 10 | */ 11 | private static final long serialVersionUID = 1L; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /beancontainer/testing/src/main/java/org/cdisource/testing/SomeQualifier.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.testing; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.Target; 6 | 7 | import javax.inject.Qualifier; 8 | 9 | import static java.lang.annotation.ElementType.FIELD; 10 | import static java.lang.annotation.ElementType.METHOD; 11 | import static java.lang.annotation.ElementType.PARAMETER; 12 | import static java.lang.annotation.ElementType.TYPE; 13 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 14 | 15 | @Qualifier 16 | @Target({ TYPE, METHOD, PARAMETER, FIELD }) 17 | @Retention(RUNTIME) 18 | @Documented 19 | public @interface SomeQualifier { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /beancontainer/testing/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | -------------------------------------------------------------------------------- /beancontainer/weld-impl/README: -------------------------------------------------------------------------------- 1 | This is CDI Advocate repository. 2 | Currently it hosts CDI beanContainer. 3 | CDI beanContainer is a small wrapper around Caucho Resin Candi and JBoss Seam Weld. 4 | It should be the basis of adding unit tests framework that works with all CDI implementations. 5 | 6 | Apache OpenWebBean support is planned. 7 | We are looking for someone to do the OpenWebBeans work. 8 | 9 | To learn more about this project go here: 10 | * Main website http://sites.google.com/site/cdipojo/ 11 | * Google project code http://code.google.com/p/jee6-cdi/ 12 | * Comprehensive CDI tutorial http://code.google.com/p/jee6-cdi/wiki/DependencyInjectionAnIntroductoryTutorial 13 | * Google Group for email support for examples http://groups.google.com/group/cdiadvocate4j?pli=1 -------------------------------------------------------------------------------- /beancontainer/weld-impl/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | org.cdisource.beancontainer 4 | beancontainer-weld-impl 5 | jar 6 | 1.0-SNAPSHOT 7 | 8 | 9 | org.cdisource 10 | cdisource-parent 11 | 1.0-SNAPSHOT 12 | ../../parent 13 | 14 | 15 | 16 | 3.0 17 | 18 | 19 | Weld Bean Container Implementation 20 | 21 | 22 | API Impl for JBoss Seam Weld 23 | 24 | 25 | 26 | 27 | 28 | org.jboss.weld.se 29 | weld-se-core 30 | 1.1.0.Final 31 | 32 | 33 | org.slf4j 34 | slf4j-simple 35 | 1.5.10 36 | 37 | 38 | org.cdisource.beancontainer 39 | beancontainer-api 40 | 1.0-SNAPSHOT 41 | 42 | 43 | junit 44 | junit 45 | 4.8.2 46 | jar 47 | test 48 | 49 | 50 | org.cdisource.beancontainer 51 | beancontainer-test 52 | 1.0-SNAPSHOT 53 | jar 54 | test 55 | 56 | 57 | 58 | 59 | 60 | 61 | jboss.maven.repo 62 | JBoss Repository 63 | http://repository.jboss.org/nexus/content/groups/public-jboss/ 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /beancontainer/weld-impl/src/main/java/org/cdisource/beancontainer/WeldBeanContainer.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.beancontainer; 2 | 3 | //import javax.enterprise.context.spi.Context; 4 | import javax.enterprise.inject.spi.BeanManager; 5 | 6 | import org.jboss.weld.environment.se.Weld; 7 | import org.jboss.weld.environment.se.WeldContainer; 8 | 9 | public class WeldBeanContainer extends AbstractBeanContainer { 10 | 11 | // @Override 12 | // public void registerContext(Context context, boolean replace) { 13 | // throw new UnsupportedOperationException("TODO"); 14 | // } 15 | 16 | WeldContainer delegate; 17 | Weld weld; 18 | 19 | @Override 20 | protected void doStart() throws Exception { 21 | weld = new Weld(); 22 | delegate = weld.initialize(); 23 | } 24 | 25 | @Override 26 | protected void doStop() { 27 | weld.shutdown(); 28 | } 29 | 30 | @Override 31 | protected boolean isInitialized() { 32 | return weld != null; 33 | } 34 | 35 | @Override 36 | protected BeanManager locateBeanManager() { 37 | return delegate.getBeanManager(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /beancontainer/weld-impl/src/main/resources/META-INF/services/org.cdisource.beancontainer.BeanContainer: -------------------------------------------------------------------------------- 1 | org.cdisource.beancontainer.WeldBeanContainer 2 | -------------------------------------------------------------------------------- /beancontainer/weld-impl/src/test/java/org/cdisource/beancontainer/WeldBeanContainerTest.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.beancontainer; 2 | 3 | import org.cdisource.testing.AbstractBeanContainerTest; 4 | 5 | /** 6 | * Extends the {@link AbstractBeanContainerTest} to implement testing for the 7 | * Weld {@link BeanContainer} implementation. 8 | * 9 | * @author Andy Gibson 10 | * 11 | */ 12 | public class WeldBeanContainerTest extends AbstractBeanContainerTest { 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /beancontainer/weld-impl/src/test/resource/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | -------------------------------------------------------------------------------- /cdsource-eclipse-formatter.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | -------------------------------------------------------------------------------- /parent/README: -------------------------------------------------------------------------------- 1 | This is CDI Advocate repository. 2 | Currently it hosts CDI beanContainer. 3 | CDI beanContainer is a small wrapper around Caucho Resin Candi and JBoss Seam Weld. 4 | It should be the basis of adding unit tests framework that works with all CDI implementations. 5 | 6 | Apache OpenWebBean support is planned. 7 | We are looking for someone to do the OpenWebBeans work. 8 | 9 | To learn more about this project go here: 10 | * Main website http://sites.google.com/site/cdipojo/ 11 | * Google project code http://code.google.com/p/jee6-cdi/ 12 | * Comprehensive CDI tutorial http://code.google.com/p/jee6-cdi/wiki/DependencyInjectionAnIntroductoryTutorial 13 | * Google Group for email support for examples http://groups.google.com/group/cdiadvocate4j?pli=1 -------------------------------------------------------------------------------- /parent/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | org.cdisource 4 | cdisource-parent 5 | pom 6 | 1.0-SNAPSHOT 7 | 8 | 9 | org.sonatype.oss 10 | oss-parent 11 | 3 12 | 13 | 14 | CDI Advocate Parent 15 | 16 | 17 | TODO put address to website here 18 | 19 | 20 | The parent POM for Weld, specifying the build parameters 21 | 22 | 23 | 24 | 25 | Apache License, Version 2.0 26 | http://www.apache.org/licenses/LICENSE-2.0 27 | 28 | 29 | 30 | 31 | 32 | Rob Williams 33 | 34 | 35 | Andy Gibson 36 | 37 | 38 | Rick Hightower 39 | 40 | 41 | 42 | 43 | CDI Advocate 44 | TODO Put URL here 45 | 46 | 47 | 48 | 49 | UTF-8 50 | UTF-8 51 | yyyyMMdd-HHmm 52 | 53 | 54 | 55 | 3.0 56 | 57 | 58 | 59 | 60 | 61 | javax.enterprise 62 | cdi-api 63 | 1.0-SP1 64 | provided 65 | jar 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | org.apache.maven.plugins 74 | maven-source-plugin 75 | 76 | 77 | attach-sources 78 | 79 | jar 80 | 81 | 82 | 83 | 84 | 85 | org.apache.maven.plugins 86 | maven-enforcer-plugin 87 | true 88 | 89 | 90 | org.codehaus.mojo 91 | build-helper-maven-plugin 92 | 93 | 94 | org.codehaus.mojo 95 | buildnumber-maven-plugin 96 | 97 | 98 | package 99 | 100 | 101 | 102 | 103 | 104 | org.apache.maven.plugins 105 | maven-antrun-plugin 106 | 1.3 107 | 108 | 109 | org.apache.maven.plugins 110 | maven-release-plugin 111 | 112 | -Drelease 113 | true 114 | forked-path 115 | true 116 | 117 | 2.0-beta-9 118 | 119 | 120 | org.apache.maven.plugins 121 | maven-surefire-report-plugin 122 | 2.6 123 | 124 | 125 | org.apache.maven.plugins 126 | maven-surefire-plugin 127 | 2.6 128 | 129 | 130 | org.apache.maven.plugins 131 | maven-clean-plugin 132 | 2.4.1 133 | 134 | 135 | org.apache.maven.plugins 136 | maven-deploy-plugin 137 | 2.5 138 | 139 | 140 | org.apache.maven.plugins 141 | maven-assembly-plugin 142 | 2.2-beta-5 143 | 144 | 145 | distribution 146 | package 147 | 148 | single 149 | 150 | 151 | 152 | src/main/assembly/assembly.xml 153 | 154 | ${project.build.finalName}-${project.version} 155 | 156 | 157 | 158 | 159 | 160 | org.apache.maven.plugins 161 | maven-install-plugin 162 | 2.3.1 163 | 164 | 165 | org.apache.maven.plugins 166 | maven-site-plugin 167 | 2.0.1 168 | 169 | 170 | org.apache.maven.plugins 171 | maven-source-plugin 172 | 2.1.2 173 | 174 | 175 | org.apache.maven.plugins 176 | maven-resources-plugin 177 | 2.4.3 178 | 179 | 180 | org.apache.maven.plugins 181 | maven-dependency-plugin 182 | 2.1 183 | 184 | 185 | org.apache.maven.plugins 186 | maven-javadoc-plugin 187 | 2.7 188 | 189 | true 190 | 191 | 192 | 193 | org.codehaus.mojo 194 | exec-maven-plugin 195 | 1.1.1 196 | 197 | 198 | org.apache.maven.plugins 199 | maven-enforcer-plugin 200 | 1.0-beta-1 201 | 202 | 203 | enforce 204 | 205 | enforce 206 | 207 | 208 | 209 | 210 | [${minimum.maven.version},) 211 | 212 | 213 | 214 | org.apache.maven.plugins:maven-eclipse-plugin 215 | org.codehaus.mojo:versions-maven-plugin 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | org.apache.maven.plugins 225 | maven-compiler-plugin 226 | 2.3.1 227 | 228 | 1.6 229 | 1.6 230 | 231 | 232 | 233 | org.apache.maven.plugins 234 | maven-jar-plugin 235 | 2.3.1 236 | 237 | 238 | 239 | ${project.url} 240 | ${project.name} 241 | ${maven.build.timestamp} 242 | ${project.organization.name} 243 | ${project.name} 244 | ${parsedVersion.osgiVersion} 245 | ${project.organization.name} 246 | 247 | 248 | 249 | Build-Information 250 | 251 | ${maven.version} 252 | ${java.version} 253 | ${java.vendor} 254 | ${os.name} 255 | ${os.arch} 256 | ${os.version} 257 | r${buildNumber} 258 | ${maven.build.timestamp} 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | org.codehaus.mojo 267 | build-helper-maven-plugin 268 | 1.5 269 | 270 | 271 | validate 272 | 273 | maven-version 274 | parse-version 275 | 276 | 277 | 278 | 279 | 280 | org.apache.maven.plugins 281 | maven-eclipse-plugin 282 | 283 | 284 | org.eclipse.jdt.launching.JRE_CONTAINER 285 | 286 | 287 | 288 | 289 | org.codehaus.mojo 290 | buildnumber-maven-plugin 291 | 1.0-beta-4 292 | 293 | 294 | set-build-properties 295 | 296 | create 297 | 298 | 299 | none 300 | 301 | true 302 | unavailable 303 | {0, date, long} {0, time, long} 304 | 305 | 306 | 307 | true 308 | 309 | 310 | org.twdata.maven 311 | maven-cli-plugin 312 | 1.0.3 313 | 314 | 315 | org.glassfish 316 | maven-embedded-glassfish-plugin 317 | 3.0 318 | 319 | glassfish 320 | ${project.build.directory}/${project.build.finalName}.war 321 | 7070 322 | ${project.build.finalName} 323 | 324 | 325 | 326 | install 327 | 328 | run 329 | 330 | 331 | 332 | 333 | 334 | org.mortbay.jetty 335 | maven-jetty-plugin 336 | 6.1.21 337 | 338 | 339 | 340 | 341 | 9090 342 | 343 | 344 | 345 | ${project.build.finalName} 346 | 348 | ${basedir}/src/main/resources/jetty-env.xml 349 | 350 | 352 | 3 353 | 354 | 355 | 356 | 357 | 358 | 359 | org.codehaus.mojo 360 | tomcat-maven-plugin 361 | 1.0-beta-1 362 | true 363 | 364 | /${project.build.finalName} 365 | 366 | 6060 367 | 370 | http://localhost:8080/manager 371 | 372 | 373 | 374 | org.apache.maven.plugins 375 | maven-war-plugin 376 | 2.1-beta-1 377 | true 378 | 379 | false 380 | ${project.build.finalName} 381 | 382 | 383 | 384 | org.apache.maven.plugins 385 | maven-archetype-plugin 386 | 2.0-alpha-5 387 | true 388 | 389 | 390 | org.codehaus.mojo 391 | jboss-maven-plugin 392 | 1.4 393 | 394 | 395 | org.codehaus.mojo 396 | emma-maven-plugin 397 | 1.0-alpha-2 398 | 399 | 400 | org.sonatype.maven.plugin 401 | emma4it-maven-plugin 402 | 1.3 403 | 404 | 405 | org.codehaus.cargo 406 | cargo-maven2-plugin 407 | 1.0.1 408 | 409 | 410 | org.codehaus.mojo 411 | selenium-maven-plugin 412 | 1.0.1 413 | 414 | 415 | org.codehaus.mojo 416 | failsafe-maven-plugin 417 | 2.4.3-alpha-1 418 | 419 | 420 | org.apache.maven.plugins 421 | maven-scm-plugin 422 | 1.4 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | release 431 | 432 | 433 | release 434 | 435 | 436 | 437 | 438 | 439 | org.apache.maven.plugins 440 | maven-gpg-plugin 441 | 442 | ${gpg.passphrase} 443 | ${gpg.useAgent} 444 | 445 | 446 | 447 | sign-artifacts 448 | verify 449 | 450 | sign 451 | 452 | 453 | 454 | 455 | 456 | org.sonatype.plugins 457 | nexus-maven-plugin 458 | 459 | true 460 | [nexus-maven-plugin] closing 461 | repository after 462 | release:perform 463 | 464 | 465 | 466 | org.codehaus.mojo 467 | buildnumber-maven-plugin 468 | 469 | 470 | validate-scm 471 | 472 | create 473 | 474 | 475 | none 476 | 477 | true 478 | true 479 | 480 | 481 | 482 | true 483 | 484 | 485 | 486 | 487 | 488 | distribution 489 | 490 | 491 | dist 492 | 493 | 494 | 495 | 496 | true 497 | 498 | 499 | 500 | 501 | org.apache.maven.plugins 502 | maven-javadoc-plugin 503 | 504 | 505 | javadoc 506 | package 507 | 508 | jar 509 | 510 | 511 | 512 | 513 | 514 | org.apache.maven.plugins 515 | maven-deploy-plugin 516 | 517 | ${maven.deploy.skip} 518 | 519 | 520 | 521 | 522 | 523 | 524 | code-coverage 525 | 526 | 527 | code-coverage 528 | 529 | 530 | 531 | 532 | 533 | 534 | org.codehaus.mojo 535 | emma-maven-plugin 536 | 537 | 538 | instrumentation 539 | process-classes 540 | 541 | instrument 542 | 543 | 544 | true 545 | 546 | 547 | 548 | instrumentation-clean 549 | clean 550 | 551 | clean 552 | 553 | 554 | 555 | 556 | 557 | 558 | org.apache.maven.plugins 559 | maven-surefire-plugin 560 | true 561 | 562 | once 563 | ${project.build.directory}/generated-classes/emma/classes 564 | 565 | 566 | 567 | 568 | org.sonatype.maven.plugin 569 | emma4it-maven-plugin 570 | 571 | 572 | report 573 | test 574 | 575 | report 576 | 577 | 578 | 579 | 580 | ${project.build.sourceDirectory} 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | cdi.advocate 598 | CDI Advocacy 599 | http://jee6-cdi.googlecode.com/svn/m2/repository/ 600 | 601 | 602 | TBD 603 | TBD 604 | TBD 605 | 606 | 607 | 608 | 609 | 610 | 611 | cdi.advocate 612 | CDI Advocacy 613 | http://jee6-cdi.googlecode.com/svn/m2/repository/ 614 | 615 | 616 | java.net 617 | Java.net repository for common APIs 618 | http://download.java.net/maven/2/ 619 | 620 | 621 | 622 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | org.cdisource.beancontainer 4 | cdisource-build-aggregator 5 | pom 6 | 1.0-SNAPSHOT 7 | 8 | 9 | org.cdisource 10 | cdisource-parent 11 | 1.0-SNAPSHOT 12 | parent 13 | 14 | 15 | 16 | 3.0 17 | 18 | 19 | CDISource Project Build Aggregator 20 | 21 | 22 | The build aggregator for CDI Advocate APIs, which takes care of calling the modules which make up CDI Advocate APIs 23 | 24 | 25 | 26 | scm:git:git://github.com/CDISource/cdisource.git 27 | http://github.com/CDISource/cdisource 28 | scm:git:git@github.com:CDISource/cdisource.git 29 | 30 | 31 | 32 | parent 33 | beancontainer/api 34 | beancontainer/resin-impl 35 | beancontainer/weld-impl 36 | beancontainer/testing 37 | beancontainer/openwebbeans-impl 38 | beancontainer/jndi-impl 39 | testing/junit 40 | web 41 | spring 42 | 43 | 44 | 45 | cdisource-${build.version} 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /spring/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | org.cdisource.springbridge 5 | springbridge 6 | jar 7 | Spring Bridge 8 | 1.0-SNAPSHOT 9 | 10 | 11 | org.cdisource 12 | cdisource-parent 13 | 1.0-SNAPSHOT 14 | ../parent 15 | 16 | 17 | 18 | 3.0 19 | 20 | 21 | 22 | 23 | Spring CDI bridge to bridge the two technologies 24 | 25 | 26 | 3.0.5.RELEASE 27 | 1.6.11.M2 28 | 29 | 30 | 31 | 32 | spring-maven-release 33 | Spring Maven Release Repository 34 | http://maven.springframework.org/release 35 | 36 | 37 | spring-maven-milestone 38 | Spring Maven Milestone Repository 39 | http://maven.springframework.org/milestone 40 | 41 | 42 | 43 | 44 | 45 | javax.enterprise 46 | cdi-api 47 | 1.0-SP1 48 | jar 49 | compile 50 | 51 | 52 | junit 53 | junit 54 | 4.8.2 55 | jar 56 | test 57 | 58 | 59 | 60 | org.aspectj 61 | aspectjrt 62 | ${aspectj.version} 63 | 64 | 65 | 66 | org.springframework 67 | spring-test 68 | ${spring.version} 69 | test 70 | 71 | 72 | org.springframework 73 | spring-context 74 | ${spring.version} 75 | 76 | 77 | org.springframework 78 | spring-aop 79 | ${spring.version} 80 | 81 | 82 | org.springframework 83 | spring-aspects 84 | ${spring.version} 85 | 86 | 87 | org.springframework 88 | spring-web 89 | ${spring.version} 90 | 91 | 92 | 93 | org.springframework 94 | spring-tx 95 | ${spring.version} 96 | 97 | 98 | 99 | org.apache.geronimo.specs 100 | geronimo-servlet_3.0_spec 101 | 1.0 102 | provided 103 | 104 | 105 | 106 | org.cdisource.beancontainer 107 | beancontainer-api 108 | 1.0-SNAPSHOT 109 | 110 | 111 | 112 | org.cdisource.testing 113 | cdisource-testing-junit 114 | 1.0-SNAPSHOT 115 | test 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | org.apache.maven.plugins 124 | maven-jar-plugin 125 | 2.3.1 126 | 127 | 128 | 129 | ${project.url} 130 | ${project.name} 131 | ${maven.build.timestamp} 132 | ${project.organization.name} 133 | ${project.name} 134 | ${parsedVersion.osgiVersion} 135 | ${project.organization.name} 136 | 137 | 138 | 139 | Build-Information 140 | 141 | ${maven.version} 142 | ${java.version} 143 | ${java.vendor} 144 | ${os.name} 145 | ${os.arch} 146 | ${os.version} 147 | r${buildNumber} 148 | ${maven.build.timestamp} 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | resin 161 | 162 | true 163 | 164 | 165 | 166 | org.cdisource.beancontainer 167 | beancontainer-resin-impl 168 | 1.0-SNAPSHOT 169 | test 170 | 171 | 172 | 173 | 174 | 175 | org.apache.maven.plugins 176 | maven-surefire-plugin 177 | 2.8 178 | 179 | true 180 | false 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | weld 189 | 190 | 191 | weld 192 | true 193 | 194 | 195 | 196 | 197 | org.cdisource.beancontainer 198 | beancontainer-weld-impl 199 | 1.0-SNAPSHOT 200 | test 201 | 202 | 203 | 204 | 205 | 206 | org.apache.maven.plugins 207 | maven-surefire-plugin 208 | 2.8 209 | 210 | true 211 | false 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | openwebbeans 220 | 221 | 222 | openwebbeans 223 | true 224 | 225 | 226 | 227 | 228 | org.cdisource.beancontainer 229 | beancontainer-openwebbeans-impl 230 | 1.0-SNAPSHOT 231 | test 232 | 233 | 234 | 235 | 236 | 237 | 238 | org.apache.maven.plugins 239 | maven-surefire-plugin 240 | 2.8 241 | 242 | true 243 | false 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | -------------------------------------------------------------------------------- /spring/src/main/java/org/cdisource/springintegration/BeanManagerLocationUtil.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | 3 | import javax.enterprise.inject.spi.BeanManager; 4 | import javax.naming.InitialContext; 5 | 6 | import org.cdisource.beancontainer.BeanContainer; 7 | import org.cdisource.beancontainer.BeanContainerManager; 8 | import org.cdisource.beancontainer.BeanManagerLocator; 9 | 10 | public class BeanManagerLocationUtil { 11 | 12 | private final String BEAN_MANAGER_LOCATION = "java:comp/BeanManager"; 13 | private BeanManager beanManager; 14 | 15 | BeanManager beanManager() { 16 | if (this.beanManager!=null) { 17 | return this.beanManager; 18 | } 19 | if (lookupInJNDI() == null) { 20 | BeanContainer beanContainer = BeanContainerManager.getInstance(); 21 | this.beanManager = ((BeanManagerLocator) beanContainer) 22 | .getBeanManager(); 23 | } 24 | 25 | if (this.beanManager==null) { 26 | throw new IllegalStateException("BEAN MANAGER IS NULL"); 27 | } 28 | return this.beanManager; 29 | 30 | } 31 | 32 | private BeanManager lookupInJNDI() { 33 | try { 34 | InitialContext ic = new InitialContext(); 35 | return (this.beanManager = (BeanManager) ic.lookup(BEAN_MANAGER_LOCATION)); 36 | } catch (Exception e) {// need to log this 37 | return null; 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /spring/src/main/java/org/cdisource/springintegration/CdiApplicationContext.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | 3 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; 4 | import org.springframework.context.support.AbstractApplicationContext; 5 | 6 | public class CdiApplicationContext extends AbstractApplicationContext { 7 | 8 | private final ConfigurableListableBeanFactory beanFactory 9 | = new CdiBeanFactory(); 10 | 11 | 12 | public CdiApplicationContext () { 13 | //refresh(); 14 | } 15 | 16 | @Override 17 | protected void refreshBeanFactory() { 18 | } 19 | 20 | @Override 21 | protected void closeBeanFactory() { 22 | } 23 | 24 | @Override 25 | public ConfigurableListableBeanFactory getBeanFactory() { 26 | return beanFactory; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /spring/src/main/java/org/cdisource/springintegration/CdiBeanFactory.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | 3 | import java.util.Set; 4 | 5 | import javax.enterprise.inject.spi.Bean; 6 | import javax.enterprise.inject.spi.BeanManager; 7 | import javax.naming.InitialContext; 8 | 9 | import org.cdisource.beancontainer.BeanContainer; 10 | import org.cdisource.beancontainer.BeanContainerImpl; 11 | import org.cdisource.beancontainer.BeanContainerInitializationException; 12 | import org.cdisource.beancontainer.BeanManagerLocator; 13 | import org.springframework.beans.factory.support.DefaultListableBeanFactory; 14 | 15 | public class CdiBeanFactory extends DefaultListableBeanFactory { 16 | 17 | 18 | /** 19 | * Creates a new bean factory adapter 20 | */ 21 | public CdiBeanFactory() { 22 | } 23 | 24 | /** 25 | * Returns true for defined beans 26 | */ 27 | @Override 28 | public boolean containsBeanDefinition(String beanName) { 29 | BeanManager beanManager = ((BeanManagerLocator)beanContainer()).getBeanManager(); 30 | Set> beans = beanManager.getBeans(beanName); 31 | return beans.isEmpty(); 32 | } 33 | 34 | /** 35 | * Returns the named beans 36 | */ 37 | @Override 38 | public String[] getBeanDefinitionNames() { 39 | return super.getBeanDefinitionNames(); 40 | } 41 | 42 | @SuppressWarnings({ "unchecked", "rawtypes" }) 43 | @Override 44 | public Object getBean(String name, Class requiredType, Object... args) { 45 | return beanContainer().getBeanByName(requiredType, name); 46 | } 47 | 48 | @Override 49 | public T getBean(Class type) { 50 | return beanContainer().getBeanByType(type); 51 | } 52 | 53 | private final String BEAN_MANAGER_LOCATION = "java:comp/BeanManager"; 54 | 55 | private BeanContainer beanContainer; 56 | 57 | private BeanContainer beanContainer() { 58 | if (beanContainer == null) { 59 | Object bean = null; 60 | 61 | try { 62 | InitialContext ic = new InitialContext(); 63 | bean = ic.lookup(BEAN_MANAGER_LOCATION); 64 | } catch (Exception e) { 65 | throw new BeanContainerInitializationException( 66 | "Unable to lookup BeanManager instance in JNDI", e); 67 | } 68 | if (bean == null) { 69 | throw new BeanContainerInitializationException( 70 | "Null value returned when looking up the BeanManager from JNDI"); 71 | } 72 | if (bean instanceof BeanManager) { 73 | beanContainer = new BeanContainerImpl((BeanManager) bean); 74 | } else { 75 | String msg = "Looked up JNDI Bean is not a BeanManager instance, bean type is " 76 | + bean.getClass().getName(); 77 | throw new BeanContainerInitializationException(msg); 78 | } 79 | } 80 | return beanContainer; 81 | 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /spring/src/main/java/org/cdisource/springintegration/CdiBeanFactoryPostProcessor.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | 3 | import java.util.Set; 4 | 5 | import javax.enterprise.inject.spi.Bean; 6 | import javax.inject.Named; 7 | import org.springframework.beans.BeansException; 8 | import org.springframework.beans.factory.config.BeanFactoryPostProcessor; 9 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; 10 | import org.springframework.beans.factory.support.BeanDefinitionBuilder; 11 | import org.springframework.beans.factory.support.DefaultListableBeanFactory; 12 | 13 | 14 | public class CdiBeanFactoryPostProcessor implements BeanFactoryPostProcessor { 15 | 16 | private boolean useLongName; 17 | 18 | private BeanManagerLocationUtil beanManagerLocationUtil = new BeanManagerLocationUtil(); 19 | 20 | 21 | @Override 22 | public void postProcessBeanFactory( 23 | ConfigurableListableBeanFactory beanFactory) throws BeansException { 24 | 25 | DefaultListableBeanFactory factory = (DefaultListableBeanFactory) beanFactory; 26 | 27 | Set> beans = beanManagerLocationUtil.beanManager().getBeans(Object.class); 28 | for (Bean bean : beans) { 29 | if (bean instanceof SpringIntegrationExtention.SpringBean) { 30 | continue; 31 | } 32 | 33 | if (bean.getName()!=null && bean.getName().equals("Spring Injection")){ 34 | continue; 35 | } 36 | BeanDefinitionBuilder definition = BeanDefinitionBuilder.rootBeanDefinition(CdiFactoryBean.class) 37 | .addPropertyValue("beanClass", bean.getBeanClass()) 38 | .addPropertyValue("beanManager", beanManagerLocationUtil.beanManager()) 39 | .setLazyInit(true); 40 | String name = generateName(bean); 41 | factory.registerBeanDefinition(name, definition.getBeanDefinition()); 42 | } 43 | } 44 | 45 | private String generateName(Bean bean) { 46 | Named named = (Named) bean.getBeanClass().getAnnotation(Named.class); 47 | String name = named != null ? named.value() : generateNameBasedOnClassName(bean); 48 | return name; 49 | } 50 | 51 | private String generateNameBasedOnClassName(Bean bean) { 52 | return !useLongName ? bean.getBeanClass().getSimpleName() + "FactoryBean" : bean.getBeanClass().getName().replace(".", "_") + "FactoryBean"; 53 | } 54 | 55 | 56 | 57 | public void setUseLongName(boolean useLongName) { 58 | this.useLongName = useLongName; 59 | } 60 | 61 | 62 | } 63 | -------------------------------------------------------------------------------- /spring/src/main/java/org/cdisource/springintegration/CdiFactoryBean.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | 3 | 4 | import javax.enterprise.inject.spi.BeanManager; 5 | 6 | import org.springframework.beans.factory.FactoryBean; 7 | import org.springframework.beans.factory.InitializingBean; 8 | import org.cdisource.beancontainer.BeanContainer; 9 | import org.cdisource.beancontainer.BeanContainerImpl; 10 | 11 | public class CdiFactoryBean implements FactoryBean, InitializingBean { 12 | 13 | private Class beanClass; 14 | private boolean singleton = true; 15 | private BeanContainer beanContainer; 16 | private BeanManager beanManager; 17 | 18 | 19 | @Override 20 | public void afterPropertiesSet() throws Exception { 21 | if (beanManager==null) throw new IllegalStateException("BeanManager must be set"); 22 | beanContainer = new BeanContainerImpl(beanManager); 23 | } 24 | 25 | public void setBeanClass(Class beanClass) { 26 | this.beanClass = beanClass; 27 | } 28 | 29 | @Override 30 | public Object getObject() throws Exception { 31 | return beanContainer.getBeanByType(beanClass); 32 | } 33 | 34 | @Override 35 | public Class getObjectType() { 36 | return beanClass; 37 | } 38 | 39 | @Override 40 | public boolean isSingleton() { 41 | return singleton; 42 | } 43 | 44 | public void setSingleton(boolean singleton) { 45 | this.singleton = singleton; 46 | } 47 | 48 | public void setBeanManager(BeanManager beanManager) { 49 | this.beanManager = beanManager; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /spring/src/main/java/org/cdisource/springintegration/Spring.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.Target; 5 | import static java.lang.annotation.ElementType.*; 6 | import static java.lang.annotation.RetentionPolicy.*; 7 | 8 | import javax.enterprise.util.Nonbinding; 9 | import javax.inject.Qualifier; 10 | 11 | 12 | @Qualifier @Retention(RUNTIME) @Target({TYPE, METHOD, FIELD, PARAMETER}) 13 | public @interface Spring { 14 | Class type() default Object.class; 15 | String name() default ""; 16 | @Nonbinding boolean required() default true; 17 | } -------------------------------------------------------------------------------- /spring/src/main/java/org/cdisource/springintegration/SpringBridge.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | 3 | public class SpringBridge { 4 | 5 | // @Spring 6 | // @Produces Object getBean(InjectionPoint injectionPoint) { 7 | // Annotated annotated = injectionPoint.getAnnotated(); 8 | // 9 | // Spring spring = annotated.getAnnotation(Spring.class); 10 | // System.out.println("Name of Spring object " + spring.name()); 11 | // return new TaskValidator(); 12 | // } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /spring/src/main/java/org/cdisource/springintegration/SpringIntegrationExtention.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | 3 | import java.lang.annotation.Annotation; 4 | import java.lang.reflect.Type; 5 | import java.util.Collections; 6 | import java.util.HashMap; 7 | import java.util.HashSet; 8 | import java.util.Map; 9 | import java.util.Set; 10 | 11 | import javax.enterprise.context.spi.CreationalContext; 12 | import javax.enterprise.event.Observes; 13 | import javax.enterprise.inject.spi.AfterBeanDiscovery; 14 | import javax.enterprise.inject.spi.AnnotatedType; 15 | import javax.enterprise.inject.spi.Bean; 16 | import javax.enterprise.inject.spi.BeanManager; 17 | import javax.enterprise.inject.spi.BeforeBeanDiscovery; 18 | import javax.enterprise.inject.spi.Extension; 19 | import javax.enterprise.inject.spi.InjectionPoint; 20 | import javax.enterprise.inject.spi.ProcessInjectionTarget; 21 | import javax.enterprise.util.AnnotationLiteral; 22 | import javax.enterprise.context.Dependent; 23 | import javax.inject.Named; 24 | 25 | import org.cdisource.springintegration.springsupport.ApplicationContextLocatorManager; 26 | import org.springframework.context.ApplicationContext; 27 | 28 | 29 | public class SpringIntegrationExtention implements Extension { 30 | Map springBeans = new HashMap(); 31 | 32 | 33 | public void processInjectionTarget (@Observes ProcessInjectionTarget pit, BeanManager bm) { 34 | 35 | Set injectionPoints = pit.getInjectionTarget().getInjectionPoints(); 36 | 37 | synchronized (springBeans) { 38 | for (InjectionPoint point: injectionPoints){ 39 | 40 | if (!(point.getType() instanceof Class)) { 41 | continue; 42 | } 43 | 44 | Class injectionType = (Class) point.getType(); 45 | Spring spring = point.getAnnotated().getAnnotation(Spring.class); 46 | if (spring!=null) { 47 | SpringBean springBean = new SpringBean(pit.getAnnotatedType(), spring, injectionType, bm); 48 | springBeans.put(springBean.key(), springBean); //we can do some validation to make sure that this bean is compatible with the one we are replacing. 49 | } else { 50 | SpringLookup springLookup = point.getAnnotated().getAnnotation(SpringLookup.class); 51 | if (springLookup!=null) { 52 | SpringBean springBean = new SpringBean(springLookup, injectionType, bm); 53 | springBeans.put(springBean.key(), springBean); 54 | } 55 | } 56 | } 57 | } 58 | } 59 | 60 | 61 | void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd) { 62 | } 63 | 64 | 65 | void afterBeanDiscovery( @Observes AfterBeanDiscovery abd, BeanManager bm) { 66 | synchronized (springBeans) { 67 | for (SpringBean bean : springBeans.values()) { 68 | abd.addBean(bean); 69 | } 70 | } 71 | } 72 | 73 | 74 | 75 | class SpringBean implements Bean { 76 | //InjectionTarget it; 77 | Spring spring; 78 | SpringLookup lookup; 79 | Class injectionType; 80 | BeanManager bm; 81 | 82 | 83 | AnnotatedType annotatedType; 84 | 85 | SpringBean(AnnotatedType annotatedType, Spring spring, Class injectionType, BeanManager bm){ 86 | this.spring = spring; 87 | this.injectionType = injectionType; 88 | this.bm = bm; 89 | this.annotatedType = annotatedType; 90 | //it = bm.createInjectionTarget(at); 91 | } 92 | 93 | public SpringBean(SpringLookup springLookup, Class type, 94 | BeanManager bm) { 95 | this.lookup = springLookup; 96 | this.injectionType = type; 97 | this.bm = bm; 98 | } 99 | 100 | public String key () { 101 | return "" + this.getName() + "::" + injectionType.toString(); 102 | } 103 | 104 | @SuppressWarnings("all") 105 | class NamedLiteral extends AnnotationLiteral implements Named { 106 | 107 | @Override 108 | public String value() { 109 | return (spring!=null) ? spring.name() : lookup.value(); 110 | } 111 | 112 | } 113 | 114 | @Override 115 | public Class getBeanClass() { 116 | return this.injectionType; 117 | } 118 | 119 | @SuppressWarnings("unchecked") 120 | @Override 121 | public Set getInjectionPoints() { 122 | return Collections.EMPTY_SET; 123 | } 124 | 125 | @Override 126 | public String getName() { 127 | return spring!=null ? spring.name() : lookup.value(); 128 | } 129 | 130 | @Override 131 | public Set getQualifiers() { 132 | Set qualifiers = new HashSet(); 133 | if (lookup==null) { 134 | qualifiers.add(new NamedLiteral()); //Added this because it causes OWB to fail if there is a Named 135 | } 136 | if (spring!=null) { 137 | qualifiers.add( spring ); 138 | } else { 139 | qualifiers.add( lookup ); 140 | } 141 | return qualifiers; 142 | } 143 | 144 | @Override 145 | public Class getScope() { 146 | return Dependent.class; 147 | } 148 | 149 | @Override 150 | public Set> getStereotypes() { 151 | return Collections.emptySet(); 152 | } 153 | 154 | @Override 155 | public Set getTypes() { 156 | Set types = new HashSet(); 157 | types.add(this.injectionType); 158 | types.add(Object.class); 159 | return types; 160 | } 161 | 162 | @Override 163 | public boolean isAlternative() { 164 | return false; 165 | } 166 | 167 | @Override 168 | public boolean isNullable() { 169 | return spring != null ? !spring.required() : false; 170 | } 171 | @Override 172 | public Object create(CreationalContext ctx) { 173 | ApplicationContext applicationContext = ApplicationContextLocatorManager.getInstance().locateApplicationContext(); 174 | if (applicationContext==null) { 175 | if (spring !=null) { 176 | System.err.printf("############## spring name=%s type=%s \n\n\n", spring.name(), spring.type()); 177 | } else { 178 | System.err.printf("############## lookup value=%s \n\n\n", lookup.value()); 179 | } 180 | throw new IllegalStateException("applicationContext was null"); 181 | } 182 | Object instance = null; 183 | if (spring!=null) { 184 | if (!spring.name().trim().equals("")) { 185 | if(!spring.required()) { 186 | if (applicationContext.containsBean(spring.name())) { 187 | instance = applicationContext.getBean(spring.name(), spring.type()); 188 | } 189 | } else { 190 | instance = applicationContext.getBean(spring.name(), spring.type()); 191 | } 192 | } else { 193 | instance = applicationContext.getBean(spring.type()); 194 | } 195 | } else { 196 | instance = applicationContext.getBean(lookup.value()); 197 | } 198 | return instance; 199 | } 200 | 201 | @Override 202 | public void destroy(Object instance, CreationalContext ctx) { 203 | ctx.release(); 204 | } 205 | 206 | public String toString() { 207 | return String.format("SpringBean(hc=%d, hc=%d, annotatedType=%s, qualifiers=%s)", this.hashCode(), SpringIntegrationExtention.this.hashCode(), this.annotatedType, this.getQualifiers() ); 208 | } 209 | 210 | } 211 | 212 | 213 | } 214 | -------------------------------------------------------------------------------- /spring/src/main/java/org/cdisource/springintegration/SpringLookup.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.Target; 5 | import static java.lang.annotation.ElementType.*; 6 | import static java.lang.annotation.RetentionPolicy.*; 7 | 8 | @Retention(RUNTIME) @Target({TYPE, METHOD, FIELD, PARAMETER}) 9 | public @interface SpringLookup { 10 | String value(); 11 | } -------------------------------------------------------------------------------- /spring/src/main/java/org/cdisource/springintegration/servletsupport/ApplicationContextFinderServletContextListener.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration.servletsupport; 2 | 3 | import javax.servlet.ServletContextEvent; 4 | import javax.servlet.ServletContextListener; 5 | //import javax.servlet.annotation.WebListener; 6 | 7 | import org.cdisource.springintegration.springsupport.ApplicationContextLocator; 8 | import org.cdisource.springintegration.springsupport.ApplicationContextLocatorImpl; 9 | import org.cdisource.springintegration.springsupport.ApplicationContextLocatorManager; 10 | import org.springframework.web.context.WebApplicationContext; 11 | import org.springframework.web.context.support.WebApplicationContextUtils; 12 | 13 | //@WebListener 14 | public class ApplicationContextFinderServletContextListener implements ServletContextListener { 15 | 16 | 17 | @Override 18 | public void contextInitialized(ServletContextEvent sce) { 19 | WebApplicationContext requiredWebApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext()); 20 | ApplicationContextLocatorImpl.putContext(requiredWebApplicationContext); 21 | ApplicationContextLocator applicationContextLocator = ApplicationContextLocatorManager.getInstance(); 22 | sce.getServletContext().setAttribute(ApplicationContextLocator.class.getName(), applicationContextLocator); 23 | } 24 | 25 | @Override 26 | public void contextDestroyed(ServletContextEvent sce) { 27 | sce.getServletContext().setAttribute(ApplicationContextLocator.class.getName(), null); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /spring/src/main/java/org/cdisource/springintegration/springsupport/ApplicationContextLocator.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration.springsupport; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | 5 | /** 6 | * Simple interface that locates a Spring application context. 7 | * 8 | * @author rick 9 | * 10 | */ 11 | public interface ApplicationContextLocator { 12 | ApplicationContext locateApplicationContext(); 13 | } 14 | -------------------------------------------------------------------------------- /spring/src/main/java/org/cdisource/springintegration/springsupport/ApplicationContextLocatorImpl.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration.springsupport; 2 | 3 | 4 | import java.lang.ref.WeakReference; 5 | import java.util.Collections; 6 | import java.util.Map; 7 | import java.util.WeakHashMap; 8 | 9 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; 10 | import org.springframework.context.ApplicationContext; 11 | import org.springframework.context.ConfigurableApplicationContext; 12 | 13 | 14 | /** Simple implementation of the ApplicationContextLocator that is web application friendly. 15 | * It does not use a normal singleton design pattern. It uses a variant that will allow the webapplication to be relaoded. 16 | * 17 | * @author rick 18 | * 19 | */ 20 | public class ApplicationContextLocatorImpl implements ApplicationContextLocator{ 21 | 22 | private static Map> map = 23 | Collections.synchronizedMap(new WeakHashMap>()); 24 | 25 | public static void putContext(ApplicationContext context) { 26 | ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); 27 | map.put(contextClassLoader, new WeakReference(context)); 28 | } 29 | 30 | public ApplicationContextLocatorImpl() { 31 | ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); 32 | 33 | WeakReference reference = map.get(contextClassLoader); 34 | 35 | /* To prevent GC from killing this until web app is gone. 36 | */ 37 | ApplicationContext applicationContext; 38 | 39 | if (reference==null) { 40 | throw new IllegalStateException("1: Applicaiton context must be associated with the current classloader first"); 41 | } else { 42 | applicationContext = reference.get(); 43 | } 44 | 45 | if (applicationContext!=null) { 46 | String beanName = ApplicationContextLocator.class.getName(); 47 | if (!applicationContext.containsBean(beanName)) { 48 | ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext)applicationContext).getBeanFactory(); 49 | beanFactory.registerSingleton(beanName, this); 50 | } 51 | } else { 52 | throw new IllegalStateException("1: Applicaiton context must be associated with the current classloader first"); 53 | } 54 | 55 | } 56 | 57 | @Override 58 | public ApplicationContext locateApplicationContext() { 59 | ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); 60 | 61 | WeakReference reference = map.get(contextClassLoader); 62 | 63 | ApplicationContext applicationContext; 64 | 65 | if (reference==null) { 66 | return null; 67 | } else { 68 | applicationContext = reference.get(); 69 | } 70 | 71 | return applicationContext; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /spring/src/main/java/org/cdisource/springintegration/springsupport/ApplicationContextLocatorManager.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration.springsupport; 2 | 3 | import java.util.Collections; 4 | import java.util.Iterator; 5 | import java.util.Map; 6 | import java.util.Properties; 7 | import java.util.ServiceLoader; 8 | import java.util.WeakHashMap; 9 | import java.lang.ref.WeakReference; 10 | 11 | import org.cdisource.logging.Logger; 12 | 13 | import static org.cdisource.logging.LogFactoryManager.logger; 14 | 15 | 16 | /** 17 | * ApplicationContextLocatorManager, this is used to find an ApplicationContextLocator. 18 | * An ApplicationContextLocator locates an application context. 19 | * This does not use a normal singleton. It uses a singleton that will not prevent a web application from reloading. 20 | * It does this by using WeakHashMap with WeakReference keyed on the current classloader. 21 | * 22 | * To load the ApplicationContextLocator it first checks to see if a property or system property has been set called 23 | * org.cdisource.springintegration.springsupport.ApplicationContextLocator. 24 | * 25 | * If this has not been set, then it checks the ServiceLoader. 26 | * If more than one item is loaded form the ServiceLoader, it throws an exception. 27 | * 28 | * If one ApplicationContextLocator is found with the ServiceLoader then it uses this ApplicationContextLocator. 29 | * 30 | * Lastly, it instantiates a ApplicationContextLocatorImpl which is the default implementation. 31 | * 32 | * @see ServiceLoader. 33 | * 34 | * @author rick 35 | * 36 | */ 37 | public class ApplicationContextLocatorManager { 38 | 39 | /** Using a WeakHash map instead of a singleton to be classloader friendly in a Java EE application. 40 | * Essentially, I don't want to hold on to a class otherwise the container will not be able to reload the webapplication. 41 | * */ 42 | private static Map> map = Collections 43 | .synchronizedMap(new WeakHashMap>()); 44 | 45 | 46 | /** Simple getInstance. Searches the System properties for service locator. 47 | * If system property not found, it then uses ServiceLoader. 48 | * 49 | * @see ApplicationContextLocatorManager 50 | * @see ServiceLoader 51 | * 52 | * */ 53 | public static ApplicationContextLocator getInstance() { 54 | Properties properties = System.getProperties(); 55 | return getInstance(properties); 56 | } 57 | 58 | /** 59 | * Same as ApplicationContextLocator.getInstance except you can pass the properties instead of using system properties. 60 | * @param properties 61 | * @return 62 | */ 63 | public static ApplicationContextLocator getInstance(Properties properties) { 64 | Logger logger = logger(ApplicationContextLocatorManager.class); 65 | 66 | 67 | ApplicationContextLocator applicationContextLocator = null; 68 | 69 | synchronized (map) { //synced so two threads will not try to put an entry in. First thread blocks until key is populated 70 | 71 | ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); 72 | WeakReference weakReference = map 73 | .get(contextClassLoader); 74 | 75 | if (weakReference == null || weakReference.get() == null) { 76 | 77 | logger.debug("application context locator was not found in singleton looking up"); 78 | 79 | applicationContextLocator = locateAppContextLocator(properties, logger); 80 | 81 | if (applicationContextLocator==null) { 82 | logger.debug("Unable to find applicationContextLocator"); 83 | } 84 | 85 | map.put(contextClassLoader, 86 | new WeakReference( 87 | applicationContextLocator)); 88 | } else { 89 | logger.debug("found application context locator"); 90 | applicationContextLocator = weakReference.get(); 91 | } 92 | 93 | } 94 | return applicationContextLocator; 95 | } 96 | 97 | /** 98 | * Location logic. This is where all of the logic for location is implemented. 99 | * @param properties 100 | * @param logger 101 | * @return 102 | */ 103 | private static ApplicationContextLocator locateAppContextLocator(Properties properties, Logger logger) { 104 | ApplicationContextLocator applicationContextLocator = null; 105 | 106 | /* See if the property is set. */ 107 | if (properties.getProperty(ApplicationContextLocator.class.getName())==null) { 108 | 109 | logger.debug("System property was not found, using service laoder"); 110 | 111 | /* if the property is not set, try to use the ServiceLoader to find the implementation. */ 112 | ServiceLoader instances = ServiceLoader.load(ApplicationContextLocator.class); 113 | Iterator iterator = instances.iterator(); 114 | 115 | /* A ServiceLoader can load more than one instance. We only need/want one. */ 116 | /* See if we have one. */ 117 | if (iterator.hasNext()) { 118 | 119 | /* If we have one, assign it. */ 120 | applicationContextLocator = iterator.next(); 121 | 122 | /* If there is more than one, than somebody messed something up in their build. Let them know. */ 123 | if (iterator.hasNext()) { 124 | throw new IllegalStateException("There is more than one instance of " + ApplicationContextLocator.class.getName()); 125 | } 126 | } else { 127 | logger.debug("ServiceLoader did not find either so now use the default"); 128 | /* If one could not be found, go ahead and supply the default. */ 129 | applicationContextLocator = new ApplicationContextLocatorImpl(); 130 | } 131 | } else { 132 | 133 | /* If the property was found, then they want to use a specific implementation. 134 | * Instantiate this using reflection. */ 135 | applicationContextLocator = instantiateUsingReflection(properties, 136 | applicationContextLocator, logger); 137 | } 138 | 139 | return applicationContextLocator; 140 | } 141 | 142 | /** 143 | * Method that creates an instance of ApplicationContextLocator using the value of properties.get(ApplicationContextLocator.class.getName()) 144 | * @param properties 145 | * @param applicationContextLocator 146 | * @param logger 147 | * @return 148 | */ 149 | private static ApplicationContextLocator instantiateUsingReflection(Properties properties, 150 | ApplicationContextLocator applicationContextLocator, Logger logger) { 151 | try { 152 | String clazz = properties.getProperty(ApplicationContextLocator.class.getName()); 153 | logger.debug("Loading class %s as the ApplicationContextLocator", clazz); 154 | applicationContextLocator = (ApplicationContextLocator) Class.forName(clazz).newInstance(); 155 | } catch (Exception e) { 156 | throw new RuntimeException(e); 157 | } 158 | return applicationContextLocator; 159 | } 160 | 161 | } 162 | -------------------------------------------------------------------------------- /spring/src/main/resources/META-INF/web-fragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spring CDI Bridge 6 | 7 | 8 | 9 | 10 | 11 | 12 | Spring CDI Bridge 13 | 14 | org.cdisource.springintegration.servletsupport.ApplicationContextFinderServletContextListener 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /spring/src/test/java/org/cdisource/springintegration/CdiBean.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | import javax.inject.Named; 3 | 4 | @Named("foo2") 5 | public class CdiBean { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /spring/src/test/java/org/cdisource/springintegration/CdiBean2.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | 3 | public class CdiBean2 { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /spring/src/test/java/org/cdisource/springintegration/CdiBeanThatHasSpringInjection.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | 3 | import javax.inject.Inject; 4 | 5 | public class CdiBeanThatHasSpringInjection { 6 | @Inject @Spring(name="fooBar") //Works with Weld and Candi but not OWB 7 | FooSpringBean springBean; 8 | @Inject @Spring(name="fooBarnotActuallyThere", required=false) //Works with Weld and Candi but not OWB 9 | FooSpringBean notActuallyThere; 10 | 11 | 12 | @Inject @Spring(type=FooSpringBean2.class) //Does not work in Weld but does work with CANDI 13 | FooSpringBean2 injectByType; 14 | /* The above causes weld to fail throughout. 15 | * 16 | * Exception 0 : 17 | org.jboss.weld.exceptions.DefinitionException: WELD-001508 Cannot create an InjectionTarget from public abstract interface class org.cdisource.springintegration.FooSpringBean2 as it is an interface 18 | at org.jboss.weld.manager.SimpleInjectionTarget.(SimpleInjectionTarget.java:71) 19 | at org.jboss.weld.manager.BeanManagerImpl.createInjectionTarget(BeanManagerImpl.java:1051) 20 | at org.cdisource.springintegration.SpringIntegrationExtention$SpringBean.(SpringIntegrationExtention.java:93) 21 | at org.cdisource.springintegration.SpringIntegrationExtention.processInjectionTarget(SpringIntegrationExtention.java:48) 22 | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 23 | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 24 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 25 | at java.lang.reflect.Method.invoke(Method.java:597) 26 | * 27 | * */ 28 | 29 | 30 | public void validate () { 31 | if (springBean==null) { 32 | throw new IllegalStateException("spring bean was null"); 33 | } 34 | if (notActuallyThere!=null) { 35 | throw new IllegalStateException("notActuallyThere should be null"); 36 | } 37 | if (injectByType==null) { 38 | throw new IllegalStateException("injectByType should be there"); 39 | } 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /spring/src/test/java/org/cdisource/springintegration/CdiBeanThatHasSpringInjection2.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | 3 | import javax.inject.Inject; 4 | 5 | public class CdiBeanThatHasSpringInjection2 { 6 | @Inject @Spring(name="fooBar7") //Works with Weld and Candi but not OWB 7 | FooSpringBean springBean; 8 | 9 | 10 | public void validate () { 11 | if (springBean==null) { 12 | throw new IllegalStateException("spring bean was null"); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /spring/src/test/java/org/cdisource/springintegration/CdiBeanThatHasSpringLookupInjection.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | 3 | import javax.inject.Inject; 4 | 5 | public class CdiBeanThatHasSpringLookupInjection { 6 | @Inject @SpringLookup("fooBar2") 7 | FooSpringBean springBean; 8 | 9 | @Inject @SpringLookup("fooBar2") 10 | FooSpringBean springBean2; 11 | 12 | 13 | public void validate () { 14 | if (springBean==null) { 15 | throw new IllegalStateException("spring bean was null"); 16 | } 17 | if (springBean2==null) { 18 | throw new IllegalStateException("spring bean2 was null"); 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /spring/src/test/java/org/cdisource/springintegration/ClassWithInjectionPoints.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | 3 | import javax.inject.Inject; 4 | 5 | public class ClassWithInjectionPoints { 6 | @Inject CdiBean bean; 7 | 8 | public CdiBean bean() {return bean;} 9 | 10 | } 11 | -------------------------------------------------------------------------------- /spring/src/test/java/org/cdisource/springintegration/FooSpringBean.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | 3 | public class FooSpringBean { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /spring/src/test/java/org/cdisource/springintegration/FooSpringBean2.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | 3 | public interface FooSpringBean2 { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /spring/src/test/java/org/cdisource/springintegration/FooSpringBean2Impl.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | 3 | public class FooSpringBean2Impl implements FooSpringBean2 { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /spring/src/test/java/org/cdisource/springintegration/NamedCdiBean.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | 3 | import javax.inject.Named; 4 | 5 | @Named("someNamedCdiBean") 6 | public class NamedCdiBean { 7 | } 8 | -------------------------------------------------------------------------------- /spring/src/test/java/org/cdisource/springintegration/SpringBeanUsingAutoWired.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | import org.springframework.beans.factory.annotation.Autowired; 3 | 4 | public class SpringBeanUsingAutoWired { 5 | @Autowired 6 | CdiBean2 bean; 7 | 8 | @Autowired 9 | ClassWithInjectionPoints foo; 10 | 11 | public void validate() { 12 | if (bean == null) { 13 | throw new IllegalStateException("CDI bean is null"); 14 | } 15 | if (foo==null) { 16 | throw new IllegalStateException("you got no foo fool!"); 17 | 18 | } 19 | 20 | if (foo.bean()==null) { 21 | throw new IllegalStateException("you got no foo bean and I pity you!"); 22 | 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /spring/src/test/java/org/cdisource/springintegration/SpringBeanUsingStandardInjection.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | 5 | public class SpringBeanUsingStandardInjection { 6 | 7 | NamedCdiBean bean; 8 | 9 | @Autowired 10 | CdiBeanThatHasSpringInjection2 injection; //Injecting a CDI bean that has a Spring injection into a Spring bean confuses weld 11 | 12 | public void setBean(NamedCdiBean bean) { 13 | this.bean = bean; 14 | } 15 | 16 | public void validate() { 17 | if (bean == null) { 18 | throw new IllegalStateException("CDI bean is null"); 19 | } 20 | if (injection == null) { 21 | throw new IllegalStateException("injection bean is null"); 22 | } 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /spring/src/test/java/org/cdisource/springintegration/SpringBridgeTest.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | import static org.junit.Assert.assertNotNull; 3 | import static org.junit.Assert.assertTrue; 4 | 5 | import org.cdisource.springintegration.springsupport.ApplicationContextLocatorImpl; 6 | import org.cdisource.testing.junit.CdiTestRunner; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.context.ApplicationContext; 10 | import org.springframework.context.support.ClassPathXmlApplicationContext; 11 | 12 | @RunWith(CdiTestRunner.class) 13 | public class SpringBridgeTest { 14 | 15 | ApplicationContext context; 16 | 17 | @Test 18 | public void injectAutowiredAnnotation() { 19 | 20 | context = new ClassPathXmlApplicationContext("applicationContext.xml"); 21 | ApplicationContextLocatorImpl.putContext(context); 22 | 23 | SpringBeanUsingAutoWired bean = context.getBean("springBeanAuto", SpringBeanUsingAutoWired.class); 24 | assertNotNull(bean); 25 | bean.validate(); 26 | 27 | ApplicationContextLocatorImpl.putContext(null); 28 | 29 | } 30 | 31 | // @Test 32 | // public void injectStandard() { 33 | // context = new ClassPathXmlApplicationContext("applicationContext.xml"); 34 | // ApplicationContextLocatorImpl.putContext(context); 35 | // 36 | // SpringBeanUsingStandardInjection bean = (SpringBeanUsingStandardInjection) context.getBean("springBeanStandard"); 37 | // assertNotNull(bean); 38 | // bean.validate(); 39 | // 40 | // ApplicationContextLocatorImpl.putContext(null); 41 | // 42 | // } 43 | 44 | @Test 45 | public void grabNamedBean() { 46 | context = new ClassPathXmlApplicationContext("applicationContext.xml"); 47 | ApplicationContextLocatorImpl.putContext(context); 48 | 49 | 50 | Object bean = context.getBean("someNamedCdiBean"); 51 | assertNotNull(bean); 52 | assertTrue(bean instanceof NamedCdiBean); 53 | 54 | ApplicationContextLocatorImpl.putContext(null); 55 | 56 | 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /spring/src/test/java/org/cdisource/springintegration/SpringIntegrationExtentionTest.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | 3 | import static org.junit.Assert.assertNotNull; 4 | 5 | import javax.inject.Inject; 6 | 7 | import org.cdisource.springintegration.springsupport.ApplicationContextLocatorManager; 8 | import org.cdisource.springintegration.springsupport.ApplicationContextLocatorImpl; 9 | import org.cdisource.testing.junit.CdiTestRunner; 10 | import org.junit.After; 11 | import org.junit.Test; 12 | import org.junit.runner.RunWith; 13 | import org.springframework.context.ApplicationContext; 14 | import org.springframework.context.support.ClassPathXmlApplicationContext; 15 | import org.cdisource.beancontainer.BeanContainer; 16 | 17 | 18 | 19 | @RunWith(CdiTestRunner.class) 20 | public class SpringIntegrationExtentionTest { 21 | 22 | @Inject 23 | BeanContainer beanContainer; 24 | 25 | ApplicationContext context; 26 | 27 | @After 28 | public void tearDown() { 29 | ApplicationContextLocatorImpl.putContext(null); 30 | } 31 | 32 | @Test 33 | public void testSpringQualifier() { 34 | context = new ClassPathXmlApplicationContext("springIntoCdiApplicationContext.xml"); 35 | ApplicationContextLocatorImpl.putContext(context); 36 | 37 | assertNotNull(beanContainer); 38 | assertNotNull(ApplicationContextLocatorManager.getInstance().locateApplicationContext()); 39 | CdiBeanThatHasSpringInjection springInjection = beanContainer.getBeanByType(CdiBeanThatHasSpringInjection.class); 40 | assertNotNull(springInjection); 41 | springInjection.validate(); 42 | } 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /spring/src/test/java/org/cdisource/springintegration/SpringIntegrationUsingLookupExtentionTest.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.springintegration; 2 | 3 | import static org.junit.Assert.assertNotNull; 4 | 5 | import javax.inject.Inject; 6 | 7 | import org.cdisource.springintegration.springsupport.ApplicationContextLocatorImpl; 8 | import org.cdisource.testing.junit.CdiTestRunner; 9 | import org.junit.After; 10 | import org.junit.Before; 11 | import org.junit.Test; 12 | import org.junit.runner.RunWith; 13 | import org.springframework.context.ApplicationContext; 14 | import org.springframework.context.support.ClassPathXmlApplicationContext; 15 | 16 | import org.cdisource.beancontainer.BeanContainer; 17 | 18 | 19 | 20 | @RunWith(CdiTestRunner.class) 21 | public class SpringIntegrationUsingLookupExtentionTest { 22 | 23 | @Inject 24 | BeanContainer beanContainer; 25 | 26 | ApplicationContext context; 27 | 28 | @Before 29 | public void setUp() { 30 | context = new ClassPathXmlApplicationContext("springIntoCdiApplicationContext.xml"); 31 | ApplicationContextLocatorImpl.putContext(context); 32 | } 33 | 34 | @After 35 | public void tearDown() { 36 | ApplicationContextLocatorImpl.putContext(null); 37 | } 38 | 39 | @Test 40 | public void testSpringLookupQualifier() { 41 | assertNotNull(beanContainer); 42 | CdiBeanThatHasSpringLookupInjection springInjection = beanContainer.getBeanByType(CdiBeanThatHasSpringLookupInjection.class); 43 | assertNotNull(springInjection); 44 | springInjection.validate(); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /spring/src/test/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /spring/src/test/resources/META-INF/services/javax.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | org.cdisource.springintegration.SpringIntegrationExtention -------------------------------------------------------------------------------- /spring/src/test/resources/META-INF/services/org.cdisource.logging.LogFactory: -------------------------------------------------------------------------------- 1 | org.cdisource.logging.SystemOutLoggerFactory -------------------------------------------------------------------------------- /spring/src/test/resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /spring/src/test/resources/springIntoCdiApplicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /testing/junit/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | org.cdisource 5 | cdisource-parent 6 | 1.0-SNAPSHOT 7 | ../../parent 8 | 9 | org.cdisource.testing 10 | cdisource-testing-junit 11 | 1.0-SNAPSHOT 12 | CDISource JUnit Test Runner 13 | Project providing support for testing with CDI and Junit 14 | 15 | 16 | junit 17 | junit 18 | 4.8.2 19 | jar 20 | provided 21 | true 22 | 23 | 24 | org.cdisource.beancontainer 25 | beancontainer-api 26 | 1.0-SNAPSHOT 27 | jar 28 | compile 29 | 30 | 31 | org.cdisource.beancontainer 32 | beancontainer-weld-impl 33 | 1.0-SNAPSHOT 34 | jar 35 | test 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /testing/junit/src/main/java/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /testing/junit/src/main/java/org/cdisource/testing/junit/CdiTestRunner.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.testing.junit; 2 | 3 | import javax.enterprise.context.RequestScoped; 4 | import javax.inject.Inject; 5 | 6 | import org.cdisource.beancontainer.BeanContainer; 7 | import org.cdisource.beancontainer.BeanContainerImpl; 8 | import org.cdisource.beancontainer.BeanContainerManager; 9 | import org.junit.runner.RunWith; 10 | import org.junit.runner.notification.RunNotifier; 11 | import org.junit.runners.BlockJUnit4ClassRunner; 12 | import org.junit.runners.model.FrameworkMethod; 13 | import org.junit.runners.model.InitializationError; 14 | 15 | /** 16 | * 17 | * CDI Test Runner class that lets you run tests on CDI beans directly while 18 | * providing injection, and interception (even production). Simply annotate your 19 | * test class using the {@link RunWith} annotation, and create your tests as 20 | * normal. Use {@link Inject} to inject components into your tests. 21 | * 22 | *
23 |  * 
24 |  * @RunWith(CdiTestRunner.class)
25 |  * public class SimpleTest {
26 |  * 
27 |  * 	@Inject
28 |  * 	private Calculator calculator;
29 |  * 
30 |  * 	@Test
31 |  * 	public void shouldAddUp() {
32 |  * 		int result = calculator.add(3, 4);
33 |  * 		assertEqual(7, result);
34 |  * 	}
35 |  * }
36 |  * 
37 |  * 
38 | * 39 | * 40 | * @author Andy Gibson 41 | * @author Rick Hightower 42 | * 43 | */ 44 | public class CdiTestRunner extends BlockJUnit4ClassRunner { 45 | 46 | public CdiTestRunner(Class klass) throws InitializationError { 47 | super(klass); 48 | } 49 | 50 | private static BeanContainer beanContainer; 51 | 52 | 53 | /** 54 | * Lazy initializes a bean container that exists on the classpath. 55 | * @param annotation 56 | * 57 | * @return instance of the CDI Bean container 58 | */ 59 | public static BeanContainer getBeanContainer() { 60 | BeanContainerManager.testEnv(); 61 | if (beanContainer == null) { 62 | beanContainer = BeanContainerManager.getInstance(); 63 | } 64 | 65 | return beanContainer; 66 | } 67 | 68 | @Override 69 | protected Object createTest() throws Exception { 70 | Class clazz = getTestClass().getJavaClass(); 71 | //this.runConfig = clazz.getAnnotation(RunConfig.class); 72 | 73 | Object result = getBeanContainer().getBeanByType(clazz); 74 | if (result == null) { 75 | result = super.createTest(); 76 | } 77 | return result; 78 | } 79 | 80 | @Override 81 | protected void runChild(FrameworkMethod method, RunNotifier notifier) 82 | { 83 | 84 | getBeanContainer().startScope(RequestScoped.class); 85 | try { 86 | super.runChild(method, notifier); 87 | } finally { 88 | getBeanContainer().stopScope(RequestScoped.class); 89 | } 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /testing/junit/src/main/java/org/cdisource/testing/junit/RunConfig.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.testing.junit; 2 | 3 | import static java.lang.annotation.ElementType.TYPE; 4 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 5 | 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.Target; 8 | 9 | @Retention(RUNTIME) @Target({TYPE}) 10 | public @interface RunConfig { 11 | boolean runInRequestScope () default false; 12 | } 13 | -------------------------------------------------------------------------------- /testing/junit/src/test/java/org/cdisource/testing/junit/Calculator.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.testing.junit; 2 | 3 | public class Calculator { 4 | 5 | public int add(int num1,int num2) { 6 | return num1+num2; 7 | } 8 | 9 | 10 | } 11 | -------------------------------------------------------------------------------- /testing/junit/src/test/java/org/cdisource/testing/junit/CdiTestRunnerTest.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.testing.junit; 2 | 3 | import javax.inject.Inject; 4 | 5 | import junit.framework.Assert; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | @RunWith(CdiTestRunner.class) 11 | public class CdiTestRunnerTest { 12 | 13 | @Inject 14 | private MessageBean messageBean; 15 | 16 | @Test 17 | public void testMessageBeanIsInjected() { 18 | Assert.assertNotNull(messageBean); 19 | //verify it is what we expect 20 | String result = messageBean.getMessage(); 21 | Assert.assertEquals("MessageFromBean", result); 22 | } 23 | 24 | @Test 25 | public void testCalculatorIsInjectedToMessageBean() { 26 | Assert.assertNotNull(messageBean); 27 | String result = messageBean.getMathMessage(3, 7); 28 | Assert.assertEquals("3+7=10", result); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /testing/junit/src/test/java/org/cdisource/testing/junit/MessageBean.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.testing.junit; 2 | 3 | import javax.inject.Inject; 4 | 5 | public class MessageBean { 6 | 7 | @Inject 8 | private Calculator calculator; 9 | 10 | public String getMessage() { 11 | return "MessageFromBean"; 12 | } 13 | 14 | public String getMathMessage(int num1,int num2) { 15 | return num1+"+"+num2+"="+calculator.add(num1,num2); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /testing/junit/src/test/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CDISource/cdisource/de5d89a9c58ac36bd312f56c8b0d212b86ea8ff0/testing/junit/src/test/resources/META-INF/beans.xml -------------------------------------------------------------------------------- /web/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.cdisource 6 | cdisource-parent 7 | 1.0-SNAPSHOT 8 | ../parent 9 | 10 | org.cdisource.web 11 | cdisource-web 12 | CDISource Web components 13 | 1.0-SNAPSHOT 14 | 15 | 16 | org.cdisource.beancontainer 17 | beancontainer-api 18 | 1.0-SNAPSHOT 19 | jar 20 | provided 21 | 22 | 23 | javax.el 24 | el-api 25 | 2.2 26 | jar 27 | provided 28 | 29 | 30 | junit 31 | junit 32 | 4.8.2 33 | jar 34 | test 35 | 36 | 37 | org.cdisource.beancontainer 38 | beancontainer-test 39 | 1.0-SNAPSHOT 40 | jar 41 | test 42 | 43 | 44 | de.odysseus.juel 45 | juel-impl 46 | 2.2.2 47 | test 48 | 49 | 50 | de.odysseus.juel 51 | juel-spi 52 | 2.2.2 53 | test 54 | 55 | 56 | org.cdisource.beancontainer 57 | beancontainer-resin-impl 58 | test 59 | 1.0-SNAPSHOT 60 | 61 | 62 | 63 | org.apache.geronimo.specs 64 | geronimo-servlet_3.0_spec 65 | 1.0 66 | provided 67 | 68 | 69 | 70 | 71 | 72 | 73 | org.apache.maven.plugins 74 | maven-surefire-plugin 75 | 2.8 76 | 77 | true 78 | false 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /web/src/main/java/org/cdisource/web/CDIExpressionResolver.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.web; 2 | 3 | import java.beans.FeatureDescriptor; 4 | import java.util.Iterator; 5 | 6 | import javax.el.ELContext; 7 | import javax.el.ELResolver; 8 | import javax.enterprise.context.spi.CreationalContext; 9 | import javax.enterprise.inject.spi.Bean; 10 | import javax.enterprise.inject.spi.BeanManager; 11 | import javax.inject.Named; 12 | 13 | import org.cdisource.beancontainer.BeanContainer; 14 | import org.cdisource.beancontainer.BeanContainerManager; 15 | import org.cdisource.beancontainer.namespace.BeanNamespace; 16 | import org.cdisource.beancontainer.BeanManagerLocator; 17 | 18 | import org.cdisource.logging.Logger; 19 | 20 | import static org.cdisource.logging.LogFactoryManager.logger; 21 | 22 | /** 23 | * Unified EL Resolver that extends the {@link ELResolver} class to provide bean 24 | * lookups using EL expressions based on the CDI {@link Named} annotation. 25 | *

26 | * This class requires an instance of a {@link BeanContainer} implementation on 27 | * the class path to provide CDI services. 28 | * 29 | * 30 | * @author Andy Gibson 31 | * @author Rick Hightower 32 | * 33 | */ 34 | public class CDIExpressionResolver extends ELResolver { 35 | 36 | private Logger logger = logger(CDIExpressionResolver.class); 37 | 38 | @Override 39 | public Object getValue(ELContext context, Object base, Object property) { 40 | logger.trace("getValue(%s, %s, %s)", context, base, property); 41 | 42 | if (context == null) { 43 | throw new NullPointerException("EL Context is null"); 44 | } 45 | 46 | if (property == null) { 47 | return null; 48 | } 49 | 50 | Object result = null; 51 | BeanContainer container = BeanContainerManager.getInstance(); 52 | String stringProperty = property.toString(); 53 | 54 | if (base instanceof BeanNamespace) { 55 | logger.debug("getValue():: base was a namespace"); 56 | BeanNamespace namespace = (BeanNamespace) base; 57 | result = namespace.findObject(stringProperty); 58 | // check to see if our new object is the end of the line. 59 | logger.debug("getValue():: base was a namespace:: result was null? %s", result == null ? "yes" : "no"); 60 | } else if (base == null) { 61 | logger.debug("getValue():: base was null"); 62 | // locate the property in the root namespace 63 | result = container.getBeanNamespace().findObject(stringProperty); 64 | logger.debug("getValue():: base was null:: result was null? %s", result == null ? "yes" : "no"); 65 | } 66 | 67 | // if we found a bean, extract it 68 | if (result instanceof Bean) { 69 | logger.debug("getValue():: result was a bean"); 70 | Bean bean = (Bean) result; 71 | BeanManager bm = ((BeanManagerLocator)container).getBeanManager(); 72 | CreationalContext creationalContext = bm 73 | .createCreationalContext(bean); 74 | result = bm.getReference(bean, bean.getBeanClass(), 75 | creationalContext); 76 | logger.debug("getValue():: result was a bean:: result was null? %s", result == null ? "yes" : "no"); 77 | } 78 | 79 | context.setPropertyResolved(result != null); 80 | return result; 81 | } 82 | 83 | @Override 84 | public Class getType(ELContext context, Object base, Object property) { 85 | return null; 86 | } 87 | 88 | @Override 89 | public void setValue(ELContext context, Object base, Object property, 90 | Object value) { 91 | 92 | } 93 | 94 | @Override 95 | public boolean isReadOnly(ELContext context, Object base, Object property) { 96 | return false; 97 | } 98 | 99 | @Override 100 | public Iterator getFeatureDescriptors(ELContext context, 101 | Object base) { 102 | return null; 103 | } 104 | 105 | @Override 106 | public Class getCommonPropertyType(ELContext context, Object base) { 107 | return null; 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /web/src/main/java/org/cdisource/web/CDIServletContextListener.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.web; 2 | 3 | import javax.servlet.ServletContextEvent; 4 | import javax.servlet.ServletContextListener; 5 | import javax.servlet.annotation.WebListener; 6 | 7 | import org.cdisource.beancontainer.BeanContainer; 8 | import org.cdisource.beancontainer.BeanContainerManager; 9 | 10 | @WebListener 11 | public class CDIServletContextListener implements ServletContextListener { 12 | 13 | @Override 14 | public void contextInitialized(ServletContextEvent sce) { 15 | sce.getServletContext().setAttribute(BeanContainer.class.getName(), BeanContainerManager.getInstance()); 16 | } 17 | 18 | @Override 19 | public void contextDestroyed(ServletContextEvent sce) { 20 | sce.getServletContext().setAttribute(BeanContainer.class.getName(), null); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /web/src/test/java/org/cdisource/web/CDIExpressionResolverTest.java: -------------------------------------------------------------------------------- 1 | package org.cdisource.web; 2 | import javax.el.CompositeELResolver; 3 | import javax.el.ELContext; 4 | import javax.el.ExpressionFactory; 5 | import javax.el.ValueExpression; 6 | 7 | import org.cdisource.testing.InjectedBean; 8 | import org.cdisource.testing.NamedBean; 9 | import org.cdisource.testing.SimpleBean; 10 | import org.junit.Test; 11 | import org.junit.Before; 12 | import static junit.framework.Assert.assertNotNull; 13 | import de.odysseus.el.util.SimpleContext; 14 | import de.odysseus.el.util.SimpleResolver; 15 | 16 | 17 | /** 18 | * 19 | * @author Rick Hightower 20 | * 21 | */ 22 | public class CDIExpressionResolverTest { 23 | 24 | ExpressionFactory expressionFactory; 25 | ELContext context; 26 | 27 | @Before 28 | public void setUp() { 29 | expressionFactory = ExpressionFactory.newInstance(); 30 | context = context(); 31 | 32 | } 33 | 34 | @Test 35 | public void testGetObjectByNameUsingEL() { 36 | 37 | ValueExpression e = expressionFactory.createValueExpression(context, "${simpleBean}", SimpleBean.class); 38 | SimpleBean namedBean = (SimpleBean) e.getValue(context); 39 | assertNotNull(namedBean); 40 | } 41 | 42 | @Test 43 | //Broken 44 | public void testGetPropertyOfObjectByUsingEL() { 45 | ExpressionFactory expressionFactory = ExpressionFactory.newInstance(); 46 | assertNotNull(expressionFactory); 47 | ELContext context = context(); 48 | 49 | ValueExpression e = expressionFactory.createValueExpression(context, "${simpleBean.injectedBean}", InjectedBean.class); 50 | InjectedBean bean = (InjectedBean) e.getValue(context); 51 | assertNotNull(bean); 52 | } 53 | 54 | @Test 55 | //Broken 56 | public void testGetObjectByComplexNameUsingEL() { 57 | 58 | ValueExpression e = expressionFactory.createValueExpression(context, "${org.long.Name}", NamedBean.class); 59 | NamedBean namedBean = (NamedBean) e.getValue(context); 60 | assertNotNull(namedBean); 61 | } 62 | 63 | 64 | private ELContext context() { 65 | SimpleContext context = new SimpleContext(); 66 | CompositeELResolver resolver = new CompositeELResolver(); 67 | resolver.add(new CDIExpressionResolver()); 68 | resolver.add(new SimpleResolver()); 69 | context.setELResolver(resolver); 70 | return context; 71 | } 72 | } 73 | --------------------------------------------------------------------------------