[Jboss-cvs] JBossAS SVN: r55828 - in projects/microcontainer/trunk: dependency/src/main/org/jboss/dependency/spi kernel/src/main/org/jboss/beans/metadata kernel/src/main/org/jboss/beans/metadata/injection kernel/src/main/org/jboss/beans/metadata/plugins kernel/src/main/org/jboss/beans/metadata/spi kernel/src/main/org/jboss/beans/metadata/spi/annotations kernel/src/main/org/jboss/kernel/plugins/dependency kernel/src/main/org/jboss/kernel/plugins/deployment/xml kernel/src/resources/schema

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Aug 11 14:27:10 EDT 2006


Author: alesj
Date: 2006-08-11 14:26:51 -0400 (Fri, 11 Aug 2006)
New Revision: 55828

Added:
   projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/injection/
   projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/injection/InjectionMode.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/injection/InjectionType.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractInjectionValueMetaData.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/
   projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/Inject.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/InjectionHandler.java
Modified:
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/Controller.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractDependencyValueMetaData.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ConfigureAction.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/InstantiateAction.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBinding.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBinding20.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBindingHelper.java
   projects/microcontainer/trunk/kernel/src/resources/schema/bean-deployer_1_0.xsd
   projects/microcontainer/trunk/kernel/src/resources/schema/bean-deployer_2_0.xsd
Log:
Added 'contextual injection'.

Modified: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/Controller.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/Controller.java	2006-08-11 16:41:52 UTC (rev 55827)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/Controller.java	2006-08-11 18:26:51 UTC (rev 55828)
@@ -110,4 +110,22 @@
     * @return the states in order
     */
    List<ControllerState> getStates();
