[jboss-cvs] JBossAS SVN: r71972 - in projects/component-injection/trunk/src/tests/org/jboss/test/component: support and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 10 14:49:04 EDT 2008


Author: scott.stark at jboss.org
Date: 2008-04-10 14:49:04 -0400 (Thu, 10 Apr 2008)
New Revision: 71972

Added:
   projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/
   projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BaseContext.java
   projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/Bean1Type.java
   projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/Bean2Type.java
   projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BeanContainer.java
   projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BeanContext.java
   projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BeanContextFactory.java
   projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BeanPool.java
   projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BeanUser.java
   projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/InstanceInterceptor.java
   projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/TestInjectionMetaData.java
   projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/TestInjectionTargetMetaData.java
   projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/TestPooledBeanFactory.java
   projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/plugin/
   projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/spi/
Removed:
   projects/component-injection/trunk/src/tests/org/jboss/test/component/container/
Log:
Copy and update the component injection tests from the kernel

Added: projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BaseContext.java
===================================================================
--- projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BaseContext.java	                        (rev 0)
+++ projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BaseContext.java	2008-04-10 18:49:04 UTC (rev 71972)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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.test.component.support.container;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @param <B> the bean type
+ * @param <C> the container type
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class BaseContext <B, C extends BeanContainer<B>>
+   implements BeanContext<C>
+{
+   protected static Logger log = Logger.getLogger(BaseContext.class);
+   protected C container;
+   protected B bean;
+   
+   protected List<Object> interceptorInstances = new ArrayList<Object>();
+
+   public BaseContext(C container)
+   {
+      this.container = container;
+      log.info("ctor, container: "+container);
+   }
+
+   public C getContainer()
+   {
+      return container;
+   }
+
+   public B getInstance()
+   {
+      return bean;
+   }
+   public void setInstance(B bean)
+   {
+      this.bean = bean;
+      log.info("setInstance, bean: "+bean);
+   }
+
+   public List<Object> getInterceptors()
+   {
+      return interceptorInstances;
+   }
+
+   public void initialiseInterceptorInstances()
+   {  
+   }
+   public void addInterceptor(Object interceptor)
+   {
+      interceptorInstances.add(interceptor);
+      log.info("addInterceptor, "+interceptor);
+   }
+   public void removeInterceptor(Object interceptor)
+   {
+      interceptorInstances.remove(interceptor);
+      log.info("removeInterceptor, "+interceptor);
+   }
+   public void remove()
+   {
+      // TODO Auto-generated method stub
+      
+   }
+}

Added: projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/Bean1Type.java
===================================================================
--- projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/Bean1Type.java	                        (rev 0)
+++ projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/Bean1Type.java	2008-04-10 18:49:04 UTC (rev 71972)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, 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.test.component.support.container;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 71333 $
+ */
+public class Bean1Type
+{
+   private static Logger log = Logger.getLogger(Bean1Type.class);
+   private String prop1;
+
+   public Bean1Type()
+   {
+      log.debug("Bean1Type.ctor, this="+this);
+   }
+
+   public String getProp1()
+   {
+      return prop1;
+   }
+   public void setProp1(String prop1)
+   {
+      this.prop1 = prop1;
+   }
+}

Added: projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/Bean2Type.java
===================================================================
--- projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/Bean2Type.java	                        (rev 0)
+++ projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/Bean2Type.java	2008-04-10 18:49:04 UTC (rev 71972)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, 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.test.component.support.container;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 71025 $
+ */
+public class Bean2Type
+{
+   private Bean1Type bean1;
+
+   public Bean1Type getBean1()
+   {
+      return bean1;
+   }
+
+   public void setBean1(Bean1Type bean1)
+   {
+      this.bean1 = bean1;
+   }
+}

