I am building an application on two layer. Web layer and business layer.
Inside the business layer I have some public method that can be called within the business layer or from the web layer.
I only want some of these methods being called from the web layer (the safe one).
I was wondering if I can create a annotation in my business layer, for example @Public which means I can call this method from the web layer, and @Private so I should not use this method from the web layer.
And when I try to call a @private method from the web layer (in eclipse) it gives me a warning?
As well: Can I have a way to list automatically all this method private and public?
AFAIK you can’t make Eclipse use annotation to determine whether you can access a method from a certain file. For this to be possible Eclipse would have to know whether the file is part of the web layer or the business layer.
In order to list all methods having a certain annotation, you could use reflection at runtime. In Eclipse there might be filters, but I don’t know of any annotation based filters.
Maybe you should choose another approach, I’ll shortly describe how we do that:
We have two interfaces that our services may implement:
We split those interfaces into two eclipse projects – one public api project and one implementation project that contains the services and internal api – and just allow access to the public api project from the web layer.
Since our services (EJB 3.0) need an interface, we have to add the internal one, if we have internal methods. However, with other technology (like EJB 3.1) you might also just provide the public interface.
Another approach might be to split the interfaces into two packages, e.g.
myproject.api.pub(public is a keyword) andmyproject.api.internal, and then use package based filters in Eclipse.