+
+   /**
+    * @return all instantiated beans that are instance of this class clazz param
+    */
+   Set getInstantiatedBeans(Class clazz);
+
+   /**
+    * add instantiated bean into beansByClass map
+    * look at all superclasses and interfaces
+    */
+   void addInstantiatedBean(Object bean);
+
+   /**
+    * remove instantiated bean from beansByClass map
+    * look at all superclasses and interfaces
+    */
+   void removeInstantiatedBean(Object bean);
+
 }

Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/injection/InjectionMode.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/injection/InjectionMode.java	2006-08-11 16:41:52 UTC (rev 55827)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/injection/InjectionMode.java	2006-08-11 18:26:51 UTC (rev 55828)
@@ -0,0 +1,64 @@
+/*
+ * 
+ */
+
+package org.jboss.beans.metadata.injection;
+
+import org.jboss.util.JBossObject;
+import org.jboss.util.JBossStringBuilder;
+
+/**
+ * @author <a href="mailto:ales.justin at genera-lynx.com">Ales Justin</a>
+ */
+public class InjectionMode extends JBossObject
+{
+   /** ByType */
+   public static final InjectionMode BY_TYPE = new InjectionMode("ByType");
+
+   /** ByName */
+   public static final InjectionMode BY_NAME = new InjectionMode("ByName");
+
+   /** The state string */
+   protected final String modeString;
+
+   /**
+    * Create a new state
+    *
+    * @param modeString the string representation
+    */
+   public InjectionMode(String modeString)
+   {
+      if (modeString == null)
+         throw new IllegalArgumentException("Null mode string");
+      this.modeString = modeString;
+   }
+
+   /**
+    * Get the state string
+    *
+    * @return the state string
+    */
+   public String getModeString()
+   {
+      return modeString;
+   }
+
+   public boolean equals(Object object)
+   {
+      if (object == null || object instanceof InjectionMode == false)
+         return false;
+      InjectionMode other = (InjectionMode) object;
+      return modeString.equals(other.getModeString());
+   }
+
+   public void toString(JBossStringBuilder buffer)
+   {
+      buffer.append(modeString);
+   }
+
+   protected int getHashCode()
+   {
+      return modeString.hashCode();
+   }
+
+}

Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/injection/InjectionType.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/injection/InjectionType.java	2006-08-11 16:41:52 UTC (rev 55827)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/injection/InjectionType.java	2006-08-11 18:26:51 UTC (rev 55828)
@@ -0,0 +1,64 @@
+/*
+ * 
+ */
+
+package org.jboss.beans.metadata.injection;
+
+import org.jboss.util.JBossObject;
+import org.jboss.util.JBossStringBuilder;
+
+/**
+ * @author <a href="mailto:ales.justin at genera-lynx.com">Ales Justin</a>
+ */
+public class InjectionType extends JBossObject
+{
+   /** Strict */
+   public static final InjectionType STRICT = new InjectionType("Strict");
+
+   /** Loose */
+   public static final InjectionType LOOSE = new InjectionType("Loose");
+
+   /** The type string */
+   protected final String typeString;
+
+   /**
+    * Create a new state
+    *
+    * @param modeString the string representation
+    */
+   public InjectionType(String typeString)
+   {
+      if (typeString == null)
+         throw new IllegalArgumentException("Null type string");
+      this.typeString = typeString;
+   }
+
+   /**
+    * Get the state string
+    *
+    * @return the state string
+    */
+   public String getTypeString()
+   {
+      return typeString;
+   }
+
+   public boolean equals(Object object)
+   {
+      if (object == null || object instanceof InjectionType == false)
+         return false;
+      InjectionType other = (InjectionType) object;
+      return typeString.equals(other.getTypeString());
+   }
+
+   public void toString(JBossStringBuilder buffer)
+   {
+      buffer.append(typeString);
+   }
+
+   protected int getHashCode()
+   {
+      return typeString.hashCode();
+   }
+
+}

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractDependencyValueMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractDependencyValueMetaData.java	2006-08-11 16:41:52 UTC (rev 55827)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractDependencyValueMetaData.java	2006-08-11 18:26:51 UTC (rev 55828)
@@ -81,16 +81,6 @@
    }
 
    /**
-    * Set the value
-    * 
-    * @param value the value
-    */
-   public void setValue(Object value)
-   {
-      super.setValue(value);
-   }
-   
-   /**
     * Get the property
     * 
     * @return the property
@@ -131,7 +121,7 @@
       ControllerState state = dependentState;
       if (state == null)
          state = ControllerState.INSTALLED;
-      ControllerContext context = controller.getContext(value, dependentState);
+      ControllerContext context = controller.getContext(value, state);
       if (context == null)
          throw new Error("Should not be here - dependency failed! " + this);
       Object result = context.getTarget();

Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractInjectionValueMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractInjectionValueMetaData.java	2006-08-11 16:41:52 UTC (rev 55827)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractInjectionValueMetaData.java	2006-08-11 18:26:51 UTC (rev 55828)
@@ -0,0 +1,145 @@
+/*
+ * 
+ */
+
+package org.jboss.beans.metadata.plugins;
+
+import java.util.Set;
+
+import org.jboss.beans.metadata.injection.InjectionMode;
+import org.jboss.beans.metadata.injection.InjectionType;
+import org.jboss.beans.metadata.spi.MetaDataVisitor;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.util.JBossStringBuilder;
+
+/**
+ * Injection value.
+ *
+ * @author <a href="ales.justin at gmail.com">Ales Justin</a>
+ */
+public class AbstractInjectionValueMetaData extends AbstractDependencyValueMetaData
+{
+   protected InjectionMode injectionMode = InjectionMode.BY_TYPE;
+
+   protected InjectionType injectionType = InjectionType.STRICT;
+
+   protected AbstractPropertyMetaData propertyMetaData;
+
+   /**
+    * Create a new injection value
+    */
+   public AbstractInjectionValueMetaData()
+   {
+   }
+
+   /**
+    * Create a new injection value
+    *
+    * @param value the value
+    */
+   public AbstractInjectionValueMetaData(Object value)
+   {
+      super(value);
+   }
+
+   /**
+    * Create a new injection value
+    *
+    * @param value    the value
+    * @param property the property
+    */
+   public AbstractInjectionValueMetaData(Object value, String property)
+   {
+      super(value, property);
+   }
+
+   public InjectionMode getInjectionMode()
+   {
+      return injectionMode;
+   }
+
+   public void setInjectionMode(InjectionMode injectionMode)
+   {
+      this.injectionMode = injectionMode;
+   }
+
+   public InjectionType getInjectionType()
+   {
+      return injectionType;
+   }
+
+   public void setInjectionType(InjectionType injectionType)
+   {
+      this.injectionType = injectionType;
+   }
+
+   public AbstractPropertyMetaData getPropertyMetaData()
+   {
+      return propertyMetaData;
+   }
+
+   public void setPropertyMetaData(AbstractPropertyMetaData propertyMetaData)
+   {
+      this.propertyMetaData = propertyMetaData;
+   }
+
+   public Object getValue(TypeInfo info, ClassLoader cl) throws Throwable
+   {
+      if (value == null)
+      {
+         // what else to use here - if not info.getType?
+         Set beans = controller.getInstantiatedBeans(info.getType());
+         int numberOfMatchingBeans = beans.size();
+         if (numberOfMatchingBeans > 1)
+         {
+            throw new Error("Should not be here, too many matching beans - dependency failed! " + this);
+         }
+         else if (numberOfMatchingBeans == 0)
+         {
+            if (InjectionType.STRICT.equals(injectionType))
+            {
+               throw new Error("Should not be here, no bean matches class type - dependency failed! " + this);
+            }
+            return null;
+         }
+      }
+      return super.getValue(info, cl);
+   }
+
+   public void visit(MetaDataVisitor visitor)
+   {
+      // determine value
+      if (getUnderlyingValue() == null)
+      {
+         if (InjectionMode.BY_NAME.equals(injectionMode))
+         {
+            setValue(propertyMetaData.getName());
+         }
+         else if (InjectionMode.BY_TYPE.equals(injectionMode))
+         {
+            // set controller
+            KernelControllerContext controllerContext = visitor.getControllerContext();
+            controller = (KernelController) controllerContext.getController();
+            visitor.visit(this); // as in AbstractValueMetaData
+            // skip AbstractDependencyVMD.visit() - no value defined
+            return;
+         }
+         else
+         {
+            throw new IllegalArgumentException("Unknown injection mode=" + injectionMode);
+         }
+      }
+      super.visit(visitor);
+   }
+
+   public void toString(JBossStringBuilder buffer)
+   {
+      super.toString(buffer);
+      if (injectionMode != null)
+         buffer.append(" injectionMode=").append(injectionMode);
+      if (injectionType != null)
+         buffer.append(" injectionType=").append(injectionType);
+   }
+}

Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/Inject.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/Inject.java	2006-08-11 16:41:52 UTC (rev 55827)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/Inject.java	2006-08-11 18:26:51 UTC (rev 55828)
@@ -0,0 +1,23 @@
+/*
+ * 
+ */
+
+package org.jboss.beans.metadata.spi.annotations;
+
+/**
+ * @author <a href="mailto:ales.justin at genera-lynx.com">Ales Justin</a>
+ */
+public @interface Inject
+{
+
+   String bean() default "";
+
+   String property() default "";
+
+   String state() default "Installed";
+
+   String mode() default "byType";
+
+   String type() default "strict";
+
+}

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ConfigureAction.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ConfigureAction.java	2006-08-11 16:41:52 UTC (rev 55827)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ConfigureAction.java	2006-08-11 18:26:51 UTC (rev 55828)
@@ -25,12 +25,17 @@
 import java.util.Set;
 
 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.injection.InjectionMode;