Added: projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BeanContainer.java
===================================================================
--- projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BeanContainer.java	                        (rev 0)
+++ projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BeanContainer.java	2008-04-10 18:49:04 UTC (rev 71972)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, 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.test.component.support.container;
+
+/**
+ * @param <T> the type
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 71195 $
+ */
+public class BeanContainer<T>
+{
+   private BeanPool<T> pool;
+
+   
+   public BeanPool<T> getPool()
+   {
+      return pool;
+   }
+   public void setPool(BeanPool<T> pool)
+   {
+      this.pool = pool;
+   }
+
+   @SuppressWarnings("unchecked")
+   public T getBean()
+      throws Throwable
+   {
+      T bean = pool.createBean();
+      return bean;
+   }
+   public void destroyBean(T bean)
+      throws Throwable
+   {
+      pool.destroyBean(bean);
+   }
+}

Added: projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BeanContext.java
===================================================================
--- projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BeanContext.java	                        (rev 0)
+++ projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BeanContext.java	2008-04-10 18:49:04 UTC (rev 71972)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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.test.component.support.container;
+
+/**
+ * @param <C> the container type
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public interface BeanContext<C extends BeanContainer<?>>
+{
+   Object getInstance();
+
+   C getContainer();
+
+   void initialiseInterceptorInstances();
+   
+   void remove();
+
+   //EJBContext getEJBContext();
+}

Added: projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BeanContextFactory.java
===================================================================
--- projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BeanContextFactory.java	                        (rev 0)
+++ projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BeanContextFactory.java	2008-04-10 18:49:04 UTC (rev 71972)
@@ -0,0 +1,210 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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.test.component.support.container;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.beans.info.spi.BeanAccessMode;
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.ValueMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.component.spi.ComponentBeanMetaDataFactory;
+import org.jboss.component.spi.ComponentNameBuilder;
+import org.jboss.component.spi.ComponentVisitor;
+import org.jboss.kernel.spi.config.KernelConfigurator;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.kernel.spi.dependency.KernelControllerContextAware;
+import org.jboss.logging.Logger;
+
+
+/**
+ * @param <T> the type
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class BeanContextFactory<T> implements ComponentBeanMetaDataFactory, KernelControllerContextAware
+{
+   private static final Logger log = Logger.getLogger(BeanContextFactory.class);
+   private String beanClass;
+   private BeanContainer<T> container;
+   private Set<TestInjectionMetaData> beanInjectionMD;
+   private KernelConfigurator configurator;
+   private Map<String, Set<TestInjectionMetaData>> interceptorInjectionMD =
+      new HashMap<String, Set<TestInjectionMetaData>>();
+   private List<String> interceptorNames;
+
+   public String getBeanClass()
+   {
+      return beanClass;
+   }
+   public void setBeanClass(String beanClass)
+   {
+      this.beanClass = beanClass;
+   }
+   public BeanContainer<T> getContainer()
+   {
+      return container;
+   }
+   public void setContainer(BeanContainer<T> container)
+   {
+      this.container = container;
+   }
+   public Set<TestInjectionMetaData> getBeanInjectionMD()
+   {
+      return beanInjectionMD;
+   }
+   public void setBeanInjectionMD(Set<TestInjectionMetaData> beanInjectionMD)
+   {
+      this.beanInjectionMD = beanInjectionMD;
+   }
+   public Map<String, Set<TestInjectionMetaData>> getInterceptorInjectionMD()
+   {
+      return interceptorInjectionMD;
+   }
+   public void setInterceptorInjectionMD(
+         Map<String, Set<TestInjectionMetaData>> interceptorInjectionMD)
+   {
+      this.interceptorInjectionMD = interceptorInjectionMD;
+   }
+   public List<String> getInterceptorNames()
+   {
+      return interceptorNames;
+   }
+   public void setInterceptorNames(List<String> interceptorNames)
+   {
+      this.interceptorNames = interceptorNames;
+   }
+
+   public void setKernelControllerContext(KernelControllerContext context)
+         throws Exception
+   {
+      if(context != null)
+      {
+         configurator = context.getKernel().getConfigurator();
+      }
+   }
+   public void unsetKernelControllerContext(KernelControllerContext context)
+         throws Exception
+   {
+      configurator = null;
+   }
+
+   /**
+    * Create the beans that make up the bean component
+    */
+   public List<BeanMetaData> getBeans(String baseName, long compID,
+         ComponentNameBuilder nameBuilder, ComponentVisitor visitor)
+   {
+      ArrayList<BeanMetaData> beans = new ArrayList<BeanMetaData>();
+      try
+      {         
+         // Create the BeanContext factory
+         String contextName = nameBuilder.buildName(baseName, "ContextFactory", compID);
+         BeanMetaDataBuilder contextBuilder = BeanMetaDataBuilder.createBuilder(contextName, BaseContext.class.getName());
+         contextBuilder.setAccessMode(BeanAccessMode.ALL);
+         // The BaseContext ctor
+         contextBuilder.addConstructorParameter(BeanContainer.class.getName(), container);
+         // BaseContext properties
+         // BaseContext.instance
+         String beanName = nameBuilder.buildName(baseName, "BeanInstance", compID);
+         ValueMetaData beanInstance = contextBuilder.createInject(beanName);
+         contextBuilder.addPropertyMetaData("instance", beanInstance);
+         // Call the visitor to augment the metadata
+         if(visitor != null)
+            visitor.visit(contextBuilder, baseName, "ContextFactory", compID);
+         BeanMetaData beanContext = contextBuilder.getBeanMetaData();
+         beans.add(beanContext);
+   
+         // Create the instance bean
+         BeanMetaDataBuilder beanBuilder = BeanMetaDataBuilder.createBuilder(beanName, beanClass);
+         beanBuilder.setAccessMode(BeanAccessMode.ALL);
+         // For every injection target get the associated property
+         if(beanInjectionMD != null)
+         {
+            addDependencyInjection(beanClass, beanInjectionMD, beanBuilder);
+         }
+         beans.add(beanBuilder.getBeanMetaData());
+   
+         // Create the interceptors
+         int count = interceptorNames != null ? interceptorNames.size() : 0;
+         for(int n = 0; n < count; n ++)
+         {
+            String iCompName = "Interceptor:"+n;
+            String iname = nameBuilder.buildName(baseName, iCompName, compID);
+            String iclass = interceptorNames.get(n);
+            BeanMetaDataBuilder ibuilder = BeanMetaDataBuilder.createBuilder(iname, iclass);
+            ibuilder.addInstallWithThis("addInterceptor", contextName);
+            ibuilder.addUninstallWithThis("removeInterceptor", contextName);
+            // Call the visitor to augment the metadata
+            if(visitor != null)
+               visitor.visit(contextBuilder, baseName, iCompName, compID);
+            Set<TestInjectionMetaData> injectMDs = interceptorInjectionMD.get(iclass);
+            if(injectMDs != null)
+               addDependencyInjection(beanClass, injectMDs, beanBuilder);
+            BeanMetaData interceptor = ibuilder.getBeanMetaData();
+            beans.add(interceptor);
+         }
+      }
+      catch(Throwable t)
+      {
+         log.error("Failed to create component beans", t);
+         throw new RuntimeException(t);
+      }
+      log.info("getBeans returning: "+beans);
+      return beans;
+   }
+
+   private void addDependencyInjection(String clazzName,
+         Set<TestInjectionMetaData> injectMDs,
+         BeanMetaDataBuilder beanBuilder)
+         throws Throwable
+   {
+      ClassLoader loader = getClass().getClassLoader();
+      BeanInfo beanInfo = configurator.getBeanInfo(clazzName, loader);
+      for(TestInjectionMetaData injectMD : injectMDs)
+      {
+         if(injectMD.getInjectionTargets() != null)
+         {
+            for(TestInjectionTargetMetaData targetMD : injectMD.getInjectionTargets())
+            {
+               ValueMetaData injectValue = beanBuilder.createInject(injectMD.getResolvedJndiName());
+               String targetName = targetMD.getInjectionTargetName();
+               PropertyInfo pinfo = beanInfo.getProperty(targetName);
+               if(pinfo != null)
+               {
+                  beanBuilder.addPropertyMetaData(targetName, injectValue);
+               }
+               else
+               {
+                  log.warn("No property found for injection target:"+targetName+", on bean: "+beanClass);
+               }
+            }
+         }
+      }
+   }
+}

