java - Change at runtime to a marker interface -
today saw next code:
public tab addtab(component c, string caption, resource icon, int position) { tab addedtab = super.addtab(c, i18ncaption, icon, position); // if not securized if (!(addedtab instanceof securizedcomponent)) { addedtab = securitywrapper.createsecuritywrapper((tabsheettabimpl)addedtab, caption); } return addedtab; }
securizedcomponent marker interface
/** * * marker interface. securized components changed @ runtime implement interface. * way, possible know if component has been securized asking component instanceof securizedcomponent * * allows framework not securize components more once * */ public interface securizedcomponent { }
the method createsecuritywrapper like:
enhancer enhancer = new enhancer(); enhancer.setsuperclass(wrapperclass); enhancer.setclassloader(source.getclass().getclassloader()); enhancer.setinterfaces(new class[]{securizedcomponent.class}); //more stuff...
i know code doing, when tab added first time, changed @ runtime implement securizedcomponent interface. question is: practice? there better way implement it?
this doesn't shock me, really. put check if (!(addedtab instanceof securizedcomponent)) {
inside securitywrapper, won't have check everywhere in code, , calling securitywrapper securized object nothing.
otherwise, use securizable interface issecured() method, implementations return false until securitywrapper works magic.
of course "security" secure code, since support change class implement securized , bypass checks...
Comments
Post a Comment