+import org.jboss.beans.metadata.injection.InjectionType;
 import org.jboss.joinpoint.spi.TargettedJoinpoint;
 import org.jboss.kernel.Kernel;
 import org.jboss.kernel.spi.config.KernelConfigurator;
 import org.jboss.kernel.spi.dependency.KernelController;
 import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.reflect.spi.*;
+import org.jboss.dependency.spi.ControllerState;
 
 /**
  * ConfigureAction.
@@ -48,11 +53,13 @@
 
       Object object = context.getTarget();
       BeanInfo info = context.getBeanInfo();
+      // todo injectWherePossible - alesj
       BeanMetaData metaData = context.getBeanMetaData();
       Set joinPoints = configurator.getPropertySetterJoinPoints(info, metaData);
       setAttributes(context, object, joinPoints, false);
+//      resolveInjections(controller, info, object);
    }
-   
+
    public void uninstallAction(KernelControllerContext context)
    {
       KernelController controller = (KernelController) context.getController();
@@ -66,13 +73,14 @@
       {
          Set joinPoints = configurator.getPropertyNullerJoinPoints(info, metaData);
          setAttributes(context, object, joinPoints, true);
+//         nullifyInjections(controller, info, object, true);
       }
       catch (Throwable t)
       {
          log.warn("Error unconfiguring bean " + context, t);
       }
    }
-   
+
    /**
     * Set the attributes
     * 
@@ -87,7 +95,7 @@
       if (joinPoints.isEmpty() == false)
       {
          boolean trace = log.isTraceEnabled();
-         
+
          for (Iterator i = joinPoints.iterator(); i.hasNext();)
          {
             TargettedJoinpoint joinPoint = (TargettedJoinpoint) i.next();
@@ -111,4 +119,112 @@
          }
       }
    }
+
+   protected void resolveInjections(KernelController controller, BeanInfo info, Object target) throws Throwable
+   {
+      Set<PropertyInfo> propertys = info.getProperties();
+      for(PropertyInfo pi : propertys)
+      {
+         MethodInfo setter = pi.getSetter();
+         AnnotationValue annotation = setter.getAnnotation("org.jboss.beans.metadata.spi.annotations.Inject");
+         if (annotation != null)
+         {
+            AnnotationInfo annotationInfo = annotation.getAnnotationType();
+            AnnotationAttribute beanAttribute = annotationInfo.getAttribute("bean");
+            AnnotationAttribute propertyAttribute = annotationInfo.getAttribute("property");
+            AnnotationAttribute stateAttribute = annotationInfo.getAttribute("state");
+            AnnotationAttribute modeAttribute = annotationInfo.getAttribute("mode");
+            AnnotationAttribute typeAttribute = annotationInfo.getAttribute("type");
+            // todo - are these right values?
+            StringValue beanValue = (StringValue) beanAttribute.getDefaultValue();
+            StringValue propertyValue = (StringValue) propertyAttribute.getDefaultValue();
+            StringValue stateValue = (StringValue) stateAttribute.getDefaultValue();
+            StringValue modeValue = (StringValue) modeAttribute.getDefaultValue();
+            StringValue typeValue = (StringValue) typeAttribute.getDefaultValue();
+
+            String value = beanValue.getValue();
+            String bean = (value != null && value.length() > 0 ? value : null);
+            value = propertyValue.getValue();
+            String property = (value != null && value.length() > 0 ? value : null);
+            ControllerState state = new ControllerState(stateValue.getValue());
+            InjectionMode injectionMode = new InjectionMode(modeValue.getValue());
+            InjectionType injectionType = new InjectionType(typeValue.getValue());
+            Object result;
+            if (bean != null)
+            {
+               result = controller.getContext(bean, state);
+            }
+            else
+            {
+               if (InjectionMode.BY_TYPE.equals(injectionMode))
+               {
+                  Set beans = controller.getInstantiatedBeans(pi.getType().getType());
+                  int numberOfMatchingBeans = beans.size();
+                  if (numberOfMatchingBeans > 1)
+                  {
+                     throw new Error("Should not be here, too many matching beans - dependency failed! " + this);
+                  }
+                  else if (numberOfMatchingBeans == 0 && InjectionType.STRICT.equals(injectionType))
+                  {
+                     throw new Error("Should not be here, no bean matches class type - dependency failed! " + this);
+                  }
+                  result = getResult(controller, beans.iterator().next(), property);
+               }
+               else if (InjectionMode.BY_NAME.equals(injectionMode))
+               {
+                  Object beanObject = controller.getContext(pi.getName(), state);
+                  result = getResult(controller, beanObject, property);
+               }
+               else
+               {
+                  throw new IllegalArgumentException("Illegal injection mode: " + injectionMode);
+               }
+            }
+            setter.invoke(target, new Object[]{result});
+         }
+      }
+   }
+
+   protected Object getResult(KernelController controller, Object target, String property) throws Throwable
+   {
+      if (property != null)
+      {
+         KernelConfigurator configurator = controller.getKernel().getConfigurator();
+         BeanInfo beanInfo = configurator.getBeanInfo(target.getClass());
+         TargettedJoinpoint joinpoint = configurator.getPropertyGetterJoinPoint(beanInfo, property);
+         joinpoint.setTarget(target);
+         return joinpoint.dispatch();
+      }
+      return target;
+   }
+
+   protected void nullifyInjections(KernelController controller, BeanInfo info, Object target, boolean ignoreErrors) throws Throwable
+   {
+      Set<PropertyInfo> propertys = info.getProperties();
+      for(PropertyInfo pi : propertys)
+      {
+         MethodInfo setter = pi.getSetter();
+         AnnotationValue annotation = setter.getAnnotation("org.jboss.beans.metadata.spi.annotations.Inject");
+         if (annotation != null)
+         {
+            try
+            {
+               setter.invoke(target, new Object[]{null});
+            }
+            catch (Throwable t)
+            {
+               if (ignoreErrors)
+               {
+                  if (log.isTraceEnabled())
+                     log.trace("Ignored for " + pi, t);
+               }
+               else
+               {
+                  throw t;
+               }
+            }
+         }
+      }
+   }
+
 }
\ No newline at end of file

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/InstantiateAction.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/InstantiateAction.java	2006-08-11 16:41:52 UTC (rev 55827)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/InstantiateAction.java	2006-08-11 18:26:51 UTC (rev 55828)
@@ -33,7 +33,7 @@
 
 /**
  * InstantiateAction.
- * 
+ *
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @version $Revision$
  */
