[jboss-cvs] JBossAS SVN: r83562 - projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vdf.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jan 28 11:03:07 EST 2009


Author: alesj
Date: 2009-01-28 11:03:07 -0500 (Wed, 28 Jan 2009)
New Revision: 83562

Added:
   projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vdf/AbstractBeanFactoryVDFConnector.java
   projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vdf/AbstractBeanTypeVDFConnector.java
   projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vdf/AbstractBeanVDFConnector.java
   projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vdf/SimpleBeanVDFConnector.java
Log:
Add bean vdf connectors.

Added: projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vdf/AbstractBeanFactoryVDFConnector.java
===================================================================
--- projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vdf/AbstractBeanFactoryVDFConnector.java	                        (rev 0)
+++ projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vdf/AbstractBeanFactoryVDFConnector.java	2009-01-28 16:03:07 UTC (rev 83562)
@@ -0,0 +1,63 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.seam.integration.jbossas.vdf;
+
+import javax.servlet.ServletContext;
+
+import org.jboss.beans.metadata.spi.factory.BeanFactory;
+
+/**
+ * AbstractBeanFactoryTypeVDFConnector.
+ *
+ * @param <T> exact bean type
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AbstractBeanFactoryVDFConnector<T> extends AbstractBeanVDFConnector<T, BeanFactory>
+{
+   protected AbstractBeanFactoryVDFConnector(ServletContext servletContext)
+   {
+      super(servletContext);
+   }
+
+   protected Class<BeanFactory> getBeanType()
+   {
+      return BeanFactory.class;
+   }
+
+   @Override
+   protected T unwrap(BeanFactory factory)
+   {
+      try
+      {
+         Object bean = factory.createBean();
+         Class<T> type = getUnwrappedType();
+         if (type.isInstance(bean) == false)
+            throw new IllegalArgumentException("Bean " + bean + " is not instance of " + type);
+
+         return type.cast(bean);
+      }
+      catch (Throwable t)
+      {
+         throw new RuntimeException(t);
+      }
+   }
+}
\ No newline at end of file

Added: projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vdf/AbstractBeanTypeVDFConnector.java
===================================================================
--- projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vdf/AbstractBeanTypeVDFConnector.java	                        (rev 0)
+++ projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vdf/AbstractBeanTypeVDFConnector.java	2009-01-28 16:03:07 UTC (rev 83562)
@@ -0,0 +1,43 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.seam.integration.jbossas.vdf;
+
+import javax.servlet.ServletContext;
+
+/**
+ * AbstractBeanTypeVDFConnector.
+ *
+ * @param <T> exact bean type
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AbstractBeanTypeVDFConnector<T> extends SimpleBeanVDFConnector<T>
+{
+   protected AbstractBeanTypeVDFConnector(ServletContext servletContext)
+   {
+      super(servletContext);
+   }
+
+   protected Object getBeanKey()
+   {
+      return getBeanType();
+   }
+}
\ No newline at end of file

Added: projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vdf/AbstractBeanVDFConnector.java
===================================================================
--- projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vdf/AbstractBeanVDFConnector.java	                        (rev 0)
+++ projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vdf/AbstractBeanVDFConnector.java	2009-01-28 16:03:07 UTC (rev 83562)
@@ -0,0 +1,136 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.seam.integration.jbossas.vdf;
+
+import javax.servlet.ServletContext;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
+import org.jboss.kernel.spi.dependency.KernelController;
+
+/**
+ * AbstractBeanVDFConnector.
+ *
+ * @param <U> exact unwrapped type
+ * @param <T> exact bean type
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AbstractBeanVDFConnector<U, T> extends AbstractVDFConnector<U, Kernel>
+{
+   /** The bean state */
+   private ControllerState state;
+
+   public AbstractBeanVDFConnector(ServletContext servletContext)
+   {
+      super(servletContext);
+   }
+
+   protected Class<Kernel> getAttributeType()
+   {
+      return Kernel.class;
+   }
+
+   protected String getAttributeKey()
+   {
+      return KernelConstants.KERNEL_NAME;
+   }
+
+   /**
+    * Get bean key.
+    *
+    * @return the bean key
+    */
+   protected abstract Object getBeanKey();
+
+   /**
+    * The bean type.
+    *
+    * @return the bean type
+    */
+   protected abstract Class<T> getBeanType();
+
+   /**
+    * Get unwrapped type.
+    * e.g. bean might be bean factory
+    *
+    * @return the unwrapped type
+    */
+   protected abstract Class<U> getUnwrappedType();
+
+   /**
+    * Unwrap bean.
+    * Default impl just re-casts.
+    *
+    * @param bean the bean
+    * @return unwrapped bean
+    */
+   protected U unwrap(T bean)
+   {
+      Class<U> unwrappedType = getUnwrappedType();
+      if (unwrappedType.isInstance(bean) == false)
+         throw new IllegalArgumentException("Bean " + bean + " is not instance of " + unwrappedType);
+
+      return unwrappedType.cast(bean);
+   }
+
+   protected U getUtilityFromAttribute(Kernel kernel)
+   {
+      KernelController controller = kernel.getController();
+      ControllerContext context;
+      if (state == null)
+         context = controller.getContext(getBeanKey(), state);
+      else
+         context = controller.getInstalledContext(getBeanKey());
+
+      if (context == null)
+         return null;
+
+      Object target = context.getTarget();
+      Class<T> beanType = getBeanType();
+      if (beanType.isInstance(target) == false)
+         throw new IllegalArgumentException("Bean " + target + " is not instance of " + beanType);
+
+      return unwrap(beanType.cast(target));
+   }
+
+   /**
+    * Set the expected bean state.
+    *
+    * @param state the bean state
+    */
+   public void setState(ControllerState state)
+   {
+      this.state = state;
+   }
+
+   @Override
+   public String toString()
+   {
+      StringBuilder builder = new StringBuilder();
+      builder.append("bean=").append(getBeanKey());
+      if (state != null)
+         builder.append(", state=").append(state);
+      return builder.toString();
+   }
+}
\ No newline at end of file

Added: projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vdf/SimpleBeanVDFConnector.java
===================================================================
--- projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vdf/SimpleBeanVDFConnector.java	                        (rev 0)
+++ projects/jboss-seam-int/trunk/jbossas/src/main/java/org/jboss/seam/integration/jbossas/vdf/SimpleBeanVDFConnector.java	2009-01-28 16:03:07 UTC (rev 83562)
@@ -0,0 +1,43 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.seam.integration.jbossas.vdf;
+
+import javax.servlet.ServletContext;
+
+/**
+ * AbstractBeanTypeVDFConnector.
+ *
+ * @param <T> exact bean type
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class SimpleBeanVDFConnector<T> extends AbstractBeanVDFConnector<T, T>
+{
+   protected SimpleBeanVDFConnector(ServletContext servletContext)
+   {
+      super(servletContext);
+   }
+
+   protected Class<T> getUnwrappedType()
+   {
+      return getBeanType();
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list