Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Single Sourcing: Some solutions for simple problems(Using reflection and apache beanutils)
Single Sourcing: Some solutions for simple problems [message #869819] Fri, 04 May 2012 12:04
Marc T. is currently offline Marc T.Friend
Messages: 17
Registered: November 2009
Junior Member

I'm just reworking a complex RCP/RAP application for single sourcing. I've read the available single sourcing howtos and guidelines, and these solutions work well.

But sometime building abstract classes and using fragment seems to be overkill for some simple problems i've found at several places in my code. I finally used reflection API to solve this problems, which worked quite well for me:

1. Calls to missing methods/constructors will not compile under RAP environment, even if the code itself is not executed:

RCP Code:

Image img=getImage();
GC gc=new GC(img);

Within RAP the Image class does not implement 'Drawable' and the code will produce a compile error.

This code is not executed when running under RAP, but I don't want to create a fragment project because of this single problem. May solution is using reflection:

RCP/RAP single source Code:

Image img=getImage();
Constructor<GC> con = GC.class.getConstructor(Drawable.class);
GC gc = con.newInstance(img);

Now the compile error is gone and it works well under RCP.

2. Some optional functionality (methods) is not available under RAP, but should be used, if available.

RCP Code:
ScrolledComposite scomp = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);

Since method 'setIncrement()' is not available in RAP, this code will not compile. The RAP version would be identical, just without the calls. I used the org.apache.commons.beanutils.PropertyUtils reflection utils to solve this:

ScrolledComposite scomp = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
try {
					"increment", Integer.valueOf(10));
					"increment", Integer.valueOf(10));
} catch (Exception e) {
 // ignore

OK, there will be an exception when executed in RAP, which can be ignored.

This approaches made things a bit easier and avoided the introduction of extra fragments for this simple problems. I did not found any hints for this approach in the single sourcing guides and thought, this might be of some help.

Any comments welcome !



Previous Topic:SingleSourcing: Server Side Image
Next Topic:Canvas only shows up after i have moved window
Goto Forum:

Current Time: Thu Oct 28 09:34:18 GMT 2021

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

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

Back to the top