@@ -49,25 +49,30 @@
       BeanInfo info = context.getBeanInfo();
       final Joinpoint joinPoint = configurator.getConstructorJoinPoint(info, metaData.getConstructor(), metaData);
 
-      Object object = dispatchJoinPoint(context, joinPoint); 
+      Object object = dispatchJoinPoint(context, joinPoint);
       context.setTarget(object);
-      
+
       MetaDataContext metaCtx = context.getMetaDataContext();
       if (metaCtx != null)
       {
          metaCtx.setTarget(object);
       }
-      
+
       try
       {
-         if (object != null && context.getBeanInfo() == null)
+         if (object != null)
          {
-            info = configurator.getBeanInfo(object.getClass());
-            context.setBeanInfo(info);
+            if (context.getBeanInfo() == null)
+            {
+               info = configurator.getBeanInfo(object.getClass());
+               context.setBeanInfo(info);
+            }
+
+            if (object instanceof KernelControllerContextAware)
+               ((KernelControllerContextAware) object).setKernelControllerContext(context);
+
+//            controller.addInstantiatedBean(object);
          }
-         
-         if (object != null && object instanceof KernelControllerContextAware)
-            ((KernelControllerContextAware) object).setKernelControllerContext(context);
       }
       catch (Throwable t)
       {
@@ -75,14 +80,21 @@
          throw t;
       }
    }
