/** * Checks if the given node is of {@link ModelType#STRING} with a string value that includes expression syntax. * If so returns a node of {@link ModelType#EXPRESSION}, else simply returns {@code node} unchanged * * @param node the node to examine. Will not be {@code null} * @return the node with expressions converted, or the original node if no conversion was performed * Cannot return {@code null} */ protected static ModelNode convertStringExpression(ModelNode node) { if (node.getType() == ModelType.STRING) { return ParseUtils.parsePossibleExpression(node.asString()); } return node; }
private static ModelNode parsePossibleExpression(final ModelNode node) { return (node.getType() == ModelType.STRING) ? ParseUtils.parsePossibleExpression(node.asString()) : node; }
private static ModelNode parsePossibleExpression(final ModelNode node) { return (node.getType() == ModelType.STRING) ? ParseUtils.parsePossibleExpression(node.asString()) : node; }
/** * Checks if the given node is of {@link ModelType#STRING} with a string value that includes expression syntax. * If so returns a node of {@link ModelType#EXPRESSION}, else simply returns {@code node} unchanged * * @param node the node to examine. Will not be {@code null} * @return the node with expressions converted, or the original node if no conversion was performed * Cannot return {@code null} */ protected static ModelNode convertStringExpression(ModelNode node) { if (node.getType() == ModelType.STRING) { return ParseUtils.parsePossibleExpression(node.asString()); } return node; }
/** * Checks if the given node is of {@link ModelType#STRING} with a string value that includes expression syntax. * If so returns a node of {@link ModelType#EXPRESSION}, else simply returns {@code node} unchanged * * @param node the node to examine. Will not be {@code null} * @return the node with expressions converted, or the original node if no conversion was performed * Cannot return {@code null} */ protected static ModelNode convertStringExpression(ModelNode node) { if (node.getType() == ModelType.STRING) { return ParseUtils.parsePossibleExpression(node.asString()); } return node; }
private static ModelNode parsePossibleExpression(final ModelNode node) { return (node.getType() == ModelType.STRING) ? ParseUtils.parsePossibleExpression(node.asString()) : node; }
/** * Checks if the given node is of {@link ModelType#STRING} with a string value that includes expression syntax. * If so returns a node of {@link ModelType#EXPRESSION}, else simply returns {@code node} unchanged * * @param node the node to examine. Will not be {@code null} * @return the node with expressions converted, or the original node if no conversion was performed * Cannot return {@code null} */ protected static ModelNode convertStringExpression(ModelNode node) { if (node.getType() == ModelType.STRING) { return ParseUtils.parsePossibleExpression(node.asString()); } return node; }
private static ModelNode parsePossibleExpression(final ModelNode node) { return (node.getType() == ModelType.STRING) ? ParseUtils.parsePossibleExpression(node.asString()) : node; }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { ModelNode toResolve = EXPRESSION.validateOperation(operation); if (toResolve.getType() == ModelType.STRING) { toResolve = ParseUtils.parsePossibleExpression(toResolve.asString()); } try { ModelNode resolved = toResolve.resolve(); ModelNode result = context.getResult(); if (resolved.isDefined()) { result.set(resolved.asString()); } context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER); } catch (SecurityException e) { throw new OperationFailedException(new ModelNode().set(ControllerMessages.MESSAGES.noPermissionToResolveExpression(toResolve, e))); } catch (IllegalStateException e) { throw new OperationFailedException(new ModelNode().set(ControllerMessages.MESSAGES.cannotResolveExpression(toResolve, e))); } } }, OperationContext.Stage.RUNTIME);
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { ModelNode toResolve = EXPRESSION.validateOperation(operation); if (toResolve.getType() == ModelType.STRING) { toResolve = ParseUtils.parsePossibleExpression(toResolve.asString()); } try { ModelNode resolved = toResolve.resolve(); ModelNode result = context.getResult(); if (resolved.isDefined()) { result.set(resolved.asString()); } context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER); } catch (SecurityException e) { throw new OperationFailedException(new ModelNode().set(ControllerMessages.MESSAGES.noPermissionToResolveExpression(toResolve, e))); } catch (IllegalStateException e) { throw new OperationFailedException(new ModelNode().set(ControllerMessages.MESSAGES.cannotResolveExpression(toResolve, e))); } } }, OperationContext.Stage.RUNTIME);
public static ModelNode parseEnvironmentVariables(final XMLExtendedStreamReader reader, final Namespace expectedNs, ModelNode addOp) throws XMLStreamException { final ModelNode properties = new ModelNode(); while (reader.nextTag() != END_ELEMENT) { requireNamespace(reader, expectedNs); if (Element.forName(reader.getLocalName()) != Element.VARIABLE) { throw unexpectedElement(reader); } final String[] array = requireAttributes(reader, Attribute.NAME.getLocalName(), Attribute.VALUE.getLocalName()); requireNoContent(reader); properties.get(array[0]).set(ParseUtils.parsePossibleExpression(array[1])); } if (!properties.isDefined()) { throw missingRequiredElement(reader, Collections.singleton(Element.OPTION)); } addOp.get(JvmAttributes.JVM_ENV_VARIABLES).set(properties); return properties; }
public static ModelNode parseEnvironmentVariables(final XMLExtendedStreamReader reader, final Namespace expectedNs, ModelNode addOp) throws XMLStreamException { final ModelNode properties = new ModelNode(); while (reader.nextTag() != END_ELEMENT) { requireNamespace(reader, expectedNs); if (Element.forName(reader.getLocalName()) != Element.VARIABLE) { throw unexpectedElement(reader); } final String[] array = requireAttributes(reader, Attribute.NAME.getLocalName(), Attribute.VALUE.getLocalName()); requireNoContent(reader); properties.get(array[0]).set(ParseUtils.parsePossibleExpression(array[1])); } if (!properties.isDefined()) { throw missingRequiredElement(reader, Collections.singleton(Element.OPTION)); } addOp.get(JvmAttributes.JVM_ENV_VARIABLES).set(properties); return properties; }
public static Property readProperty(final XMLExtendedStreamReader reader, boolean supportsExpressions) throws XMLStreamException { final int cnt = reader.getAttributeCount(); String name = null; ModelNode value = null; for (int i = 0; i < cnt; i++) { String uri = reader.getAttributeNamespace(i); if (uri != null&&!"".equals(XMLConstants.NULL_NS_URI)) { throw unexpectedAttribute(reader, i); } final String localName = reader.getAttributeLocalName(i); if (localName.equals("name")) { name = reader.getAttributeValue(i); } else if (localName.equals("value")) { if (supportsExpressions) { value = parsePossibleExpression(reader.getAttributeValue(i)); } else { value = new ModelNode(reader.getAttributeValue(i)); } } else { throw unexpectedAttribute(reader, i); } } if (name == null) { throw missingRequired(reader, Collections.singleton("name")); } if (reader.next() != END_ELEMENT) { throw unexpectedElement(reader); } return new Property(name, new ModelNode().set(value == null ? new ModelNode() : value)); }
public static ModelNode parseEnvironmentVariables(final XMLExtendedStreamReader reader, final Namespace expectedNs, ModelNode addOp) throws XMLStreamException { final ModelNode properties = new ModelNode(); while (reader.nextTag() != END_ELEMENT) { requireNamespace(reader, expectedNs); if (Element.forName(reader.getLocalName()) != Element.VARIABLE) { throw unexpectedElement(reader); } final String[] array = requireAttributes(reader, Attribute.NAME.getLocalName(), Attribute.VALUE.getLocalName()); requireNoContent(reader); properties.add(array[0], ParseUtils.parsePossibleExpression(array[1])); } if (!properties.isDefined()) { throw missingRequiredElement(reader, Collections.singleton(Element.OPTION)); } addOp.get(JvmAttributes.JVM_ENV_VARIABLES).set(properties); return properties; }
public static ModelNode parseBoundedIntegerAttribute(final XMLExtendedStreamReader reader, final int index, final int minInclusive, final int maxInclusive, boolean allowExpression) throws XMLStreamException { final String stringValue = reader.getAttributeValue(index); if (allowExpression) { ModelNode expression = parsePossibleExpression(stringValue); if (expression.getType() == ModelType.EXPRESSION) { return expression; } } try { final int value = Integer.parseInt(stringValue); if (value < minInclusive || value > maxInclusive) { throw ControllerLogger.ROOT_LOGGER.invalidAttributeValue(value, reader.getAttributeName(index), minInclusive, maxInclusive, reader.getLocation()); } return new ModelNode().set(value); } catch (NumberFormatException nfe) { throw ControllerLogger.ROOT_LOGGER.invalidAttributeValueInt(nfe, stringValue, reader.getAttributeName(index), reader.getLocation()); } }
public static ModelNode parseBoundedIntegerAttribute(final XMLExtendedStreamReader reader, final int index, final int minInclusive, final int maxInclusive, boolean allowExpression) throws XMLStreamException { final String stringValue = reader.getAttributeValue(index); if (allowExpression) { ModelNode expression = parsePossibleExpression(stringValue); if (expression.getType() == ModelType.EXPRESSION) { return expression; } } try { final int value = Integer.parseInt(stringValue); if (value < minInclusive || value > maxInclusive) { throw ControllerLogger.ROOT_LOGGER.invalidAttributeValue(value, reader.getAttributeName(index), minInclusive, maxInclusive, reader.getLocation()); } return new ModelNode().set(value); } catch (NumberFormatException nfe) { throw ControllerLogger.ROOT_LOGGER.invalidAttributeValueInt(nfe, stringValue, reader.getAttributeName(index), reader.getLocation()); } }
public static ModelNode parseBoundedIntegerAttribute(final XMLExtendedStreamReader reader, final int index, final int minInclusive, final int maxInclusive, boolean allowExpression) throws XMLStreamException { final String stringValue = reader.getAttributeValue(index); if (allowExpression) { ModelNode expression = parsePossibleExpression(stringValue); if (expression.getType() == ModelType.EXPRESSION) { return expression; } } try { final int value = Integer.parseInt(stringValue); if (value < minInclusive || value > maxInclusive) { throw MESSAGES.invalidAttributeValue(value, reader.getAttributeName(index), minInclusive, maxInclusive, reader.getLocation()); } return new ModelNode().set(value); } catch (NumberFormatException nfe) { throw MESSAGES.invalidAttributeValueInt(nfe, stringValue, reader.getAttributeName(index), reader.getLocation()); } }
public static ModelNode parseBoundedIntegerAttribute(final XMLExtendedStreamReader reader, final int index, final int minInclusive, final int maxInclusive, boolean allowExpression) throws XMLStreamException { final String stringValue = reader.getAttributeValue(index); if (allowExpression) { ModelNode expression = parsePossibleExpression(stringValue); if (expression.getType() == ModelType.EXPRESSION) { return expression; } } try { final int value = Integer.parseInt(stringValue); if (value < minInclusive || value > maxInclusive) { throw MESSAGES.invalidAttributeValue(value, reader.getAttributeName(index), minInclusive, maxInclusive, reader.getLocation()); } return new ModelNode().set(value); } catch (NumberFormatException nfe) { throw MESSAGES.invalidAttributeValueInt(nfe, stringValue, reader.getAttributeName(index), reader.getLocation()); } }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { ModelNode toResolve = EXPRESSION.validateOperation(operation); if (toResolve.getType() == ModelType.STRING) { toResolve = ParseUtils.parsePossibleExpression(toResolve.asString()); } try { ModelNode resolved = ExpressionResolver.SIMPLE.resolveExpressions(toResolve); ModelNode result = context.getResult(); if (resolved.isDefined()) { result.set(resolved.asString()); } context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER); } catch (SecurityException e) { throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.noPermissionToResolveExpression(toResolve, e)); } catch (IllegalStateException e) { final ModelNode failureDescription = ControllerLogger.ROOT_LOGGER.cannotResolveExpression(toResolve.asString()).getFailureDescription(); deferFailureReporting(context, failureDescription); } catch (OperationFailedException e) { deferFailureReporting(context, e.getFailureDescription()); } }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { ModelNode toResolve = EXPRESSION.validateOperation(operation); if (toResolve.getType() == ModelType.STRING) { toResolve = ParseUtils.parsePossibleExpression(toResolve.asString()); } try { ModelNode resolved = ExpressionResolver.SIMPLE.resolveExpressions(toResolve); ModelNode result = context.getResult(); if (resolved.isDefined()) { result.set(resolved.asString()); } context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER); } catch (SecurityException e) { throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.noPermissionToResolveExpression(toResolve, e)); } catch (IllegalStateException e) { final ModelNode failureDescription = ControllerLogger.ROOT_LOGGER.cannotResolveExpression(toResolve.asString()).getFailureDescription(); deferFailureReporting(context, failureDescription); } catch (OperationFailedException e) { deferFailureReporting(context, e.getFailureDescription()); } }