Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] String Trimming anyone???

Yep, I thought so, but for some reason I could not get my around() advice to work until you sent me yorus:  The following now works:
 
privileged aspect CaptureStringSets {
 void around(String val): set(* com.circuitcity.RtvCmRs.dto..*.*) && args(val) {
        System.out.println("Before[" + val + "]");
        System.out.println("Before[" + val.hashCode() + "]");
        val = val.trim();
        System.out.println("After[" + val + "]");
        System.out.println("After[" + val.hashCode() + "]");
        proceed(val);
    }
}
 
Thanks ALL!

	-----Original Message----- 
	From: Bo Yi [mailto:boyi@xxxxxxxxxx] 
	Sent: Thu 9/15/2005 4:40 PM 
	To: aspectj-users@xxxxxxxxxxx 
	Cc: aspectj-users@xxxxxxxxxxx; aspectj-users-bounces@xxxxxxxxxxx 
	Subject: Re: [aspectj-users] String Trimming anyone???
	
	

	Hi, 
	
	Java parameter is passing by value, thus val is a reference to the original string when it get into the this advice. And the assignment just assign the trimmed string to this parameter variable but never change the original string nor the parameter variable in the set. 
	
	You can achieve what you want with around advice: 
	
	void around (String val) : set(* dto..*.*) && args(val) { 
	        proceed (val.trim()); 
	} 
	
	Let me know if it works. 
	
	Regards, 
	
	Bo
	----------------------------------------------------------
	 Dr. Bo Yi
	 WebSphere Development & Testing
	 IBM Toronto Lab 
	 A2-713/Q2Z/8200/MKM
	 8200 Warden Ave. Markham ONT. L6G 1C7
	 Phone: 905-413-4819 
	 Tie Line: 969-4819
	 E-Mail: boyi@xxxxxxxxxx
	
	
	
	
"Ron DiFrango" <rdifrango@xxxxxxxxxxxxxxxxxxx> 
Sent by: aspectj-users-bounces@xxxxxxxxxxx 

09/15/2005 04:27 PM 
Please respond to
aspectj-users


To
<aspectj-users@xxxxxxxxxxx> 
cc
Subject
[aspectj-users] String Trimming anyone???	

		




	All,
	
	I am working with a database [DB2] where the fields are padded with spaces and I want to strip them on when I set the values in my DTO.  So I created the following aspect:
	
	privileged aspect CaptureStringSets {
	before(String val): set(* dto..*.*) && args(val) {
	       System.out.println("Before[" + val + "]");
	       val = val.trim();
	       System.out.println("After[" + val + "]");
	   }
	}
	
	Test Program:
	
	public class TestDBUtils {
	public static void main(String[] args) {
	 // TODO Auto-generated method stub
	 ApproveHeaderTO to = new ApproveHeaderTO();
	 to.setVendorName("Ron's Aspect Company       ");
	 System.out.println("{" + to.getVendorName() + "}");
	}
	}
	
	It properly captrues the join points, but the output is as follows:
	
	Before[Ron's Aspect Company ]
	After[Ron's Aspect Company]
	{Ron's Aspect Company }
	
	I am wondering why the change to the String is not taking affect, it is like a pass by value/reference thing, but I am not sure why.  Anyone else create such a monster?  
	
	BTW I thnk this would be a good re-usable aspect if we can get it working.
	
	Ron
	
	_______________________________________________
	aspectj-users mailing list
	aspectj-users@xxxxxxxxxxx
	https://dev.eclipse.org/mailman/listinfo/aspectj-users
	
	


Back to the top