-   
+
    public void uninstallAction(KernelControllerContext context)
    {
       try
       {
          Object object = context.getTarget();
-         if (object != null && object instanceof KernelControllerContextAware)
-            ((KernelControllerContextAware) object).unsetKernelControllerContext(context);
+         if (object != null)
+         {
+            if (object instanceof KernelControllerContextAware)
+               ((KernelControllerContextAware) object).unsetKernelControllerContext(context);
+
+//            KernelController controller = (KernelController) context.getController();
+//            controller.removeInstantiatedBean(object);
+         }
+
       }
       catch (Throwable ignored)
       {

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBinding.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBinding.java	2006-08-11 16:41:52 UTC (rev 55827)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBinding.java	2006-08-11 18:26:51 UTC (rev 55828)
@@ -29,23 +29,7 @@
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
 
-import org.jboss.beans.metadata.plugins.AbstractArrayMetaData;
-import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
-import org.jboss.beans.metadata.plugins.AbstractClassLoaderMetaData;
-import org.jboss.beans.metadata.plugins.AbstractCollectionMetaData;
-import org.jboss.beans.metadata.plugins.AbstractConstructorMetaData;
-import org.jboss.beans.metadata.plugins.AbstractDemandMetaData;
-import org.jboss.beans.metadata.plugins.AbstractDependencyMetaData;
-import org.jboss.beans.metadata.plugins.AbstractDependencyValueMetaData;
-import org.jboss.beans.metadata.plugins.AbstractLifecycleMetaData;
-import org.jboss.beans.metadata.plugins.AbstractListMetaData;
-import org.jboss.beans.metadata.plugins.AbstractMapMetaData;
-import org.jboss.beans.metadata.plugins.AbstractParameterMetaData;
-import org.jboss.beans.metadata.plugins.AbstractPropertyMetaData;
-import org.jboss.beans.metadata.plugins.AbstractSetMetaData;
-import org.jboss.beans.metadata.plugins.AbstractSupplyMetaData;
-import org.jboss.beans.metadata.plugins.AbstractValueMetaData;
-import org.jboss.beans.metadata.plugins.StringValueMetaData;
+import org.jboss.beans.metadata.plugins.*;
 import org.jboss.beans.metadata.plugins.factory.GenericBeanFactoryMetaData;
 import org.jboss.beans.metadata.spi.BeanMetaDataFactory;
 import org.jboss.beans.metadata.spi.DemandMetaData;
@@ -55,6 +39,8 @@
 import org.jboss.beans.metadata.spi.PropertyMetaData;
 import org.jboss.beans.metadata.spi.SupplyMetaData;
 import org.jboss.beans.metadata.spi.ValueMetaData;
+import org.jboss.beans.metadata.injection.InjectionMode;
+import org.jboss.beans.metadata.injection.InjectionType;
 import org.jboss.dependency.spi.ControllerMode;
 import org.jboss.dependency.spi.ControllerState;
 import org.jboss.kernel.plugins.deployment.AbstractKernelDeployment;
@@ -160,6 +146,9 @@
    /** The dependency binding */
    private static final QName dependencyTypeQName = new QName(BEAN_DEPLOYER_NS, "dependencyType");
 
+   /** The injection binding */
+   private static final QName injectionTypeQName = new QName(BEAN_DEPLOYER_NS, "injectionType");
+
    /** The inject element name */
    private static final QName injectQName = new QName(BEAN_DEPLOYER_NS, "inject");
 
@@ -958,6 +947,43 @@
          }
       });
 
