当前位置: 首页>>代码示例>>Java>>正文


Java Scripting类代码示例

本文整理汇总了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));
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:21,代码来源:ScriptValidator.java

示例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;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:27,代码来源:TimeBetweenQueryMacroHandler.java

示例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));
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:10,代码来源:AbstractOptionsBaseLoader.java

示例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));
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:10,代码来源:LookupFieldLoader.java

示例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;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:16,代码来源:WindowInfo.java

示例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"));
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:15,代码来源:CustomConditionDescriptor.java

示例7: ResourcesImpl

import com.haulmont.cuba.core.global.Scripting; //导入依赖的package包/类
@Inject
public ResourcesImpl(Scripting scripting) {
    super(scripting.getClassLoader());
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:5,代码来源:ResourcesImpl.java

示例8: CustomDecorator

import com.haulmont.cuba.core.global.Scripting; //导入依赖的package包/类
public CustomDecorator(String className) {
    this.decoratorClass = AppBeans.get(Scripting.class).loadClassNN(className);
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:4,代码来源:CustomDecorator.java

示例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);
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:6,代码来源:DsContextLoader.java

示例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;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:54,代码来源:DynamicAttributeCustomFieldGenerator.java

示例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);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:46,代码来源:AbstractCondition.java

示例12: setUp

import com.haulmont.cuba.core.global.Scripting; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    scripting = AppBeans.get(Scripting.class);
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:5,代码来源:ScriptingTest.java


注:本文中的com.haulmont.cuba.core.global.Scripting类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。