Source:
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { PathAddress address = context.getCurrentAddress(); PathAddress parentAddress = address.getParent(); PathElement path = address.getLastElement(); OperationStepHandler parentHandler = context.getRootResourceRegistration().getOperationHandler(parentAddress, ModelDescriptionConstants.ADD); if (parentHandler instanceof DescribedAddStepHandler) { AddStepHandlerDescriptor parentDescriptor = ((DescribedAddStepHandler) parentHandler).getDescriptor(); if (parentDescriptor.getRequiredChildren().contains(path)) { if (context.readResourceFromRoot(parentAddress, false).hasChild(path)) { context.addStep(Util.createRemoveOperation(address), context.getRootResourceRegistration().getOperationHandler(address, ModelDescriptionConstants.REMOVE), OperationContext.Stage.MODEL); context.addStep(operation, this, OperationContext.Stage.MODEL); return; } } Optional<PathElement> singletonPathResult = Optional.empty(); for (PathElement requiredPath : parentDescriptor.getRequiredSingletonChildren()) { if (requiredPath.getKey().equals(path.getKey())) { singletonPathResult = Optional.of(requiredPath); break; } } if (singletonPathResult.isPresent()) { PathElement singletonPath = singletonPathResult.get(); Set<String> childrenNames = context.readResourceFromRoot(parentAddress, false).getChildrenNames(singletonPath.getKey()); if (!childrenNames.isEmpty()) { for (String childName : childrenNames) { PathAddress singletonAddress = parentAddress.append(singletonPath.getKey(), childName); context.addStep(Util.createRemoveOperation(singletonAddress), context.getRootResourceRegistration().getOperationHandler(singletonAddress, ModelDescriptionConstants.REMOVE), OperationContext.Stage.MODEL); } context.addStep(operation, this, OperationContext.Stage.MODEL); return; } } } super.execute(context, operation); if (this.requiresRuntime(context)) { for (RuntimeResourceRegistration r : this.descriptor.getRuntimeResourceRegistrations()) { context.addStep((c, op) -> r.register(c), OperationContext.Stage.MODEL); } } }

Target:
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { PathAddress address = context.getCurrentAddress(); PathAddress parentAddress = address.getParent(); PathElement path = address.getLastElement(); OperationStepHandler parentHandler = context.getRootResourceRegistration().getOperationHandler(parentAddress, ModelDescriptionConstants.ADD); if (parentHandler instanceof DescribedAddStepHandler) { AddStepHandlerDescriptor parentDescriptor = ((DescribedAddStepHandler) parentHandler).getDescriptor(); if (parentDescriptor.getRequiredChildren().contains(path)) { if (context.readResourceFromRoot(parentAddress, false).hasChild(path)) { context.addStep(Util.createRemoveOperation(address), context.getRootResourceRegistration().getOperationHandler(address, ModelDescriptionConstants.REMOVE), OperationContext.Stage.MODEL); context.addStep(operation, this, OperationContext.Stage.MODEL); return; } } for (PathElement requiredPath : parentDescriptor.getRequiredSingletonChildren()) { final String pathKey = requiredPath.getKey(); if (pathKey.equals(path.getKey())) { Set<String> childrenNames = context.readResourceFromRoot(parentAddress, false).getChildrenNames(pathKey); if (! childrenNames.isEmpty()) { for (String childName : childrenNames) { PathAddress singletonAddress = parentAddress.append(pathKey, childName); context.addStep(Util.createRemoveOperation(singletonAddress), context.getRootResourceRegistration().getOperationHandler(singletonAddress, ModelDescriptionConstants.REMOVE), OperationContext.Stage.MODEL); } context.addStep(operation, this, OperationContext.Stage.MODEL); return; } } } } super.execute(context, operation); if (this.requiresRuntime(context)) { for (RuntimeResourceRegistration r : this.descriptor.getRuntimeResourceRegistrations()) { context.addStep((c, op) -> r.register(c), OperationContext.Stage.MODEL); } } }