+      // injection binding
+      TypeBinding injectionType = schemaBinding.getType(injectionTypeQName);
+      injectionType.setHandler(new DefaultElementHandler()
+      {
+         public Object startElement(Object parent, QName name, ElementBinding element)
+         {
+            return new AbstractInjectionValueMetaData();
+         }
+
+         public void setParent(Object parent, Object o, QName qName, ElementBinding element, ElementBinding parentElement)
+         {
+            AbstractPropertyMetaData x = (AbstractPropertyMetaData) parent;
+            AbstractInjectionValueMetaData child = (AbstractInjectionValueMetaData) o;
+            child.setPropertyMetaData(x);
+         }
+
+         public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
+         {
+            AbstractInjectionValueMetaData injection = (AbstractInjectionValueMetaData) o;
+            for (int i = 0; i < attrs.getLength(); ++i)
+            {
+               String localName = attrs.getLocalName(i);
+               if ("bean".equals(localName))
+                  injection.setValue(attrs.getValue(i));
+               else if ("property".equals(localName))
+                  injection.setProperty(attrs.getValue(i));
+               else if ("state".equals(localName))
+                  injection.setDependentState(new ControllerState(attrs.getValue(i)));
+               else if ("injectionMode".equals(localName))
+                  injection.setInjectionMode(new InjectionMode(localName));
+               else if ("injectionType".equals(localName))
+                  injection.setInjectionType(new InjectionType(localName));
+            }
+         }
+
+      });
+
       // value binding
       TypeBinding plainValueType = schemaBinding.getType(plainValueTypeQName);
       plainValueType.setHandler(new DefaultElementHandler()

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBinding20.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBinding20.java	2006-08-11 16:41:52 UTC (rev 55827)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBinding20.java	2006-08-11 18:26:51 UTC (rev 55828)
@@ -134,6 +134,9 @@
    /** The dependency binding */
    public static final QName dependencyTypeQName = new QName(BEAN_DEPLOYER_NS, "dependencyType");
 
+   /** The dependency binding */
+   public static final QName injectionTypeQName = new QName(BEAN_DEPLOYER_NS, "injectionType");
+
    /** The factory binding */
    public static final QName factoryTypeQName = new QName(BEAN_DEPLOYER_NS, "factoryType");
 
@@ -294,6 +297,10 @@
       TypeBinding dependencyType = schemaBinding.getType(dependencyTypeQName);
       BeanSchemaBindingHelper.initDependencyHandlers(dependencyType);
 
+      // injection binding
+      TypeBinding injectionType = schemaBinding.getType(injectionTypeQName);
+      BeanSchemaBindingHelper.initInjectionHandlers(injectionType);
+
       // factory binding
       TypeBinding factoryType = schemaBinding.getType(factoryTypeQName);
       BeanSchemaBindingHelper.initFactoryHandlers(factoryType);

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBindingHelper.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBindingHelper.java	2006-08-11 16:41:52 UTC (rev 55827)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBindingHelper.java	2006-08-11 18:26:51 UTC (rev 55828)
@@ -311,6 +311,16 @@
    }
 
    /**
+    * Initialize the handlers for the injection type
+    *
+    * @param dependencyType the dependency type
+    */
+   public static void initInjectionHandlers(TypeBinding dependencyType)
+   {
+      dependencyType.setHandler(InjectionHandler.HANDLER);
+   }
+
+   /**
     * Initialize the handlers for the factory type
     * 
     * @param factoryType the factory type

Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/InjectionHandler.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/InjectionHandler.java	2006-08-11 16:41:52 UTC (rev 55827)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/InjectionHandler.java	2006-08-11 18:26:51 UTC (rev 55828)
@@ -0,0 +1,61 @@
+/*
+ * 
+ */
+
+package org.jboss.kernel.plugins.deployment.xml;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+
+import org.jboss.beans.metadata.injection.InjectionMode;
+import org.jboss.beans.metadata.injection.InjectionType;
+import org.jboss.beans.metadata.plugins.AbstractInjectionValueMetaData;
+import org.jboss.beans.metadata.plugins.AbstractPropertyMetaData;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.xb.binding.sunday.unmarshalling.DefaultElementHandler;
+import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
+import org.xml.sax.Attributes;
+
+/**
+ * DependencyHandler.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 43106 $
+ */
+public class InjectionHandler extends DefaultElementHandler
+{
+   /** The handler */
+   public static final InjectionHandler HANDLER = new InjectionHandler();
+
+   public Object startElement(Object parent, QName name, ElementBinding element)
+   {
+      return new AbstractInjectionValueMetaData();
+   }
+
+   public void setParent(Object parent, Object o, QName qName, ElementBinding element, ElementBinding parentElement)
+   {
+      AbstractPropertyMetaData x = (AbstractPropertyMetaData) parent;
+      AbstractInjectionValueMetaData child = (AbstractInjectionValueMetaData) o;
+      child.setPropertyMetaData(x);
+   }
+
+   public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
+   {
+      AbstractInjectionValueMetaData injection = (AbstractInjectionValueMetaData) o;
+      for (int i = 0; i < attrs.getLength(); ++i)
+      {
+         String localName = attrs.getLocalName(i);
+         if ("bean".equals(localName))
+            injection.setValue(attrs.getValue(i));
+         else if ("property".equals(localName))
+            injection.setProperty(attrs.getValue(i));
+         else if ("state".equals(localName))
+            injection.setDependentState(new ControllerState(attrs.getValue(i)));
+         else if ("injectionMode".equals(localName))
+            injection.setInjectionMode(new InjectionMode(localName));
+         else if ("injectionType".equals(localName))
+            injection.setInjectionType(new InjectionType(localName));
+      }
+   }
+
+}

