Weld SVN: r6155 - extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-04-25 15:11:51 -0400 (Sun, 25 Apr 2010)
New Revision: 6155
Removed:
extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/WeldBeanManagerProvider.java
Log:
Fix compile problems by removing WeldManagerProvider for now (more discussion needed about where to put it)
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/WeldBeanManagerProvider.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/WeldBeanManagerProvider.java 2010-04-24 21:52:50 UTC (rev 6154)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/WeldBeanManagerProvider.java 2010-04-25 19:11:51 UTC (rev 6155)
@@ -1,46 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.weld.extensions.beanManager;
-
-import javax.enterprise.inject.spi.BeanManager;
-
-import org.jboss.weld.Container;
-
-/**
- * A Weld-specific BeanManager provider
- *
- * @author Nicklas Karlsson
- *
- */
-public class WeldBeanManagerProvider implements BeanManagerProvider
-{
-
- public BeanManager getBeanManager()
- {
- return Container.instance().deploymentManager();
- }
-
- public int getPrecedence()
- {
- return 30;
- }
-}
14 years, 8 months
Weld SVN: r6154 - in extensions/trunk/src/main: resources/META-INF/services and 1 other directory.
by weld-commits@lists.jboss.org
Author: nickarls
Date: 2010-04-24 17:52:50 -0400 (Sat, 24 Apr 2010)
New Revision: 6154
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/WeldBeanManagerProvider.java
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerAware.java
extensions/trunk/src/main/resources/META-INF/services/org.jboss.weld.extensions.beanManager.BeanManagerProvider
Log:
BeanManagerAware for faces module
Fixed precedence
Lazy loading of providers
Weld-specific provider (Pete, can we have this in weld-extensions?)
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerAware.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerAware.java 2010-04-24 00:06:56 UTC (rev 6153)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerAware.java 2010-04-24 21:52:50 UTC (rev 6154)
@@ -51,26 +51,21 @@
private final List<BeanManagerProvider> beanManagerProviders = new ArrayList<BeanManagerProvider>();
- public BeanManagerAware()
- {
- loadServices();
- Collections.sort(beanManagerProviders, new ProviderWeightSorter());
- }
-
private void loadServices()
{
+ beanManagerProviders.clear();
Iterator<BeanManagerProvider> providers = DefaultServiceLoader.load(BeanManagerProvider.class).iterator();
while (providers.hasNext())
{
beanManagerProviders.add(providers.next());
}
}
-
+
private class ProviderWeightSorter implements Comparator<BeanManagerProvider>
{
public int compare(BeanManagerProvider provider1, BeanManagerProvider provider2)
{
- return Integer.valueOf(provider1.getPrecedence()).compareTo(Integer.valueOf(provider2.getPrecedence()));
+ return -1 * Integer.valueOf(provider1.getPrecedence()).compareTo(Integer.valueOf(provider2.getPrecedence()));
}
}
@@ -78,19 +73,42 @@
{
if (beanManager == null)
{
+ if (beanManagerProviders.isEmpty())
+ {
+ loadServices();
+ Collections.sort(beanManagerProviders, new ProviderWeightSorter());
+ }
beanManager = lookupBeanManager();
}
if (beanManager == null)
{
- throw new IllegalStateException("Could not locate a BeanManager from the providers " + beanManagerProviders);
+ throw new IllegalStateException("Could not locate a BeanManager from the providers " + providersToString());
}
return beanManager;
}
+ private String providersToString()
+ {
+ StringBuffer out = new StringBuffer();
+ int i = 0;
+ for (BeanManagerProvider provider : beanManagerProviders)
+ {
+ if (i > 0)
+ {
+ out.append(", ");
+ }
+ out.append(provider.getClass().getName());
+ out.append("(");
+ out.append(provider.getPrecedence());
+ out.append(")");
+ i++;
+ }
+ return out.toString();
+ }
+
private BeanManager lookupBeanManager()
{
BeanManager beanManager = null;
-
for (BeanManagerProvider provider : beanManagerProviders)
{
beanManager = provider.getBeanManager();
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/WeldBeanManagerProvider.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/WeldBeanManagerProvider.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/WeldBeanManagerProvider.java 2010-04-24 21:52:50 UTC (rev 6154)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.weld.extensions.beanManager;
+
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.jboss.weld.Container;
+
+/**
+ * A Weld-specific BeanManager provider
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+public class WeldBeanManagerProvider implements BeanManagerProvider
+{
+
+ public BeanManager getBeanManager()
+ {
+ return Container.instance().deploymentManager();
+ }
+
+ public int getPrecedence()
+ {
+ return 30;
+ }
+}
Modified: extensions/trunk/src/main/resources/META-INF/services/org.jboss.weld.extensions.beanManager.BeanManagerProvider
===================================================================
--- extensions/trunk/src/main/resources/META-INF/services/org.jboss.weld.extensions.beanManager.BeanManagerProvider 2010-04-24 00:06:56 UTC (rev 6153)
+++ extensions/trunk/src/main/resources/META-INF/services/org.jboss.weld.extensions.beanManager.BeanManagerProvider 2010-04-24 21:52:50 UTC (rev 6154)
@@ -1,2 +1,3 @@
org.jboss.weld.extensions.beanManager.DefaultJndiBeanManagerProvider
org.jboss.weld.extensions.beanManager.JBossJndiBeanManagerProvider
+org.jboss.weld.extensions.beanManager.WeldBeanManagerProvider
14 years, 8 months
Weld SVN: r6153 - in extensions/trunk/src: main/java/org/jboss/weld/extensions/beanlookup and 3 other directories.
by weld-commits@lists.jboss.org
Author: swd847
Date: 2010-04-23 20:06:56 -0400 (Fri, 23 Apr 2010)
New Revision: 6153
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/beanlookup/
extensions/trunk/src/test/java/org/jboss/weld/test/extensions/beanlookup/
Removed:
extensions/trunk/src/main/java/org/jboss/weld/extensions/beanid/
extensions/trunk/src/test/java/org/jboss/weld/test/extensions/beanid/
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/beanlookup/AnnotatedTypeIdentifier.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/beanlookup/IdentifiableBeanExtension.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/beanlookup/IdentifiableInjectionTarget.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/beanlookup/RequiresIdentification.java
extensions/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
extensions/trunk/src/test/java/org/jboss/weld/test/extensions/beanlookup/IdentifiableBean.java
extensions/trunk/src/test/java/org/jboss/weld/test/extensions/beanlookup/IdentifiableBeansTest.java
extensions/trunk/src/test/java/org/jboss/weld/test/extensions/beanlookup/IdentifiableInterceptorBinding.java
Log:
change package name
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/beanlookup (from rev 6152, extensions/trunk/src/main/java/org/jboss/weld/extensions/beanid)
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/beanlookup/AnnotatedTypeIdentifier.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/beanid/AnnotatedTypeIdentifier.java 2010-04-23 21:44:59 UTC (rev 6152)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/beanlookup/AnnotatedTypeIdentifier.java 2010-04-24 00:06:56 UTC (rev 6153)
@@ -1,4 +1,4 @@
-package org.jboss.weld.extensions.beanid;
+package org.jboss.weld.extensions.beanlookup;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.inject.Inject;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/beanlookup/IdentifiableBeanExtension.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/beanid/IdentifiableBeanExtension.java 2010-04-23 21:44:59 UTC (rev 6152)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/beanlookup/IdentifiableBeanExtension.java 2010-04-24 00:06:56 UTC (rev 6153)
@@ -1,4 +1,4 @@
-package org.jboss.weld.extensions.beanid;
+package org.jboss.weld.extensions.beanlookup;
import java.lang.annotation.Annotation;
import java.util.Collections;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/beanlookup/IdentifiableInjectionTarget.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/beanid/IdentifiableInjectionTarget.java 2010-04-23 21:44:59 UTC (rev 6152)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/beanlookup/IdentifiableInjectionTarget.java 2010-04-24 00:06:56 UTC (rev 6153)
@@ -1,4 +1,4 @@
-package org.jboss.weld.extensions.beanid;
+package org.jboss.weld.extensions.beanlookup;
import java.util.Map;
import java.util.Set;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/beanlookup/RequiresIdentification.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/beanid/RequiresIdentification.java 2010-04-23 21:44:59 UTC (rev 6152)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/beanlookup/RequiresIdentification.java 2010-04-24 00:06:56 UTC (rev 6153)
@@ -1,4 +1,4 @@
-package org.jboss.weld.extensions.beanid;
+package org.jboss.weld.extensions.beanlookup;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Modified: extensions/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
===================================================================
--- extensions/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 2010-04-23 21:44:59 UTC (rev 6152)
+++ extensions/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 2010-04-24 00:06:56 UTC (rev 6153)
@@ -1,5 +1,5 @@
org.jboss.weld.extensions.genericbeans.GenericExtension
org.jboss.weld.extensions.resources.servlet.ServletResourceExtension
-org.jboss.weld.extensions.beanid.IdentifiableBeanExtension
+org.jboss.weld.extensions.beanlookup.IdentifiableBeanExtension
org.jboss.weld.extensions.CoreExtension
org.jboss.weld.extensions.managedproducer.ManagedProducerExtension
\ No newline at end of file
Copied: extensions/trunk/src/test/java/org/jboss/weld/test/extensions/beanlookup (from rev 6152, extensions/trunk/src/test/java/org/jboss/weld/test/extensions/beanid)
Modified: extensions/trunk/src/test/java/org/jboss/weld/test/extensions/beanlookup/IdentifiableBean.java
===================================================================
--- extensions/trunk/src/test/java/org/jboss/weld/test/extensions/beanid/IdentifiableBean.java 2010-04-23 21:44:59 UTC (rev 6152)
+++ extensions/trunk/src/test/java/org/jboss/weld/test/extensions/beanlookup/IdentifiableBean.java 2010-04-24 00:06:56 UTC (rev 6153)
@@ -1,4 +1,4 @@
-package org.jboss.weld.test.extensions.beanid;
+package org.jboss.weld.test.extensions.beanlookup;
@IdentifiableInterceptorBinding
public class IdentifiableBean
{
Modified: extensions/trunk/src/test/java/org/jboss/weld/test/extensions/beanlookup/IdentifiableBeansTest.java
===================================================================
--- extensions/trunk/src/test/java/org/jboss/weld/test/extensions/beanid/IdentifiableBeansTest.java 2010-04-23 21:44:59 UTC (rev 6152)
+++ extensions/trunk/src/test/java/org/jboss/weld/test/extensions/beanlookup/IdentifiableBeansTest.java 2010-04-24 00:06:56 UTC (rev 6153)
@@ -1,4 +1,4 @@
-package org.jboss.weld.test.extensions.beanid;
+package org.jboss.weld.test.extensions.beanlookup;
import javax.enterprise.inject.Default;
import javax.enterprise.inject.spi.AnnotatedType;
@@ -6,11 +6,11 @@
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.Classes;
-import org.jboss.weld.extensions.beanid.AnnotatedTypeIdentifier;
+import org.jboss.weld.extensions.beanlookup.AnnotatedTypeIdentifier;
import org.jboss.weld.test.AbstractWeldTest;
import org.testng.annotations.Test;
@Artifact
-@Classes(packages = { "org.jboss.weld.extensions.beanid" })
+@Classes(packages = { "org.jboss.weld.extensions.beanlookup" })
public class IdentifiableBeansTest extends AbstractWeldTest
{
@Test
Modified: extensions/trunk/src/test/java/org/jboss/weld/test/extensions/beanlookup/IdentifiableInterceptorBinding.java
===================================================================
--- extensions/trunk/src/test/java/org/jboss/weld/test/extensions/beanid/IdentifiableInterceptorBinding.java 2010-04-23 21:44:59 UTC (rev 6152)
+++ extensions/trunk/src/test/java/org/jboss/weld/test/extensions/beanlookup/IdentifiableInterceptorBinding.java 2010-04-24 00:06:56 UTC (rev 6153)
@@ -1,4 +1,4 @@
-package org.jboss.weld.test.extensions.beanid;
+package org.jboss.weld.test.extensions.beanlookup;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -7,7 +7,7 @@
import javax.interceptor.InterceptorBinding;
-import org.jboss.weld.extensions.beanid.RequiresIdentification;
+import org.jboss.weld.extensions.beanlookup.RequiresIdentification;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,ElementType.TYPE})
14 years, 8 months
Weld SVN: r6152 - extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager.
by weld-commits@lists.jboss.org
Author: nickarls
Date: 2010-04-23 17:44:59 -0400 (Fri, 23 Apr 2010)
New Revision: 6152
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerAware.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerProvider.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/DefaultJndiBeanManagerProvider.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/JBossJndiBeanManagerProvider.java
Log:
Drop static provider list from BeanManagerAware due to possible classloader issues
Change precedences to favor ServletContext
Document behaviour of equal precedence
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerAware.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerAware.java 2010-04-22 19:14:18 UTC (rev 6151)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerAware.java 2010-04-23 21:44:59 UTC (rev 6152)
@@ -49,28 +49,28 @@
{
private BeanManager beanManager;
- private static final List<BeanManagerProvider> beanManagerProviders = new ArrayList<BeanManagerProvider>();
+ private final List<BeanManagerProvider> beanManagerProviders = new ArrayList<BeanManagerProvider>();
- static
+ public BeanManagerAware()
{
loadServices();
- Collections.sort(beanManagerProviders, new ProviderWeightSorter());
+ Collections.sort(beanManagerProviders, new ProviderWeightSorter());
}
-
- private static class ProviderWeightSorter implements Comparator<BeanManagerProvider>
+
+ private void loadServices()
{
- public int compare(BeanManagerProvider provider1, BeanManagerProvider provider2)
+ Iterator<BeanManagerProvider> providers = DefaultServiceLoader.load(BeanManagerProvider.class).iterator();
+ while (providers.hasNext())
{
- return Integer.valueOf(provider1.getPrecedence()).compareTo(Integer.valueOf(provider2.getPrecedence()));
+ beanManagerProviders.add(providers.next());
}
}
-
- private static void loadServices()
+
+ private class ProviderWeightSorter implements Comparator<BeanManagerProvider>
{
- Iterator<BeanManagerProvider> providers = DefaultServiceLoader.load(BeanManagerProvider.class).iterator();
- while (providers.hasNext())
+ public int compare(BeanManagerProvider provider1, BeanManagerProvider provider2)
{
- beanManagerProviders.add(providers.next());
+ return Integer.valueOf(provider1.getPrecedence()).compareTo(Integer.valueOf(provider2.getPrecedence()));
}
}
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerProvider.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerProvider.java 2010-04-22 19:14:18 UTC (rev 6151)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerProvider.java 2010-04-23 21:44:59 UTC (rev 6152)
@@ -41,7 +41,7 @@
/**
* An integer precedence value that indicates how favorable the implementation
* considers itself amongst alternatives. A higher value is a higher
- * precedence.
+ * precedence. If two implementations have the save precedence, the order is undetermined.
*/
public abstract int getPrecedence();
}
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/DefaultJndiBeanManagerProvider.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/DefaultJndiBeanManagerProvider.java 2010-04-22 19:14:18 UTC (rev 6151)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/DefaultJndiBeanManagerProvider.java 2010-04-23 21:44:59 UTC (rev 6152)
@@ -40,7 +40,7 @@
public int getPrecedence()
{
- return 10;
+ return 11;
}
}
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/JBossJndiBeanManagerProvider.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/JBossJndiBeanManagerProvider.java 2010-04-22 19:14:18 UTC (rev 6151)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/JBossJndiBeanManagerProvider.java 2010-04-23 21:44:59 UTC (rev 6152)
@@ -39,7 +39,7 @@
public int getPrecedence()
{
- return 11;
+ return 10;
}
}
14 years, 8 months
Weld SVN: r6151 - in extensions/trunk/src/main: java/org/jboss/weld/extensions/beanManager and 3 other directories.
by weld-commits@lists.jboss.org
Author: nickarls
Date: 2010-04-22 15:14:18 -0400 (Thu, 22 Apr 2010)
New Revision: 6151
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/
extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/AbstractJndiBeanManagerProvider.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerAware.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerProvider.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/DefaultJndiBeanManagerProvider.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/JBossJndiBeanManagerProvider.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/service/
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/service/DefaultServiceLoader.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/service/DefaultServiceLoaderFactory.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/service/ServiceLoaderFactory.java
extensions/trunk/src/main/resources/META-INF/services/org.jboss.weld.extensions.beanManager.BeanManagerProvider
Log:
BeanManagerAware infrastructure
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/AbstractJndiBeanManagerProvider.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/AbstractJndiBeanManagerProvider.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/AbstractJndiBeanManagerProvider.java 2010-04-22 19:14:18 UTC (rev 6151)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.weld.extensions.beanManager;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+/**
+ * A BeanManager provider for JNDI contexts
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+public abstract class AbstractJndiBeanManagerProvider implements BeanManagerProvider
+{
+ public BeanManager getBeanManager()
+ {
+ try
+ {
+ return (BeanManager) new InitialContext().lookup(getLocation());
+ }
+ catch (NamingException e)
+ {
+ // No panic, it's just not there
+ }
+ return null;
+ }
+
+ protected abstract String getLocation();
+
+}
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerAware.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerAware.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerAware.java 2010-04-22 19:14:18 UTC (rev 6151)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.weld.extensions.beanManager;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.Extension;
+import javax.inject.Inject;
+
+import org.jboss.weld.extensions.util.service.DefaultServiceLoader;
+
+/**
+ * Super-class for non-CDI-native components that need a reference to the
+ * {@link BeanManager}
+ * <p>
+ * <b>**WARNING**</b> This class is <b>NEVER</b> safe to use outside of specific
+ * seam-faces implementation classes, and should be <b>avoided at all costs</b>.
+ * If you need a handle to the {@link BeanManager} you should probably register
+ * an {@link Extension} instead of using this class; have you tried using @
+ * {@link Inject}?
+ *
+ * @author Nicklas Karlsson
+ */
+public class BeanManagerAware
+{
+ private BeanManager beanManager;
+
+ private static final List<BeanManagerProvider> beanManagerProviders = new ArrayList<BeanManagerProvider>();
+
+ static
+ {
+ loadServices();
+ Collections.sort(beanManagerProviders, new ProviderWeightSorter());
+ }
+
+ private static class ProviderWeightSorter implements Comparator<BeanManagerProvider>
+ {
+ public int compare(BeanManagerProvider provider1, BeanManagerProvider provider2)
+ {
+ return Integer.valueOf(provider1.getPrecedence()).compareTo(Integer.valueOf(provider2.getPrecedence()));
+ }
+ }
+
+ private static void loadServices()
+ {
+ Iterator<BeanManagerProvider> providers = DefaultServiceLoader.load(BeanManagerProvider.class).iterator();
+ while (providers.hasNext())
+ {
+ beanManagerProviders.add(providers.next());
+ }
+ }
+
+ protected BeanManager getBeanManager()
+ {
+ if (beanManager == null)
+ {
+ beanManager = lookupBeanManager();
+ }
+ if (beanManager == null)
+ {
+ throw new IllegalStateException("Could not locate a BeanManager from the providers " + beanManagerProviders);
+ }
+ return beanManager;
+ }
+
+ private BeanManager lookupBeanManager()
+ {
+ BeanManager beanManager = null;
+
+ for (BeanManagerProvider provider : beanManagerProviders)
+ {
+ beanManager = provider.getBeanManager();
+ if (beanManager != null)
+ {
+ break;
+ }
+ }
+ return beanManager;
+ }
+}
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerProvider.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerProvider.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerProvider.java 2010-04-22 19:14:18 UTC (rev 6151)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.weld.extensions.beanManager;
+
+import javax.enterprise.inject.spi.BeanManager;
+
+/**
+ * Provider for obtaining a BeanManager
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+public interface BeanManagerProvider
+{
+ /**
+ * Try to obtain a BeanManager
+ *
+ * @return The BeanManager (or null if non found at this location)
+ */
+ public abstract BeanManager getBeanManager();
+
+ /**
+ * An integer precedence value that indicates how favorable the implementation
+ * considers itself amongst alternatives. A higher value is a higher
+ * precedence.
+ */
+ public abstract int getPrecedence();
+}
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/DefaultJndiBeanManagerProvider.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/DefaultJndiBeanManagerProvider.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/DefaultJndiBeanManagerProvider.java 2010-04-22 19:14:18 UTC (rev 6151)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.weld.extensions.beanManager;
+
+import javax.enterprise.inject.spi.Extension;
+
+/**
+ * A BeanManagerProvider that looks it up from the standard JNDI location
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+public class DefaultJndiBeanManagerProvider extends AbstractJndiBeanManagerProvider implements Extension
+{
+
+ @Override
+ protected String getLocation()
+ {
+ return "java:comp/BeanManager";
+ }
+
+ public int getPrecedence()
+ {
+ return 10;
+ }
+
+}
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/JBossJndiBeanManagerProvider.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/JBossJndiBeanManagerProvider.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/JBossJndiBeanManagerProvider.java 2010-04-22 19:14:18 UTC (rev 6151)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.weld.extensions.beanManager;
+
+import javax.enterprise.inject.spi.Extension;
+
+/**
+ * A temp workaround BeanManagerProvider for JBoss AS 6 <M2 that bound it to a non-standard location
+ *
+ * @author Nicklas Karlsson
+ */
+public class JBossJndiBeanManagerProvider extends AbstractJndiBeanManagerProvider implements Extension
+{
+
+ @Override
+ protected String getLocation()
+ {
+ return "java:app/BeanManager";
+ }
+
+ public int getPrecedence()
+ {
+ return 11;
+ }
+
+}
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/service/DefaultServiceLoader.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/service/DefaultServiceLoader.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/service/DefaultServiceLoader.java 2010-04-22 19:14:18 UTC (rev 6151)
@@ -0,0 +1,336 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.weld.extensions.util.service;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class handles looking up service providers on the class path. It
+ * implements the <a href="http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#Service%2..."
+ * >Service Provider section of the JAR File Specification</a>.
+ *
+ * The Service Provider programmatic lookup was not specified prior to Java 6 so
+ * this interface allows use of the specification prior to Java 6.
+ *
+ * The API is copied from <a
+ * href="http://java.sun.com/javase/6/docs/api/java/util/ServiceLoader.html"
+ * >java.util.ServiceLoader</a>
+ *
+ * @author Pete Muir
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ * @author Nicklas Karlsson
+ */
+public class DefaultServiceLoader<S> implements Iterable<S>
+{
+ private static final String SERVICES = "META-INF/services";
+
+ private static final Logger log = LoggerFactory.getLogger(DefaultServiceLoader.class);
+
+ /**
+ * Creates a new service loader for the given service type, using the current
+ * thread's context class loader.
+ *
+ * An invocation of this convenience method of the form
+ *
+ * {@code ServiceLoader.load(service)</code>}
+ *
+ * is equivalent to
+ *
+ * <code>ServiceLoader.load(service,
+ * Thread.currentThread().getContextClassLoader())</code>
+ *
+ * @param service The interface or abstract class representing the service
+ * @return A new service loader
+ */
+ public static <S> DefaultServiceLoader<S> load(Class<S> service)
+ {
+ return load(SERVICES, service, Thread.currentThread().getContextClassLoader());
+ }
+
+ public static <S> DefaultServiceLoader<S> load(String directoryName, Class<S> service)
+ {
+ return load(directoryName, service, Thread.currentThread().getContextClassLoader());
+ }
+
+ public static <S> DefaultServiceLoader<S> load(String directoryName, Class<S> service, ClassLoader loader)
+ {
+ if (loader == null)
+ {
+ loader = service.getClassLoader();
+ }
+ return new DefaultServiceLoader<S>(directoryName, service, loader);
+ }
+
+ /**
+ * Creates a new service loader for the given service type and class loader.
+ *
+ * @param service The interface or abstract class representing the service
+ * @param loader The class loader to be used to load provider-configuration
+ * files and provider classes, or null if the system class loader
+ * (or, failing that, the bootstrap class loader) is to be used
+ * @return A new service loader
+ */
+ public static <S> DefaultServiceLoader<S> load(Class<S> service, ClassLoader loader)
+ {
+ return load(SERVICES, service, loader);
+ }
+
+ /**
+ * Creates a new service loader for the given service type, using the
+ * extension class loader.
+ *
+ * This convenience method simply locates the extension class loader, call it
+ * extClassLoader, and then returns
+ *
+ * <code>ServiceLoader.load(service, extClassLoader)</code>
+ *
+ * If the extension class loader cannot be found then the system class loader
+ * is used; if there is no system class loader then the bootstrap class
+ * loader is used.
+ *
+ * This method is intended for use when only installed providers are desired.
+ * The resulting service will only find and load providers that have been
+ * installed into the current Java virtual machine; providers on the
+ * application's class path will be ignored.
+ *
+ * @param service The interface or abstract class representing the service
+ * @return A new service loader
+ */
+ public static <S> DefaultServiceLoader<S> loadInstalled(Class<S> service)
+ {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+
+ private final String serviceFile;
+ private Class<S> expectedType;
+ private final ClassLoader loader;
+
+ private Set<S> providers;
+
+ private DefaultServiceLoader(String prefix, Class<S> service, ClassLoader loader)
+ {
+ this.loader = loader;
+ this.serviceFile = prefix + "/" + service.getName();
+ this.expectedType = service;
+ }
+
+ /**
+ * Clear this loader's provider cache so that all providers will be reloaded.
+ *
+ * After invoking this method, subsequent invocations of the iterator method
+ * will lazily look up and instantiate providers from scratch, just as is
+ * done by a newly-created loader.
+ *
+ * This method is intended for use in situations in which new providers can
+ * be installed into a running Java virtual machine.
+ */
+ public void reload()
+ {
+ providers = new HashSet<S>();
+
+ for (URL serviceFile : loadServiceFiles())
+ {
+ loadServiceFile(serviceFile);
+ }
+ }
+
+ private List<URL> loadServiceFiles()
+ {
+ List<URL> serviceFiles = new ArrayList<URL>();
+ try
+ {
+ Enumeration<URL> serviceFileEnumerator = loader.getResources(serviceFile);
+ while (serviceFileEnumerator.hasMoreElements())
+ {
+ serviceFiles.add(serviceFileEnumerator.nextElement());
+ }
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Could not load resources from " + serviceFile, e);
+ }
+ return serviceFiles;
+ }
+
+ private void loadServiceFile(URL serviceFile)
+ {
+ InputStream is = null;
+ try
+ {
+ is = serviceFile.openStream();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+ String serviceClassName = null;
+ while ((serviceClassName = reader.readLine()) != null)
+ {
+ serviceClassName = trim(serviceClassName);
+ if (serviceClassName.length() > 0)
+ {
+ loadService(serviceClassName);
+ }
+ }
+ }
+ catch (IOException e)
+ {
+ // FIXME: correct exception
+ throw new RuntimeException("Could not read services file " + serviceFile);
+ }
+ finally
+ {
+ if (is != null)
+ {
+ try
+ {
+ is.close();
+ }
+ catch (IOException e)
+ {
+ // FIXME: correct exception
+ throw new RuntimeException("Could not close services file " + serviceFile, e);
+ }
+ }
+ }
+ }
+
+ private String trim(String line)
+ {
+ final int comment = line.indexOf('#');
+
+ if (comment > -1)
+ {
+ line = line.substring(0, comment);
+ }
+ return line.trim();
+ }
+
+ private void loadService(String serviceClassName)
+ {
+ Class<? extends S> serviceClass = loadClass(serviceClassName);
+ if (serviceClass == null)
+ {
+ return;
+ }
+ S serviceInstance = prepareInstance(serviceClass);
+ if (serviceInstance == null)
+ {
+ return;
+ }
+ providers.add(serviceInstance);
+ }
+
+ private Class<? extends S> loadClass(String serviceClassName)
+ {
+ Class<?> clazz = null;
+ Class<? extends S> serviceClass = null;
+ try
+ {
+ clazz = loader.loadClass(serviceClassName);
+ serviceClass = clazz.asSubclass(expectedType);
+ }
+ catch (ClassNotFoundException e)
+ {
+ log.warn("Could not load service class " + serviceClassName);
+ }
+ catch (ClassCastException e)
+ {
+ log.warn("Service class " + serviceClassName + " didn't implement the Extension interface");
+ }
+ return serviceClass;
+ }
+
+ private S prepareInstance(Class<? extends S> serviceClass)
+ {
+ try
+ {
+ // FIXME: SM compatible instatiation
+ return serviceClass.newInstance();
+ }
+ catch (Exception e)
+ {
+ log.warn("Could not instantiate service class " + serviceClass.getName(), e);
+ }
+ return null;
+ }
+
+ /**
+ * Lazily loads the available providers of this loader's service.
+ *
+ * The iterator returned by this method first yields all of the elements of
+ * the provider cache, in instantiation order. It then lazily loads and
+ * instantiates any remaining providers, adding each one to the cache in
+ * turn.
+ *
+ * To achieve laziness the actual work of parsing the available
+ * provider-configuration files and instantiating providers must be done by
+ * the iterator itself. Its hasNext and next methods can therefore throw a
+ * ServiceConfigurationError if a provider-configuration file violates the
+ * specified format, or if it names a provider class that cannot be found and
+ * instantiated, or if the result of instantiating the class is not
+ * assignable to the service type, or if any other kind of exception or error
+ * is thrown as the next provider is located and instantiated. To write
+ * robust code it is only necessary to catch ServiceConfigurationError when
+ * using a service iterator.
+ *
+ * If such an error is thrown then subsequent invocations of the iterator
+ * will make a best effort to locate and instantiate the next available
+ * provider, but in general such recovery cannot be guaranteed.
+ *
+ * Design Note Throwing an error in these cases may seem extreme. The
+ * rationale for this behavior is that a malformed provider-configuration
+ * file, like a malformed class file, indicates a serious problem with the
+ * way the Java virtual machine is configured or is being used. As such it is
+ * preferable to throw an error rather than try to recover or, even worse,
+ * fail silently.
+ *
+ * The iterator returned by this method does not support removal. Invoking
+ * its remove method will cause an UnsupportedOperationException to be
+ * thrown.
+ *
+ * @return An iterator that lazily loads providers for this loader's service
+ */
+ public Iterator<S> iterator()
+ {
+ if (providers == null)
+ {
+ reload();
+ }
+ return providers.iterator();
+ }
+
+ /**
+ * Returns a string describing this service.
+ *
+ * @return A descriptive string
+ */
+ @Override
+ public String toString()
+ {
+ return "Services for " + serviceFile;
+ }
+}
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/service/DefaultServiceLoaderFactory.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/service/DefaultServiceLoaderFactory.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/service/DefaultServiceLoaderFactory.java 2010-04-22 19:14:18 UTC (rev 6151)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.weld.extensions.util.service;
+
+public class DefaultServiceLoaderFactory implements ServiceLoaderFactory
+{
+ public <S> DefaultServiceLoader<S> load(Class<S> service)
+ {
+ return DefaultServiceLoader.load(service);
+ }
+
+ public <S> DefaultServiceLoader<S> load(Class<S> service, ClassLoader loader)
+ {
+ return DefaultServiceLoader.load(service, loader);
+ }
+}
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/service/ServiceLoaderFactory.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/service/ServiceLoaderFactory.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/service/ServiceLoaderFactory.java 2010-04-22 19:14:18 UTC (rev 6151)
@@ -0,0 +1,24 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.weld.extensions.util.service;
+
+public interface ServiceLoaderFactory
+{
+ public <S> DefaultServiceLoader<S> load(Class<S> service);
+
+ public <S> DefaultServiceLoader<S> load(Class<S> service, ClassLoader loader);
+}
Added: extensions/trunk/src/main/resources/META-INF/services/org.jboss.weld.extensions.beanManager.BeanManagerProvider
===================================================================
--- extensions/trunk/src/main/resources/META-INF/services/org.jboss.weld.extensions.beanManager.BeanManagerProvider (rev 0)
+++ extensions/trunk/src/main/resources/META-INF/services/org.jboss.weld.extensions.beanManager.BeanManagerProvider 2010-04-22 19:14:18 UTC (rev 6151)
@@ -0,0 +1,2 @@
+org.jboss.weld.extensions.beanManager.DefaultJndiBeanManagerProvider
+org.jboss.weld.extensions.beanManager.JBossJndiBeanManagerProvider
14 years, 8 months
Weld SVN: r6150 - core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy.
by weld-commits@lists.jboss.org
Author: dallen6
Date: 2010-04-22 09:43:49 -0400 (Thu, 22 Apr 2010)
New Revision: 6150
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java
Log:
Fixed problem with wrong classloader usage for javax packages
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java 2010-04-22 12:20:07 UTC (rev 6149)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java 2010-04-22 13:43:49 UTC (rev 6150)
@@ -84,7 +84,7 @@
public ProxyFactory(Class<?> proxiedBeanType)
{
this.beanType = proxiedBeanType;
- if (beanType.getName().startsWith("java."))
+ if (beanType.getName().startsWith("java"))
{
this.classLoader = this.getClass().getClassLoader();
this.protectionDomain = this.getClass().getProtectionDomain();
@@ -148,7 +148,7 @@
public Class<T> getProxyClass()
{
String proxyClassName = beanType.getName() + "_$$_Weld" + getProxyNameSuffix();
- if (proxyClassName.startsWith("java."))
+ if (proxyClassName.startsWith("java"))
{
proxyClassName = proxyClassName.replaceFirst("java", "org.jboss.weld");
}
14 years, 8 months
Weld SVN: r6149 - in extensions/trunk/src: main/java/org/jboss/weld/extensions/annotations and 5 other directories.
by weld-commits@lists.jboss.org
Author: swd847
Date: 2010-04-22 08:20:07 -0400 (Thu, 22 Apr 2010)
New Revision: 6149
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotations/
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotations/ManagedProducer.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/beans/CustomInjectionPoint.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/
extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerBean.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerExtension.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerInvocationHandler.java
extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/
extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/BeanProducer.java
extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/MPType.java
extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/ManagedProducerTest.java
extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/ManagedReciever.java
extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/ProducedBean.java
extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/ProducedInterface.java
Modified:
extensions/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
Log:
Initial implementation of managed producers
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotations/ManagedProducer.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotations/ManagedProducer.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotations/ManagedProducer.java 2010-04-22 12:20:07 UTC (rev 6149)
@@ -0,0 +1,13 @@
+package org.jboss.weld.extensions.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+(a)Retention(RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.METHOD })
+public @interface ManagedProducer
+{
+
+}
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/beans/CustomInjectionPoint.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/beans/CustomInjectionPoint.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/beans/CustomInjectionPoint.java 2010-04-22 12:20:07 UTC (rev 6149)
@@ -0,0 +1,132 @@
+package org.jboss.weld.extensions.beans;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+/**
+ * implementation of InjectionPoint that can be used by other extensions
+ *
+ * @author stuart
+ *
+ */
+public class CustomInjectionPoint implements InjectionPoint
+{
+
+ public CustomInjectionPoint(AnnotatedField<?> field, Set<Annotation> qualifiers, Bean<?> bean, boolean trans, boolean delegate)
+ {
+ this.annotated = field;
+ this.member = field.getJavaMember();
+ this.qualifiers = new HashSet<Annotation>(qualifiers);
+ this.type = field.getJavaMember().getGenericType();
+ this.trans = trans;
+ this.delegate = delegate;
+ this.bean = bean;
+ }
+
+ public CustomInjectionPoint(AnnotatedField<?> field, BeanManager beanManager, Bean<?> bean, boolean trans, boolean delegate)
+ {
+ this.annotated = field;
+ this.member = field.getJavaMember();
+ this.qualifiers = new HashSet<Annotation>();
+ this.type = field.getJavaMember().getGenericType();
+ this.trans = trans;
+ this.delegate = delegate;
+ this.bean = bean;
+ for (Annotation a : field.getAnnotations())
+ {
+ if (beanManager.isQualifier(a.annotationType()))
+ {
+ qualifiers.add(a);
+ }
+ }
+ }
+
+ public CustomInjectionPoint(AnnotatedParameter<?> param, Set<Annotation> qualifiers, Bean<?> bean, boolean trans, boolean delegate)
+ {
+ this.annotated = param;
+ this.member = param.getDeclaringCallable().getJavaMember();
+ this.qualifiers = new HashSet<Annotation>(qualifiers);
+ this.trans = trans;
+ this.delegate = delegate;
+ this.bean = bean;
+ this.type = param.getBaseType();
+ }
+
+ public CustomInjectionPoint(AnnotatedParameter<?> param, BeanManager beanManager, Bean<?> bean, boolean trans, boolean delegate)
+ {
+ this.annotated = param;
+ this.member = param.getDeclaringCallable().getJavaMember();
+ this.qualifiers = new HashSet<Annotation>();
+ this.trans = trans;
+ this.delegate = delegate;
+ this.bean = bean;
+ this.type = param.getBaseType();
+ for (Annotation a : annotated.getAnnotations())
+ {
+ if (beanManager.isQualifier(a.annotationType()))
+ {
+ qualifiers.add(a);
+ }
+ }
+ }
+
+ private final Annotated annotated;
+
+ private final Member member;
+
+ private final Bean<?> bean;
+
+ private final Set<Annotation> qualifiers;
+
+ private final Type type;
+
+ private final boolean trans;
+
+ private final boolean delegate;
+
+ public Annotated getAnnotated()
+ {
+ return annotated;
+ }
+
+ public Bean<?> getBean()
+ {
+ return bean;
+ }
+
+ public Member getMember()
+ {
+ return member;
+ }
+
+ public Set<Annotation> getQualifiers()
+ {
+ return qualifiers;
+ }
+
+ public Type getType()
+ {
+ return type;
+ }
+
+ public boolean isDelegate()
+ {
+ return delegate;
+ }
+
+ public boolean isTransient()
+ {
+ return trans;
+ }
+
+}
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerBean.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerBean.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerBean.java 2010-04-22 12:20:07 UTC (rev 6149)
@@ -0,0 +1,200 @@
+package org.jboss.weld.extensions.managedproducer;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Proxy;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.Default;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.util.AnnotationLiteral;
+import javax.inject.Named;
+
+/**
+ * Bean implementation that produces a JDK proxy
+ *
+ * when a method is invoked on the proxy it calls the managed producer method
+ * and invokes the method on the returned object
+ *
+ * @author stuart
+ *
+ * @param <M>
+ */
+public class ManagedProducerBean<M> implements Bean<M>
+{
+
+ final Class<?> beanClass;
+
+ final String name;
+
+ final Set<Annotation> qualifiers;
+
+ final Set<Type> types;
+
+ final Class<?> proxyClass;
+
+ final BeanManager manager;
+
+ final Constructor<?> proxyConstructor;
+
+
+ final AnnotatedMethod<?> method;
+
+ public ManagedProducerBean(AnnotatedMethod<?> method, BeanManager manager)
+ {
+ this.method = method;
+ beanClass = method.getDeclaringType().getJavaClass();
+ // get the name
+ if (method.isAnnotationPresent(Named.class))
+ {
+ name = method.getAnnotation(Named.class).value();
+ }
+ else
+ {
+ name = null;
+ }
+ // get the qualifiers
+ qualifiers = new HashSet<Annotation>();
+ for (Annotation a : method.getAnnotations())
+ {
+ if (manager.isQualifier(a.annotationType()))
+ {
+ qualifiers.add(a);
+ }
+ }
+ if (qualifiers.isEmpty())
+ {
+ qualifiers.add(new AnnotationLiteral<Default>()
+ {
+ });
+ }
+ // get the bean types
+ types = new HashSet<Type>();
+ Set<Class<?>> interfaces = new HashSet<Class<?>>();
+ for (Type t : method.getTypeClosure())
+ {
+ if (t instanceof Class<?>)
+ {
+ Class<?> c = (Class<?>) t;
+ if (c.isInterface())
+ {
+ types.add(c);
+ interfaces.add(c);
+ }
+ }
+ else if (t instanceof ParameterizedType)
+ {
+ ParameterizedType p = (ParameterizedType) t;
+ Class<?> c = (Class<?>) p.getRawType();
+ if (c.isInterface())
+ {
+ types.add(t);
+ }
+ }
+ }
+ // build the properties
+ Class<?>[] iarray = new Class[interfaces.size()];
+ int count = 0;
+ this.manager = manager;
+ for (Class<?> c : interfaces)
+ {
+ iarray[count++] = c;
+ }
+ proxyClass = Proxy.getProxyClass(beanClass.getClassLoader(), iarray);
+ try
+ {
+ proxyConstructor = proxyClass.getConstructor(new Class[] { InvocationHandler.class });
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+
+
+ }
+
+ public Class<?> getBeanClass()
+ {
+ return beanClass;
+ }
+
+ public Set<InjectionPoint> getInjectionPoints()
+ {
+ return Collections.emptySet();
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public Set<Annotation> getQualifiers()
+ {
+ return qualifiers;
+ }
+
+ /**
+ * the proxies that are injected all have Dependant scope
+ */
+ public Class<? extends Annotation> getScope()
+ {
+ return Dependent.class;
+ }
+
+ public Set<Class<? extends Annotation>> getStereotypes()
+ {
+ return Collections.emptySet();
+ }
+
+ public Set<Type> getTypes()
+ {
+ return types;
+ }
+
+ public boolean isAlternative()
+ {
+ return false;
+ }
+
+ public boolean isNullable()
+ {
+ return false;
+ }
+
+ public M create(CreationalContext<M> creationalContext)
+ {
+ Annotation[] quals = { new AnnotationLiteral<Default>()
+ {
+ } };
+ Set<Bean<?>> beans = manager.getBeans(InjectionPoint.class, quals);
+ Bean injectionPointBean = (Bean) beans.iterator().next();
+ InjectionPoint injectionPoint = (InjectionPoint) manager.getReference(injectionPointBean, InjectionPoint.class, creationalContext);
+ ManagedProducerInvocationHandler<?> hdl = new ManagedProducerInvocationHandler(manager, this.method, this, injectionPoint);
+ try
+ {
+ M obj = (M) proxyConstructor.newInstance(new Object[] { hdl });
+ creationalContext.push(obj);
+ return obj;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void destroy(M instance, CreationalContext<M> creationalContext)
+ {
+ creationalContext.release();
+ }
+
+}
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerExtension.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerExtension.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerExtension.java 2010-04-22 12:20:07 UTC (rev 6149)
@@ -0,0 +1,50 @@
+package org.jboss.weld.extensions.managedproducer;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+
+import org.jboss.weld.extensions.annotations.ManagedProducer;
+
+/**
+ * An extension that allows the use of @ManagedProducer methods
+ *
+ * these methods work in a similar manner to @Unwrap methods in seam 2
+ *
+ * @author stuart
+ *
+ */
+public class ManagedProducerExtension implements Extension
+{
+
+ Set<ManagedProducerBean<?>> beans = new HashSet<ManagedProducerBean<?>>();
+
+ public void processAnnotatedType(@Observes ProcessAnnotatedType<?> type, BeanManager manager)
+ {
+ for (AnnotatedMethod<?> m : type.getAnnotatedType().getMethods())
+ {
+ if (m.isAnnotationPresent(ManagedProducer.class))
+ {
+ // we have a managed producer
+ // lets make a not of it and register it later
+
+ beans.add(new ManagedProducerBean(m, manager));
+ }
+ }
+ }
+
+ public void afterBeanDiscovery(@Observes AfterBeanDiscovery afterBean)
+ {
+ for (ManagedProducerBean<?> b : beans)
+ {
+ afterBean.addBean(b);
+ }
+ }
+
+}
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerInvocationHandler.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerInvocationHandler.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerInvocationHandler.java 2010-04-22 12:20:07 UTC (rev 6149)
@@ -0,0 +1,92 @@
+package org.jboss.weld.extensions.managedproducer;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.AmbiguousResolutionException;
+import javax.enterprise.inject.UnsatisfiedResolutionException;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import org.jboss.weld.extensions.beans.CustomInjectionPoint;
+
+public class ManagedProducerInvocationHandler<T> implements InvocationHandler
+{
+
+ final BeanManager manager;
+ final AnnotatedMethod<?> annotatedMethod;
+ final Method method;
+ final Bean<?> bean;
+ final InjectionPoint[] injectionPoints;
+ final Map<Method, Method> methods = Collections.synchronizedMap(new HashMap<Method, Method>());
+ final Bean<?> mainClassBean;
+ final InjectionPoint injectionPoint;
+
+
+ public ManagedProducerInvocationHandler(BeanManager manager, AnnotatedMethod<?> method, Bean<?> bean, InjectionPoint injectionPoint)
+ {
+ this.manager = manager;
+ this.method = method.getJavaMember();
+ this.annotatedMethod = method;
+ this.bean = bean;
+ injectionPoints = new InjectionPoint[this.method.getTypeParameters().length];
+ for (int i = 0; i < injectionPoints.length; ++i)
+ {
+ injectionPoints[i] = new CustomInjectionPoint(method.getParameters().get(i), manager, bean, false, false);
+ }
+ Type mainType = method.getDeclaringType().getBaseType();
+ HashSet<Annotation> mainClassQualifiers = new HashSet<Annotation>();
+ for (Annotation a : method.getDeclaringType().getAnnotations())
+ {
+ if (manager.isQualifier(a.annotationType()))
+ {
+ mainClassQualifiers.add(a);
+ }
+ }
+ Set<Bean<?>> beans = manager.getBeans(mainType, mainClassQualifiers.toArray(new Annotation[0]));
+ if (beans.isEmpty())
+ {
+ throw new UnsatisfiedResolutionException("could not find declaring bean for managed producer method " + method.getDeclaringType().getJavaClass() + "." + this.method.getName());
+ }
+ else if (beans.size() > 1)
+ {
+ throw new AmbiguousResolutionException("could not find declaring bean for managed producer method " + method.getDeclaringType().getJavaClass() + "." + this.method.getName());
+ }
+ mainClassBean = beans.iterator().next();
+ this.injectionPoint = injectionPoint;
+ }
+
+ public Object invoke(Object proxy, Method m, Object[] args) throws Throwable
+ {
+ CreationalContext<?> ctx = manager.createCreationalContext(bean);
+ Object[] params = new Object[method.getParameterTypes().length];
+ for (int i = 0; i < this.method.getParameterTypes().length; ++i)
+ {
+ if (InjectionPoint.class.isAssignableFrom(this.method.getParameterTypes()[i]))
+ {
+ params[i] = injectionPoint;
+ }
+ else
+ {
+ params[i] = manager.getInjectableReference(injectionPoints[i], ctx);
+ }
+ }
+ Object base = manager.getReference(mainClassBean, annotatedMethod.getDeclaringType().getJavaClass(), ctx);
+
+ Object result = method.invoke(base, params);
+ Object ret = m.invoke(result, args);
+ ctx.release();
+ return ret;
+ }
+
+}
Modified: extensions/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
===================================================================
--- extensions/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 2010-04-22 09:42:38 UTC (rev 6148)
+++ extensions/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 2010-04-22 12:20:07 UTC (rev 6149)
@@ -1,3 +1,5 @@
org.jboss.weld.extensions.genericbeans.GenericExtension
org.jboss.weld.extensions.resources.servlet.ServletResourceExtension
-org.jboss.weld.extensions.beanid.IdentifiableBeanExtension
\ No newline at end of file
+org.jboss.weld.extensions.beanid.IdentifiableBeanExtension
+org.jboss.weld.extensions.CoreExtension
+org.jboss.weld.extensions.managedproducer.ManagedProducerExtension
\ No newline at end of file
Added: extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/BeanProducer.java
===================================================================
--- extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/BeanProducer.java (rev 0)
+++ extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/BeanProducer.java 2010-04-22 12:20:07 UTC (rev 6149)
@@ -0,0 +1,16 @@
+package org.jboss.weld.test.extensions.managedproducer;
+
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import org.jboss.weld.extensions.annotations.ManagedProducer;
+
+public class BeanProducer
+{
+ @ManagedProducer
+ public ProducedInterface produce(InjectionPoint injectionPoint)
+ {
+ ProducedBean b = new ProducedBean();
+ b.setValue(injectionPoint.getAnnotated().getAnnotation(MPType.class).value());
+ return b;
+ }
+}
Added: extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/MPType.java
===================================================================
--- extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/MPType.java (rev 0)
+++ extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/MPType.java 2010-04-22 12:20:07 UTC (rev 6149)
@@ -0,0 +1,10 @@
+package org.jboss.weld.test.extensions.managedproducer;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface MPType
+{
+ String value();
+}
Added: extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/ManagedProducerTest.java
===================================================================
--- extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/ManagedProducerTest.java (rev 0)
+++ extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/ManagedProducerTest.java 2010-04-22 12:20:07 UTC (rev 6149)
@@ -0,0 +1,17 @@
+package org.jboss.weld.test.extensions.managedproducer;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.weld.test.AbstractWeldTest;
+import org.testng.annotations.Test;
+
+@Artifact
+public class ManagedProducerTest extends AbstractWeldTest
+{
+ @Test
+ public void testManagedProducers()
+ {
+ ManagedReciever bean = getReference(ManagedReciever.class);
+ assert bean.bean1.getValue().equals("bean1") : " value: " + bean.bean1.getValue();
+ assert bean.bean2.getValue().equals("bean2") : " value: " + bean.bean1.getValue();
+ }
+}
Added: extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/ManagedReciever.java
===================================================================
--- extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/ManagedReciever.java (rev 0)
+++ extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/ManagedReciever.java 2010-04-22 12:20:07 UTC (rev 6149)
@@ -0,0 +1,15 @@
+package org.jboss.weld.test.extensions.managedproducer;
+
+import javax.inject.Inject;
+
+public class ManagedReciever
+{
+ @MPType("bean1")
+ @Inject
+ ProducedInterface bean1;
+
+ @MPType("bean2")
+ @Inject
+ ProducedInterface bean2;
+
+}
Added: extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/ProducedBean.java
===================================================================
--- extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/ProducedBean.java (rev 0)
+++ extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/ProducedBean.java 2010-04-22 12:20:07 UTC (rev 6149)
@@ -0,0 +1,19 @@
+package org.jboss.weld.test.extensions.managedproducer;
+
+import org.jboss.weld.extensions.Veto;
+
+@Veto
+public class ProducedBean implements ProducedInterface
+{
+ String value = "wrong";
+
+ public String getValue()
+ {
+ return value;
+ }
+
+ public void setValue(String value)
+ {
+ this.value = value;
+ }
+}
Added: extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/ProducedInterface.java
===================================================================
--- extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/ProducedInterface.java (rev 0)
+++ extensions/trunk/src/test/java/org/jboss/weld/test/extensions/managedproducer/ProducedInterface.java 2010-04-22 12:20:07 UTC (rev 6149)
@@ -0,0 +1,8 @@
+package org.jboss.weld.test.extensions.managedproducer;
+
+public interface ProducedInterface
+{
+
+ public abstract String getValue();
+
+}
\ No newline at end of file
14 years, 8 months
Weld SVN: r6148 - core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/util.
by weld-commits@lists.jboss.org
Author: dallen6
Date: 2010-04-22 05:42:38 -0400 (Thu, 22 Apr 2010)
New Revision: 6148
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/util/ClassloaderClassPath.java
Log:
Put the resource paths back to the original separator
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/util/ClassloaderClassPath.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/util/ClassloaderClassPath.java 2010-04-22 08:09:31 UTC (rev 6147)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/util/ClassloaderClassPath.java 2010-04-22 09:42:38 UTC (rev 6148)
@@ -17,7 +17,6 @@
package org.jboss.weld.bean.proxy.util;
-import java.io.File;
import java.io.InputStream;
import java.net.URL;
@@ -47,13 +46,13 @@
public URL find(String classname)
{
- String resourceName = classname.replace('.', File.separatorChar) + ".class";
+ String resourceName = classname.replace('.', '/') + ".class";
return classLoader.getResource(resourceName);
}
public InputStream openClassfile(String classname) throws NotFoundException
{
- String resourceName = classname.replace('.', File.separatorChar) + ".class";
+ String resourceName = classname.replace('.', '/') + ".class";
return classLoader.getResourceAsStream(resourceName);
}
14 years, 8 months
Weld SVN: r6147 - in cdi-tck/branches/1.0/impl/src/main: java/org/jboss/jsr299/tck/tests/extensions/beanManager and 2 other directories.
by weld-commits@lists.jboss.org
Author: dallen6
Date: 2010-04-22 04:09:31 -0400 (Thu, 22 Apr 2010)
New Revision: 6147
Added:
cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/AfterBeanDiscoveryObserver.java
cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/CowBean.java
cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/PassivationIdTest.java
cdi-tck/branches/1.0/impl/src/main/resources/org/jboss/jsr299/tck/tests/extensions/beanManager/
cdi-tck/branches/1.0/impl/src/main/resources/org/jboss/jsr299/tck/tests/extensions/beanManager/javax.enterprise.inject.spi.Extension
Modified:
cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/passivating/broken/decoratorWithNonPassivatingInitializerMethod/UnderwaterCity.java
Log:
CDITCK-134 CDITCK-121
Modified: cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/passivating/broken/decoratorWithNonPassivatingInitializerMethod/UnderwaterCity.java
===================================================================
--- cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/passivating/broken/decoratorWithNonPassivatingInitializerMethod/UnderwaterCity.java 2010-04-22 08:06:25 UTC (rev 6146)
+++ cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/passivating/broken/decoratorWithNonPassivatingInitializerMethod/UnderwaterCity.java 2010-04-22 08:09:31 UTC (rev 6147)
@@ -18,9 +18,9 @@
import java.io.Serializable;
-import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.SessionScoped;
-@RequestScoped
+@SessionScoped
class UnderwaterCity implements CityInterface, Serializable
{
Added: cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/AfterBeanDiscoveryObserver.java
===================================================================
--- cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/AfterBeanDiscoveryObserver.java (rev 0)
+++ cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/AfterBeanDiscoveryObserver.java 2010-04-22 08:09:31 UTC (rev 6147)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.jsr299.tck.tests.extensions.beanManager;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.Extension;
+
+public class AfterBeanDiscoveryObserver implements Extension
+{
+
+ public void addABean(@Observes AfterBeanDiscovery afterBeanDiscovery)
+ {
+ afterBeanDiscovery.addBean(new CowBean());
+ }
+
+}
Added: cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/CowBean.java
===================================================================
--- cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/CowBean.java (rev 0)
+++ cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/CowBean.java 2010-04-22 08:09:31 UTC (rev 6147)
@@ -0,0 +1,85 @@
+package org.jboss.jsr299.tck.tests.extensions.beanManager;
+
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.PassivationCapable;
+
+import org.jboss.jsr299.tck.literals.DefaultLiteral;
+
+public class CowBean implements Bean<Cow>, PassivationCapable, Serializable
+{
+ private static final long serialVersionUID = 6249623250272328272L;
+ public static final String PASSIVATION_ID = "Cow-6249623250272328272L";
+ private final Set<Annotation> qualifiers = new HashSet<Annotation>(Arrays.asList(new DefaultLiteral()));
+ private final Set<Type> types = new HashSet<Type>(Arrays.<Type>asList(Cow.class));
+
+ public Class<?> getBeanClass()
+ {
+ return Cow.class;
+ }
+
+ public Set<InjectionPoint> getInjectionPoints()
+ {
+ return Collections.emptySet();
+ }
+
+ public String getName()
+ {
+ return "cow";
+ }
+
+ public Set<Annotation> getQualifiers()
+ {
+ return qualifiers;
+ }
+
+ public Class<? extends Annotation> getScope()
+ {
+ return Dependent.class;
+ }
+
+ public Set<Class<? extends Annotation>> getStereotypes()
+ {
+ return Collections.emptySet();
+ }
+
+ public Set<Type> getTypes()
+ {
+ return types;
+ }
+
+ public boolean isAlternative()
+ {
+ return false;
+ }
+
+ public boolean isNullable()
+ {
+ return false;
+ }
+
+ public Cow create(CreationalContext<Cow> creationalContext)
+ {
+ return new Cow("Betsy");
+ }
+
+ public void destroy(Cow instance, CreationalContext<Cow> creationalContext)
+ {
+ }
+
+ public String getId()
+ {
+ return PASSIVATION_ID;
+ }
+
+}
Added: cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/PassivationIdTest.java
===================================================================
--- cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/PassivationIdTest.java (rev 0)
+++ cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/PassivationIdTest.java 2010-04-22 08:09:31 UTC (rev 6147)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc. and/or its affiliates, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.jsr299.tck.tests.extensions.beanManager;
+
+import javax.enterprise.inject.spi.Bean;
+
+import org.jboss.jsr299.tck.AbstractJSR299Test;
+import org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.test.audit.annotations.SpecVersion;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.IntegrationTest;
+import org.jboss.testharness.impl.packaging.jsr299.Extension;
+import org.testng.annotations.Test;
+
+/**
+ * Tests retrieving beans with the BeanManager by the ID for a passivation-capable
+ * bean.
+ *
+ * @author David Allen
+ *
+ */
+@Artifact
+@IntegrationTest
+@Extension("javax.enterprise.inject.spi.Extension")
+@SpecVersion(spec="cdi", version="20091101")
+public class PassivationIdTest extends AbstractJSR299Test
+{
+ @Test
+ @SpecAssertion(section = "11.3.6", id = "a")
+ public void testGetPassivationCapableBeanById()
+ {
+ Bean<?> passivatingBean = getCurrentManager().getPassivationCapableBean(CowBean.PASSIVATION_ID);
+ assert passivatingBean.getBeanClass().equals(Cow.class);
+ }
+}
Added: cdi-tck/branches/1.0/impl/src/main/resources/org/jboss/jsr299/tck/tests/extensions/beanManager/javax.enterprise.inject.spi.Extension
===================================================================
--- cdi-tck/branches/1.0/impl/src/main/resources/org/jboss/jsr299/tck/tests/extensions/beanManager/javax.enterprise.inject.spi.Extension (rev 0)
+++ cdi-tck/branches/1.0/impl/src/main/resources/org/jboss/jsr299/tck/tests/extensions/beanManager/javax.enterprise.inject.spi.Extension 2010-04-22 08:09:31 UTC (rev 6147)
@@ -0,0 +1 @@
+org.jboss.jsr299.tck.tests.extensions.beanManager.AfterBeanDiscoveryObserver
\ No newline at end of file
14 years, 8 months
Weld SVN: r6146 - cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/passivating/broken/decoratorWithNonPassivatingInitializerMethod.
by weld-commits@lists.jboss.org
Author: dallen6
Date: 2010-04-22 04:06:25 -0400 (Thu, 22 Apr 2010)
New Revision: 6146
Modified:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/passivating/broken/decoratorWithNonPassivatingInitializerMethod/UnderwaterCity.java
Log:
CDITCK-134
Modified: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/passivating/broken/decoratorWithNonPassivatingInitializerMethod/UnderwaterCity.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/passivating/broken/decoratorWithNonPassivatingInitializerMethod/UnderwaterCity.java 2010-04-22 02:13:38 UTC (rev 6145)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/passivating/broken/decoratorWithNonPassivatingInitializerMethod/UnderwaterCity.java 2010-04-22 08:06:25 UTC (rev 6146)
@@ -18,9 +18,9 @@
import java.io.Serializable;
-import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.SessionScoped;
-@RequestScoped
+@SessionScoped
class UnderwaterCity implements CityInterface, Serializable
{
14 years, 8 months