Added: projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BeanPool.java
===================================================================
--- projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BeanPool.java	                        (rev 0)
+++ projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BeanPool.java	2008-04-10 18:49:04 UTC (rev 71972)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, 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.test.component.support.container;
+
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+import org.jboss.beans.metadata.spi.factory.BeanFactory;
+import org.jboss.logging.Logger;
+
+/**
+ * 
+ * @param <T> the type
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 71916 $
+ */
+public class BeanPool<T>
+{
+   private Logger log;
+   /** The pooling policy */
+   private ArrayBlockingQueue<T> pool;
+   private boolean poolInitialized = false;
+   private BeanFactory factory;
+
+   public BeanPool()
+   {
+      this(3);
+   }
+   public BeanPool(int capacity)
+   {
+      pool = new ArrayBlockingQueue<T>(capacity);
+   }
+
+   public BeanFactory getFactory()
+   {
+      return factory;
+   }
+
+   public void setFactory(BeanFactory factory)
+   {
+      this.factory = factory;
+   }
+
+   public int size()
+   {
+      return pool.size();
+   }
+   public int remainingCapacity()
+   {
+      return pool.remainingCapacity();
+   }
+
+   @SuppressWarnings("unchecked")
+   public synchronized T createBean()
+      throws Throwable
+   {
+      if(poolInitialized == false)
+      {
+         T bean = (T) factory.createBean();
+         pool.put(bean);
+         log = Logger.getLogger("BeanPool<"+bean.getClass().getSimpleName()+">");
+         log.debug("createBean, initializing pool, remainingCapacity: "+pool.remainingCapacity());
+         int capacity = pool.remainingCapacity();
+         // Fill the pool
+         for(int n = 0; n < capacity; n ++)
+         {
+            bean = (T) factory.createBean();
+            pool.put(bean);
+         }
+         poolInitialized = true;
+      }
+      T bean = pool.poll(1, TimeUnit.SECONDS);
+      if(bean == null)
+         throw new IllegalStateException(this+" is emtpy");
+      log.debug("End createBean, size: "+pool.size()+", bean: "+bean);
+      return bean;
+   }
+   @SuppressWarnings("unchecked")
+   public void destroyBean(T bean)
+      throws Throwable
+   {
+      bean = (T) factory.createBean();
+      pool.put(bean);
+   }
+   public void releaseBean(T bean)
+      throws Throwable
+   {
+      pool.put(bean);
+   }
+}

