[aspectwerkz-user] Hot deploying aspects

"Edwards, John C (Credit)" <[email protected]>
Newsgroups gmane.comp.java.aspectwerkz.user
Message-ID <AA27E643E40EBF41B50341BB8DBFB0F20E1F616E@gslnp13es.firmwide.corp.gs.com>
I have a simple example of hot deploying aspects which I'm trying to get
working. I have a simple aspect which is a field interceptor for a
collection. In my aspect I have two methods for deploying and undeploying
the aspect:

  public static void undeployAspect(String aspectName){
        Deployer.undeploy(aspectName,ClassLoader.getSystemClassLoader());
    }

    public static void deployAspect(String aspectName, String
collectionName) {
        String xmlDef = "<aspect name='" + aspectName
                + "'
class='"+FieldInterceptionAspect.class.getClass().getName()+"'
deployment-model='perClass'>"
                + "<pointcut name='interceptGet' expression='get(Collection
"+collectionName+")' />"
                + "</aspect>";
        System.out.println(xmlDef);
        Deployer.deploy(FieldInterceptionAspect.class, xmlDef);
    }


If I put an entry in aop.xml then the aspect is deployed to begin with and
then it appears I can undeploy it and redeploy it. Great. But I'd like to
move to a situation where aop.xml can be empty and I do everything (i.e.
register, set the pointcut and deploy) at runtime. Note that when aop.xml is
empty, my main class fails after the first call to Deployer.deploy(..) 


  public static void main(String args[]) {
         Company company = new Company();
         if(company.offices !=null){
             throw new RuntimeException("Offices should be null");
         }

         FieldInterceptionAspect.deployAspect("fieldInterceptor",
"com.quantboy.domain.Company.offices");
         Company company1 = new Company();
         if(company.offices ==null){
             throw new RuntimeException("Offices should not be null after
hot deployment");
         }

         FieldInterceptionAspect.undeployAspect("fieldInterceptor");
         Company company2 = new Company();
         if(company2.offices!=null){
             throw new RuntimeException("Offices should be null after Aspect
is hot undeployed");
         }

         FieldInterceptionAspect.deployAspect("fieldInterceptor",
"com.quantboy.domain.Company.offices");
         Company company3 = new Company();
         if(company3.offices==null){
             throw new RuntimeException("Locations should not be null after
Aspect is hot deployed");
         }


Am I trying to do something which is impossible? I'm quite fuzzy about the
notion of hot-deploying. Can one only hot deploy an aspect which is
prespecified in aop.xml ?


Regards,


John
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.