[jboss-cvs] JBossAS SVN: r89524 - in projects/reloaded/trunk/injection/src: main/java/org/jboss/reloaded/injection/deployer and 9 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri May 29 04:17:55 EDT 2009


Author: wolfc
Date: 2009-05-29 04:17:55 -0400 (Fri, 29 May 2009)
New Revision: 89524

Added:
   projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/DefaultManagedBeanInstance.java
   projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/Injector.java
   projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/
   projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/Reference.java
   projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/reflect/
   projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/reflect/AbstractPropertyInjector.java
   projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/naming/JndiPropertyInjector.java
   projects/reloaded/trunk/injection/src/main/resources/schema/
   projects/reloaded/trunk/injection/src/main/resources/schema/jboss-mb_0_1.xsd
   projects/reloaded/trunk/injection/src/test/java/org/jboss/reloaded/injection/test/common/AbstractInjectionTestCase.java
Modified:
   projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/ManagedBeanFactory.java
   projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/ManagedBeanFactoryBuilder.java
   projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/deployer/ManagedBeanDeployer.java
   projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/reflect/AbstractAccessibleObjectBeanProperty.java
   projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/reflect/BeanProperty.java
   projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/reflect/BeanPropertyFactory.java
   projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/reflect/FieldBeanProperty.java
   projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/reflect/MethodBeanProperty.java
   projects/reloaded/trunk/injection/src/test/java/org/jboss/reloaded/injection/test/simple/SimpleResourceBean.java
   projects/reloaded/trunk/injection/src/test/java/org/jboss/reloaded/injection/test/simple/unit/SimpleResourceTestCase.java
   projects/reloaded/trunk/injection/src/test/resources/simple/jboss-mb.xml
Log:
RELOADED-8: injection targets working

Added: projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/DefaultManagedBeanInstance.java
===================================================================
--- projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/DefaultManagedBeanInstance.java	                        (rev 0)
+++ projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/DefaultManagedBeanInstance.java	2009-05-29 08:17:55 UTC (rev 89524)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.reloaded.injection;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class DefaultManagedBeanInstance<T> implements ManagedBeanInstance<T>
+{
+   private T bean;
+
+   protected DefaultManagedBeanInstance(Class<T> type, T bean)
+   {
+      this.bean = bean;
+   }
+   
+   public T getBean()
+   {
+      return bean;
+   }
+}

Added: projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/Injector.java
===================================================================
--- projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/Injector.java	                        (rev 0)
+++ projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/Injector.java	2009-05-29 08:17:55 UTC (rev 89524)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.reloaded.injection;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface Injector<T>
+{
+   void inject(ManagedBeanInstance<T> bean);
+}

Modified: projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/ManagedBeanFactory.java
===================================================================
--- projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/ManagedBeanFactory.java	2009-05-29 07:56:59 UTC (rev 89523)
+++ projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/ManagedBeanFactory.java	2009-05-29 08:17:55 UTC (rev 89524)
@@ -24,7 +24,9 @@
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
@@ -43,20 +45,56 @@
    private static final Logger log = Logger.getLogger(ManagedBeanFactory.class);
    
    private String name;
+   private Class<T> beanClass;
    private Map<String, Binder> binders = new HashMap<String, Binder>();
+   private Map<Class<?>, Set<Injector<T>>> injectors = new HashMap<Class<?>, Set<Injector<T>>>();
 
    private Context enc;
    
-   public ManagedBeanFactory(String name)
+   public ManagedBeanFactory(String name, Class<T> beanClass)
    {
       this.name = name;
+      this.beanClass = beanClass;
+      injectors.put(beanClass, new HashSet<Injector<T>>());
    }
    
-   public ManagedBeanInstance<T> createBean()
+   protected void addInjector(Class<?> cls, Injector<T> injector)
    {
-      throw new RuntimeException("NYI");
+      // assume that the class belongs to this component
+      Set<Injector<T>> set = injectors.get(cls);
+      if(set == null)
+         throw new IllegalArgumentException("Class " + cls + " does not belong to this managed bean");
+      set.add(injector);
    }
    
