Re: [aspectwerkz-user] Hot deploying aspects
Alexandre Vasseur <[email protected]>
| Newsgroups | gmane.comp.java.aspectwerkz.user |
|---|---|
| Message-ID | <[email protected]> |
in such a scenario, you should deploy the aspect to a deployment scope. Only the deployment scope will have to be defined in the aop.xml file. Alex On 4/20/05, Edwards, John C (Credit) <[email protected]> wrote: > 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 >