Package org.jboss.aop.advice

Examples of org.jboss.aop.advice.AdviceBinding


      loader2.addClassMetaData("class", "class2");
      loader2.addMethodMetaData("* someMethod(..)", "fm", "someMethod2");
      loader2.addFieldMetaData("i", "fm", "i2");
     
      getInstanceDomain(pojo1).addClassMetaData(loader1.getClassMetaDataBinding());
      AdviceBinding binding1 = new AdviceBinding("all(@TEST)", null);
      binding1.addInterceptor(MetadataInterceptor.class);
      getInstanceDomain(pojo1).addBinding(binding1);
     
      AdviceBinding binding2 = new AdviceBinding("all(@TEST)", null);
      getInstanceDomain(pojo2).addClassMetaData(loader2.getClassMetaDataBinding());
      binding2.addInterceptor(MetadataInterceptor.class);
      getInstanceDomain(pojo2).addBinding(binding2);
     
      AdviceBinding binding3 = new AdviceBinding("all(org.jboss.test.aop.dynamicgenadvisor.POJO)", null);
      binding3.addInterceptor(MetadataInterceptor.class);
      getInstanceDomain(pojo3).addBinding(binding3);
     
      MetadataInterceptor.clear();
      System.out.println("---POJO1 set i");
      pojo1.i = 10;
View Full Code Here


      POJO pojo = new POJO();
      POJO pojo1 = new POJO();
      pojo.someMethod(123);
      assertFalse(MetadataInterceptor.intercepted);

      AdviceBinding binding1 = new AdviceBinding("all(org.jboss.test.aop.dynamicgenadvisor.POJO)", null);
      binding1.addInterceptor(MetadataInterceptor.class);
      AspectManager.instance().addBinding(binding1);

      DynamicSimpleClassMetadataLoader loader = new DynamicSimpleClassMetadataLoader(
            "TEST", "org.jboss.test.aop.dynamicgenadvisor.POJO");
      loader.addDefaultMetaData("default", "default");
      loader.addClassMetaData("class", "class");
      loader.addMethodMetaData("* someMethod(..)", "fm", "someMethod");
      loader.addFieldMetaData("i", "fm", "i");
      AspectManager.instance().addClassMetaData(loader.getClassMetaDataBinding());
     
      DynamicSimpleClassMetadataLoader instanceLoader = new DynamicSimpleClassMetadataLoader(
            "TEST", "org.jboss.test.aop.dynamicgenadvisor.POJO");
      instanceLoader.addDefaultMetaData("default", "defaultXXX");
      instanceLoader.addClassMetaData("class", "classXXX");
      instanceLoader.addMethodMetaData("* someMethod(..)", "fm", "someMethodXXX");
      instanceLoader.addFieldMetaData("i", "fm", "iXXX");
      getInstanceDomain(pojo1).addClassMetaData(instanceLoader.getClassMetaDataBinding());

      MetadataInterceptor.clear();
      pojo.someMethod(123);
      pojo.i = 1000;
      assertEquals(2, MetadataInterceptor.lastDefaultMetadata.size());
      assertEquals(2, MetadataInterceptor.lastClassMetadata.size());
      assertEquals(1, MetadataInterceptor.lastMethodMetadata.size());
      assertEquals(1, MetadataInterceptor.lastFieldMetadata.size());
     
      //Make sure we get the metadata expected
      assertEquals("default", MetadataInterceptor.lastDefaultMetadata.get(0));
      assertEquals("default", MetadataInterceptor.lastDefaultMetadata.get(1));
     
      assertEquals("class", MetadataInterceptor.lastClassMetadata.get(0));
      assertEquals("class", MetadataInterceptor.lastClassMetadata.get(1));
     
      assertEquals("someMethod", MetadataInterceptor.lastMethodMetadata.get(0));
     
      assertEquals("i", MetadataInterceptor.lastFieldMetadata.get(0));

      MetadataInterceptor.clear();
      pojo1.someMethod(123);
      pojo1.i = 1000;
      assertEquals(2, MetadataInterceptor.lastDefaultMetadata.size());
      assertEquals(2, MetadataInterceptor.lastClassMetadata.size());
      assertEquals(1, MetadataInterceptor.lastMethodMetadata.size());
      assertEquals(1, MetadataInterceptor.lastFieldMetadata.size());
     
      //Make sure we get the metadata expected
      assertEquals("defaultXXX", MetadataInterceptor.lastDefaultMetadata.get(0));
      assertEquals("defaultXXX", MetadataInterceptor.lastDefaultMetadata.get(1));
     
      assertEquals("classXXX", MetadataInterceptor.lastClassMetadata.get(0));
      assertEquals("classXXX", MetadataInterceptor.lastClassMetadata.get(1));
     
      assertEquals("someMethodXXX", MetadataInterceptor.lastMethodMetadata.get(0));
     
      assertEquals("iXXX", MetadataInterceptor.lastFieldMetadata.get(0));


      getInstanceDomain(pojo1).removeClassMetaData(instanceLoader.getClassMetaDataBinding().getName());
     
      MetadataInterceptor.clear();
      pojo1.someMethod(123);
      pojo1.i = 1000;
      assertEquals(2, MetadataInterceptor.lastDefaultMetadata.size());
      assertEquals(2, MetadataInterceptor.lastClassMetadata.size());
      assertEquals(1, MetadataInterceptor.lastMethodMetadata.size());
      assertEquals(1, MetadataInterceptor.lastFieldMetadata.size());
     
      //Make sure we get the metadata expected
      assertEquals("default", MetadataInterceptor.lastDefaultMetadata.get(0));
      assertEquals("default", MetadataInterceptor.lastDefaultMetadata.get(1));
     
      assertEquals("class", MetadataInterceptor.lastClassMetadata.get(0));
      assertEquals("class", MetadataInterceptor.lastClassMetadata.get(1));
     
      assertEquals("someMethod", MetadataInterceptor.lastMethodMetadata.get(0));
     
      assertEquals("i", MetadataInterceptor.lastFieldMetadata.get(0));
     
      AspectManager.instance().removeClassMetaData(loader.getClassMetaDataBinding().getName());
      AspectManager.instance().removeBinding(binding1.getName());
      MetadataInterceptor.clear();
      pojo.someMethod(123);
      assertFalse(MetadataInterceptor.intercepted);
   }
