Search in sources :

Example 6 with ValueExpression

use of org.jboss.dmr.ValueExpression in project wildfly by wildfly.

the class ExpressionSupportSmokeTestCase method organizeAttributes.

private void organizeAttributes(PathAddress address, ModelNode description, ModelNode resource, ModelNode resourceNoDefaults, Map<String, ModelNode> expressionAttrs, Map<String, ModelNode> otherAttrs, Map<String, ModelNode> expectedAttrs) {
    ModelNode attributeDescriptions = description.get(ATTRIBUTES);
    for (Property descProp : attributeDescriptions.asPropertyList()) {
        String attrName = descProp.getName();
        ModelNode attrDesc = descProp.getValue();
        if (isAttributeExcluded(address, attrName, attrDesc, resourceNoDefaults)) {
            continue;
        }
        ModelNode noDefaultValue = resourceNoDefaults.get(attrName);
        if (!noDefaultValue.isDefined()) {
            // We need to see if it's legal to set this attribute, or whether it's undefined
            // because an alternative attribute is defined or a required attribute is not defined.
            Set<String> base = new HashSet<String>();
            base.add(attrName);
            if (attrDesc.hasDefined(REQUIRES)) {
                for (ModelNode node : attrDesc.get(REQUIRES).asList()) {
                    base.add(node.asString());
                }
            }
            boolean conflict = false;
            for (String baseAttr : base) {
                if (!resource.hasDefined(baseAttr)) {
                    conflict = true;
                    break;
                }
                ModelNode baseAttrAlts = attributeDescriptions.get(baseAttr, ALTERNATIVES);
                if (baseAttrAlts.isDefined()) {
                    for (ModelNode alt : baseAttrAlts.asList()) {
                        String altName = alt.asString();
                        if (resourceNoDefaults.hasDefined(alt.asString()) || expressionAttrs.containsKey(altName) || otherAttrs.containsKey(altName)) {
                            conflict = true;
                            break;
                        }
                    }
                }
            }
            if (conflict) {
                conflicts++;
                logHandling("Skipping conflicted attribute " + attrName + " at " + address.toModelNode().asString());
                continue;
            }
        }
        ModelNode attrValue = resource.get(attrName);
        ModelType attrType = attrValue.getType();
        if (attrDesc.get(EXPRESSIONS_ALLOWED).asBoolean(false)) {
            // If it's defined and not an expression, use the current value to create an expression
            if (attrType != ModelType.UNDEFINED && attrType != ModelType.EXPRESSION) {
                // Deal with complex types specially
                if (COMPLEX_TYPES.contains(attrType)) {
                    ModelNode valueType = attrDesc.get(VALUE_TYPE);
                    if (valueType.getType() == ModelType.TYPE) {
                        // Simple collection whose elements support expressions
                        handleSimpleCollection(address, attrName, attrValue, valueType.asType(), expressionAttrs, otherAttrs, expectedAttrs);
                    } else if (valueType.isDefined()) {
                        handleComplexCollection(address, attrName, attrValue, attrType, valueType, expressionAttrs, otherAttrs, expectedAttrs);
                    } else {
                        noSimple++;
                        logNoExpressions(address, attrName);
                        otherAttrs.put(attrName, attrValue);
                        expectedAttrs.put(attrName, attrValue);
                    }
                } else {
                    if (attrType == ModelType.STRING) {
                        checkForUnconvertedExpression(address, attrName, attrValue);
                    }
                    String expression = "${exp.test:" + attrValue.asString() + "}";
                    expressionAttrs.put(attrName, new ModelNode(expression));
                    expectedAttrs.put(attrName, new ModelNode().set(new ValueExpression(expression)));
                    simple++;
                    logHandling("Added expression to simple attribute " + attrName + " at " + address.toModelNode().asString());
                }
            } else {
                if (attrType != ModelType.EXPRESSION) {
                    supportedUndefined++;
                    logHandling("Expression supported but value undefined on simple attribute " + attrName + " at " + address.toModelNode().asString());
                } else {
                    simple++;
                    logHandling("Already found an expression on simple attribute " + attrName + " at " + address.toModelNode().asString());
                }
                otherAttrs.put(attrName, attrValue);
                expectedAttrs.put(attrName, attrValue);
            }
        } else if (COMPLEX_TYPES.contains(attrType) && attrDesc.get(VALUE_TYPE).getType() != ModelType.TYPE && attrDesc.get(VALUE_TYPE).isDefined()) {
            handleComplexCollection(address, attrName, attrValue, attrType, attrDesc.get(VALUE_TYPE), expressionAttrs, otherAttrs, expectedAttrs);
        } else /*if (!attrDesc.hasDefined(DEPRECATED))*/
        {
            noSimple++;
            logNoExpressions(address, attrName);
            otherAttrs.put(attrName, attrValue);
            expectedAttrs.put(attrName, attrValue);
        }
    }
}
Also used : ValueExpression(org.jboss.dmr.ValueExpression) ModelType(org.jboss.dmr.ModelType) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property) HashSet(java.util.HashSet)

Example 7 with ValueExpression

use of org.jboss.dmr.ValueExpression in project wildfly by wildfly.

the class WebMigrateOperation method createWelcomeContentHandler.

/**
     * create a handler for serving welcome content
     */
private void createWelcomeContentHandler(Map<PathAddress, ModelNode> migrationOperations) {
    PathAddress address = pathAddress(pathElement(SUBSYSTEM, UndertowExtension.SUBSYSTEM_NAME), pathElement(Constants.CONFIGURATION, Constants.HANDLER));
    migrationOperations.put(address, createAddOperation(address));
    address = pathAddress(pathElement(SUBSYSTEM, UndertowExtension.SUBSYSTEM_NAME), pathElement(Constants.CONFIGURATION, Constants.HANDLER), pathElement(Constants.FILE, "welcome-content"));
    final ModelNode add = createAddOperation(address);
    add.get(Constants.PATH).set(new ModelNode(new ValueExpression("${jboss.home.dir}/welcome-content")));
    migrationOperations.put(address, add);
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) ValueExpression(org.jboss.dmr.ValueExpression) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

ModelNode (org.jboss.dmr.ModelNode)7 ValueExpression (org.jboss.dmr.ValueExpression)7 Property (org.jboss.dmr.Property)4 ModelType (org.jboss.dmr.ModelType)3 Test (org.junit.Test)2 HashSet (java.util.HashSet)1 Matcher (java.util.regex.Matcher)1 PathAddress (org.jboss.as.controller.PathAddress)1