Сегодня я увидел следующий код:Изменения во время выполнения на интерфейс маркеров
public Tab addTab(Component c, String caption, Resource icon, int position) {
Tab addedTab = super.addTab(c, i18nCaption, icon, position);
// if is not securized
if (!(addedTab instanceof SecurizedComponent)) {
addedTab = SecurityWrapper.createSecurityWrapper((TabSheetTabImpl)addedTab, caption);
}
return addedTab;
}
SecurizedComponent является интерфейсом маркеров
/**
*
* This is a marker interface. All securized components will be changed at runtime to implement this interface.
* This way, is possible to know if a component has been securized asking for component instanceof SecurizedComponent
*
* Allows the framework not to securize components more than once
*
*/
public interface SecurizedComponent {
}
Метод createSecurityWrapper сделать что-то вроде:
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(wrapperClass);
enhancer.setClassLoader(source.getClass().getClassLoader());
enhancer.setInterfaces(new Class[]{SecurizedComponent.class});
//more stuff...
Я знаю, что делает этот код, в основном, когда вкладка добавлена в первый раз, она изменяется во время выполнения до i Дополнить интерфейс SecurizedComponent. Но мой вопрос: это хорошая практика? Есть ли лучший способ его реализовать?