From 1faca6452e1f364e93c31c5eb4a8b94957b4480f Mon Sep 17 00:00:00 2001 From: Yuriy Artamonov Date: Mon, 12 Feb 2018 18:33:16 +0400 Subject: [PATCH] PL-10274 Make class and componentLoader optional in ui-component.xsd --- .../DesktopExternalUIComponentsSource.java | 48 +++++++++++++------ .../src/com/haulmont/cuba/gui/components.xsd | 42 ++++++++-------- .../sys/WebExternalUIComponentsSource.java | 48 +++++++++++++------ 3 files changed, 89 insertions(+), 49 deletions(-) diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/sys/DesktopExternalUIComponentsSource.java b/modules/desktop/src/com/haulmont/cuba/desktop/sys/DesktopExternalUIComponentsSource.java index e018c03b50..caa4e8118f 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/sys/DesktopExternalUIComponentsSource.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/sys/DesktopExternalUIComponentsSource.java @@ -149,24 +149,42 @@ public class DesktopExternalUIComponentsSource implements ExternalUIComponentsSo tag = name; } - Class componentLoaderClass = classLoader.loadClass(componentLoaderClassName); - Class componentClass = classLoader.loadClass(componentClassName); - - if (Component.class.isAssignableFrom(componentClass)) { - log.trace("Register component {} class {}", name, componentClass.getCanonicalName()); - - DesktopComponentsFactory.registerComponent(name, (Class) componentClass); - } else { - log.warn("Component {} is not a subclass of com.haulmont.cuba.gui.components.Component", componentClassName); + if (StringUtils.isEmpty(name) && StringUtils.isEmpty(tag)) { + log.warn("You have to provide name or tag for custom component"); + // skip this element + continue; } - if (ComponentLoader.class.isAssignableFrom(componentLoaderClass)) { - log.trace("Register tag {} loader {}", tag, componentLoaderClass.getCanonicalName()); + if (StringUtils.isEmpty(componentLoaderClassName) && StringUtils.isEmpty(componentClassName)) { + log.warn("You have to provide at least or for custom component {} / <{}>", + name, tag); + // skip this element + continue; + } - LayoutLoaderConfig.registerLoader(tag, (Class) componentLoaderClass); - } else { - log.warn("Component loader {} is not a subclass of com.haulmont.cuba.gui.xml.layout.ComponentLoader", - componentLoaderClassName); + if (StringUtils.isNotEmpty(name) && StringUtils.isNotEmpty(componentClassName)) { + Class componentClass = classLoader.loadClass(componentClassName); + + if (Component.class.isAssignableFrom(componentClass)) { + log.trace("Register component {} class {}", name, componentClass.getCanonicalName()); + + DesktopComponentsFactory.registerComponent(name, (Class) componentClass); + } else { + log.warn("Component {} is not a subclass of com.haulmont.cuba.gui.components.Component", componentClassName); + } + } + + if (StringUtils.isNotEmpty(tag) && StringUtils.isNotEmpty(componentLoaderClassName)) { + Class componentLoaderClass = classLoader.loadClass(componentLoaderClassName); + + if (ComponentLoader.class.isAssignableFrom(componentLoaderClass)) { + log.trace("Register tag {} loader {}", tag, componentLoaderClass.getCanonicalName()); + + LayoutLoaderConfig.registerLoader(tag, (Class) componentLoaderClass); + } else { + log.warn("Component loader {} is not a subclass of com.haulmont.cuba.gui.xml.layout.ComponentLoader", + componentLoaderClassName); + } } } diff --git a/modules/gui/src/com/haulmont/cuba/gui/components.xsd b/modules/gui/src/com/haulmont/cuba/gui/components.xsd index ec3f231bda..38b7c6bb73 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/components.xsd +++ b/modules/gui/src/com/haulmont/cuba/gui/components.xsd @@ -26,6 +26,28 @@ + + + + + + + + + + + + + + + + + + + + + + @@ -35,25 +57,7 @@ - - - - - - - - - - - - - - - - - - - + diff --git a/modules/web/src/com/haulmont/cuba/web/sys/WebExternalUIComponentsSource.java b/modules/web/src/com/haulmont/cuba/web/sys/WebExternalUIComponentsSource.java index 093581d902..ee62d2525f 100644 --- a/modules/web/src/com/haulmont/cuba/web/sys/WebExternalUIComponentsSource.java +++ b/modules/web/src/com/haulmont/cuba/web/sys/WebExternalUIComponentsSource.java @@ -154,24 +154,42 @@ public class WebExternalUIComponentsSource implements ExternalUIComponentsSource tag = name; } - Class componentLoaderClass = classLoader.loadClass(componentLoaderClassName); - Class componentClass = classLoader.loadClass(componentClassName); - - if (Component.class.isAssignableFrom(componentClass)) { - log.trace("Register component {} class {}", name, componentClass.getCanonicalName()); - - webComponentsFactory.register(name, (Class) componentClass); - } else { - log.warn("Component {} is not a subclass of com.haulmont.cuba.gui.components.Component", componentClassName); + if (StringUtils.isEmpty(name) && StringUtils.isEmpty(tag)) { + log.warn("You have to provide name or tag for custom component"); + // skip this element + continue; } - if (ComponentLoader.class.isAssignableFrom(componentLoaderClass)) { - log.trace("Register tag {} loader {}", tag, componentLoaderClass.getCanonicalName()); + if (StringUtils.isEmpty(componentLoaderClassName) && StringUtils.isEmpty(componentClassName)) { + log.warn("You have to provide at least or for custom component {} / <{}>", + name, tag); + // skip this element + continue; + } - LayoutLoaderConfig.registerLoader(tag, (Class) componentLoaderClass); - } else { - log.warn("Component loader {} is not a subclass of com.haulmont.cuba.gui.xml.layout.ComponentLoader", - componentLoaderClassName); + if (StringUtils.isNotEmpty(name) && StringUtils.isNotEmpty(componentClassName)) { + Class componentClass = classLoader.loadClass(componentClassName); + + if (Component.class.isAssignableFrom(componentClass)) { + log.trace("Register component {} class {}", name, componentClass.getCanonicalName()); + + webComponentsFactory.register(name, (Class) componentClass); + } else { + log.warn("Component {} is not a subclass of com.haulmont.cuba.gui.components.Component", componentClassName); + } + } + + if (StringUtils.isNotEmpty(tag) && StringUtils.isNotEmpty(componentLoaderClassName)) { + Class componentLoaderClass = classLoader.loadClass(componentLoaderClassName); + + if (ComponentLoader.class.isAssignableFrom(componentLoaderClass)) { + log.trace("Register tag {} loader {}", tag, componentLoaderClass.getCanonicalName()); + + LayoutLoaderConfig.registerLoader(tag, (Class) componentLoaderClass); + } else { + log.warn("Component loader {} is not a subclass of com.haulmont.cuba.gui.xml.layout.ComponentLoader", + componentLoaderClassName); + } } }