Δευτέρα 3 Ιανουαρίου 2011

How to check who calls your method!

If you want to lock some method so that it will be public but only some specific methods or classes or packages will be allowed to access, then you can modify the following method in order to verify whether the caller should be allowed to execute the method or you should rise an exception instead!


public static boolean isAllowedToCall(){
String callerClassName= new Throwable().getStackTrace()[2].getClassName();
return (callerClassName.startsWith("com.gorbas")||callerClassName.contains("binding"));
}

In my case I allow only packages starting with com.gorbas and classes that contain the word "binding" in their full name.

Κυριακή 2 Ιανουαρίου 2011

Καλή Χρονιά, ευτυχισμένο το 2011

Θα μπορούσα να βάλω εναν Αγιο Βασίλη με δώρα, ή ενα πλουσιο τραπέζι με πολλά φαγητά.. αλλά προτιμησα κατι πιο ρεαλιστικό...

LinkWithin

Blog Widget by LinkWithin

Mobile edition