<?xml version="1.0" encoding="UTF-8"?>

<deployment xmlns="urn:jboss:bean-deployer:2.0">

   <bean name="Repository" class="org.jboss.metadata.plugins.repository.basic.BasicMetaDataRepository"/>

   <bean name="AspectManager" class="org.jboss.aop.AspectManager">
      <constructor factoryClass="org.jboss.aop.AspectManager" factoryMethod="instance"/>
   </bean>

	<!-- Define the jndi binding advice -->
   <beanfactory name="JndiAdvice" class="org.jboss.aop.microcontainer.aspects.jndi.JndiIntroduction">
   	<property name="env">
           <map class="java.util.Properties" keyClass="java.lang.String" valueClass="java.lang.String">
              <entry>
                 <key>java.naming.factory.initial</key>
                 <value>org.jboss.example.microcontainer.aspects.EnvInitialContextFactory</value>
              </entry>
           </map>
   	</property>
   </beanfactory>

   <bean name="JndiAspect" class="org.jboss.aop.microcontainer.beans.Aspect">
      <property name="advice"><inject bean="JndiAdvice"/></property>
      <property name="manager"><inject bean="AspectManager"/></property>
   </bean>

   <!-- Introduce the KernelControllerContextAware interface to the JndiBinding annotation -->
   <bean name="JndiIntroduction" class="org.jboss.aop.microcontainer.beans.IntroductionBinding">
      <property name="classes">@org.jboss.aop.microcontainer.aspects.jndi.JndiBinding</property>
      <property name="interfaces">
         <list elementClass="java.lang.String">
            <value>org.jboss.kernel.spi.dependency.KernelControllerContextAware</value>
         </list>
      </property>
      <property name="manager"><inject bean="AspectManager"/></property>
   </bean>

   <!-- Apply the jndi binding to all KernelControllerContextAware interface callbacks -->
   <bean name="JndiBinding" class="org.jboss.aop.microcontainer.beans.AspectBinding">
      <property name="pointcut">execution(* $instanceof{org.jboss.kernel.spi.dependency.KernelControllerContextAware}->$implements{org.jboss.kernel.spi.dependency.KernelControllerContextAware}(..))</property>
      <property name="aspect"><inject bean="JndiAspect" property="definition"/></property>
      <property name="manager"><inject bean="AspectManager"/></property>
   </bean>

   <bean name="Bean" class="org.jboss.example.microcontainer.aspects.SimpleBean">
      <annotation>@org.jboss.aop.microcontainer.aspects.jndi.JndiBinding(name="beans/SimpleBean", aliases={"beans/XmlAnnotatedSimpleBean"})</annotation>
   </bean>

   <bean name="AnnotatedBean" class="org.jboss.example.microcontainer.aspects.AnnotatedSimpleBean" />

   <bean name="lookup" class="org.jboss.example.microcontainer.aspects.SimpleBeanLookup">
      <property name="env">
           <map class="java.util.Properties" keyClass="java.lang.String" valueClass="java.lang.String">
              <entry>
                 <key>java.naming.factory.initial</key>
                 <value>org.jboss.example.microcontainer.aspects.EnvInitialContextFactory</value>
              </entry>
           </map>
      </property>
      <demand>JndiBinding</demand>
   </bean>

</deployment>
