public PropertyAttributeDefinition build() { if (xmlName == null) xmlName = name; if (propertyName == null) propertyName = name; return new PropertyAttributeDefinition(name, xmlName, propertyName, resolver, defaultValue, type, allowNull, allowExpression, measurementUnit, corrector, validator, validateNull, alternatives, requires, attributeMarshaller, resourceOnly, deprecated, flags); }
private static void handleProperty(final AttributeDefinition attribute, final OperationContext context, final ModelNode model, final LoggerConfiguration configuration, final boolean resolveValue) throws OperationFailedException { if (FILTER_SPEC.equals(attribute)) { final ModelNode valueNode = (resolveValue ? FILTER_SPEC.resolveModelAttribute(context, model) : model); final String resolvedValue = (valueNode.isDefined() ? valueNode.asString() : null); configuration.setFilter(resolvedValue); } else if (LEVEL.equals(attribute)) { final String resolvedValue = (resolveValue ? LEVEL.resolvePropertyValue(context, model) : LEVEL.resolver().resolveValue(context, model)); configuration.setLevel(resolvedValue); } else if (HANDLERS.equals(attribute)) { final Collection<String> resolvedValue = (resolveValue ? HANDLERS.resolvePropertyValue(context, model) : HANDLERS.resolver().resolveValue(context, model)); configuration.setHandlerNames(resolvedValue); } else if (USE_PARENT_HANDLERS.equals(attribute)) { final ModelNode useParentHandlers = (resolveValue ? USE_PARENT_HANDLERS.resolveModelAttribute(context, model) : model); final Boolean resolvedValue = (useParentHandlers.isDefined() ? useParentHandlers.asBoolean() : null); configuration.setUseParentHandlers(resolvedValue); } }
private static void parseFilter(final Namespace namespace, final ModelNode node, final XMLExtendedStreamReader reader) throws XMLStreamException { if (namespace == Namespace.LOGGING_1_0 || namespace == Namespace.LOGGING_1_1) { // No attributes if (reader.getAttributeCount() > 0) { throw unexpectedAttribute(reader, 0); } final StringBuilder filter = new StringBuilder(); parseFilterChildren(filter, false, reader); node.get(FILTER_SPEC.getName()).set(filter.toString()); } else { FILTER_SPEC.parseAndSetParameter(readStringAttributeElement(reader, Attribute.VALUE.getLocalName()), node, reader); } }
private void writeSyslogHandler(final XMLExtendedStreamWriter writer, final ModelNode model, final String name) throws XMLStreamException { writer.writeStartElement(Element.SYSLOG_HANDLER.getLocalName()); writer.writeAttribute(HANDLER_NAME.getXmlName(), name); ENABLED.marshallAsAttribute(model, false, writer); LEVEL.marshallAsElement(model, writer); SERVER_ADDRESS.marshallAsElement(model, writer); HOSTNAME.marshallAsElement(model, writer); PORT.marshallAsElement(model, writer); APP_NAME.marshallAsElement(model, writer); SYSLOG_FORMATTER.marshallAsElement(model, writer); FACILITY.marshallAsElement(model, writer); writer.writeEndElement(); }
@Override public void marshallAsElement(final AttributeDefinition attribute, final ModelNode resourceModel, final boolean marshallDefault, final XMLStreamWriter writer) throws XMLStreamException { if (isMarshallable(attribute, resourceModel, marshallDefault)) { writer.writeStartElement(attribute.getXmlName()); final String pattern = resourceModel.get(PATTERN.getName()).asString(); writer.writeAttribute(PATTERN.getXmlName(), pattern); if (resourceModel.hasDefined(COLOR_MAP.getName())) { final String colorMap = resourceModel.get(COLOR_MAP.getName()).asString(); writer.writeAttribute(COLOR_MAP.getXmlName(), colorMap); } writer.writeEndElement(); } }
@Override protected boolean applyUpdate(final OperationContext context, final String attributeName, final String addressName, final ModelNode value, final LogContextConfiguration logContextConfiguration) { final FormatterConfiguration configuration = logContextConfiguration.getFormatterConfiguration(addressName); for (PropertyAttributeDefinition attribute : ATTRIBUTES) { if (attribute.getName().equals(attributeName)) { configuration.setPropertyValueString(attribute.getPropertyName(), value.asString()); break; } } return false; } };
throws OperationFailedException { final boolean result; if (attribute.getName().equals(ENABLED.getName())) { final boolean resolvedValue = ENABLED.resolveModelAttribute(context, model).asBoolean(); final boolean currentValue; if (configuration.hasProperty(ENABLED.getPropertyName())) { currentValue = Boolean.parseBoolean(configuration.getPropertyValueString(ENABLED.getPropertyName())); } else { currentValue = isDisabledHandler(logContextConfiguration.getLogContext(), configuration.getName()); } else if (attribute.getName().equals(ENCODING.getName())) { final String resolvedValue = ENCODING.resolvePropertyValue(context, model); final String currentValue = configuration.getEncoding(); result = (resolvedValue == null ? currentValue == null : resolvedValue.equals(currentValue)); } else if (attribute.getName().equals(FORMATTER.getName())) { final String formatterName = configuration.getName(); final FormatterConfiguration fmtConfig; if (logContextConfiguration.getFormatterNames().contains(formatterName)) { fmtConfig = logContextConfiguration.getFormatterConfiguration(formatterName); final String resolvedValue = FORMATTER.resolvePropertyValue(context, model); final String currentValue = fmtConfig.getPropertyValueString("pattern"); result = (resolvedValue == null ? currentValue == null : resolvedValue.equals(currentValue)); } else if (attribute.getName().equals(FILTER_SPEC.getName())) { final ModelNode valueNode = FILTER_SPEC.resolveModelAttribute(context, model); final String resolvedValue = (valueNode.isDefined() ? valueNode.asString() : null); final String currentValue = configuration.getFilter(); result = (resolvedValue == null ? currentValue == null : resolvedValue.equals(currentValue)); } else if (attribute.getName().equals(LEVEL.getName())) {
@Override public void updateModel(final OperationContext context, final ModelNode operation, final ModelNode model) { // Set the enable attribute to true model.get(CommonAttributes.ENABLED.getName()).set(true); }
void parsePatternFormatterElement(final XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException { final EnumSet<Attribute> required = EnumSet.of(Attribute.PATTERN); final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { requireNoNamespaceAttribute(reader, i); final String value = reader.getAttributeValue(i); final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); required.remove(attribute); switch (attribute) { case PATTERN: { PatternFormatterResourceDefinition.PATTERN.parseAndSetParameter(value, operation, reader); break; } case COLOR_MAP: { PatternFormatterResourceDefinition.COLOR_MAP.parseAndSetParameter(value, operation, reader); break; } default: throw unexpectedAttribute(reader, i); } } if (!required.isEmpty()) { throw missingRequired(reader, required); } requireNoContent(reader); }
@Override public String resolvePropertyValue(final OperationContext context, final ModelNode model) throws OperationFailedException { String result = null; final ModelNode value = resolveModelAttribute(context, model); if (value.isDefined()) { if (resolver == null) { result = value.asString(); } else { result = resolver.resolveValue(context, value); } } return result; }
final PropertyAttributeDefinition propertyAttribute = (PropertyAttributeDefinition) attribute; if (value.isDefined()) { final ModelNodeResolver<String> resolver = propertyAttribute.resolver(); String resolvedValue = value.asString(); if (resolver != null) { resolvedValue = resolver.resolveValue(context, value); configuration.setPropertyValueString(propertyAttribute.getPropertyName(), resolvedValue); } else { configuration.removeProperty(propertyAttribute.getPropertyName());
final String attributeName = reader.getAttributeLocalName(i); final String value = reader.getAttributeValue(i); if (attributeName.equals(StructuredFormatterResourceDefinition.DATE_FORMAT.getXmlName())) { StructuredFormatterResourceDefinition.DATE_FORMAT.parseAndSetParameter(value, operation, reader); } else if (attributeName.equals(StructuredFormatterResourceDefinition.PRETTY_PRINT.getXmlName())) { StructuredFormatterResourceDefinition.PRETTY_PRINT.parseAndSetParameter(value, operation, reader); } else if (attributeName.equals(StructuredFormatterResourceDefinition.PRINT_DETAILS.getXmlName())) { StructuredFormatterResourceDefinition.PRINT_DETAILS.parseAndSetParameter(value, operation, reader); } else if (attributeName.equals(StructuredFormatterResourceDefinition.ZONE_ID.getXmlName())) { StructuredFormatterResourceDefinition.ZONE_ID.parseAndSetParameter(value, operation, reader); } else { boolean invalid = true; throw unexpectedElement(reader); if (elementName.equals(StructuredFormatterResourceDefinition.EXCEPTION_OUTPUT_TYPE.getXmlName())) { StructuredFormatterResourceDefinition.EXCEPTION_OUTPUT_TYPE.parseAndSetParameter(readValueAttribute(reader), operation, reader); } else if (elementName.equals(StructuredFormatterResourceDefinition.RECORD_DELIMITER.getXmlName())) { StructuredFormatterResourceDefinition.RECORD_DELIMITER.parseAndSetParameter(readValueAttribute(reader), operation, reader); } else if (elementName.equals(StructuredFormatterResourceDefinition.KEY_OVERRIDES.getXmlName())) { StructuredFormatterResourceDefinition.KEY_OVERRIDES.getParser().parseElement(StructuredFormatterResourceDefinition.KEY_OVERRIDES, reader, operation);
@Override public void marshallAsElement(final AttributeDefinition attribute, final ModelNode resourceModel, final boolean marshallDefault, final XMLStreamWriter writer) throws XMLStreamException { if (isMarshallable(attribute, resourceModel, marshallDefault)) { writer.writeStartElement(FORMATTER.getXmlName()); writer.writeStartElement(attribute.getXmlName()); String content = resourceModel.get(attribute.getName()).asString(); writer.writeAttribute(CommonAttributes.NAME.getName(), content); writer.writeEndElement(); writer.writeEndElement(); } } })
private void writeLogger(final XMLExtendedStreamWriter writer, String name, final ModelNode node) throws XMLStreamException { writer.writeStartElement(Element.LOGGER.getLocalName()); writer.writeAttribute(CATEGORY.getXmlName(), name); USE_PARENT_HANDLERS.marshallAsAttribute(node, writer); writeCommonLogger(writer, node); writer.writeEndElement(); }
private void writeCommonHandler(final XMLExtendedStreamWriter writer, final ModelNode node) throws XMLStreamException { LEVEL.marshallAsElement(node, writer); ENCODING.marshallAsElement(node, writer); FILTER_SPEC.marshallAsElement(node, writer); FORMATTER.marshallAsElement(node, writer); }
@Override public void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model, final LogContextConfiguration logContextConfiguration) throws OperationFailedException { final String name = context.getCurrentAddressValue(); HandlerConfiguration configuration = logContextConfiguration.getHandlerConfiguration(name); if (configuration == null) { configuration = logContextConfiguration.addHandlerConfiguration(null, DelayedHandler.class.getName(), name); } else { if (!(configuration.getInstance() instanceof DelayedHandler)) { throw LoggingLogger.ROOT_LOGGER.invalidType(DelayedHandler.class, configuration.getInstance().getClass()); } } ENABLED.setPropertyValue(context, model, configuration); final ModelNode filter = FILTER_SPEC.resolveModelAttribute(context, model); if (filter.isDefined()) { configuration.setFilter(filter.asString()); } configuration.setLevel(LEVEL.resolvePropertyValue(context, model)); configuration.setFormatterName(NAMED_FORMATTER.resolveModelAttribute(context, model).asString()); }
@Override public void setPropertyValue(final OperationContext context, final ModelNode model, final PropertyConfigurable configuration) throws OperationFailedException { final String value = resolvePropertyValue(context, model); if (value == null) { configuration.removeProperty(propertyName); } else { configuration.setPropertyValueString(propertyName, value); } }
throws OperationFailedException { final boolean result; if (attribute.getName().equals(ENABLED.getName())) { final boolean resolvedValue = ENABLED.resolveModelAttribute(context, model).asBoolean(); final boolean currentValue; if (configuration.hasProperty(ENABLED.getPropertyName())) { currentValue = Boolean.parseBoolean(configuration.getPropertyValueString(ENABLED.getPropertyName())); } else { currentValue = isDisabledHandler(logContextConfiguration.getLogContext(), configuration.getName()); } else if (attribute.getName().equals(ENCODING.getName())) { final String resolvedValue = ENCODING.resolvePropertyValue(context, model); final String currentValue = configuration.getEncoding(); result = (resolvedValue == null ? currentValue == null : resolvedValue.equals(currentValue)); } else if (attribute.getName().equals(FORMATTER.getName())) { if (logContextConfiguration.getFormatterNames().contains(formatterName)) { fmtConfig = logContextConfiguration.getFormatterConfiguration(formatterName); final String resolvedValue = FORMATTER.resolvePropertyValue(context, model); final String currentValue = fmtConfig.getPropertyValueString(PATTERN.getName()); result = (resolvedValue == null ? currentValue == null : resolvedValue.equals(currentValue)); } else { } else if (attribute.getName().equals(FILTER_SPEC.getName())) { final ModelNode valueNode = FILTER_SPEC.resolveModelAttribute(context, model); final String resolvedValue = (valueNode.isDefined() ? valueNode.asString() : null); final String currentValue = configuration.getFilter(); result = (resolvedValue == null ? currentValue == null : resolvedValue.equals(currentValue)); } else if (attribute.getName().equals(LEVEL.getName())) {
private void writeSyslogHandler(final XMLExtendedStreamWriter writer, final ModelNode node, final String name) throws XMLStreamException { writer.writeStartElement(Element.SYSLOG_HANDLER.getLocalName()); writer.writeAttribute(HANDLER_NAME.getXmlName(), name); ENABLED.marshallAsAttribute(node, false, writer); LEVEL.marshallAsElement(node, writer); SERVER_ADDRESS.marshallAsElement(node, writer); HOSTNAME.marshallAsElement(node, writer); PORT.marshallAsElement(node, writer); APP_NAME.marshallAsElement(node, writer); SYSLOG_FORMATTER.marshallAsElement(node, writer); FACILITY.marshallAsElement(node, writer); writer.writeEndElement(); }
@Override public void updateModel(final OperationContext context, final ModelNode operation, final ModelNode model) { // Set the enable attribute to false model.get(CommonAttributes.ENABLED.getName()).set(false); }