Modified: projects/microcontainer/trunk/kernel/src/resources/schema/bean-deployer_1_0.xsd
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/schema/bean-deployer_1_0.xsd	2006-08-11 16:41:52 UTC (rev 55827)
+++ projects/microcontainer/trunk/kernel/src/resources/schema/bean-deployer_1_0.xsd	2006-08-11 18:26:51 UTC (rev 55828)
@@ -246,6 +246,35 @@
       <xsd:attribute name="state" type="controllerStateType" use="optional"/>
    </xsd:complexType>
 
+   <!-- todo use extension with dependencyType -->
+   <xsd:complexType name="injectionType">
+      <xsd:annotation>
+         <xsd:documentation>
+           <![CDATA[
+           A dependency represents an injection into the bean.
+           They can be used anywhere a string value can appear.
+
+           e.g. Bean instance - "InjectedIntoMe".setSomeProperty("BeanInjected");
+           <bean name="InjectedIntoMe" ...>
+              <property name="someProperty"><inject bean="BeanInjected"/>
+           </bean>
+           <bean name="BeanInjected" .../>
+
+           e.g. Bean property - "InjectedIntoMe".setSomeProperty("BeanInjected".getOtherProperty());
+           <bean name="InjectedIntoMe" ...>
+              <property name="someProperty"><inject bean="BeanInjected" property="otherProperty"/>
+           </bean>
+           <bean name="BeanInjected" .../>
+           ]]>
+         </xsd:documentation>
+      </xsd:annotation>
+      <xsd:attribute name="bean" type="xsd:string" use="optional"/>
+      <xsd:attribute name="property" type="xsd:string" use="optional"/>
+      <xsd:attribute name="state" type="controllerStateType" use="optional"/>
+      <xsd:attribute name="injectionMode" type="xsd:string" use="optional" default="ByType"/>
+      <xsd:attribute name="injectionType" type="xsd:string" use="optional" default="Strict"/>
+   </xsd:complexType>
+
    <xsd:complexType name="parameterType" mixed="true">
       <xsd:annotation>
          <xsd:documentation>
