PL-10274 Make class and componentLoader optional in ui-component.xsd

This commit is contained in:
Yuriy Artamonov 2018-02-12 18:33:16 +04:00
parent 07d200ab4e
commit 1faca6452e
3 changed files with 89 additions and 49 deletions

View File

@ -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<? extends Component>) 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 <component> 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 <class> or <componentLoader> for custom component {} / <{}>",
name, tag);
// skip this <component> element
continue;
}
LayoutLoaderConfig.registerLoader(tag, (Class<? extends ComponentLoader>) 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<? extends Component>) 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<? extends ComponentLoader>) componentLoaderClass);
} else {
log.warn("Component loader {} is not a subclass of com.haulmont.cuba.gui.xml.layout.ComponentLoader",
componentLoaderClassName);
}
}
}

View File

@ -26,6 +26,28 @@
<xs:element name="component">
<xs:complexType>
<xs:all>
<!-- ComponentsFactory create component NAME-CLASS -->
<xs:element name="name" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="class" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<!-- ComponentsFactory XML loaders TAG-LOADER_CLASS -->
<xs:element name="tag" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
@ -35,25 +57,7 @@
</xs:complexType>
</xs:element>
<xs:element name="name">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="class">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="componentLoader">
<xs:element name="componentLoader" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">

View File

@ -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<? extends Component>) 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 <component> 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 <class> or <componentLoader> for custom component {} / <{}>",
name, tag);
// skip this <component> element
continue;
}
LayoutLoaderConfig.registerLoader(tag, (Class<? extends ComponentLoader>) 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<? extends Component>) 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<? extends ComponentLoader>) componentLoaderClass);
} else {
log.warn("Component loader {} is not a subclass of com.haulmont.cuba.gui.xml.layout.ComponentLoader",
componentLoaderClassName);
}
}
}