de.tsl2.nano.h5.NanoH5Util Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tsl2.nano.h5 Show documentation
Show all versions of tsl2.nano.h5 Show documentation
TSL2 Framework Html5 Extensions (WebServer, Html5Presentation, RuleCover, BeanConfigurator, LogicTable-Sheet, Expression-Descriptors for Actions, Rules, URLs, Queries)
package de.tsl2.nano.h5;
import java.io.Serializable;
import java.util.Collection;
import org.apache.commons.logging.Log;
import de.tsl2.nano.bean.def.AttributeDefinition;
import de.tsl2.nano.bean.def.BeanCollector;
import de.tsl2.nano.bean.def.BeanDefinition;
import de.tsl2.nano.bean.def.Constraint;
import de.tsl2.nano.bean.def.IAttributeDefinition;
import de.tsl2.nano.bean.def.ValueExpression;
import de.tsl2.nano.core.ENV;
import de.tsl2.nano.core.ManagedException;
import de.tsl2.nano.core.log.LogFactory;
import de.tsl2.nano.core.util.Util;
import de.tsl2.nano.h5.collector.CSheet;
import de.tsl2.nano.h5.collector.Controller;
import de.tsl2.nano.h5.collector.QueryResult;
import de.tsl2.nano.h5.collector.Statistic;
import de.tsl2.nano.h5.configuration.BeanConfigurator;
import de.tsl2.nano.specification.Pool;
import de.tsl2.nano.specification.SpecificationExchange;
import de.tsl2.nano.specification.actions.Action;
/**
* convenience class to create and configure bean types and their attributes.
*
* @author ts
*/
public interface NanoH5Util {
static final Log LOG = LogFactory.getLog(NanoH5Util.class);
static String ve(String expression) {
return "{" + expression + "}";
}
/**
* define
*
* @param valueExpression
* @param type
*/
static BeanDefinition define(Class type, StringBuilder icon, String valueExpression, String... attributeFilter) {
BeanDefinition bean = BeanDefinition.getBeanDefinition(type);
assureHtml5Presentation(bean);
String ve = valueExpression.contains("{") ? valueExpression : "{" + valueExpression + "}";
bean.setValueExpression(new ValueExpression(ve, type));
if (!Util.isEmpty(attributeFilter))
bean.setAttributeFilter(attributeFilter);
if (icon != null)
bean.getPresentable().setIcon(ENV.getConfigPathRel() + icon.toString());
bean.saveDefinition();
return bean;
}
static void define(String attributePropertyPath, Object value) {
AttributeDefinition.getAttributePropertyFromPath(attributePropertyPath).setValue(value);
}
static void assureHtml5Presentation(BeanDefinition bean) {
if (!(bean.getPresentationHelper() instanceof Html5Presentation))
bean.setPresentationHelper(new Html5Presentation<>(bean));
}
/**
* icon
* @param name
* @return
*/
static StringBuilder icon(String name) {
return new StringBuilder("icons/" + name + ".png");
}
/**
* @param cls class holding the source method
* @param methodName method name
* @param methodArgTypes methods argument types (classes)
* @param pars optional action argument constraints
* @return new created Action that is hold and provided by the {@link Pool}.
*/
static Action