Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AspectJ » aspect in J2ee
aspect in J2ee [message #45206] Tue, 21 December 2004 01:07 Go to next message
Eclipse UserFriend
Originally posted by: sekar.gopinathan.fhlbny.com

Hi,
I am using aspects to do make my code independant of the J2EE container
without going into Spring framework. In order to accomplish this I have
a stateless session EJB that merely acts as wrapper providing
transactional capabilities. Inside the EJB, I instantialte a
BusinessService class and set the BusinessSessionContext(contains info
such as the current user). For every call to the ejb I set the context
and then call the business methods in the service object. I am planning
to refactor the application such that aspect sets the "business session
context" into the service object before calling the business methods of
the service. This will let the service know the currently logged on user
and hence can use this info during audit.(Which again is an aspect). So
I wrote two aspects
1. for setting the session context
2. for doing the audit after each service is completed
The aspects look like
1.
public aspect Context {

pointcut setSessionContext(AbstractBusinessServiceEjbBean
businessServiceEjb):
call(* AbstractBusinessService.execute(..)) &&
target(businessServiceEjb) ;

before(AbstractBusinessServiceEjbBean businessServiceEjb) throws
InvalidCTXParamException :setSessionContext(businessServiceEjb){
SessionContext sessionContext=new SessionContext();

sessionContext.storeContext(Constants.SESSION_CONTEXT_USER_K EY,businessServiceEjb.getUserId());
businessServiceEjb.getService().setSessionContext(sessionCon text);

}

}
2.
public aspect DoAudit {

pointcut writingAudit() :
call(* AuditService.execute(..));

declare warning : writingAudit() && !within(DoAudit)
: "Only DoAudit policy can call AuditService";

pointcut doAudit(AbstractBusinessService businessService) :
execution(* execute(..)) && this(businessService);

after(AbstractBusinessService businessService) throws SystemException :
doAudit(businessService) {
AuditService auditStep=null;
auditStep=(AuditService)new
BusinessFactory().create(AuditService.class.getName());
((AbstractBusinessService)auditStep).setSessionContext(busin essService.getSessionContext());
auditStep.execute((BusinessStep)businessService);
}

}
When I clean the project and rebuild the project, I get a BCEException
right around the line
" ((AbstractBusinessService)auditStep).setSessionContext(busin essService.getSessionContext()); "

Exception reads:
BCE Exception:illegal change to pointcut declaration:
setSessionContext(BindingTypePattern(com.xxx.backoffice.comm on.sb.Abs...(not
clear after this)

Note: I had my "incremental compile" turned on.

I am kind of stuck. Any help here appreciated.

Thanks
SG
Re: aspect in J2ee [message #45238 is a reply to message #45206] Tue, 21 December 2004 01:16 Go to previous message
Eclipse UserFriend
Originally posted by: sekar.gopinathan.fhlbny.com

Never mind. I was using the "setSessionContext" as the pointcut name.
This name is used inside the advice as well. Sorry for the confusion

Thanks


Sekar Gopinathan wrote:

> Hi,
> I am using aspects to do make my code independant of the J2EE container
> without going into Spring framework. In order to accomplish this I have
> a stateless session EJB that merely acts as wrapper providing
> transactional capabilities. Inside the EJB, I instantialte a
> BusinessService class and set the BusinessSessionContext(contains info
> such as the current user). For every call to the ejb I set the context
> and then call the business methods in the service object. I am planning
> to refactor the application such that aspect sets the "business session
> context" into the service object before calling the business methods of
> the service. This will let the service know the currently logged on user
> and hence can use this info during audit.(Which again is an aspect). So
> I wrote two aspects
> 1. for setting the session context
> 2. for doing the audit after each service is completed
> The aspects look like
> 1.
> public aspect Context {

> pointcut setSessionContext(AbstractBusinessServiceEjbBean
> businessServiceEjb):
> call(* AbstractBusinessService.execute(..)) &&
> target(businessServiceEjb) ;

> before(AbstractBusinessServiceEjbBean businessServiceEjb) throws
> InvalidCTXParamException :setSessionContext(businessServiceEjb){
> SessionContext sessionContext=new SessionContext();

>
sessionContext.storeContext(Constants.SESSION_CONTEXT_USER_K EY,businessServiceEjb.getUserId());
> businessServiceEjb.getService().setSessionContext(sessionCon text);

> }

> }
> 2.
> public aspect DoAudit {

> pointcut writingAudit() :
> call(* AuditService.execute(..));

> declare warning : writingAudit() && !within(DoAudit)
> : "Only DoAudit policy can call AuditService";

> pointcut doAudit(AbstractBusinessService businessService) :
> execution(* execute(..)) && this(businessService);

> after(AbstractBusinessService businessService) throws SystemException :
> doAudit(businessService) {
> AuditService auditStep=null;
> auditStep=(AuditService)new
> BusinessFactory().create(AuditService.class.getName());
>
((AbstractBusinessService)auditStep).setSessionContext(busin essService.getSessionContext());
> auditStep.execute((BusinessStep)businessService);
> }

> }
> When I clean the project and rebuild the project, I get a BCEException
> right around the line
>
" ((AbstractBusinessService)auditStep).setSessionContext(busin essService.getSessionContext()); "

> Exception reads:
> BCE Exception:illegal change to pointcut declaration:
> setSessionContext(BindingTypePattern(com.xxx.backoffice.comm on.sb.Abs...(not
> clear after this)

> Note: I had my "incremental compile" turned on.

> I am kind of stuck. Any help here appreciated.

> Thanks
> SG
Re: aspect in J2ee [message #585413 is a reply to message #45206] Tue, 21 December 2004 01:16 Go to previous message
Eclipse UserFriend
Originally posted by: sekar.gopinathan.fhlbny.com

Never mind. I was using the "setSessionContext" as the pointcut name.
This name is used inside the advice as well. Sorry for the confusion

Thanks


Sekar Gopinathan wrote:

> Hi,
> I am using aspects to do make my code independant of the J2EE container
> without going into Spring framework. In order to accomplish this I have
> a stateless session EJB that merely acts as wrapper providing
> transactional capabilities. Inside the EJB, I instantialte a
> BusinessService class and set the BusinessSessionContext(contains info
> such as the current user). For every call to the ejb I set the context
> and then call the business methods in the service object. I am planning
> to refactor the application such that aspect sets the "business session
> context" into the service object before calling the business methods of
> the service. This will let the service know the currently logged on user
> and hence can use this info during audit.(Which again is an aspect). So
> I wrote two aspects
> 1. for setting the session context
> 2. for doing the audit after each service is completed
> The aspects look like
> 1.
> public aspect Context {

> pointcut setSessionContext(AbstractBusinessServiceEjbBean
> businessServiceEjb):
> call(* AbstractBusinessService.execute(..)) &&
> target(businessServiceEjb) ;

> before(AbstractBusinessServiceEjbBean businessServiceEjb) throws
> InvalidCTXParamException :setSessionContext(businessServiceEjb){
> SessionContext sessionContext=new SessionContext();

>
sessionContext.storeContext(Constants.SESSION_CONTEXT_USER_K EY,businessServiceEjb.getUserId());
> businessServiceEjb.getService().setSessionContext(sessionCon text);

> }

> }
> 2.
> public aspect DoAudit {

> pointcut writingAudit() :
> call(* AuditService.execute(..));

> declare warning : writingAudit() && !within(DoAudit)
> : "Only DoAudit policy can call AuditService";

> pointcut doAudit(AbstractBusinessService businessService) :
> execution(* execute(..)) && this(businessService);

> after(AbstractBusinessService businessService) throws SystemException :
> doAudit(businessService) {
> AuditService auditStep=null;
> auditStep=(AuditService)new
> BusinessFactory().create(AuditService.class.getName());
>
((AbstractBusinessService)auditStep).setSessionContext(busin essService.getSessionContext());
> auditStep.execute((BusinessStep)businessService);
> }

> }
> When I clean the project and rebuild the project, I get a BCEException
> right around the line
>
" ((AbstractBusinessService)auditStep).setSessionContext(busin essService.getSessionContext()); "

> Exception reads:
> BCE Exception:illegal change to pointcut declaration:
> setSessionContext(BindingTypePattern(com.xxx.backoffice.comm on.sb.Abs...(not
> clear after this)

> Note: I had my "incremental compile" turned on.

> I am kind of stuck. Any help here appreciated.

> Thanks
> SG
Previous Topic:aspect in J2ee
Next Topic:AJDT and Eclipse 3.1M4
Goto Forum:
  


Current Time: Tue Apr 23 16:27:25 GMT 2024

Powered by FUDForum. Page generated in 0.03269 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top