Added: projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BeanUser.java
===================================================================
--- projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BeanUser.java	                        (rev 0)
+++ projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/BeanUser.java	2008-04-10 18:49:04 UTC (rev 71972)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, 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.test.component.support.container;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 71025 $
+ */
+public class BeanUser
+{
+   private Bean1Type bean1;
+   private Bean2Type bean2;
+
+   public Bean1Type getBean1()
+   {
+      return bean1;
+   }
+   public void setBean1(Bean1Type bean1)
+   {
+      this.bean1 = bean1;
+   }
+   public Bean2Type getBean2()
+   {
+      return bean2;
+   }
+   public void setBean2(Bean2Type bean2)
+   {
+      this.bean2 = bean2;
+   }
+
+   
+}

Added: projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/InstanceInterceptor.java
===================================================================
--- projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/InstanceInterceptor.java	                        (rev 0)
+++ projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/InstanceInterceptor.java	2008-04-10 18:49:04 UTC (rev 71972)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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.test.component.support.container;
+
+import java.lang.reflect.Method;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class InstanceInterceptor
+{
+   private static Logger log = Logger.getLogger(InstanceInterceptor.class);
+   private BeanPool<BeanContext<?>> pool;
+
+   public InstanceInterceptor()
+   {
+      log.info("ctor");
+   }
+
+   public Object invoke(Object...args)
+      throws Throwable
+   {
+      BeanContext<?> ctx = pool.createBean();
+      Object bean = ctx.getInstance();
+
+      boolean discard = false;
+      Object value = null;
+
+      try
+      {
+         String name = (String) args[0];
+         Class<?>[] paramTypes = {};
+         Method m = bean.getClass().getMethod(name, paramTypes);
+         Object[] empty = {};
+         value = m.invoke(bean, empty);
+         return value;
+      }
+      catch (Exception ex)
+      {
+         throw ex;
+      }
+      finally
+      {
+         if (discard)
+            pool.destroyBean(ctx);
+         else pool.releaseBean(ctx);
+      }
+   }
+}

Added: projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/TestInjectionMetaData.java
===================================================================
--- projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/TestInjectionMetaData.java	                        (rev 0)
+++ projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/TestInjectionMetaData.java	2008-04-10 18:49:04 UTC (rev 71972)
@@ -0,0 +1,160 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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.test.component.support.container;
+
+import java.util.Set;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class TestInjectionMetaData
+{
+   /** The mapped name */
+   private String mappedName;
+   private String resolvedJndiName;
+   private boolean ignoreDependency;
+
+   /** The injection targets */
+   private Set<TestInjectionTargetMetaData> injectionTargets;
+   
+   /**
+    * Create a new ResourceInjectionMetaData.
+    */
+   public TestInjectionMetaData()
+   {
+      // For serialization
+   }
+
+   /**
+    * Get the jndiName.
+    * 
+    * @return the jndiName.
+    */
+   public String getJndiName()
+   {
+      return getMappedName();
+   }
+
+   /**
+    * Set the jndiName.
+    * 
+    * @param jndiName the jndiName.
+    * @throws IllegalArgumentException for a null jndiName
+    */
+   public void setJndiName(String jndiName)
+   {
+      setMappedName(jndiName);
+   }
+   
+   /**
+    * Get the mappedName.
+    * 
+    * @return the mappedName.
+    */
+   public String getMappedName()
+   {
+      return mappedName;
+   }
+
+   /**
+    * Set the mappedName.
+    * 
+    * @param mappedName the mappedName.
+    * @throws IllegalArgumentException for a null mappedName
+    */
+   public void setMappedName(String mappedName)
+   {
+      if (mappedName == null)
+         throw new IllegalArgumentException("Null mappedName");
+      this.mappedName = mappedName;
+   }
+
+   /**
+    * An unmanaged runtime jndi name for the resource. Used by deployers to
+    * propagate resolved resource location.
+    * 
+    * @return the resolved jndi name
+    */
+   public String getResolvedJndiName()
+   {
+      return resolvedJndiName;
+   }
+   public void setResolvedJndiName(String resolvedJndiName)
+   {
+      this.resolvedJndiName = resolvedJndiName;
+   }
+
+   /**
+    * Get the injectionTargets.
+    * 
+    * @return the injectionTargets.
+    */
+   public Set<TestInjectionTargetMetaData> getInjectionTargets()
+   {
+      return injectionTargets;
+   }
+
+   /**
+    * Set the injectionTargets.
+    * 
+    * @param injectionTargets the injectionTargets.
+    * @throws IllegalArgumentException for a null injectionTargets
+    */
+   public void setInjectionTargets(Set<TestInjectionTargetMetaData> injectionTargets)
+   {
+      if (injectionTargets == null)
+         throw new IllegalArgumentException("Null injectionTargets");
+      this.injectionTargets = injectionTargets;
+   }
+
+   /**
+    * Get the ignoreDependency.
+    * 
+    * @return the ignoreDependency.
+    */
+   public boolean getIgnoreDependency()
+   {
+      return ignoreDependency;
+   }
+
+   /**
+    * Set the ignoreDependency.
+    * 
+    * @param flag the ignoreDependency.
+    * @throws IllegalArgumentException for a null ignoreDependency
+    */
+   public void setIgnoreDependency(boolean flag)
+   {
+      this.ignoreDependency = flag;
+   }
+
+   /**
+    * Get whether the dependency is ignored
+    * 
+    * @return true when the dependency is ignored
+    */
+   public boolean isDependencyIgnored()
+   {
+      return ignoreDependency;
+   }
+}

