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

Title: Weird problem with declare parent and javax.naming.InitialContext

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_dnbnor_it01_aspects_NamingServiceAspect$1$75cc02b7(NamingServiceAspect.aj:57)

        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.InitialContextManagementBean 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.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *