svn commit: r1294413 - /struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/inject/ContainerImpl.java
Author: rgielen Date: Tue Feb 28 00:28:57 2012 New Revision: 1294413 URL: http://svn.apache.org/viewvc?rev=1294413&view=rev Log: Simple code reformatting, no actual change. Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/inject/ContainerImpl.java Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/inject/ContainerImpl.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/inject/ContainerImpl.java?rev=1294413&r1=1294412&r2=1294413&view=diff == --- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/inject/ContainerImpl.java (original) +++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/inject/ContainerImpl.java Tue Feb 28 00:28:57 2012 @@ -28,594 +28,602 @@ import java.security.AccessControlExcept /** * Default {@link Container} implementation. * - * @see ContainerBuilder * @author crazy...@google.com (Bob Lee) + * @see ContainerBuilder */ class ContainerImpl implements Container { - final Map, InternalFactory> factories; - final Map,Set> factoryNamesByType; + final Map, InternalFactory> factories; + final Map, Set> factoryNamesByType; - ContainerImpl(Map, InternalFactory> factories) { -this.factories = factories; -Map,Set> map = new HashMap,Set>(); -for (Key key : factories.keySet()) { - Set names = map.get(key.getType()); - if (names == null) { -names = new HashSet(); -map.put(key.getType(), names); - } - names.add(key.getName()); -} - -for (Entry,Set> entry : map.entrySet()) { - entry.setValue(Collections.unmodifiableSet(entry.getValue())); -} - -this.factoryNamesByType = Collections.unmodifiableMap(map); - } - - @SuppressWarnings("unchecked") - InternalFactory getFactory(Key key) { -return (InternalFactory) factories.get(key); - } - - /** - * Field and method injectors. - */ - final Map, List> injectors = - new ReferenceCache, List>() { -@Override -protected List create(Class key) { - List injectors = new ArrayList(); - addInjectors(key, injectors); - return injectors; -} - }; - - /** - * Recursively adds injectors for fields and methods from the given class to - * the given list. Injects parent classes before sub classes. - */ - void addInjectors(Class clazz, List injectors) { -if (clazz == Object.class) { - return; -} - -// Add injectors for superclass first. -addInjectors(clazz.getSuperclass(), injectors); - -// TODO (crazybob): Filter out overridden members. -addInjectorsForFields(clazz.getDeclaredFields(), false, injectors); -addInjectorsForMethods(clazz.getDeclaredMethods(), false, injectors); - } - - void injectStatics(List> staticInjections) { -final List injectors = new ArrayList(); - -for (Class clazz : staticInjections) { - addInjectorsForFields(clazz.getDeclaredFields(), true, injectors); - addInjectorsForMethods(clazz.getDeclaredMethods(), true, injectors); -} - -callInContext(new ContextualCallable() { - public Void call(InternalContext context) { -for (Injector injector : injectors) { - injector.inject(context, null); -} -return null; - } -}); - } - - void addInjectorsForMethods(Method[] methods, boolean statics, - List injectors) { -addInjectorsForMembers(Arrays.asList(methods), statics, injectors, -new InjectorFactory() { - public Injector create(ContainerImpl container, Method method, - String name) throws MissingDependencyException { -return new MethodInjector(container, method, name); - } -}); - } - - void addInjectorsForFields(Field[] fields, boolean statics, - List injectors) { -addInjectorsForMembers(Arrays.asList(fields), statics, injectors, -new InjectorFactory() { - public Injector create(ContainerImpl container, Field field, - String name) throws MissingDependencyException { -return new FieldInjector(container, field, name); - } -}); - } - - void addInjectorsForMembers( - List members, boolean statics, List injectors, - InjectorFactory injectorFactory) { -for (M member : members) { - if (isStatic(member) == statics) { -Inject inject = member.getAnnotation(Inject.class); -if (inject != null) { - try { -injectors.add(injectorFactory.create(this, member, inject.value())); - } catch (MissingDependencyException e) { -if (inject.required()) { - throw new DependencyException(e); -} - } -} - } -} - } - - interface InjectorFactory { -Injector create(ContainerImpl container, M memb
svn commit: r1294420 - /struts/struts2/trunk/plugins/cdi/src/main/java/org/apache/struts2/cdi/CdiObjectFactory.java
Author: rgielen Date: Tue Feb 28 00:35:04 2012 New Revision: 1294420 URL: http://svn.apache.org/viewvc?rev=1294420&view=rev Log: WW-3767: - added support for servlet container JNDI lookup key java:comp/env/BeanManager - added support for custom configuration constant to override standard lookup Modified: struts/struts2/trunk/plugins/cdi/src/main/java/org/apache/struts2/cdi/CdiObjectFactory.java Modified: struts/struts2/trunk/plugins/cdi/src/main/java/org/apache/struts2/cdi/CdiObjectFactory.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/cdi/src/main/java/org/apache/struts2/cdi/CdiObjectFactory.java?rev=1294420&r1=1294419&r2=1294420&view=diff == --- struts/struts2/trunk/plugins/cdi/src/main/java/org/apache/struts2/cdi/CdiObjectFactory.java (original) +++ struts/struts2/trunk/plugins/cdi/src/main/java/org/apache/struts2/cdi/CdiObjectFactory.java Tue Feb 28 00:35:04 2012 @@ -20,6 +20,7 @@ package org.apache.struts2.cdi; import com.opensymphony.xwork2.ObjectFactory; +import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.util.logging.Logger; import com.opensymphony.xwork2.util.logging.LoggerFactory; @@ -35,6 +36,13 @@ import java.util.concurrent.ConcurrentHa /** * CdiObjectFactory allows Struts 2 managed objects, like Actions, Interceptors or Results, to be injected by a Contexts * and Dependency Injection container (JSR299 / WebBeans). + * The BeanManager instance will be searched in the container's JNDI context, according to following algorithm: + * + * if a value for configuration constant struts.objectFactory.cdi.jndiKey is given, this key will be looked up + * if no BeanManager found so far, look under {@link #CDI_JNDIKEY_BEANMANAGER_COMP} + * if no BeanManager found so far, look under {@link #CDI_JNDIKEY_BEANMANAGER_APP} + * if no BeanManager found so far, look under {@link #CDI_JNDIKEY_BEANMANAGER_COMP_ENV} + * */ public class CdiObjectFactory extends ObjectFactory { @@ -48,8 +56,20 @@ public class CdiObjectFactory extends Ob * The key under which the BeanManager can be found according to JBoss Weld docs */ public static final String CDI_JNDIKEY_BEANMANAGER_APP = "java:app/BeanManager"; + /** +* The key under which the BeanManager can be found in pure Servlet containers according to JBoss Weld docs. +*/ + public static final String CDI_JNDIKEY_BEANMANAGER_COMP_ENV = "java:comp/env/BeanManager"; -protected BeanManager beanManager; + + private String jndiKey; + + @Inject(value = "struts.objectFactory.cdi.jndiKey", required = false) + public void setJndiKey( String jndiKey ) { + this.jndiKey = jndiKey; + } + + protected BeanManager beanManager; protected CreationalContext ctx; Map, InjectionTarget> injectionTargetCache = new ConcurrentHashMap, InjectionTarget>(); @@ -66,33 +86,72 @@ public class CdiObjectFactory extends Ob } } -/** - * Try to find the CDI BeanManager from JNDI context. First the key {@link #CDI_JNDIKEY_BEANMANAGER_COMP} will be - * tested. If nothing is found there, the key {@link #CDI_JNDIKEY_BEANMANAGER_APP} will be checked. - * - * @return the BeanManager, if found. null otherwise. - */ -protected BeanManager findBeanManager() { -BeanManager bm; -try { -Context initialContext = new InitialContext(); -LOG.info("[findBeanManager]: Checking for BeanManager under JNDI key " + CDI_JNDIKEY_BEANMANAGER_COMP); -try { -bm = (BeanManager) initialContext.lookup(CdiObjectFactory.CDI_JNDIKEY_BEANMANAGER_COMP); -} catch (NamingException e) { -LOG.warn("[findBeanManager]: Lookup failed.", e); -LOG.info("[findBeanManager]: Checking for BeanManager under JNDI key " + CDI_JNDIKEY_BEANMANAGER_APP); -bm = (BeanManager) initialContext.lookup(CdiObjectFactory.CDI_JNDIKEY_BEANMANAGER_APP); -} -LOG.info("[findBeanManager]: BeanManager found."); -return bm; -} catch (NamingException e) { -LOG.error("Could not get BeanManager from JNDI context", e); -} -return null; -} + /** +* Try to find the CDI BeanManager from JNDI context. First, if provided, the key given by +* struts.objectFactory.cdi.jndiKey will be checked. Then, if nothing was found or no explicit configuration was +* given, the key {@link #CDI_JNDIKEY_BEANMANAGER_COMP} will be tested. If nothing is found there, the key {@link +* #CDI_JNDIKEY_BEANMANAGER_APP} will be checked. If still nothing is found there, the key {@link +* #CDI_JNDIKEY_BEANMANAGER_COMP_ENV} will be checked. +* +* @return the BeanManager, if found. null otherwise. +*/ + prot
[CONF] Confluence Changes in the last 24 hours
This is a daily summary of all recent changes in Confluence. - Updated Spaces: - Apache ACE (https://cwiki.apache.org/confluence/display/ACE) Pages - Board Report (2012-02) created by nanthrax (08:36 AM) https://cwiki.apache.org/confluence/display/ACE/Board+Report+%282012-02%29 Apache Bigtop (incubating) (https://cwiki.apache.org/confluence/display/BIGTOP) Pages - Writing integration and system tests created by s...@cloudera.com (03:22 AM) https://cwiki.apache.org/confluence/display/BIGTOP/Writing+integration+and+system+tests Index edited by s...@cloudera.com (03:37 AM) https://cwiki.apache.org/confluence/display/BIGTOP/Index Apache Camel (https://cwiki.apache.org/confluence/display/CAMEL) Pages - AWS edited by bibryam (08:54 PM) https://cwiki.apache.org/confluence/display/CAMEL/AWS Component List edited by bibryam (08:54 PM) https://cwiki.apache.org/confluence/display/CAMEL/Component+List AWS-DDB created by bibryam (08:39 PM) https://cwiki.apache.org/confluence/display/CAMEL/AWS-DDB AWS-SDB edited by bibryam (06:50 PM) https://cwiki.apache.org/confluence/display/CAMEL/AWS-SDB Camel 2.10.0 Release edited by bibryam (06:34 PM) https://cwiki.apache.org/confluence/display/CAMEL/Camel+2.10.0+Release Articles edited by rkettelerij (02:09 PM) https://cwiki.apache.org/confluence/display/CAMEL/Articles Camel Maven Archetypes edited by boday (12:55 PM) https://cwiki.apache.org/confluence/display/CAMEL/Camel+Maven+Archetypes Apache CXF Documentation (https://cwiki.apache.org/confluence/display/CXF20DOC) Pages - JAX-RS Filters edited by mazzag (11:20 AM) https://cwiki.apache.org/confluence/display/CXF20DOC/JAX-RS+Filters Apache Deft (https://cwiki.apache.org/confluence/display/DEFT) Pages - Architecture edited by slemesle (04:31 PM) https://cwiki.apache.org/confluence/display/DEFT/Architecture Apache DeltaSpike (https://cwiki.apache.org/confluence/display/DeltaSpike) Pages - Temporary Documentation edited by rdebusscher (03:04 PM) https://cwiki.apache.org/confluence/display/DeltaSpike/Temporary+Documentation OFBiz (Open For Business) Project Open Wiki (https://cwiki.apache.org/confluence/display/OFBIZ) Pages - Sub Second TimeStamp Not Supported for Storage edited by mbrohl (08:17 AM) https://cwiki.apache.org/confluence/display/OFBIZ/Sub+Second+TimeStamp+Not+Supported+for+Storage Jackrabbit Branch Development edited by sascha (05:15 AM) https://cwiki.apache.org/confluence/display/OFBIZ/Jackrabbit+Branch+Development Requirements and Ideas created by sascha (05:12 AM) https://cwiki.apache.org/confluence/display/OFBIZ/Requirements+and+Ideas Initial integration of the Jackrabbit repository - features and architecture description created by sascha (05:01 AM) https://cwiki.apache.org/confluence/display/OFBIZ/Initial+integration+of+the+Jackrabbit+repository+-+features+and+architecture+description FAQ - Tips - Tricks - Cookbook - HowTo edited by jacques.le.roux (02:57 AM) https://cwiki.apache.org/confluence/display/OFBIZ/FAQ+-+Tips+-+Tricks+-+Cookbook+-+HowTo Apache OpenOffice Community (https://cwiki.apache.org/confluence/display/OOOUSERS) Pages - OpenOffice.org Migration Status edited by kschenk (05:23 PM) https://cwiki.apache.org/confluence/display/OOOUSERS/OpenOffice.org+Migration+Status AOO 3.4 Unofficial Developer Snapshots edited by jsc (12:37 PM) https://cwiki.apache.org/confluence/display/OOOUSERS/AOO+3.4+Unofficial+Developer+Snapshots Apache Openmeetings (https://cwiki.apache.org/confluence/display/OPENMEETINGS) Pages - NewAudioVideoComponents edited by timur.tleuke...@gmail.com (11:47 PM) https://cwiki.apache.org/confluence/display/OPENMEETINGS/NewAudioVideoComponents Apache Pig (https://cwiki.apache.org/confluence/display/PIG) Pages - GSoc2012 created by daijy (01:58 PM) https://cwiki.apache.org/confluence/display/PIG/GSoc2012 UIMA (https://cwiki.apache.org/confluence/display/UIMA) Pages - Configuring UIMA Pipelines Externally for a particular run edited by schor (04:06 PM) https://cwiki.apache.org/confluence/display/UIMA/Configuring+UIMA+Pipelines+Extern