3 Replies Latest reply on Aug 25, 2004 2:25 PM by Bill Burke

    Setting dynamic metadata

    rkadayam Newbie

      When I browse the API it seems like I could do some dynamic metadata setting (SimpleMetaData and ThreadMetaData) but again not entirely sure if its possible.

      Can anyone illustrate a sample of how I could maybe associate some metadata to a method pointcut (crosscutting session beans) after everything has been deployed and would expect it to be visible in Interceptor/Advice implementations.

      Bear in mind that the entity that would be doing the actual dynamic metada setting may only have visibility to the "AspectManager" instance and not the actual java bean that is being aspected.

      The idea being that I could set ad-hoc properties at the pointcut level which would be more dynamic than the properties at the interceptor/advice level.

      Thanks
      Rajiv

        • 1. Re: Setting dynamic metadata
          rkadayam Newbie

          I think there is a bug in AspectManager.addClassMetaData. The line

          if (meta.matches(advisor, advisor.getClass()))
          


          should actually be

          if (meta.matches(advisor, ((ClassAdvisor)advisor).getClazz()))
          



          I've rephrased the method implementation here.

          
           public void addClassMetaData(ClassMetaDataBinding meta)
           {
           removeClassMetaData(meta.getName());
           synchronized (advisors)
           {
           Iterator it = advisors.values().iterator();
           while (it.hasNext())
           {
           Advisor advisor = (Advisor) it.next();
           if (advisor instanceof ClassAdvisor) {
           if (meta.matches(advisor, ((ClassAdvisor)advisor).getClazz()))
           {
           meta.addAdvisor(advisor);
           }
           }
           }
           synchronized (classMetaData)
           {
           classMetaData.put(meta.getName(), meta);
           }
           }
          


          After this fix, I managed to get the meta-data that were set dynamically as illustrated in the previous post.

          Would it be possible to roll this fix into the CVS Head

          thanks
          rajiv

          • 2. Re: Setting dynamic metadata
            rkadayam Newbie

            I think there is a bug in AspectManager.addClassMetaData. The line

            if (meta.matches(advisor, advisor.getClass()))
            


            should actually be

            if (meta.matches(advisor, ((ClassAdvisor)advisor).getClazz()))
            



            I've rephrased the method implementation here.

            
             public void addClassMetaData(ClassMetaDataBinding meta)
             {
             removeClassMetaData(meta.getName());
             synchronized (advisors)
             {
             Iterator it = advisors.values().iterator();
             while (it.hasNext())
             {
             Advisor advisor = (Advisor) it.next();
             if (advisor instanceof ClassAdvisor) {
             if (meta.matches(advisor, ((ClassAdvisor)advisor).getClazz()))
             {
             meta.addAdvisor(advisor);
             }
             }
             }
             synchronized (classMetaData)
             {
             classMetaData.put(meta.getName(), meta);
             }
             }
            


            After this fix, I managed to get the meta-data that were set dynamically as illustrated in the previous post.

            Would it be possible to roll this fix into the CVS Head

            thanks
            rajiv