本文整理汇总了Java中com.haulmont.cuba.core.global.Scripting类的典型用法代码示例。如果您正苦于以下问题:Java Scripting类的具体用法?Java Scripting怎么用?Java Scripting使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Scripting类属于com.haulmont.cuba.core.global包,在下文中一共展示了Scripting类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import com.haulmont.cuba.core.global.Scripting; //导入依赖的package包/类
@Override
public void validate(Object value) throws ValidationException {
Boolean isValid = false;
if (params == null) {
params = new HashMap<>();
params.put("value", value);
} else {
params.put("value", value);
}
Scripting scripting = AppBeans.get(Scripting.NAME);
if (innerScript) {
isValid = scripting.evaluateGroovy(script, params);
} else if (scriptPath != null) {
isValid = scripting.runGroovyScript(scriptPath, params);
}
if (!isValid) {
String msg = message != null ? messages.getTools().loadString(messagesPack, message) : "Invalid value '%s'";
throw new ValidationException(String.format(msg, value));
}
}
示例2: getParam
import com.haulmont.cuba.core.global.Scripting; //导入依赖的package包/类
protected String getParam(String[] args, int idx, TimeZone timeZone) {
String arg = args[idx].trim();
String unit = args[3].trim();
Matcher matcher = PARAM_PATTERN.matcher(arg);
if (!matcher.find())
throw new RuntimeException("Invalid macro argument: " + arg);
int num = 0;
try {
String expr = matcher.group(2);
if (!Strings.isNullOrEmpty(expr)) {
Scripting scripting = AppBeans.get(Scripting.class);
num = scripting.evaluateGroovy(expr, new Binding());
}
} catch (NumberFormatException e) {
throw new RuntimeException("Invalid macro argument: " + arg, e);
}
Date date = computeDate(num, unit, timeZone);
String paramName = args[0].trim().replace(".", "_") + "_" + count + "_" + idx;
params.put(paramName, date);
return paramName;
}
示例3: loadOptionsEnum
import com.haulmont.cuba.core.global.Scripting; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected void loadOptionsEnum(T resultComponent, Element element) {
String optionsEnumClass = element.attributeValue("optionsEnum");
if (StringUtils.isNotEmpty(optionsEnumClass)) {
Scripting scripting = AppBeans.get(Scripting.class);
resultComponent.setOptionsEnum(
(Class<? extends EnumClass>) scripting.loadClass(optionsEnumClass));
}
}
示例4: loadOptionsEnum
import com.haulmont.cuba.core.global.Scripting; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected void loadOptionsEnum(LookupField resultComponent, Element element) {
String optionsEnumClass = element.attributeValue("optionsEnum");
if (StringUtils.isNotEmpty(optionsEnumClass)) {
Scripting scripting = AppBeans.get(Scripting.class);
resultComponent.setOptionsEnum(
(Class<? extends EnumClass>) scripting.loadClass(optionsEnumClass));
}
}
示例5: getScreenClass
import com.haulmont.cuba.core.global.Scripting; //导入依赖的package包/类
/**
* Screen class as set in <code>screens.xml</code>
*/
@Nullable
public Class getScreenClass() {
if (screenClass == null) {
String className = descriptor.attributeValue("class");
if (className != null) {
Scripting scripting = AppBeans.get(Scripting.NAME);
screenClass = scripting.loadClass(className);
}
}
return screenClass;
}
示例6: getJavaClass
import com.haulmont.cuba.core.global.Scripting; //导入依赖的package包/类
@Override
public Class getJavaClass() {
String className = element.attributeValue("paramClass");
if (className == null) {
className = element.attributeValue("class");
}
if (className == null) {
return null;
} else {
Scripting scripting = AppBeans.get(Scripting.NAME);
return scripting.loadClass(element.attributeValue("paramClass"));
}
}
示例7: ResourcesImpl
import com.haulmont.cuba.core.global.Scripting; //导入依赖的package包/类
@Inject
public ResourcesImpl(Scripting scripting) {
super(scripting.getClassLoader());
}
示例8: CustomDecorator
import com.haulmont.cuba.core.global.Scripting; //导入依赖的package包/类
public CustomDecorator(String className) {
this.decoratorClass = AppBeans.get(Scripting.class).loadClassNN(className);
}
示例9: DsContextLoader
import com.haulmont.cuba.core.global.Scripting; //导入依赖的package包/类
public DsContextLoader(DataSupplier dataservice) {
this.dataservice = dataservice;
this.scripting = AppBeans.get(Scripting.NAME);
this.metadata = AppBeans.get(Metadata.NAME);
}
示例10: generateField
import com.haulmont.cuba.core.global.Scripting; //导入依赖的package包/类
@Override
public Component generateField(Datasource datasource, String propertyId) {
ComponentsFactory componentsFactory = AppBeans.get(ComponentsFactory.class);
ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
MetaPropertyPath metaPropertyPath = DynamicAttributesUtils.getMetaPropertyPath(datasource.getMetaClass(), propertyId);
if (metaPropertyPath == null) {
log.error("MetaPropertyPath for dynamic attribute {} not found", propertyId);
return null;
}
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaPropertyPath.getMetaProperty());
if (categoryAttribute == null) {
log.error("Dynamic attribute {} not found", propertyId);
return null;
}
listEditor.setEntityJoinClause(categoryAttribute.getJoinClause());
listEditor.setEntityWhereClause(categoryAttribute.getWhereClause());
ListEditor.ItemType itemType = listEditorItemTypeFromDynamicAttrType(categoryAttribute.getDataType());
listEditor.setItemType(itemType);
Metadata metadata = AppBeans.get(Metadata.class);
Scripting scripting = AppBeans.get(Scripting.class);
if (!Strings.isNullOrEmpty(categoryAttribute.getEntityClass())) {
Class<?> clazz = scripting.loadClass(categoryAttribute.getEntityClass());
if (clazz == null) {
log.error("Unable to find class of entity {} for dynamic attribute {}",
categoryAttribute.getEntityClass(), categoryAttribute.getCode());
return null;
}
MetaClass metaClass = metadata.getClassNN(clazz);
listEditor.setEntityName(metaClass.getName());
listEditor.setUseLookupField(BooleanUtils.isTrue(categoryAttribute.getLookup()));
}
//noinspection unchecked
datasource.addStateChangeListener(e -> {
if (e.getState() == Datasource.State.VALID) {
Object value = datasource.getItem().getValue(propertyId);
if (value != null && value instanceof Collection) {
listEditor.setValue(value);
}
}
});
listEditor.addValueChangeListener(e -> {
datasource.getItem().setValue(propertyId, e.getValue());
});
listEditor.setWidthFull();
return listEditor;
}
示例11: resolveParam
import com.haulmont.cuba.core.global.Scripting; //导入依赖的package包/类
protected void resolveParam(Element element) {
Scripting scripting = AppBeans.get(Scripting.NAME);
String aclass = element.attributeValue("class");
if (!isBlank(aclass)) {
javaClass = scripting.loadClass(aclass);
}
String operatorName = element.attributeValue("operatorType", null);
if (operatorName != null) {
operator = Op.valueOf(operatorName);
}
List<Element> paramElements = Dom4j.elements(element, "param");
if (!paramElements.isEmpty()) {
Element paramElem = paramElements.iterator().next();
if (BooleanUtils.toBoolean(paramElem.attributeValue("hidden", "false"), "true", "false")) {
paramElem = paramElements.iterator().next();
}
paramName = paramElem.attributeValue("name");
if (!isBlank(paramElem.attributeValue("javaClass"))) {
paramClass = scripting.loadClass(paramElem.attributeValue("javaClass"));
}
ConditionParamBuilder paramBuilder = AppBeans.get(ConditionParamBuilder.class);
if (Strings.isNullOrEmpty(paramName)) {
paramName = paramBuilder.createParamName(this);
}
param = paramBuilder.createParam(this);
param.setDateInterval(BooleanUtils.toBoolean(paramElem.attributeValue("isDateInterval", "false"), "true", "false"));
param.parseValue(paramElem.getText());
param.setDefaultValue(param.getValue());
}
if ("EMPTY".equals(operatorName)) {
//for backward compatibility with old filters that still use EMPTY operator
operatorName = "NOT_EMPTY";
if (BooleanUtils.isTrue((Boolean) param.getValue()))
param.setValue(false);
param.setDefaultValue(false);
operator = Op.valueOf(operatorName);
}
}
示例12: setUp
import com.haulmont.cuba.core.global.Scripting; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
scripting = AppBeans.get(Scripting.class);
}