Added: projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/TestInjectionTargetMetaData.java
===================================================================
--- projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/TestInjectionTargetMetaData.java	                        (rev 0)
+++ projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/TestInjectionTargetMetaData.java	2008-04-10 18:49:04 UTC (rev 71972)
@@ -0,0 +1,127 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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.test.component.support.container;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class TestInjectionTargetMetaData
+{
+   /** The injection target class */
+   private String injectionTargetClass;
+   
+   /** The injection target name */
+   private String injectionTargetName;
+   
+   /**
+    * Create a new ResourceInjectionTargetMetaData.
+    */
+   public TestInjectionTargetMetaData()
+   {
+   }
+
+   /**
+    * Get the injectionTargetClass.
+    * 
+    * @return the injectionTargetClass.
+    */
+   public String getInjectionTargetClass()
+   {
+      return injectionTargetClass;
+   }
+
+   /**
+    * Set the injectionTargetClass.
+    * 
+    * @param injectionTargetClass the injectionTargetClass.
+    * @throws IllegalArgumentException for a null injectionTargetClass
+    */
+   //@JBossXmlNsPrefix(prefix="jee")
+   public void setInjectionTargetClass(String injectionTargetClass)
+   {
+      if (injectionTargetClass == null)
+         throw new IllegalArgumentException("Null injectionTargetClass");
+      this.injectionTargetClass = injectionTargetClass;
+   }
+
+   /**
+    * Get the injectionTargetName.
+    * 
+    * @return the injectionTargetName.
+    */
+   public String getInjectionTargetName()
+   {
+      return injectionTargetName;
+   }
+
+   /**
+    * Set the injectionTargetName.
+    * 
+    * @param injectionTargetName the injectionTargetName.
+    * @throws IllegalArgumentException for a null injectionTargetName
+    */
+   //@JBossXmlNsPrefix(prefix="jee")
+   public void setInjectionTargetName(String injectionTargetName)
+   {
+      if (injectionTargetName == null)
+         throw new IllegalArgumentException("Null injectionTargetName");
+      this.injectionTargetName = injectionTargetName;
+   }
+
+   @Override
+   public int hashCode()
+   {
+      final int PRIME = 31;
+      int result = 1;
+      result = PRIME * result + ((injectionTargetClass == null) ? 0 : injectionTargetClass.hashCode());
+      result = PRIME * result + ((injectionTargetName == null) ? 0 : injectionTargetName.hashCode());
+      return result;
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (this == obj)
+         return true;
+      if (obj == null)
+         return false;
+      if (getClass() != obj.getClass())
+         return false;
+      final TestInjectionTargetMetaData other = (TestInjectionTargetMetaData) obj;
+      if (injectionTargetClass == null)
+      {
+         if (other.injectionTargetClass != null)
+            return false;
+      }
+      else if (!injectionTargetClass.equals(other.injectionTargetClass))
+         return false;
+      if (injectionTargetName == null)
+      {
+         if (other.injectionTargetName != null)
+            return false;
+      }
+      else if (!injectionTargetName.equals(other.injectionTargetName))
+         return false;
+      return true;
+   }
+}

Added: projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/TestPooledBeanFactory.java
===================================================================
--- projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/TestPooledBeanFactory.java	                        (rev 0)
+++ projects/component-injection/trunk/src/tests/org/jboss/test/component/support/container/TestPooledBeanFactory.java	2008-04-10 18:49:04 UTC (rev 71972)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, 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.test.component.support.container;
+
+import org.jboss.beans.metadata.plugins.factory.GenericBeanFactory;
+import org.jboss.kernel.spi.config.KernelConfigurator;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 71105 $
+ */
+public class TestPooledBeanFactory extends GenericBeanFactory
+{
+   public TestPooledBeanFactory(KernelConfigurator configurator, int size)
+   {
+      super(configurator);
+   }
+}




More information about the jboss-cvs-commits mailing list