View Full Code Here

   {
      try
      {
//         new Caller2();  // concallcon wont work if the class is already loaded by the cl
        
         AdviceBinding bindingCall = new AdviceBinding(
               "call(org.jboss.test.aop.rebuildcallerchain.Caller1->new(int))", null);
         bindingCall.addInterceptor(RebuildCallerChainInterceptor.class);
         AspectManager.instance().addBinding(bindingCall);

         RebuildCallerChainInterceptor.call = false;
         new Caller2(true);
         assertTrue("caller2 was not rebuilded", RebuildCallerChainInterceptor.call);
View Full Code Here

   {
      try
      {
         new Caller1().execute();
        
         AdviceBinding bindingCall = new AdviceBinding(
               "call(* org.jboss.test.aop.rebuildcallerchain.*->execute())", null);
         bindingCall.addInterceptor(RebuildCallerChainInterceptor.class);
         AspectManager.instance().addBinding(bindingCall);

         new Caller1().execute();
         assertTrue("caller1 was not rebuilded", RebuildCallerChainInterceptor.call);
         RebuildCallerChainInterceptor.call = false;
View Full Code Here

   public void removeBinding(String name)
   {
      lock.lockWrite();
      try
      {
         AdviceBinding binding = internalRemoveBinding(name);
         if (binding != null)
         {
            binding.clearAdvisors();
            dynamicStrategy.interceptorChainsUpdated();
         }
      }
      finally
      {
View Full Code Here

    * Add an interceptor pointcut with a given name
    */
   public void addBinding(AdviceBinding binding)
   {
      Set<Advisor> affectedAdvisors = null;
      AdviceBinding removedBinding = null;
      lock.lockWrite();
      try
      {
         removedBinding = internalRemoveBinding(binding.getName());
         affectedAdvisors = removedBinding == null ? null : new HashSet<Advisor>(removedBinding.getAdvisors());        
         bindingCollection.add(binding, this);
         synchronized (advisors)
         {
            Set<Advisor> handledAdvisors = new HashSet<Advisor>();
            updateAdvisorsForAddedBinding(binding, handledAdvisors);
View Full Code Here

    *
    * @param name the binding to be removed.
    */
   private AdviceBinding internalRemoveBinding(String name)
   {
      AdviceBinding binding = bindingCollection.removeBinding(name);
      if (binding == null)
      {
         return null;
      }
      Pointcut pointcut = binding.getPointcut();
      this.removePointcut(pointcut.getName());
      return binding;
   }
View Full Code Here

      AspectDefinition def = new AspectDefinition("aspect" + index, scope, new GenericAspectFactory(aspectClass, null));
     
      InterceptorFactory advice = (adviceName != null) ? new AdviceFactory(def, "advice") : new ScopedInterceptorFactory(def);
      PointcutExpression pc = new PointcutExpression("pc2" + index, pointcut);
      InterceptorFactory[] interceptors = {advice};
      AdviceBinding binding = new AdviceBinding("binding" + index, pc, null, null, interceptors);

      manager.addAspectDefinition(def);
      manager.addInterceptorFactory(advice.getName(), advice);
      manager.addPointcut(pc);
      manager.addBinding(binding);
View Full Code Here

      //PointcutExpression pointcut = new PointcutExpression("pointcut", "execution(java.lang.String $instanceof{" + POJO.class.getName() + "}->helloWorld(..))");
      {
      PointcutExpression pointcut = new PointcutExpression("pointcut", "execution(java.lang.String " + POJO.class.getName() + "->helloWorld(..))");
      domain.addPointcut(pointcut);
      InterceptorFactory[] interceptors = {advice};
      AdviceBinding binding = new AdviceBinding("pojo-binding", pointcut, null, null, interceptors);
      domain.addBinding(binding);
      }

      {
      PointcutExpression pointcut = new PointcutExpression("mixin-pointcut", "execution(java.lang.String $instanceof{" + MixinInterface.class.getName() + "}->intercepted(..))");
      domain.addPointcut(pointcut);
      InterceptorFactory[] interceptors = {advice};
      AdviceBinding binding = new AdviceBinding("mixin-binding", pointcut, null, null, interceptors);
      domain.addBinding(binding);
      }

      Class<?> proxyClass = ContainerProxyFactory.getProxyClass(POJO.class, domain);
      ClassProxyContainer container = new ClassProxyContainer("test", domain);
View Full Code Here

      domain.addInterceptorFactory(advice.getName(), advice);
      {
      PointcutExpression pointcut = new PointcutExpression("pointcut", "execution(* " + POJOWithFinalMethods.class.getName() + "->*(..))");
      domain.addPointcut(pointcut);
      InterceptorFactory[] interceptors = {advice};
      AdviceBinding binding = new AdviceBinding("pojo-binding", pointcut, null, null, interceptors);
      domain.addBinding(binding);
      }

      Class<?> proxyClass = ContainerProxyFactory.getProxyClass(POJOWithFinalMethods.class, domain);
      ClassProxyContainer container = new ClassProxyContainer("test", domain);
View Full Code Here

TOP

Related Classes of org.jboss.aop.advice.AdviceBinding

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.