PL-7975 Simplify overriding of WindowLoader, FrameLoader, LookupLoader, EditorLoader

This commit is contained in:
Daniil Tsarev 2017-12-14 14:32:31 +04:00
parent 57ac3f102a
commit d370c650c0
5 changed files with 334 additions and 113 deletions

View File

@ -41,6 +41,7 @@ import com.haulmont.cuba.gui.events.sys.UiEventsMulticaster;
import com.haulmont.cuba.gui.logging.UserActionsLogger;
import com.haulmont.cuba.gui.theme.ThemeConstants;
import com.haulmont.cuba.gui.theme.ThemeConstantsRepository;
import com.haulmont.cuba.gui.xml.layout.ExternalUIComponentsSource;
import com.haulmont.cuba.security.entity.User;
import com.haulmont.cuba.security.global.LoginException;
import com.haulmont.cuba.security.global.UserSession;
@ -149,6 +150,8 @@ public class App implements ConnectionListener {
initTestMode();
initUI();
initExceptionHandling();
AppBeans.get(ExternalUIComponentsSource.class)
.checkInitialized();
} catch (Throwable t) {
log.error("Error initializing application", t);
System.exit(-1);

View File

@ -16,14 +16,144 @@
package com.haulmont.cuba.desktop.sys;
import com.google.common.collect.ImmutableMap;
import com.haulmont.bali.util.Dom4j;
import com.haulmont.cuba.core.global.Resources;
import com.haulmont.cuba.core.sys.AppContext;
import com.haulmont.cuba.desktop.App;
import com.haulmont.cuba.gui.xml.layout.ExternalUIComponentsSource;
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
import com.haulmont.cuba.gui.xml.layout.loaders.FrameLoader;
import com.haulmont.cuba.gui.xml.layout.loaders.WindowLoader;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.text.StrTokenizer;
import org.dom4j.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
import javax.inject.Inject;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
/**
* Please notice that {@code DesktopExternalUIComponentsSource} registers only window loaders.
*/
@Component(ExternalUIComponentsSource.NAME)
public class DesktopExternalUIComponentsSource implements ExternalUIComponentsSource {
private static final String DESKTOP_COMPONENTS_CONFIG_XML_PROP = "cuba.desktop.componentsConfig";
private final Logger log = LoggerFactory.getLogger(DesktopExternalUIComponentsSource.class);
protected static final String WINDOW_LOADER_EL = "windowLoader";
protected static final String FRAME_LOADER_EL = "frameLoader";
protected static final String EDITOR_LOADER_EL = "editorLoader";
protected static final String LOOKUP_LOADER_EL = "lookupLoader";
protected static final Map<String, Class<? extends FrameLoader>> loaders = ImmutableMap.of(
WINDOW_LOADER_EL, WindowLoader.class,
FRAME_LOADER_EL, FrameLoader.class,
EDITOR_LOADER_EL, WindowLoader.Editor.class,
LOOKUP_LOADER_EL, WindowLoader.Lookup.class
);
@Inject
protected Resources resources;
protected volatile boolean initialized;
@Override
public void checkInitialized() {
// do nothing
// Desktop client does not support loading of external components
if (!initialized) {
synchronized (this) {
if (!initialized) {
log.debug("Init external UI components");
init();
initialized = true;
}
}
}
}
protected void init() {
try {
_registerWindowLoaders();
} catch (Exception e) {
log.error("Error on custom UI components registration", e);
}
}
protected void _registerWindowLoaders() {
String configName = AppContext.getProperty(DESKTOP_COMPONENTS_CONFIG_XML_PROP);
StrTokenizer tokenizer = new StrTokenizer(configName);
for (String location : tokenizer.getTokenArray()) {
Resource resource = resources.getResource(location);
if (resource.exists()) {
InputStream stream = null;
try {
stream = resource.getInputStream();
Element rootElement = Dom4j.readDocument(stream)
.getRootElement();
_loadWindowLoaders(rootElement);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
IOUtils.closeQuietly(stream);
}
} else {
log.warn("Resource {} not found, ignore it", location);
}
}
}
@SuppressWarnings("unchecked")
protected void _loadWindowLoaders(Element rootElement) {
Class loader = loadWindowLoader(rootElement, WINDOW_LOADER_EL);
if (loader != null) {
LayoutLoaderConfig.registerWindowLoader(loader);
}
loader = loadWindowLoader(rootElement, FRAME_LOADER_EL);
if (loader != null) {
LayoutLoaderConfig.registerFrameLoader(loader);
}
loader = loadWindowLoader(rootElement, EDITOR_LOADER_EL);
if (loader != null) {
LayoutLoaderConfig.registerEditorLoader(loader);
}
loader = loadWindowLoader(rootElement, LOOKUP_LOADER_EL);
if (loader != null) {
LayoutLoaderConfig.registerLookupLoader(loader);
}
}
protected Class loadWindowLoader(Element rootElement, String loaderElem) {
ClassLoader classLoader = App.class.getClassLoader();
Element elem = rootElement.element(loaderElem);
if (elem == null) {
return null;
}
String loaderClass = elem.element("class").getStringValue();
try {
Class clazz = classLoader.loadClass(loaderClass);
if (loaders.get(loaderElem).isAssignableFrom(clazz)) {
//noinspection unchecked
return clazz;
}
log.warn("Class {} is not suitable as {}", loaderClass, loaderElem);
} catch (ClassNotFoundException e) {
log.warn("Unable to load window loader class: {}", loaderClass);
}
return null;
}
}

View File

@ -19,16 +19,14 @@
<xs:schema targetNamespace="http://schemas.haulmont.com/cuba/components.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.haulmont.com/cuba/components.xsd"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
elementFormDefault="qualified">
<xs:element name="components">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="component">
<xs:complexType>
<xs:all>
<xs:element name="tag" minOccurs="0" maxOccurs="1">
<xs:element name="tag" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
@ -37,7 +35,7 @@
</xs:complexType>
</xs:element>
<xs:element name="name" minOccurs="1" maxOccurs="1">
<xs:element name="name">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
@ -46,7 +44,7 @@
</xs:complexType>
</xs:element>
<xs:element name="class" minOccurs="1" maxOccurs="1">
<xs:element name="class">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
@ -55,7 +53,7 @@
</xs:complexType>
</xs:element>
<xs:element name="componentLoader" minOccurs="1" maxOccurs="1">
<xs:element name="componentLoader">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
@ -66,7 +64,30 @@
</xs:all>
</xs:complexType>
</xs:element>
<xs:group ref="loadersGroup" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:group name="loadersGroup">
<xs:all>
<xs:element name="windowLoader" type="loaderType" minOccurs="0"/>
<xs:element name="frameLoader" type="loaderType" minOccurs="0"/>
<xs:element name="editorLoader" type="loaderType" minOccurs="0"/>
<xs:element name="lookupLoader" type="loaderType" minOccurs="0"/>
</xs:all>
</xs:group>
<xs:complexType name="loaderType">
<xs:sequence>
<xs:element name="class">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>

View File

@ -26,113 +26,99 @@ import java.util.concurrent.ConcurrentHashMap;
public class LayoutLoaderConfig {
private Map<String, Class<? extends ComponentLoader>> loaders = new ConcurrentHashMap<>();
private static Map<String, Class<? extends ComponentLoader>> loaders = new ConcurrentHashMap<>();
private static LayoutLoaderConfig windowLoaders = new LayoutLoaderConfig();
private static LayoutLoaderConfig editorLoaders = new LayoutLoaderConfig();
private static LayoutLoaderConfig lookupLoaders = new LayoutLoaderConfig();
private static LayoutLoaderConfig frameLoaders = new LayoutLoaderConfig();
private static Class<? extends WindowLoader> windowLoader = WindowLoader.class;
private static Class<? extends FrameLoader> frameLoader = FrameLoader.class;
private static Class<? extends WindowLoader.Editor> editorLoader = WindowLoader.Editor.class;
private static Class<? extends WindowLoader.Lookup> lookupLoader = WindowLoader.Lookup.class;
private static Map<String, Class<? extends ComponentLoader>> customLoaders = new ConcurrentHashMap<>();
private static LayoutLoaderConfig llc = new LayoutLoaderConfig();
static {
windowLoaders.register("window", WindowLoader.class);
registerComponents(windowLoaders);
loaders.put(HBoxLayout.NAME, HBoxLayoutLoader.class);
loaders.put(VBoxLayout.NAME, VBoxLayoutLoader.class);
loaders.put(GridLayout.NAME, GridLayoutLoader.class);
loaders.put(ScrollBoxLayout.NAME, ScrollBoxLayoutLoader.class);
loaders.put(GroupBoxLayout.NAME, GroupBoxLayoutLoader.class);
loaders.put(HtmlBoxLayout.NAME, HtmlBoxLayoutLoader.class);
loaders.put(FlowBoxLayout.NAME, FlowBoxLayoutLoader.class);
loaders.put(CssLayout.NAME, CssLayoutLoader.class);
editorLoaders.register("window", WindowLoader.Editor.class);
registerComponents(editorLoaders);
loaders.put(Button.NAME, ButtonLoader.class);
loaders.put(LinkButton.NAME, LinkButtonLoader.class);
loaders.put(CheckBox.NAME, CheckBoxLoader.class);
loaders.put(Label.NAME, LabelLoader.class);
loaders.put(Link.NAME, LinkLoader.class);
lookupLoaders.register("window", WindowLoader.Lookup.class);
registerComponents(lookupLoaders);
loaders.put(TextField.NAME, TextFieldLoader.class);
loaders.put(MaskedField.NAME, MaskedFieldLoader.class);
loaders.put(TextArea.NAME, ResizableTextAreaLoader.class);
loaders.put(SourceCodeEditor.NAME, SourceCodeEditorLoader.class);
loaders.put(PasswordField.NAME, PasswordFieldLoader.class);
loaders.put(RichTextArea.NAME, RichTextAreaLoader.class);
frameLoaders.register("window", FrameLoader.class);
registerComponents(frameLoaders);
}
loaders.put(DateField.NAME, DateFieldLoader.class);
loaders.put(TimeField.NAME, TimeFieldLoader.class);
loaders.put(DatePicker.NAME, DatePickerLoader.class);
loaders.put(LookupField.NAME, LookupFieldLoader.class);
loaders.put(SuggestionField.NAME, SuggestionFieldLoader.class);
loaders.put(SuggestionPickerField.NAME, SuggestionPickerFieldLoader.class);
loaders.put(PickerField.NAME, PickerFieldLoader.class);
loaders.put(ColorPicker.NAME, ColorPickerLoader.class);
loaders.put(LookupPickerField.NAME, LookupPickerFieldLoader.class);
loaders.put(SearchPickerField.NAME, SearchPickerFieldLoader.class);
loaders.put(OptionsGroup.NAME, OptionsGroupLoader.class);
loaders.put(OptionsList.NAME, OptionsListLoader.class);
loaders.put(FileUploadField.NAME, FileUploadFieldLoader.class);
loaders.put(FileMultiUploadField.NAME, FileMultiUploadFieldLoader.class);
loaders.put(CurrencyField.NAME, CurrencyFieldLoader.class);
private static void registerComponents(LayoutLoaderConfig config) {
config.register(HBoxLayout.NAME, HBoxLayoutLoader.class);
config.register(VBoxLayout.NAME, VBoxLayoutLoader.class);
config.register(GridLayout.NAME, GridLayoutLoader.class);
config.register(ScrollBoxLayout.NAME, ScrollBoxLayoutLoader.class);
config.register(GroupBoxLayout.NAME, GroupBoxLayoutLoader.class);
config.register(HtmlBoxLayout.NAME, HtmlBoxLayoutLoader.class);
config.register(FlowBoxLayout.NAME, FlowBoxLayoutLoader.class);
config.register(CssLayout.NAME, CssLayoutLoader.class);
loaders.put(Table.NAME, TableLoader.class);
loaders.put(TreeTable.NAME, TreeTableLoader.class);
loaders.put(GroupTable.NAME, GroupTableLoader.class);
loaders.put(DataGrid.NAME, DataGridLoader.class);
config.register(Button.NAME, ButtonLoader.class);
config.register(LinkButton.NAME, LinkButtonLoader.class);
config.register(CheckBox.NAME, CheckBoxLoader.class);
config.register(Label.NAME, LabelLoader.class);
config.register(Link.NAME, LinkLoader.class);
loaders.put(Calendar.NAME, CalendarLoader.class);
config.register(TextField.NAME, TextFieldLoader.class);
config.register(MaskedField.NAME, MaskedFieldLoader.class);
config.register(TextArea.NAME, ResizableTextAreaLoader.class);
config.register(SourceCodeEditor.NAME, SourceCodeEditorLoader.class);
config.register(PasswordField.NAME, PasswordFieldLoader.class);
config.register(RichTextArea.NAME, RichTextAreaLoader.class);
config.register(DateField.NAME, DateFieldLoader.class);
config.register(TimeField.NAME, TimeFieldLoader.class);
config.register(DatePicker.NAME, DatePickerLoader.class);
config.register(LookupField.NAME, LookupFieldLoader.class);
config.register(SuggestionField.NAME, SuggestionFieldLoader.class);
config.register(SuggestionPickerField.NAME, SuggestionPickerFieldLoader.class);
config.register(PickerField.NAME, PickerFieldLoader.class);
config.register(ColorPicker.NAME, ColorPickerLoader.class);
config.register(LookupPickerField.NAME, LookupPickerFieldLoader.class);
config.register(SearchPickerField.NAME, SearchPickerFieldLoader.class);
config.register(OptionsGroup.NAME, OptionsGroupLoader.class);
config.register(OptionsList.NAME, OptionsListLoader.class);
config.register(FileUploadField.NAME, FileUploadFieldLoader.class);
config.register(FileMultiUploadField.NAME, FileMultiUploadFieldLoader.class);
config.register(CurrencyField.NAME, CurrencyFieldLoader.class);
config.register(Table.NAME, TableLoader.class);
config.register(TreeTable.NAME, TreeTableLoader.class);
config.register(GroupTable.NAME, GroupTableLoader.class);
config.register(DataGrid.NAME, DataGridLoader.class);
config.register(Calendar.NAME, CalendarLoader.class);
config.register(Frame.NAME, FrameComponentLoader.class);
config.register("iframe", FrameComponentLoader.class); // for backward compatibility
config.register(RuntimePropertiesFrame.NAME, RuntimePropertiesFrameLoader.class);
config.register(SplitPanel.NAME, SplitPanelLoader.class);
config.register(Tree.NAME, TreeLoader.class);
config.register(TabSheet.NAME, TabSheetLoader.class);
config.register(Accordion.NAME, AccordionLoader.class);
config.register(Embedded.NAME, EmbeddedLoader.class);
config.register(Image.NAME, ImageLoader.class);
config.register(BrowserFrame.NAME, BrowserFrameLoader.class);
config.register(Filter.NAME, FilterLoader.class);
config.register(ButtonsPanel.NAME, ButtonsPanelLoader.class);
config.register(PopupButton.NAME, PopupButtonLoader.class);
config.register(PopupView.NAME, PopupViewLoader.class);
config.register(FieldGroup.NAME, FieldGroupLoader.class);
config.register(TokenList.NAME, TokenListLoader.class);
config.register(WidgetsTree.NAME, WidgetsTreeLoader.class);
config.register(TwinColumn.NAME, TwinColumnLoader.class);
config.register(ProgressBar.NAME, ProgressBarLoader.class);
config.register(SearchField.NAME, SearchFieldLoader.class);
config.register(RelatedEntities.NAME, RelatedEntitiesLoader.class);
config.register(BulkEditor.NAME, BulkEditorLoader.class);
loaders.put(Frame.NAME, FrameComponentLoader.class);
loaders.put("iframe", FrameComponentLoader.class); // for backward compatibility
loaders.put(RuntimePropertiesFrame.NAME, RuntimePropertiesFrameLoader.class);
loaders.put(SplitPanel.NAME, SplitPanelLoader.class);
loaders.put(Tree.NAME, TreeLoader.class);
loaders.put(TabSheet.NAME, TabSheetLoader.class);
loaders.put(Accordion.NAME, AccordionLoader.class);
loaders.put(Embedded.NAME, EmbeddedLoader.class);
loaders.put(Image.NAME, ImageLoader.class);
loaders.put(BrowserFrame.NAME, BrowserFrameLoader.class);
loaders.put(Filter.NAME, FilterLoader.class);
loaders.put(ButtonsPanel.NAME, ButtonsPanelLoader.class);
loaders.put(PopupButton.NAME, PopupButtonLoader.class);
loaders.put(PopupView.NAME, PopupViewLoader.class);
loaders.put(FieldGroup.NAME, FieldGroupLoader.class);
loaders.put(TokenList.NAME, TokenListLoader.class);
loaders.put(WidgetsTree.NAME, WidgetsTreeLoader.class);
loaders.put(TwinColumn.NAME, TwinColumnLoader.class);
loaders.put(ProgressBar.NAME, ProgressBarLoader.class);
loaders.put(SearchField.NAME, SearchFieldLoader.class);
loaders.put(RelatedEntities.NAME, RelatedEntitiesLoader.class);
loaders.put(BulkEditor.NAME, BulkEditorLoader.class);
/* Main window components */
config.register(AppMenu.NAME, AppMenuLoader.class);
config.register(AppWorkArea.NAME, AppWorkAreaLoader.class);
config.register(LogoutButton.NAME, LogoutButtonLoader.class);
config.register(NewWindowButton.NAME, NewWindowButtonLoader.class);
config.register(UserIndicator.NAME, UserIndicatorLoader.class);
config.register(FoldersPane.NAME, FoldersPaneLoader.class);
config.register(FtsField.NAME, FtsFieldLoader.class);
config.register(TimeZoneIndicator.NAME, TimeZoneIndicatorLoader.class);
config.register(SideMenu.NAME, SideMenuLoader.class);
loaders.put(AppMenu.NAME, AppMenuLoader.class);
loaders.put(AppWorkArea.NAME, AppWorkAreaLoader.class);
loaders.put(LogoutButton.NAME, LogoutButtonLoader.class);
loaders.put(NewWindowButton.NAME, NewWindowButtonLoader.class);
loaders.put(UserIndicator.NAME, UserIndicatorLoader.class);
loaders.put(FoldersPane.NAME, FoldersPaneLoader.class);
loaders.put(FtsField.NAME, FtsFieldLoader.class);
loaders.put(TimeZoneIndicator.NAME, TimeZoneIndicatorLoader.class);
loaders.put(SideMenu.NAME, SideMenuLoader.class);
}
public static void registerLoader(String tagName, Class<? extends ComponentLoader> aClass) {
customLoaders.put(tagName, aClass);
loaders.put(tagName, aClass);
}
/**
@ -143,34 +129,49 @@ public class LayoutLoaderConfig {
for (ComponentPalette palette : palettes) {
Map<String, Class<? extends ComponentLoader>> loaders = palette.getLoaders();
for (Map.Entry<String, Class<? extends ComponentLoader>> loaderEntry : loaders.entrySet()) {
customLoaders.put(loaderEntry.getKey(), loaderEntry.getValue());
loaders.put(loaderEntry.getKey(), loaderEntry.getValue());
}
}
}
public static LayoutLoaderConfig getWindowLoaders() {
return windowLoaders;
llc.register("window", windowLoader);
return llc;
}
public static LayoutLoaderConfig getEditorLoaders() {
return editorLoaders;
llc.register("window", editorLoader);
return llc;
}
public static LayoutLoaderConfig getFrameLoaders() {
return frameLoaders;
llc.register("window", frameLoader);
return llc;
}
public static LayoutLoaderConfig getLookupLoaders() {
return lookupLoaders;
llc.register("window", lookupLoader);
return llc;
}
public Class<? extends ComponentLoader> getLoader(String name) {
final Class<? extends ComponentLoader> loader = customLoaders.get(name);
if (loader == null) {
return loaders.get(name);
}
return loaders.get(name);
}
return loader;
public static void registerWindowLoader(Class<? extends WindowLoader> loader) {
windowLoader = loader;
}
public static void registerFrameLoader(Class<? extends FrameLoader> loader) {
frameLoader = loader;
}
public static void registerEditorLoader(Class<? extends WindowLoader.Editor> loader) {
editorLoader = loader;
}
public static void registerLookupLoader(Class<? extends WindowLoader.Lookup> loader) {
lookupLoader = loader;
}
protected void register(String tagName, Class<? extends ComponentLoader> loaderClass) {

View File

@ -17,6 +17,7 @@
package com.haulmont.cuba.web.sys;
import com.google.common.collect.ImmutableMap;
import com.haulmont.bali.util.Dom4j;
import com.haulmont.cuba.core.global.Resources;
import com.haulmont.cuba.core.sys.AppContext;
@ -24,12 +25,13 @@ import com.haulmont.cuba.gui.components.Component;
import com.haulmont.cuba.gui.xml.layout.ComponentLoader;
import com.haulmont.cuba.gui.xml.layout.ExternalUIComponentsSource;
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
import com.haulmont.cuba.gui.xml.layout.loaders.FrameLoader;
import com.haulmont.cuba.gui.xml.layout.loaders.WindowLoader;
import com.haulmont.cuba.web.App;
import com.haulmont.cuba.web.gui.WebComponentsFactory;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.text.StrTokenizer;
import org.dom4j.Document;
import org.dom4j.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -41,6 +43,7 @@ import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import static org.apache.commons.lang.StringUtils.trimToEmpty;
@ -55,6 +58,18 @@ public class WebExternalUIComponentsSource implements ExternalUIComponentsSource
private final Logger log = LoggerFactory.getLogger(WebExternalUIComponentsSource.class);
protected static final String WINDOW_LOADER_EL = "windowLoader";
protected static final String FRAME_LOADER_EL = "frameLoader";
protected static final String EDITOR_LOADER_EL = "editorLoader";
protected static final String LOOKUP_LOADER_EL = "lookupLoader";
protected static final Map<String, Class<? extends FrameLoader>> loaders = ImmutableMap.of(
WINDOW_LOADER_EL, WindowLoader.class,
FRAME_LOADER_EL, FrameLoader.class,
EDITOR_LOADER_EL, WindowLoader.Editor.class,
LOOKUP_LOADER_EL, WindowLoader.Lookup.class
);
@Inject
protected Resources resources;
@ -123,11 +138,12 @@ public class WebExternalUIComponentsSource implements ExternalUIComponentsSource
}
}
@SuppressWarnings("unchecked")
protected void _registerComponent(InputStream is) throws ClassNotFoundException {
ClassLoader classLoader = App.class.getClassLoader();
Document document = Dom4j.readDocument(is);
List<Element> components = document.getRootElement().elements("component");
Element rootElement = Dom4j.readDocument(is).getRootElement();
List<Element> components = rootElement.elements("component");
for (Element component : components) {
String name = trimToEmpty(component.elementText("name"));
String componentClassName = trimToEmpty(component.elementText("class"));
@ -158,5 +174,55 @@ public class WebExternalUIComponentsSource implements ExternalUIComponentsSource
componentLoaderClassName);
}
}
_loadWindowLoaders(rootElement);
}
@SuppressWarnings("unchecked")
protected void _loadWindowLoaders(Element rootElement) {
Class loader = loadWindowLoader(rootElement, WINDOW_LOADER_EL);
if (loader != null) {
LayoutLoaderConfig.registerWindowLoader(loader);
}
loader = loadWindowLoader(rootElement, FRAME_LOADER_EL);
if (loader != null) {
LayoutLoaderConfig.registerFrameLoader(loader);
}
loader = loadWindowLoader(rootElement, EDITOR_LOADER_EL);
if (loader != null) {
LayoutLoaderConfig.registerEditorLoader(loader);
}
loader = loadWindowLoader(rootElement, LOOKUP_LOADER_EL);
if (loader != null) {
LayoutLoaderConfig.registerLookupLoader(loader);
}
}
protected Class loadWindowLoader(Element rootElement, String loaderElem) {
ClassLoader classLoader = App.class.getClassLoader();
Element elem = rootElement.element(loaderElem);
if (elem == null) {
return null;
}
String loaderClass = elem.element("class").getStringValue();
try {
Class clazz = classLoader.loadClass(loaderClass);
if (loaders.get(loaderElem).isAssignableFrom(clazz)) {
//noinspection unchecked
return clazz;
}
log.warn("Class {} is not suitable as {}", loaderClass, loaderElem);
} catch (ClassNotFoundException e) {
log.warn("Unable to load window loader class: {}", loaderClass);
}
return null;
}
}