@@ -381,6 +410,7 @@
          <xsd:element name="array" type="arrayType"/>
          <xsd:element name="map" type="mapType"/>
          <xsd:element name="inject" type="dependencyType"/>
+         <!--<xsd:element name="inject" type="injectionType"/>-->
          <xsd:element name="null">
             <xsd:complexType/>
          </xsd:element>

Modified: projects/microcontainer/trunk/kernel/src/resources/schema/bean-deployer_2_0.xsd
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/schema/bean-deployer_2_0.xsd	2006-08-11 16:41:52 UTC (rev 55827)
+++ projects/microcontainer/trunk/kernel/src/resources/schema/bean-deployer_2_0.xsd	2006-08-11 18:26:51 UTC (rev 55828)
@@ -303,6 +303,34 @@
       <xsd:attribute name="state" type="controllerStateType" use="optional"/>
    </xsd:complexType>
 
+   <xsd:complexType name="injectionType">
+      <xsd:annotation>
+         <xsd:documentation>
+           <![CDATA[
+           A dependency represents an injection into the bean.
+           They can be used anywhere a string value can appear.
+
+           e.g. Bean instance - "InjectedIntoMe".setSomeProperty("BeanInjected");
+           <bean name="InjectedIntoMe" ...>
+              <property name="someProperty"><inject bean="BeanInjected"/>
+           </bean>
+           <bean name="BeanInjected" .../>
+
+           e.g. Bean property - "InjectedIntoMe".setSomeProperty("BeanInjected".getOtherProperty());
+           <bean name="InjectedIntoMe" ...>
+              <property name="someProperty"><inject bean="BeanInjected" property="otherProperty"/>
+           </bean>
+           <bean name="BeanInjected" .../>
+           ]]>
+         </xsd:documentation>
+      </xsd:annotation>
+      <xsd:attribute name="bean" type="xsd:string" use="optional"/>
+      <xsd:attribute name="property" type="xsd:string" use="optional"/>
+      <xsd:attribute name="state" type="controllerStateType" use="optional"/>
+      <xsd:attribute name="injectionMode" type="xsd:string" use="optional" default="ByType"/>
+      <xsd:attribute name="injectionType" type="xsd:string" use="optional" default="Strict"/>
+   </xsd:complexType>
+
    <xsd:complexType name="factoryType">
       <xsd:annotation>
          <xsd:documentation>
@@ -470,6 +498,7 @@
          <xsd:element name="array" type="arrayType"/>
          <xsd:element name="map" type="mapType"/>
          <xsd:element name="inject" type="dependencyType"/>
+         <!--<xsd:element name="inject" type="injectionType"/>-->
          <xsd:element name="null">
             <xsd:complexType/>
          </xsd:element>




More information about the jboss-cvs-commits mailing list