static void buildTransformation(
      ModelVersion version, ResourceTransformationDescriptionBuilder builder) {

    if (InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
      // Converts pool name to its JNDI name
      Converter converter =
          new Converter() {
            @Override
            public void convert(
                PathAddress address,
                String name,
                ModelNode value,
                ModelNode model,
                TransformationContext context) {
              if (value.isDefined()) {
                PathAddress rootAddress = address.subAddress(0, address.size() - 4);
                PathAddress subsystemAddress =
                    rootAddress.append(
                        PathElement.pathElement(
                            ModelDescriptionConstants.SUBSYSTEM, "datasources"));
                Resource subsystem = context.readResourceFromRoot(subsystemAddress);
                String poolName = value.asString();
                for (String type : Arrays.asList("data-source", "xa-data-source")) {
                  if (subsystem.hasChildren(type)) {
                    for (Resource.ResourceEntry entry : subsystem.getChildren(type)) {
                      if (entry.getName().equals(poolName)) {
                        value.set(entry.getModel().get("jndi-name"));
                        return;
                      }
                    }
                  }
                }
              }
            }
          };
      builder
          .getAttributeBuilder()
          .addRename(Attribute.DATA_SOURCE.getName(), DeprecatedAttribute.DATASOURCE.getName())
          .setValueConverter(
              new SimpleAttributeConverter(converter), Attribute.DATA_SOURCE.getDefinition());
    }

    if (InfinispanModel.VERSION_3_0_0.requiresTransformation(version)) {
      builder
          .addOperationTransformationOverride(ModelDescriptionConstants.ADD)
          .setCustomOperationTransformer(
              new SimpleOperationTransformer(new LegacyPropertyAddOperationTransformer()))
          .inheritResourceAttributeDefinitions();
    }

    if (InfinispanModel.VERSION_2_0_0.requiresTransformation(version)) {
      builder
          .getAttributeBuilder()
          .setDiscard(DiscardAttributeChecker.UNDEFINED, Attribute.DIALECT.getDefinition())
          .addRejectCheck(RejectAttributeChecker.DEFINED, Attribute.DIALECT.getDefinition())
          .end();
    }

    StoreResourceDefinition.buildTransformation(version, builder);
  }
  static void buildTransformation(
      ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
    ResourceTransformationDescriptionBuilder builder =
        InfinispanModel.VERSION_4_0_0.requiresTransformation(version)
            ? parent.addChildRedirection(PATH, LEGACY_PATH)
            : parent.addChildResource(PATH);

    if (InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
      builder
          .getAttributeBuilder()
          .setValueConverter(
              new AttributeConverter.DefaultAttributeConverter() {
                @Override
                protected void convertAttribute(
                    PathAddress address,
                    String attributeName,
                    ModelNode attributeValue,
                    TransformationContext context) {
                  if (attributeValue.isDefined()) {
                    List<ModelNode> remoteServers = attributeValue.clone().asList();
                    ModelNode legacyListObject = new ModelNode();
                    for (ModelNode server : remoteServers) {
                      ModelNode legacyListItem = new ModelNode();
                      legacyListItem.get("outbound-socket-binding").set(server);
                      legacyListObject.add(legacyListItem);
                    }
                    attributeValue.set(legacyListObject);
                  }
                }
              },
              Attribute.SOCKET_BINDINGS.getDefinition());
    }

    if (InfinispanModel.VERSION_3_0_0.requiresTransformation(version)) {
      builder
          .addOperationTransformationOverride(ModelDescriptionConstants.ADD)
          .setCustomOperationTransformer(
              new SimpleOperationTransformer(new LegacyPropertyAddOperationTransformer()))
          .inheritResourceAttributeDefinitions();

      builder.setCustomResourceTransformer(new LegacyPropertyResourceTransformer());
    }

    StoreResourceDefinition.buildTransformation(version, builder);
  }
 static void registerTransformers300(ResourceTransformationDescriptionBuilder parentBuilder) {
   ResourceTransformationDescriptionBuilder builder =
       parentBuilder.addChildResource(PATH_DISTRIBUTED_WORK_MANAGER);
   builder
       .addOperationTransformationOverride("add")
       .inheritResourceAttributeDefinitions()
       .setCustomOperationTransformer(
           new OperationTransformer() {
             @Override
             public TransformedOperation transformOperation(
                 TransformationContext context, PathAddress address, ModelNode operation)
                 throws OperationFailedException {
               ModelNode copy = operation.clone();
               copy.add("transport-jgroups-cluster").set(address.getLastElement().toString());
               return new TransformedOperation(copy, TransformedOperation.ORIGINAL_RESULT);
             }
           })
       .end();
 }
  static void registerTransformers111(ResourceTransformationDescriptionBuilder parentBuilder) {
    ResourceTransformationDescriptionBuilder builder =
        parentBuilder.addChildResource(PATH_XA_DATASOURCE);
    builder
        .getAttributeBuilder()
        .setDiscard(
            DiscardAttributeChecker.UNDEFINED,
            org.jboss.as.connector.subsystems.common.pool.Constants.INITIAL_POOL_SIZE,
            CONNECTION_LISTENER_CLASS,
            CONNECTION_LISTENER_PROPERTIES,
            URL_PROPERTY,
            org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_CLASS,
            org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_CLASS,
            org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_PROPERTIES,
            org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_PROPERTIES)
        .setDiscard(
            new DiscardAttributeChecker() {

              @Override
              public boolean isDiscardExpressions() {
                return false;
              }

              @Override
              public boolean isDiscardUndefined() {
                return true;
              }

              @Override
              public boolean isOperationParameterDiscardable(
                  PathAddress address,
                  String attributeName,
                  ModelNode attributeValue,
                  ModelNode operation,
                  TransformationContext context) {
                return false;
              }

              @Override
              public boolean isResourceAttributeDiscardable(
                  PathAddress address,
                  String attributeName,
                  ModelNode attributeValue,
                  TransformationContext context) {
                return true;
              }
            },
            ENABLED)
        .addRejectCheck(
            RejectAttributeChecker.DEFINED,
            org.jboss.as.connector.subsystems.common.pool.Constants.INITIAL_POOL_SIZE,
            CONNECTION_LISTENER_CLASS,
            CONNECTION_LISTENER_PROPERTIES,
            URL_PROPERTY,
            org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_CLASS,
            org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_CLASS,
            org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_PROPERTIES,
            org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_PROPERTIES)
        .end();
    builder
        .addOperationTransformationOverride(ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION)
        .inheritResourceAttributeDefinitions()
        .setCustomOperationTransformer(ENABLE_TRANSFORMER)
        .end()
        .addOperationTransformationOverride(ModelDescriptionConstants.UNDEFINE_ATTRIBUTE_OPERATION)
        .inheritResourceAttributeDefinitions()
        .setCustomOperationTransformer(ENABLE_TRANSFORMER)
        .end();
  }
 public void registerTransformers_2_0(ResourceTransformationDescriptionBuilder builder) {
   builder.addOperationTransformationOverride(NamingSubsystemModel.REBIND).setReject();
 }