Friday, January 23, 2009

calling java from arc

Rainbow adds six builtin functions for calling java code from arc. Theoretically this is all you need to interact with any java library from arc code.




java-new (classname . args)

Create and return a new instance of classname, passing args to the constructor


java-class (classname)

Return a java-object wrapping the class identified by classname


java-invoke (obj method . args)

Invoke method on obj with args. 'defcall binds this function to java-object so that you should only rarely need to call this explicitly. Return the value of the method if there
is any, wrapping into arc types where possible.


java-static-invoke (classname method . args)

Invoke static method on classname with args.


java-static-field (classname fieldname)

Return the value of the specified static field


java-implement (interfacename strictly methods)

Returns a java-object which implements the java interface identified by interfacename, the implementation being provided by the arc code given in methods, where methods is a hash mapping method-name to corresponding implementation. The strictly parameter determines whether an error should be raised if methods does not include all of the methods defined on the interface. java-implement is necessary for implementing, for example, mouse and keyboards handlers for a desktop application, or servlets and filters for a web application.




Following in the arc tradition of using arc-code wrappers for builtin functions (eg 'w/stdout for 'call-w/stdout, 'atomic for 'atomic-invoke, 'thread for 'new-thread), rainbow provides some wrappers to make java interaction a little less ugly and possibly a little more arcish. The 'implement macro removes some boilerplate around 'java-implement, so you can create an implementation of, for example, an iterator (where xs is a list) thus:



(def to-iterator (xs)
(implement "java.util.Iterator"
hasNext (fn () xs)
next (fn () (pop xs))))


The 'bean function instantiates and configures a java object via its setter methods. Here is an example of creating a JFrame object, specifying its bounds and title:



(def frame (left top width height title)
(bean "javax.swing.JFrame"
'bounds (list left top width height)
'title title
'contentPane (box 'vertical)))


Behind the scenes, bean is going to call setBounds, setTitle, and setContentPane on a newly-instantiated JFrame object, finally returning the JFrame.



There are lots more goodies defined in rainbow's swing.arc, but that's a topic for another day.

3 comments:

Unknown said...

Là 1 công ty Uy Tín – Đáng Tin Cậy. sở hữu nhiều năm kinh nghiệm trong lĩnh vực chi phí. Chúng tôi luôn đặt “Lời ích quý khách khi vay tiền lên hàng đầu”. Sau thoáng đãng năm phát triễn nghiên cứu. nhận diện được sự phiền toái và thủ tục rượm rà lúc vay tiền bây giờ. nên chúng tôi đưa ra giải pháp mới phù hợp sở hữu khuynh hướng mới Vay tiền mặt – có tiền nhanh trong ngày.

1. Thủ tục vay đơn thuần nhất hiện giờ
Chỉ nên giấy tờ không buộc phải giám định rườm rà. Bằng tài xế hoặc Hộ khẩu đã vay được tiền.
2. thời gian giải ngân tiền mặt nhanh nhất hiện thời
Cam kết xem xét hồ sơ trong 15 – 30 phút. Giải ngân tiền mặt sau 30 phút – tới 2h trường hợp khiến giấy tờ trước 21H Tối. Chúng tôi cam kết giải quyết trong ngày. ko để tồn sang hôm sau.
3. Vay toền online miễn là bạn có mạng internet
đa số khi số đông nơi. xem xét website. Chúng tôi sẽ mang chuyên viên tham vấn nhiều năm kinh nghiệm hỗ trợ bạn. Bạn không bắt buộc phải đi xa chờ đợi. Chỉ nhu cầu nhấc máy và gọi. Sẽ vay được tiền.
4. không hề tài sản bảo đảm, chẳng phải chứng tỏ thu nhập
Chỉ đề nghị thủ tục giản đơn như trên. Chúng tôi không buộc phải ai bảo lãnh khoản vay cho bạn. nên cực kỳ yên ổn tâm không làm cho phiền người nhà bạn.

vay tien nhanh, vay tiền nhanh, vay tiền online, vay tien online, vay tien, vay tiền, vay tien, vay tín chấp, vay tin chap, vay tiền nhanh nhất, vay tien nhanh online, vay tiền nhanh online, vay tiền online nhanh, vvay tien online nhanh,
vay tien nhanh nhat,

hallonahdace said...

Lucky Star Casino - Mapyro
Find the location of Lucky Star Casino, with address, telephone number, map, driving 태백 출장마사지 directions, 남양주 출장안마 and other information 당진 출장마사지 for Lucky Star Casino, 안성 출장안마 Las 밀양 출장샵 Vegas,

Nguyen Quynh Trang said...

Dịch vụ vận chuyển hàng hóa Bắc Nam của Hoàng Phát được khách hàng đánh giá cao. Nếu bạn muốn gửi hàng từ Hà Nội vào Sài Gòn thì là một lựa chọn tuyệt vời.
Công ty nhận gửi hàng đi Đà Nẵng, gửi hàng đi Hải Phòng, gửi hàng đi Nha Trang, ... và trên các tỉnh thành toàn quốc.
Với đội xe tải chở hàng lớn sẽ đáp ứng mọi nhu cầu vận chuyển của khách hàng.

muaantoan.com