static Class<? extends Protocol> findProtocolClass(OperationContext context, String protocolName, String moduleName) throws OperationFailedException { String className = protocolName; if (moduleName.equals(AbstractProtocolResourceDefinition.Attribute.MODULE.getDefinition().getDefaultValue().asString()) && !protocolName.startsWith(org.jgroups.conf.ProtocolConfiguration.protocol_prefix)) { className = String.join(".", org.jgroups.conf.ProtocolConfiguration.protocol_prefix, protocolName); } try { return Module.getContextModuleLoader().loadModule(moduleName).getClassLoader().loadClass(className).asSubclass(Protocol.class); } catch (ClassNotFoundException | ModuleLoadException e) { throw JGroupsLogger.ROOT_LOGGER.unableToLoadProtocolClass(className); } } }
public RejectedValueConfig(Attribute attribute, Predicate<ModelNode> rejection) { this(attribute, rejection, value -> attribute.getDefinition().getDefaultValue()); }
@Override public final P createProtocol(ProtocolStackConfiguration stackConfiguration) { // A "native" protocol is one that is not specified as a class name boolean nativeProtocol = this.moduleName.equals(AbstractProtocolResourceDefinition.Attribute.MODULE.getDefinition().getDefaultValue().asString()) && !this.name.startsWith(org.jgroups.conf.ProtocolConfiguration.protocol_prefix); String className = nativeProtocol ? String.join(".", org.jgroups.conf.ProtocolConfiguration.protocol_prefix, this.name) : this.name; try { Module module = this.loader.get().loadModule(this.moduleName); Class<? extends Protocol> protocolClass = module.getClassLoader().loadClass(className).asSubclass(Protocol.class); Map<String, String> properties = new HashMap<>(this.defaults.get().getProperties(protocolClass)); properties.putAll(this.properties); PrivilegedExceptionAction<Protocol> action = () -> { try { return protocolClass.newInstance().setProperties(properties); } catch (InstantiationException | IllegalAccessException e) { throw new IllegalStateException(e); } }; @SuppressWarnings("unchecked") P protocol = (P) WildFlySecurityManager.doUnchecked(action); this.accept(protocol); protocol.enableStats(this.statisticsEnabled != null ? this.statisticsEnabled : stackConfiguration.isStatisticsEnabled()); return protocol; } catch (Exception e) { throw new IllegalArgumentException(e); } } }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { if (this.readHandler != null) { this.readHandler.execute(context, operation); } else { try { // If attribute has no read handler, simulate one ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel(); ModelNode result = context.getResult(); if (model.hasDefined(this.targetAttribute.getName())) { result.set(model.get(this.targetAttribute.getName())); } else if (Operations.isIncludeDefaults(operation)) { result.set(this.targetAttribute.getDefinition().getDefaultValue()); } } catch (Resource.NoSuchResourceException ignore) { // If the target resource does not exist return UNDEFINED return; } } ModelNode result = context.getResult(); result.set(this.translator.translate(context, result)); } }
static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) { ResourceTransformationDescriptionBuilder builder = parent.addChildResource(WILDCARD_PATH); if (ModClusterModel.VERSION_6_0_0.requiresTransformation(version)) { builder.getAttributeBuilder() .setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(Attribute.MODULE.getDefinition().getDefaultValue()), Attribute.MODULE.getDefinition()) .addRejectCheck(new RejectAttributeChecker.SimpleAcceptAttributeChecker(Attribute.MODULE.getDefinition().getDefaultValue()), Attribute.MODULE.getDefinition()) .end(); } } }
.setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(IIOPRootDefinition.CLIENT_REQUIRES_SSL.getDefaultValue()), IIOPRootDefinition.CLIENT_REQUIRES_SSL) .setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(IIOPRootDefinition.SERVER_REQUIRES_SSL.getDefaultValue()), IIOPRootDefinition.SERVER_REQUIRES_SSL) .setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(IIOPRootDefinition.INTEROP_IONA.getDefaultValue()), IIOPRootDefinition.INTEROP_IONA) .setDiscard(DiscardAttributeChecker.UNDEFINED, IIOPRootDefinition.AUTHENTICATION_CONTEXT, IIOPRootDefinition.SERVER_SSL_CONTEXT, IIOPRootDefinition.CLIENT_SSL_CONTEXT) .addRejectCheck(new RejectAttributeChecker.DefaultRejectAttributeChecker() {
static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder builder) { if (InfinispanModel.VERSION_6_0_0.requiresTransformation(version)) { Converter converter = (PathAddress address, String name, ModelNode value, ModelNode model, TransformationContext context) -> { PathAddress storeAddress = address.getParent(); PathElement storePath = storeAddress.getLastElement(); if (storePath.equals(StringKeyedJDBCStoreResourceDefinition.STRING_JDBC_PATH) || storePath.equals(StringKeyedJDBCStoreResourceDefinition.LEGACY_PATH)) { storeAddress = storeAddress.getParent().append(StringKeyedJDBCStoreResourceDefinition.PATH); } else if (storePath.equals(BinaryKeyedJDBCStoreResourceDefinition.LEGACY_PATH)) { storeAddress = storeAddress.getParent().append(BinaryKeyedJDBCStoreResourceDefinition.PATH); } else if (storePath.equals(MixedKeyedJDBCStoreResourceDefinition.LEGACY_PATH)) { storeAddress = storeAddress.getParent().append(MixedKeyedJDBCStoreResourceDefinition.PATH); } ModelNode store = context.readResourceFromRoot(storeAddress).getModel(); value.set(store.hasDefined(StoreResourceDefinition.Attribute.MAX_BATCH_SIZE.getName()) ? store.get(StoreResourceDefinition.Attribute.MAX_BATCH_SIZE.getName()) : StoreResourceDefinition.Attribute.MAX_BATCH_SIZE.getDefinition().getDefaultValue()); }; builder.getAttributeBuilder().setValueConverter(new SimpleAttributeConverter(converter), DeprecatedAttribute.BATCH_SIZE.getDefinition()); } }
writer.writeAttribute(JcaDistributedWorkManagerDefinition.DWmParameters.NAME.getAttribute().getXmlName(), prop.getValue().asString()); else writer.writeAttribute(JcaDistributedWorkManagerDefinition.DWmParameters.NAME.getAttribute().getXmlName(), JcaDistributedWorkManagerDefinition.DWmParameters.POLICY.getAttribute().getDefaultValue().asString()); if (workManager.hasDefined(JcaDistributedWorkManagerDefinition.DWmParameters.POLICY_OPTIONS.getAttribute().getName())) { for (Property option : workManager.get(JcaDistributedWorkManagerDefinition.DWmParameters.POLICY_OPTIONS.getAttribute().getName()).asPropertyList()) {
static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) { ResourceTransformationDescriptionBuilder builder = parent.addChildResource(WILDCARD_PATH); if (InfinispanModel.VERSION_5_0_0.requiresTransformation(version)) { builder.getAttributeBuilder() .setValueConverter(new AttributeConverter.DefaultValueAttributeConverter(Attribute.L1_LIFESPAN.getDefinition()), Attribute.L1_LIFESPAN.getDefinition()) .end(); } if (InfinispanModel.VERSION_3_0_0.requiresTransformation(version)) { builder.getAttributeBuilder() .setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(Attribute.CAPACITY_FACTOR.getDefinition().getDefaultValue()), Attribute.CAPACITY_FACTOR.getDefinition()) .addRejectCheck(RejectAttributeChecker.DEFINED, Attribute.CAPACITY_FACTOR.getDefinition()) .end(); } SegmentedCacheResourceDefinition.buildTransformation(version, builder); }
.addChildResource(PathElement.pathElement(Constants.MOD_CLUSTER)) .getAttributeBuilder() .setDiscard(new DiscardAttributeValueChecker(FAILOVER_STRATEGY.getDefaultValue()), FAILOVER_STRATEGY) .setDiscard(new DiscardAttributeValueChecker(ModClusterDefinition.MAX_RETRIES.getDefaultValue()), ModClusterDefinition.MAX_RETRIES) .setDiscard(DiscardAttributeChecker.UNDEFINED, SSL_CONTEXT) .addRejectCheck(RejectAttributeChecker.SIMPLE_EXPRESSIONS, MAX_AJP_PACKET_SIZE)
builder.getAttributeBuilder() .setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(Attribute.STATUS_INTERVAL.getDefinition().getDefaultValue()), Attribute.STATUS_INTERVAL.getDefinition()) .addRejectCheck(new RejectAttributeChecker.SimpleAcceptAttributeChecker(Attribute.STATUS_INTERVAL.getDefinition().getDefaultValue()), Attribute.STATUS_INTERVAL.getDefinition())
.setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(Attribute.MODULE.getDefinition().getDefaultValue()), Attribute.MODULE.getDefinition()) .addRejectCheck(RejectAttributeChecker.DEFINED, Attribute.MODULE.getDefinition()) .setValueConverter(typeConverter, DeprecatedAttribute.TYPE.getDefinition())
@Override protected void convertAttribute(PathAddress address, String name, ModelNode value, TransformationContext context) { if (!value.isDefined()) { value.set(this.attribute.getDefaultValue()); } } }
private ModelNode attribute( OperationContext context, ModelNode model, AttributeDefinition defn ) throws OperationFailedException { assert defn.getDefaultValue() != null && defn.getDefaultValue().isDefined(); return defn.resolveModelAttribute(context, model); }
private boolean attribNotChanging(String attributeName, ModelNode newValue, ModelNode oldValue) { AttributeDefinition attribDef = KeycloakSubsystemDefinition.lookup(attributeName); if (!oldValue.isDefined()) { oldValue = attribDef.getDefaultValue(); } if (!newValue.isDefined()) { newValue = attribDef.getDefaultValue(); } return newValue.equals(oldValue); } }
/** * Gets whether the given {@code resourceModel} has a value for this attribute that should be marshalled to XML. * * @param attribute - attribute for which marshaling is being done * @param resourceModel the model, a non-null node of {@link org.jboss.dmr.ModelType#OBJECT}. * @param marshallDefault {@code true} if the value should be marshalled even if it matches the default value * @return {@code true} if the given {@code resourceModel} has a defined value under this attribute's {@link AttributeDefinition#getName()} () name} * and {@code marshallDefault} is {@code true} or that value differs from this attribute's {@link AttributeDefinition#getDefaultValue() default value}. */ public boolean isMarshallable(final AttributeDefinition attribute, final ModelNode resourceModel, final boolean marshallDefault) { return resourceModel.hasDefined(attribute.getName()) && (marshallDefault || !resourceModel.get(attribute.getName()).equals(attribute.getDefaultValue())); }
/** * Gets whether the given {@code resourceModel} has a value for this attribute that should be marshalled to XML. * * @param attribute - attribute for which marshaling is being done * @param resourceModel the model, a non-null node of {@link org.jboss.dmr.ModelType#OBJECT}. * @param marshallDefault {@code true} if the value should be marshalled even if it matches the default value * @return {@code true} if the given {@code resourceModel} has a defined value under this attribute's {@link AttributeDefinition#getName()} () name} * and {@code marshallDefault} is {@code true} or that value differs from this attribute's {@link AttributeDefinition#getDefaultValue() default value}. */ public boolean isMarshallable(final AttributeDefinition attribute, final ModelNode resourceModel, final boolean marshallDefault) { return resourceModel.hasDefined(attribute.getName()) && (marshallDefault || !resourceModel.get(attribute.getName()).equals(attribute.getDefaultValue())); }
/** * Gets whether the given {@code resourceModel} has a value for this attribute that should be marshalled to XML. * * @param attribute - attribute for which marshaling is being done * @param resourceModel the model, a non-null node of {@link org.jboss.dmr.ModelType#OBJECT}. * @param marshallDefault {@code true} if the value should be marshalled even if it matches the default value * @return {@code true} if the given {@code resourceModel} has a defined value under this attribute's {@link AttributeDefinition#getName()} () name} * and {@code marshallDefault} is {@code true} or that value differs from this attribute's {@link AttributeDefinition#getDefaultValue() default value}. */ public boolean isMarshallable(final AttributeDefinition attribute, final ModelNode resourceModel, final boolean marshallDefault) { return resourceModel.hasDefined(attribute.getName()) && (marshallDefault || !resourceModel.get(attribute.getName()).equals(attribute.getDefaultValue())); }
/** * Gets whether the given {@code resourceModel} has a value for this attribute that should be marshalled to XML. * * @param attribute - attribute for which marshaling is being done * @param resourceModel the model, a non-null node of {@link org.jboss.dmr.ModelType#OBJECT}. * @param marshallDefault {@code true} if the value should be marshalled even if it matches the default value * @return {@code true} if the given {@code resourceModel} has a defined value under this attribute's {@link AttributeDefinition#getName()} () name} * and {@code marshallDefault} is {@code true} or that value differs from this attribute's {@link AttributeDefinition#getDefaultValue() default value}. */ public boolean isMarshallable(final AttributeDefinition attribute, final ModelNode resourceModel, final boolean marshallDefault) { return resourceModel.hasDefined(attribute.getName()) && (marshallDefault || !resourceModel.get(attribute.getName()).equals(attribute.getDefaultValue())); }
private boolean isSameValue(OperationContext context, ModelNode resolvedValue, ModelNode currentValue, String attributeName) throws OperationFailedException { if (resolvedValue.equals(getAttributeDefinition(attributeName).resolveValue(context, currentValue))) { return true; } if (!currentValue.isDefined()) { return resolvedValue.equals(getAttributeDefinition(attributeName).getDefaultValue()); } return false; }