Java Code Examples for org.jboss.dmr.ModelType#BYTES

The following examples show how to use org.jboss.dmr.ModelType#BYTES . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Util.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void replaceFilePathsWithBytes(ModelNode request, ModelNode opDescOutcome) throws CommandFormatException {
    ModelNode requestProps = opDescOutcome.get("result", "request-properties");
    for (Property prop : requestProps.asPropertyList()) {
        ModelNode typeDesc = prop.getValue().get("type");
        if (typeDesc.getType() == ModelType.TYPE && typeDesc.asType() == ModelType.BYTES
                && request.hasDefined(prop.getName())) {
            String filePath = request.get(prop.getName()).asString();
            File localFile = new File(filePath);
            if (!localFile.exists())
                continue;
            try {
                request.get(prop.getName()).set(Util.readBytes(localFile));
            } catch (OperationFormatException e) {
                throw new CommandFormatException(e);
            }
        }
    }
}
 
Example 2
Source File: OperationDialog.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void setInputComponent() {
    this.label = makeLabel();
    if (type == ModelType.BOOLEAN && !expressionsAllowed) {
        this.valueComponent = new JCheckBox(makeLabelString(false));
        this.valueComponent.setToolTipText(description);
        this.label = new JLabel(); // checkbox doesn't need a label
    } else if (type == ModelType.UNDEFINED) {
        JLabel jLabel = new JLabel();
        this.valueComponent = jLabel;
    } else if (props.get("allowed").isDefined()) {
        JComboBox comboBox = makeJComboBox(props.get("allowed").asList());
        this.valueComponent = comboBox;
    } else if (type == ModelType.LIST) {
        ListEditor listEditor = new ListEditor(OperationDialog.this);
        this.valueComponent = listEditor;
    } else if (type == ModelType.BYTES) {
        this.valueComponent = new BrowsePanel(OperationDialog.this);
    } else {
        JTextField textField = new JTextField(30);
        this.valueComponent = textField;
    }
}
 
Example 3
Source File: DeploymentOverlayContentDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public ModelNode correct(ModelNode newValue, ModelNode currentValue) {
    if (newValue.isDefined() && newValue.getType() == ModelType.BYTES) {
        //The generated add from the model sync does not wrap the hash, adjust that here
        ModelNode corrected = new ModelNode();
        corrected.get(HASH).set(newValue);
        return corrected;
    }
    return newValue;
}
 
Example 4
Source File: CommandExecutor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private boolean replaceFilePathsWithBytes(ModelNode request) throws CommandFormatException, IOException {
    boolean didReplacement = false;
    ModelNode opDesc = new ModelNode();
    opDesc.get("address").set(request.get("address"));
    opDesc.get("operation").set("read-operation-description");
    final String opName = request.get("operation").asString();
    opDesc.get("name").set(opName);
    ModelNode response = execute(opDesc, false).getResponseNode();
    if (response.hasDefined("result", "request-properties")) {
        final ModelNode requestProps = response.get("result", "request-properties");
        for (Property prop : requestProps.asPropertyList()) {
            ModelNode typeDesc = prop.getValue().get("type");
            if (typeDesc.getType() == ModelType.TYPE && typeDesc.asType() == ModelType.BYTES
                    && request.hasDefined(prop.getName())) {
                String filePath = request.get(prop.getName()).asString();
                File localFile = new File(filePath);
                if (!localFile.exists())
                    continue;
                try {
                    request.get(prop.getName()).set(Util.readBytes(localFile));
                    didReplacement = true;
                } catch (OperationFormatException e) {
                    throw new CommandFormatException(e);
                }
            }
        }
    }
    return didReplacement;
}
 
Example 5
Source File: ModelTestModelDescriptionValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public String validate(ModelType currentType, ModelNode currentNode, String descriptor) {
    if (currentNode.hasDefined(descriptor)) {
        if (currentType != ModelType.LIST && currentType != ModelType.STRING &&
                currentType != ModelType.BYTES) {
            return "Unnecessary '" + descriptor + "' for non-numeric type=" + currentType;
        }
        try {
            currentNode.get(descriptor).asLong();
        } catch (Exception e) {
            return "'" + descriptor + "' is not an int/long";
        }
    }
    return null;
}
 
Example 6
Source File: ModelTypeValidatorUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testBytes() {
    ModelTypeValidator testee = new ModelTypeValidator(ModelType.BYTES, false, false, false);
    assertOk(testee, new ModelNode().set(new byte[0]));
    assertInvalid(testee, new ModelNode().set("bytes"));
}
 
Example 7
Source File: DeploymentAttributes.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public HashValidator(boolean nillable) {
    super(ModelType.BYTES, nillable);
}
 
Example 8
Source File: DeploymentOverlayContentDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public HashValidator(boolean nillable) {
    super(ModelType.BYTES, nillable);
}
 
Example 9
Source File: ValueTypeCompleter.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
boolean isCompliantType(ModelNode t) {
    return t.getType() == ModelType.BYTES;
}
 
Example 10
Source File: BytesValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Creates a BytesValidator that allows potentially more than one type.
 * @param min the minimum length of the byte[]
 * @param max the maximum length of the byte[]
 * @param nullable whether an undefined value is allowed
 */
public BytesValidator(final int min, final int max, final boolean nullable) {
    super(ModelType.BYTES, nullable);
    this.min = min;
    this.max = max;
}
 
Example 11
Source File: BytesValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Creates a BytesValidator
 * @param min the minimum length of the byte[]
 * @param max the maximum length of the byte[]
 * @param otherValidTypes additional valid types (i.e one of those whose value can convert to a byte[].) May be {@code null}
 */
public BytesValidator(final int min, final int max, final ModelType... otherValidTypes) {
    super(false, false, false, ModelType.BYTES, otherValidTypes);
    this.min = min;
    this.max = max;
}