Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
SV: [aspectj-users] Weird problem with declare parent andjavax.naming.InitialContext

Hi

Ok, I'll give execution a try - Funny though, it works for all other Aspects
I have that advice different classes. I was starting to wonder it it had
something to do with the fact that InitialContext resides with Java's rt.jar


Hermod

-----Opprinnelig melding-----
Fra: aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] På vegne av Andy Clement
Sendt: 21. januar 2008 17:49
Til: aspectj-users@xxxxxxxxxxx
Emne: Re: [aspectj-users] Weird problem with declare parent
andjavax.naming.InitialContext

You can get into trouble using declare parents and call together.  You will
be better using 'execution' if you can.  The resolution sequence the VM
chooses means we may not get to see things in the order we would like and so
your itd may not get applied soon enough.  There are a few open bugs on this
in bugzilla.

Andy.

On 21/01/2008, hermod.opstvedt@xxxxxxxxx <hermod.opstvedt@xxxxxxxxx> wrote:
>
>
>
> Hi
>
> I have several aspects that introduce a bean into several types, used 
> for management. All except one functions as intented. The culprit in 
> this case is javax.naming.InitialContext.
>
> In my aop.xml:
>
> <aspectj>
>         <!-- -showWeaveInfo -verbose -debug -->
>         <weaver
>                 options="-proceedOnError 
> -Xlintfile:META-INF/Xlint.properties -showWeaveInfo -verbose -debug"> 
> ...
>                 <include within="javax.naming.InitialContext+" /> ...
>         </weaver>
> ...
>         <aspects>
> ...
>                 <aspect
> name="no.dnbnor.it01.aspects.NamingServiceAspect" />
>                 <aspect
> name="no.dnbnor.it01.aspects.BaseAspect" /> ...
>         </aspects>
> </aspectj>
>
> My aspect:
>
> public aspect NamingServiceAspect extends BaseAspect {
>
>         public interface IInitialContextManagedBean {
>
>                 public InitialContextManagementBean getManagedBean();
>
>                 public void
> setManagedBean(InitialContextManagementBean context);
>         }
>
>         private InitialContextManagementBean 
> IInitialContextManagedBean.managementBean;
>
>         public InitialContextManagementBean
> IInitialContextManagedBean.getManagedBean() {
>                 return this.managementBean;
>         }
>
>         public void
> IInitialContextManagedBean.setManagedBean(
>                         InitialContextManagementBean context) {
>                 this.managementBean = context;
>         }
>
>         declare parents : javax.naming.Context+ implements 
> IInitialContextManagedBean; ...
>         public pointcut nsConstruction() : call(Context+.new(..)); ...
>         after() returning(Context context): nsConstruction(){
>                 if
> (thisJoinPointStaticPart.getSignature().getDeclaringType()
> != context
>                                 .getClass()) {
>                         System.err.println("Not context.getClass())");
>                         return;
>                 }
>                 // Check that we have not already managed this context
>                 if (((IInitialContextManagedBean) 
> context).getManagedBean() != null) {
>                         return;
>                 }
>                 System.out.println("In after nsConstruction");
>         }
> ..
> }
>
> My testclass:
> public class Test {
>
>         /**
>          * @param args
>          */
>         public static void main(String[] args) throws Exception {
>
>                 Test7 me = new Test7();
>                 me.doIt();
>         }
>
>         public void doIt() throws Exception {
>                 try {
>                         Context ctx1=new InitialContext();
>                 } catch (RemoteException e) {
>                         e.printStackTrace();
>                 } catch (CreateException e) {
>                         e.printStackTrace();
>                 }
>
>         }
>
> }
>
> When I run this, I get
>
> java.lang.ClassCastException: javax.naming.InitialContext
>         at
> no.dnbnor.it01.aspects.NamingServiceAspect.ajc$afterReturning$no_dnbno
> r_it01_aspects_NamingServiceAspect$1$75cc02b7(NamingServiceAspect.aj:5
> 7)
>
>         at no.dnbnor.it01.test.Test7.doIt(Test7.java:45)
>         at no.dnbnor.it01.test.Test.main(Test.java:23)
> Exception in thread "main"
>
> In the standard output I do get entries like [AppClassLoader@499b33db] 
> weaveinfo Join point 'constructor-call(void 
> javax.naming.InitialContext.<init>())' in Type 'no.dnbnor.it01.test.Test7'
> (Test7.java:45) advised by afterReturning advice from 
> 'no.dnbnor.it01.aspects.NamingServiceAspect'
> (NamingServiceAspect.aj:49)
>
> ...
> [AppClassLoader@499b33db] weaveinfo Extending interface set for type 
> 'com.ibm.ws.naming.util.WsnInitCtx' (WsnInitCtx.java) to include 
> 'no.dnbnor.it01.aspects.NamingServiceAspect$IInitialContextManagedBean'
> (NamingServiceAspect.aj)
>
> [AppClassLoader@499b33db] weaveinfo Type 
> 'com.ibm.ws.naming.util.WsnInitCtx' (WsnInitCtx.java) has intertyped 
> field from 'no.dnbnor.it01.aspects.NamingServiceAspect'
> (NamingServiceAspect.aj:'no.dnbnor.it01.aspectj.beans.InitialContextMa
> nagementBean
> no.dnbnor.it01.aspects.NamingServiceAspect$IInitialContextManagedBean.
> managementBean')
>
> However I never see a intertype declaration for InititalContext - 
> Anyone have a clue?
>
> Hermod * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
> * * *
> * * *
>
> This email with attachments is solely for the use of the individual or 
> entity to whom it is addressed. Please also be aware that the DnB NOR 
> Group cannot accept any payment orders or other legally binding 
> correspondence with customers as a part of an email.
>
> This email message has been virus checked by the anti virus programs 
> used in the DnB NOR Group.
>
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
> * * *
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users




Back to the top