net.n2oapp.framework.config.metadata.compile.ComponentCompiler Maven / Gradle / Ivy
package net.n2oapp.framework.config.metadata.compile;
import net.n2oapp.framework.api.exception.N2oException;
import net.n2oapp.framework.api.metadata.Component;
import net.n2oapp.framework.api.metadata.SourceComponent;
import net.n2oapp.framework.api.metadata.aware.ExtensionAttributesAware;
import net.n2oapp.framework.api.metadata.compile.CompileContext;
import net.n2oapp.framework.api.metadata.compile.CompileProcessor;
import net.n2oapp.framework.api.metadata.compile.building.Placeholders;
import net.n2oapp.framework.config.util.StylesResolver;
import static net.n2oapp.framework.api.metadata.local.util.CompileUtil.castDefault;
/**
* Сборка компонента
*/
public abstract class ComponentCompiler>
implements BaseSourceCompiler {
protected void compileComponent(D compiled, S source, C context, CompileProcessor p) {
if (getSrcProperty() == null) {
compiled.setSrc(source.getSrc());
} else {
compiled.setSrc(castDefault(source.getSrc(), () -> p.resolve(Placeholders.property(getSrcProperty()), String.class)));
}
if (compiled.getSrc() == null)
throw new N2oException("component src is required");
compiled.setClassName(source.getCssClass());
compiled.setStyle(StylesResolver.resolveStyles(source.getStyle()));
compiled.setProperties(p.mapAndResolveAttributes(source));
}
/**
* Свойство содержащее React компонент по умолчанию
*/
protected String getSrcProperty() {
return null;
}
}