+   public ManagedBeanInstance<T> createBean() throws Exception
+   {
+      try
+      {
+         T instance = beanClass.newInstance();
+         ManagedBeanInstance<T> bean = new DefaultManagedBeanInstance<T>(beanClass, instance);
+         
+         Set<Injector<T>> beanInjectors = injectors.get(beanClass);
+         assert beanInjectors != null;
+         
+         for(Injector<T> injector : beanInjectors)
+         {
+            injector.inject(bean);
+         }
+         
+         // TODO: lifecycle
+         return bean;
+      }
+      catch (InstantiationException e)
+      {
+         throw handleThrowable(e.getCause());
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
    public void destroyBean(ManagedBeanInstance<T> bean)
    {
       throw new RuntimeException("NYI");
@@ -67,11 +105,27 @@
       return binders;
    }
    
+   protected Context getEnc()
+   {
+      return enc;
+   }
+   
+   private Exception handleThrowable(Throwable t)
+   {
+      if(t instanceof Error)
+         throw (Error) t;
+      if(t instanceof RuntimeException)
+         throw (RuntimeException) t;
+      return (Exception) t;
+   }
+   
    public Object invoke(Object proxy, Method method, Object args[]) throws Throwable
    {
       ENCFactory.pushContextId(name);
       try
       {
+         if(proxy instanceof ManagedBeanInstance)
+            proxy = ((ManagedBeanInstance<?>) proxy).getBean();
          return method.invoke(proxy, args);
       }
       finally

Modified: projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/ManagedBeanFactoryBuilder.java
===================================================================
--- projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/ManagedBeanFactoryBuilder.java	2009-05-29 07:56:59 UTC (rev 89523)
+++ projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/ManagedBeanFactoryBuilder.java	2009-05-29 08:17:55 UTC (rev 89524)
@@ -21,8 +21,13 @@
  */
 package org.jboss.reloaded.injection;
 
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.util.Collection;
 
+import javax.naming.Context;
+
 import org.jboss.beans.metadata.plugins.builder.BeanMetaDataBuilderFactory;
 import org.jboss.beans.metadata.spi.BeanMetaData;
 import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
@@ -39,7 +44,12 @@
 import org.jboss.metadata.javaee.spec.ResourceEnvironmentReferencesMetaData;
 import org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData;
 import org.jboss.metadata.javaee.spec.ResourceReferencesMetaData;
+import org.jboss.reloaded.injection.lang.Reference;
+import org.jboss.reloaded.injection.lang.reflect.BeanProperty;
+import org.jboss.reloaded.injection.lang.reflect.BeanPropertyFactory;
+import org.jboss.reloaded.injection.metadata.ManagedBeanMetaData;
 import org.jboss.reloaded.injection.naming.Binder;
+import org.jboss.reloaded.injection.naming.JndiPropertyInjector;
 import org.jboss.reloaded.injection.naming.ValueBinder;
 import org.jboss.reloaded.injection.spi.PersistenceUnitDependencyResolver;
 import org.jboss.reloaded.injection.spi.Resolver;
@@ -55,13 +65,19 @@
    private Resolver<AbstractEJBReferenceMetaData> ejbReferenceResolver;
    private PersistenceUnitDependencyResolver persistenceUnitDependencyResolver;
    
-   public BeanMetaData createManagedObjectFactoryMetaData(String name, DeploymentUnit deploymentUnit, RemoteEnvironment env)
+   public BeanMetaData createManagedObjectFactoryMetaData(String name, DeploymentUnit deploymentUnit, ManagedBeanMetaData metaData) throws ClassNotFoundException
    {
+      String beanClassName = metaData.getBeanClass();
+      ClassLoader loader = deploymentUnit.getClassLoader();
+      Class<?> beanClass = loader.loadClass(beanClassName);
+      
       BeanMetaDataBuilder builder = BeanMetaDataBuilderFactory.createBuilder(name, ManagedBeanFactory.class.getName());
       
-      ManagedBeanFactory<?> container = new ManagedBeanFactory<Object>(name);
+      ManagedBeanFactory<?> container = new ManagedBeanFactory(name, beanClass);
       builder.setConstructorValue(container);
       
+      RemoteEnvironment env = metaData.getEnvironment();
+      
       if(env == null)
          return builder.getBeanMetaData();
       
@@ -149,12 +165,49 @@
       }
    }
    
-   protected void injectionTargets(Collection<ResourceInjectionTargetMetaData> targets)
+   protected static AccessibleObject findInjectionTarget(Class<?> injectionTarget, ResourceInjectionTargetMetaData target)
    {
+      for (Field field : injectionTarget.getDeclaredFields())
+      {
+         if (target.getInjectionTargetName().equals(field.getName())) return field;
+      }
+
+      for (Method method : injectionTarget.getDeclaredMethods())
+      {
+         if (method.getName().equals(target.getInjectionTargetName())) return method;
+      }
+
+      throw new RuntimeException("<injection-target> could not be found: " + injectionTarget.getName() + "." + target.getInjectionTargetName());
+   }
+   
+   protected <T> void injectionTargets(ClassLoader loader, String jndiName, final ManagedBeanFactory<T> container, Collection<ResourceInjectionTargetMetaData> targets)
+   {
       if(targets == null)
          return;
       
-      throw new RuntimeException("NYI");
+      for(ResourceInjectionTargetMetaData target : targets)
+      {
+         Class<?> injectionTarget = null;
+         try
+         {
+            injectionTarget = loader.loadClass(target.getInjectionTargetClass());
+         }
+         catch (ClassNotFoundException e)
+         {
+            throw new RuntimeException("<injection-target> class: " + target.getInjectionTargetClass() + " was not found in deployment");
+         }
+
+         AccessibleObject ao = findInjectionTarget(injectionTarget, target);
+         BeanProperty property = BeanPropertyFactory.create(ao);
+         Reference<Context> ref = new Reference<Context>() {
+            public Context get()
+            {
+               return container.getEnc();
+            }
+         };
+         JndiPropertyInjector<T> injector = new JndiPropertyInjector<T>(property, jndiName, ref);
+         container.addInjector(injectionTarget, injector);
+      }
    }
    
    private static final boolean isEmpty(String s)
@@ -209,7 +262,7 @@
          {
             String encName = "env/" + envEntry.getName();
             
-            injectionTargets(envEntry.getInjectionTargets());
+            injectionTargets(deploymentUnit.getClassLoader(), encName, container, envEntry.getInjectionTargets());
             
             if(container.getBinders().containsKey(encName))
                continue;

Modified: projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/deployer/ManagedBeanDeployer.java
===================================================================
--- projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/deployer/ManagedBeanDeployer.java	2009-05-29 07:56:59 UTC (rev 89523)
+++ projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/deployer/ManagedBeanDeployer.java	2009-05-29 08:17:55 UTC (rev 89524)
@@ -47,10 +47,17 @@
    @Override
    public void deploy(DeploymentUnit unit, ManagedBeanMetaData deployment) throws DeploymentException
    {
-      log.info("Deploying " + deployment);
-      
-      String name = "jboss:service=ManagedBean,name=" + deployment.getName();
-      unit.getParent().addAttachment(BeanMetaData.class.getName() + "." + name, builder.createManagedObjectFactoryMetaData(name, unit, deployment.getEnvironment()), BeanMetaData.class);
+      try
+      {
+         log.info("Deploying " + deployment);
+         
+         String name = "jboss:service=ManagedBean,name=" + deployment.getName();
+         unit.getParent().addAttachment(BeanMetaData.class.getName() + "." + name, builder.createManagedObjectFactoryMetaData(name, unit, deployment), BeanMetaData.class);
+      }
+      catch(ClassNotFoundException e)
+      {
+         throw new DeploymentException(e);
+      }
    }
    
    @Inject

Added: projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/Reference.java
===================================================================
--- projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/Reference.java	                        (rev 0)
+++ projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/Reference.java	2009-05-29 08:17:55 UTC (rev 89524)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.reloaded.injection.lang;
+
+/**
+ * Lazy reference something.
+ * 
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface Reference<T>
+{
+   T get();
+}

Copied: projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/reflect (from rev 89488, projects/ejb3/trunk/core/src/main/java/org/jboss/injection/lang/reflect)


Property changes on: projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/reflect
___________________________________________________________________
Name: svn:mergeinfo
   + 

Modified: projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/reflect/AbstractAccessibleObjectBeanProperty.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/lang/reflect/AbstractAccessibleObjectBeanProperty.java	2009-05-28 06:04:04 UTC (rev 89488)
+++ projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/reflect/AbstractAccessibleObjectBeanProperty.java	2009-05-29 08:17:55 UTC (rev 89524)
@@ -19,7 +19,7 @@
  * 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.injection.lang.reflect;
+package org.jboss.reloaded.injection.lang.reflect;
 
 import java.lang.reflect.AccessibleObject;
 
@@ -40,12 +40,11 @@
       obj.setAccessible(true);
    }
    
-   public T getAccessibleObject()
+   protected T getAccessibleObject()
    {
       return obj;
    }
    
-   
    public String toString()
    {
       return getDeclaringClass().getName() + "." + getName();

Added: projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/reflect/AbstractPropertyInjector.java
===================================================================
--- projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/reflect/AbstractPropertyInjector.java	                        (rev 0)
+++ projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/reflect/AbstractPropertyInjector.java	2009-05-29 08:17:55 UTC (rev 89524)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.reloaded.injection.lang.reflect;
+
+import org.jboss.reloaded.injection.Injector;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public abstract class AbstractPropertyInjector<T> implements Injector<T>
+{
+   protected BeanProperty property;
+   
+   protected AbstractPropertyInjector(BeanProperty property)
+   {
+      this.property = property;
+   }
+}

Modified: projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/reflect/BeanProperty.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/lang/reflect/BeanProperty.java	2009-05-28 06:04:04 UTC (rev 89488)
+++ projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/reflect/BeanProperty.java	2009-05-29 08:17:55 UTC (rev 89524)
@@ -19,12 +19,10 @@
  * 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.injection.lang.reflect;
+package org.jboss.reloaded.injection.lang.reflect;
 
-import java.lang.reflect.AccessibleObject;
-
 /**
- * A bean property defines a propery of a pojo from the EJB3 point of view.
+ * A bean property defines a property of a pojo from the EJB3 point of view.
  * It can be used to inject values into it.
  *
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
@@ -32,9 +30,6 @@
  */
 public interface BeanProperty
 {
-   // TODO: should not be exposed
-   AccessibleObject getAccessibleObject();
-   
    Class<?> getDeclaringClass();
    
    String getName();

Modified: projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/reflect/BeanPropertyFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/lang/reflect/BeanPropertyFactory.java	2009-05-28 06:04:04 UTC (rev 89488)
+++ projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/reflect/BeanPropertyFactory.java	2009-05-29 08:17:55 UTC (rev 89524)
@@ -19,7 +19,7 @@
  * 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.injection.lang.reflect;
+package org.jboss.reloaded.injection.lang.reflect;
 
 import java.lang.reflect.AccessibleObject;
 import java.lang.reflect.Field;

Modified: projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/reflect/FieldBeanProperty.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/lang/reflect/FieldBeanProperty.java	2009-05-28 06:04:04 UTC (rev 89488)
+++ projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/reflect/FieldBeanProperty.java	2009-05-29 08:17:55 UTC (rev 89524)
@@ -19,7 +19,7 @@
  * 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.injection.lang.reflect;
+package org.jboss.reloaded.injection.lang.reflect;
 
 import java.lang.reflect.Field;
 

Modified: projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/reflect/MethodBeanProperty.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/lang/reflect/MethodBeanProperty.java	2009-05-28 06:04:04 UTC (rev 89488)
+++ projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/lang/reflect/MethodBeanProperty.java	2009-05-29 08:17:55 UTC (rev 89524)
@@ -19,7 +19,7 @@
  * 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.injection.lang.reflect;
+package org.jboss.reloaded.injection.lang.reflect;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;

Added: projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/naming/JndiPropertyInjector.java
===================================================================
--- projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/naming/JndiPropertyInjector.java	                        (rev 0)
+++ projects/reloaded/trunk/injection/src/main/java/org/jboss/reloaded/injection/naming/JndiPropertyInjector.java	2009-05-29 08:17:55 UTC (rev 89524)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
+ * 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.reloaded.injection.naming;
+
+import java.util.Arrays;
+
+import javax.naming.Context;
+import javax.naming.LinkRef;
+import javax.naming.NamingException;
+
+import org.jboss.logging.Logger;
+import org.jboss.reloaded.injection.Injector;
+import org.jboss.reloaded.injection.ManagedBeanInstance;
+import org.jboss.reloaded.injection.lang.Reference;
+import org.jboss.reloaded.injection.lang.reflect.AbstractPropertyInjector;
+import org.jboss.reloaded.injection.lang.reflect.BeanProperty;
+
+/**
+ * Injects a JNDI dependency into a bean property.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class JndiPropertyInjector<T> extends AbstractPropertyInjector<T> implements Injector<T>
+{
+   @SuppressWarnings("unused")
+   private static final Logger log = Logger.getLogger(JndiPropertyInjector.class);
+   
+   private String jndiName;
+   private Reference<Context> ref;
+
+   public JndiPropertyInjector(BeanProperty property, String jndiName, Reference<Context> ref)
+   {
+      super(property);
+      this.jndiName = jndiName;
+      this.ref = ref;
+   }
+
+   protected Object lookup(String jndiName)
+   {
+      Object dependency = null;
+      
+      try
+      {
+         dependency = ref.get().lookup(jndiName);
+      }
+      catch (NamingException e)
+      {
+         Throwable cause = e;
+         while(cause.getCause() != null)
+            cause = cause.getCause();
+         throw new RuntimeException("Unable to inject jndi dependency: " + jndiName + " into property " + property + ": " + cause.getMessage(), e);
+      }
+      return dependency;
+   }
+   
+   public void inject(ManagedBeanInstance<T> bean)
+   {
+      Object value = lookup(jndiName);
+            
+      T instance = bean.getBean();
+      log.trace("injecting " + value + " from " + jndiName + " into " + property + " of " + instance);
+      try
+      {
+         property.set(instance, value);
+      }
+      catch(IllegalArgumentException e)
+      {
+         // We found something to inject, but it happened to be the wrong thing
+         String realJndiName;
+         try
+         {
+            // TODO: check whether it's a real link beforehand
+            Object link = ref.get().lookupLink(jndiName);
+            realJndiName = jndiName + (link instanceof LinkRef ? " (link -> " + ((LinkRef) link).getLinkName() + ")" : "");
+         }
+         catch(NamingException ne)
+         {
+            log.trace("Failed to obtain the real JNDI name", ne);
+            realJndiName = jndiName;
+         }
+         Class<?> interfaces[] = value.getClass().getInterfaces();
+         String interfacesStr = (interfaces.length > 0 ? " (implements " + Arrays.toString(interfaces) + ")" : "");
+         String msg = "failed to inject " + value + interfacesStr + " from " + realJndiName + " into " + property + " of " + instance;
+         throw new IllegalArgumentException(msg, e);
+      }
+   }
+}

Added: projects/reloaded/trunk/injection/src/main/resources/schema/jboss-mb_0_1.xsd
===================================================================
--- projects/reloaded/trunk/injection/src/main/resources/schema/jboss-mb_0_1.xsd	                        (rev 0)
+++ projects/reloaded/trunk/injection/src/main/resources/schema/jboss-mb_0_1.xsd	2009-05-29 08:17:55 UTC (rev 89524)
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
+       targetNamespace="http://www.jboss.com/xml/ns/javaee"
+       xmlns:javaee="http://java.sun.com/xml/ns/javaee"
+       xmlns:jboss="http://www.jboss.com/xml/ns/javaee"
+       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+       elementFormDefault="qualified"
+       attributeFormDefault="unqualified"
+       version="0.1">
+
+   <!-- xsd:import namespace="http://java.sun.com/xml/ns/javaee" schemaLocation="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"/ -->
+   <xsd:import namespace="http://java.sun.com/xml/ns/javaee" schemaLocation="http://java.sun.com/xml/ns/javaee/javaee_5.xsd"/>
+   
+   <xsd:element name="jboss-mb" type="jboss:jboss-mbType">
+      <xsd:key name="name-key">
+         <xsd:annotation>
+            <xsd:documentation>
+               The name must be unique within the descriptor file.
+            </xsd:documentation>
+         </xsd:annotation>
+         <xsd:selector xpath="jboss:managed-beans/*"/>
+         <xsd:field xpath="jboss:name"/>
+      </xsd:key>
+   </xsd:element>
+   
+   <xsd:complexType name="bean-classType">
+      <xsd:simpleContent>
+         <xsd:restriction base="javaee:fully-qualified-classType"/>
+      </xsd:simpleContent>
+   </xsd:complexType>
+   
+   <xsd:complexType name="jboss-mbType">
+      <xsd:sequence>
+         <xsd:group ref="javaee:descriptionGroup" />
+         <xsd:element name="managed-beans"
+            type="jboss:managed-beansType" minOccurs="0" />
+         <!-- 
+         <xsd:element name="interceptors" type="javaee:interceptorsType"
+            minOccurs="0" />
+         -->
+      </xsd:sequence>
+   </xsd:complexType>
+   
+   <xsd:complexType name="managed-beanType">
+      <xsd:sequence>
+         <xsd:group ref="javaee:descriptionGroup"/>
+         <xsd:element name="name" type="jboss:nameType"/>
+         <xsd:element name="bean-class" type="jboss:bean-classType" minOccurs="0">
+         <xsd:group ref="javaee:jndiEnvironmentRefsGroup"/>
+      </xsd:sequence>
+   </xsd:complexType>
+   
+   <xsd:complexType name="managed-beansType">
+      <xsd:sequence>
+         <xsd:element name="managed-bean" type="jboss:managed-beanType" />
+      </xsd:sequence>
+   </xsd:complexType>
+   
+   <xsd:complexType name="nameType">
+   </xsd:complexType>
+</xsd:schema>
\ No newline at end of file

Added: projects/reloaded/trunk/injection/src/test/java/org/jboss/reloaded/injection/test/common/AbstractInjectionTestCase.java
===================================================================
--- projects/reloaded/trunk/injection/src/test/java/org/jboss/reloaded/injection/test/common/AbstractInjectionTestCase.java	                        (rev 0)
+++ projects/reloaded/trunk/injection/src/test/java/org/jboss/reloaded/injection/test/common/AbstractInjectionTestCase.java	2009-05-29 08:17:55 UTC (rev 89524)
@@ -0,0 +1,159 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.reloaded.injection.test.common;
+
+import java.io.IOException;
+import java.net.URL;
+
+import org.jboss.bootstrap.spi.lifecycle.LifecycleState;
+import org.jboss.bootstrap.spi.mc.config.MCServerConfig;
+import org.jboss.bootstrap.spi.mc.config.MCServerConfigFactory;
+import org.jboss.bootstrap.spi.mc.server.MCServer;
+import org.jboss.bootstrap.spi.mc.server.MCServerFactory;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.client.spi.main.MainDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
+import org.jboss.deployers.vfs.spi.client.VFSDeployment;
+import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public abstract class AbstractInjectionTestCase
+{
+   private static MCServer server;
+   private static MainDeployer mainDeployer;
+   
+   @AfterClass
+   public static void afterClass() throws Exception
+   {
+      if(server != null && server.getState() == LifecycleState.STARTED)
+         server.shutdown();
+      server = null;
+   }
+   
+   @BeforeClass
+   public static void beforeClass() throws Exception
+   {
+      VFS.init();
+      // TODO: use jboss-cl
+      ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+      MCServerConfig config = MCServerConfigFactory.createServerConfig(classLoader);
+      config.bootstrapHome("file:src/test/resources/conf");
+      server = MCServerFactory.createServer(classLoader);
+      server.setConfiguration(config);
+      server.initialize();
+      ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+      Thread.currentThread().setContextClassLoader(classLoader);
+      try
+      {
+         server.start();
+         
+         mainDeployer = getBean("MainDeployer", ControllerState.INSTALLED, MainDeployer.class);
+      }
+      finally
+      {
+         Thread.currentThread().setContextClassLoader(oldClassLoader);
+      }
+   }
+   
+   protected static void deploy(Deployment... deployments) throws DeploymentException
+   {
+      mainDeployer.deploy(deployments);
+   }
+   
+   protected static <T> Deployment deployment(String name, Class<T> attachmentType, T attachment)
+   {
+      try
+      {
+         URL url = new URL("vfsmemory", name, "");
+         VirtualFile root = VFS.getRoot(url);
+         VFSDeployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(root);
+         MutableAttachments attachments = (MutableAttachments) deployment.getPredeterminedManagedObjects();
+         attachments.addAttachment(attachmentType, attachment);
+         return deployment;
+      }
+      catch(IOException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   /**
+    * Get a bean
+    *
+    * @param name the name of the bean
+    * @param state the state of the bean
+    * @return the bean
+    * @throws IllegalStateException when the bean does not exist at that state
+    */
+   protected static Object getBean(final Object name, final ControllerState state) throws IllegalStateException
+   {
+      KernelControllerContext context = getControllerContext(name, state);
+      return context.getTarget();
+   }
+
+   /**
+    * Get a bean
+    *
+    * @param <T> the expected type
+    * @param name the name of the bean
+    * @param state the state of the bean
+    * @param expected the expected type
+    * @return the bean
+    * @throws ClassCastException when the bean can not be cast to the expected type
+    * @throws IllegalStateException when the bean does not exist at that state
+    */
+   protected static <T> T getBean(final Object name, final ControllerState state, final Class<T> expected) throws ClassCastException, IllegalStateException
+   {
+      if (expected == null)
+         throw new IllegalArgumentException("Null expected");
+      Object bean = getBean(name, state);
+      return expected.cast(bean);
+   }
+
+   /**
+    * Get a context
+    *
+    * @param name the name of the bean
+    * @param state the state of the bean
+    * @return the context
+    * @throws IllegalStateException when the context does not exist at that state
+    */
+   protected static KernelControllerContext getControllerContext(final Object name, final ControllerState state) throws IllegalStateException
+   {
+      KernelController controller = server.getKernel().getController();
+      KernelControllerContext context = (KernelControllerContext) controller.getContext(name, state);
+      if (context == null)
+         throw new IllegalStateException("Bean not found " + name + " at state " + state + " in controller " + controller);
+      return context;
+   }
+}

Modified: projects/reloaded/trunk/injection/src/test/java/org/jboss/reloaded/injection/test/simple/SimpleResourceBean.java
===================================================================
--- projects/reloaded/trunk/injection/src/test/java/org/jboss/reloaded/injection/test/simple/SimpleResourceBean.java	2009-05-29 07:56:59 UTC (rev 89523)
+++ projects/reloaded/trunk/injection/src/test/java/org/jboss/reloaded/injection/test/simple/SimpleResourceBean.java	2009-05-29 08:17:55 UTC (rev 89524)
@@ -21,20 +21,17 @@
  */
 package org.jboss.reloaded.injection.test.simple;
 
-import javax.annotation.Resource;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 
-import org.jboss.reloaded.injection.test.common.ManagedBean;
-
 /**
  * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
  * @version $Revision: $
  */
- at ManagedBean
+//@ManagedBean
 public class SimpleResourceBean
 {
-   @Resource(name="test")
+   //@Resource(name="test")
    private int test;
    
    public Object getCompEntry(String name) throws NamingException
@@ -42,4 +39,9 @@
       InitialContext ctx = new InitialContext();
       return ctx.lookup("java:comp/" + name);
    }
+   
+   public int getTest()
+   {
+      return test;
+   }
 }

Modified: projects/reloaded/trunk/injection/src/test/java/org/jboss/reloaded/injection/test/simple/unit/SimpleResourceTestCase.java
===================================================================
--- projects/reloaded/trunk/injection/src/test/java/org/jboss/reloaded/injection/test/simple/unit/SimpleResourceTestCase.java	2009-05-29 07:56:59 UTC (rev 89523)
+++ projects/reloaded/trunk/injection/src/test/java/org/jboss/reloaded/injection/test/simple/unit/SimpleResourceTestCase.java	2009-05-29 08:17:55 UTC (rev 89524)
@@ -21,32 +21,22 @@
  */
 package org.jboss.reloaded.injection.test.simple.unit;
 
+import static org.junit.Assert.assertEquals;
+
 import java.io.BufferedReader;
 import java.io.FileReader;
-import java.io.IOException;
-import java.net.URL;
+import java.lang.reflect.Method;
 
-import org.jboss.bootstrap.spi.lifecycle.LifecycleState;
-import org.jboss.bootstrap.spi.mc.config.MCServerConfig;
-import org.jboss.bootstrap.spi.mc.config.MCServerConfigFactory;
-import org.jboss.bootstrap.spi.mc.server.MCServer;
-import org.jboss.bootstrap.spi.mc.server.MCServerFactory;
 import org.jboss.dependency.spi.ControllerState;
 import org.jboss.deployers.client.spi.Deployment;
-import org.jboss.deployers.client.spi.main.MainDeployer;
-import org.jboss.deployers.spi.attachments.MutableAttachments;
-import org.jboss.deployers.vfs.spi.client.VFSDeployment;
-import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
-import org.jboss.kernel.spi.dependency.KernelController;
-import org.jboss.kernel.spi.dependency.KernelControllerContext;
 import org.jboss.reloaded.injection.ManagedBeanFactory;
+import org.jboss.reloaded.injection.ManagedBeanInstance;
 import org.jboss.reloaded.injection.metadata.ManagedBeanJarMetaData;
-import org.jboss.virtual.VFS;
-import org.jboss.virtual.VirtualFile;
+import org.jboss.reloaded.injection.test.common.AbstractInjectionTestCase;
+import org.jboss.reloaded.injection.test.simple.SimpleResourceBean;
 import org.jboss.xb.binding.Unmarshaller;
 import org.jboss.xb.binding.UnmarshallerFactory;
 import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
-import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -54,122 +44,21 @@
  * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
  * @version $Revision: $
  */
-public class SimpleResourceTestCase
+public class SimpleResourceTestCase extends AbstractInjectionTestCase
 {
-   private static MCServer server;
-   private static MainDeployer mainDeployer;
-   
-   @AfterClass
-   public static void afterClass() throws Exception
-   {
-      if(server != null && server.getState() == LifecycleState.STARTED)
-         server.shutdown();
-      server = null;
-   }
-   
    @BeforeClass
    public static void beforeClass() throws Exception
    {
-      VFS.init();
-      // TODO: use jboss-cl
-      ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-      MCServerConfig config = MCServerConfigFactory.createServerConfig(classLoader);
-      config.bootstrapHome("file:src/test/resources/conf");
-      server = MCServerFactory.createServer(classLoader);
-      server.setConfiguration(config);
-      server.initialize();
-      ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
-      Thread.currentThread().setContextClassLoader(classLoader);
-      try
-      {
-         server.start();
-         
-         mainDeployer = getBean("MainDeployer", ControllerState.INSTALLED, MainDeployer.class);
-      }
-      finally
-      {
-         Thread.currentThread().setContextClassLoader(oldClassLoader);
-      }
-   }
-   
-   private static <T> Deployment deployment(String name, Class<T> attachmentType, T attachment)
-   {
-      try
-      {
-         URL url = new URL("vfsmemory", name, "");
-         VirtualFile root = VFS.getRoot(url);
-         VFSDeployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(root);
-         MutableAttachments attachments = (MutableAttachments) deployment.getPredeterminedManagedObjects();
-         attachments.addAttachment(attachmentType, attachment);
-         return deployment;
-      }
-      catch(IOException e)
-      {
-         throw new RuntimeException(e);
-      }
-   }
-   
-   /**
-    * Get a bean
-    *
-    * @param name the name of the bean
-    * @param state the state of the bean
-    * @return the bean
-    * @throws IllegalStateException when the bean does not exist at that state
-    */
-   protected static Object getBean(final Object name, final ControllerState state) throws IllegalStateException
-   {
-      KernelControllerContext context = getControllerContext(name, state);
-      return context.getTarget();
-   }
-
-   /**
-    * Get a bean
-    *
-    * @param <T> the expected type
-    * @param name the name of the bean
-    * @param state the state of the bean
-    * @param expected the expected type
-    * @return the bean
-    * @throws ClassCastException when the bean can not be cast to the expected type
-    * @throws IllegalStateException when the bean does not exist at that state
-    */
-   protected static <T> T getBean(final Object name, final ControllerState state, final Class<T> expected) throws ClassCastException, IllegalStateException
-   {
-      if (expected == null)
-         throw new IllegalArgumentException("Null expected");
-      Object bean = getBean(name, state);
-      return expected.cast(bean);
-   }
-
-   /**
-    * Get a context
-    *
-    * @param name the name of the bean
-    * @param state the state of the bean
-    * @return the context
-    * @throws IllegalStateException when the context does not exist at that state
-    */
-   protected static KernelControllerContext getControllerContext(final Object name, final ControllerState state) throws IllegalStateException
-   {
-      KernelController controller = server.getKernel().getController();
-      KernelControllerContext context = (KernelControllerContext) controller.getContext(name, state);
-      if (context == null)
-         throw new IllegalStateException("Bean not found " + name + " at state " + state + " in controller " + controller);
-      return context;
-   }
-
-   @Test
-   public void test1() throws Throwable
-   {
-//      ManagedBeanJarMetaData jar = new ManagedBeanJarMetaData();
-//      List<ManagedBeanMetaData> managedBeans = new ArrayList<ManagedBeanMetaData>();
-//      jar.setManagedBeans(managedBeans);
-//      ManagedBeanMetaData managedBeanMetaData = new ManagedBeanMetaData();
-//      managedBeanMetaData.setName(SimpleResourceBean.class.getSimpleName());
-//      managedBeanMetaData.setBeanClass(SimpleResourceBean.class.getName());
-//      managedBeans.add(managedBeanMetaData);
+      AbstractInjectionTestCase.beforeClass();
       
+//    ManagedBeanJarMetaData jar = new ManagedBeanJarMetaData();
+//    List<ManagedBeanMetaData> managedBeans = new ArrayList<ManagedBeanMetaData>();
+//    jar.setManagedBeans(managedBeans);
+//    ManagedBeanMetaData managedBeanMetaData = new ManagedBeanMetaData();
+//    managedBeanMetaData.setName(SimpleResourceBean.class.getSimpleName());
+//    managedBeanMetaData.setBeanClass(SimpleResourceBean.class.getName());
+//    managedBeans.add(managedBeanMetaData);
+      
       Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
       unmarshaller.setSchemaValidation(false);
       unmarshaller.setValidation(false);
@@ -187,16 +76,31 @@
       }
       
       Deployment deployment = deployment("test1", ManagedBeanJarMetaData.class, jar);
-      mainDeployer.deploy(deployment);
-      
+      deploy(deployment);
+   }
+   
+   @Test
+   public void test1() throws Throwable
+   {
       ManagedBeanFactory<?> container = getBean("jboss:service=ManagedBean,name=SimpleResourceBean", ControllerState.INSTALLED, ManagedBeanFactory.class);
       
-      /*
       ManagedBeanInstance<?> bean = container.createBean();
       
       Method method = SimpleResourceBean.class.getMethod("getCompEntry", String.class);
       Object args[] = { "env/test" };
-      container.invoke(bean, method, args);
-      */
+      Object result = container.invoke(bean, method, args);
+      assertEquals(42, result);
    }
+   
+   @Test
+   public void test2() throws Throwable
+   {
+      ManagedBeanFactory<?> container = getBean("jboss:service=ManagedBean,name=SimpleResourceBean", ControllerState.INSTALLED, ManagedBeanFactory.class);
+      
+      ManagedBeanInstance<?> bean = container.createBean();
+      
+      Method method = SimpleResourceBean.class.getMethod("getTest");
+      Object result = container.invoke(bean, method, null);
+      assertEquals(42, result);      
+   }
 }

Modified: projects/reloaded/trunk/injection/src/test/resources/simple/jboss-mb.xml
===================================================================
--- projects/reloaded/trunk/injection/src/test/resources/simple/jboss-mb.xml	2009-05-29 07:56:59 UTC (rev 89523)
+++ projects/reloaded/trunk/injection/src/test/resources/simple/jboss-mb.xml	2009-05-29 08:17:55 UTC (rev 89524)
@@ -2,7 +2,7 @@
 <jboss-mb xmlns="http://www.jboss.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee
-                            http://www.jboss.org/j2ee/schema/jboss_mb_0_1.xsd"
+                            http://www.jboss.org/j2ee/schema/jboss-mb_0_1.xsd"
         version="0.1">
    <managed-beans>
       <managed-bean>
@@ -12,6 +12,10 @@
            <env-entry-name>test</env-entry-name>
            <env-entry-type>java.lang.Integer</env-entry-type>
            <env-entry-value>42</env-entry-value>
+           <injection-target>
+              <injection-target-class>org.jboss.reloaded.injection.test.simple.SimpleResourceBean</injection-target-class>
+              <injection-target-name>test</injection-target-name>
+           </injection-target>
         </env-entry>
       </managed-bean>
    </managed-beans>




More information about the jboss-cvs-commits mailing list