return op;
}
private void registerTransformers1_0_0(SubsystemRegistration registration) {
// Register the transformers
final TransformersSubRegistration transformers = registration.registerModelTransformers(ModelVersion.create(1, 0, 0), new ResourceTransformer() {
@Override
public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
ModelNode model = resource.getModel();
//The existance of the expose-model=>resolved child is translated into the show-model=>true attribute
Resource exposeResolvedResource = resource.getChild(PathElement.pathElement(CommonAttributes.EXPOSE_MODEL, CommonAttributes.RESOLVED));
boolean showModel = false;
if (exposeResolvedResource != null) {
showModel = model.isDefined();
}
model.get(CommonAttributes.SHOW_MODEL).set(showModel);
ResourceTransformationContext childContext = context.addTransformedResource(PathAddress.EMPTY_ADDRESS, resource);
//Process all the child resources skipping the expose-model=>* children
for (String type :resource.getChildTypes()) {
if (!type.equals(CommonAttributes.EXPOSE_MODEL)) {
for (ResourceEntry child : resource.getChildren(type)) {
childContext.processChild(child.getPathElement(), child);
}
}
}
}
});
TransformersSubRegistration expressions = transformers.registerSubResource(ExposeModelResourceExpression.INSTANCE.getPathElement());
expressions.discardOperations(ADD, REMOVE, WRITE_ATTRIBUTE_OPERATION, READ_ATTRIBUTE_OPERATION);
TransformersSubRegistration resolved = transformers.registerSubResource(ExposeModelResourceResolved.INSTANCE.getPathElement());
resolved.discardOperations(WRITE_ATTRIBUTE_OPERATION);
resolved.registerOperationTransformer(ADD, new AbstractOperationTransformer() {
@Override
protected ModelNode transform(TransformationContext context, PathAddress address, ModelNode operation) {
ModelNode node = new ModelNode();
node.get(OP).set(WRITE_ATTRIBUTE_OPERATION);
node.get(OP_ADDR).set(address.subAddress(0, address.size() - 1).toModelNode());
node.get(NAME).set(CommonAttributes.SHOW_MODEL);
node.get(VALUE).set(true);
return node;
}
});
resolved.registerOperationTransformer(REMOVE, new AbstractOperationTransformer() {
@Override
protected ModelNode transform(TransformationContext context, PathAddress address, ModelNode operation) {
ModelNode node = new ModelNode();
node.get(OP).set(WRITE_ATTRIBUTE_OPERATION);
node.get(OP_ADDR).set(address.subAddress(0, address.size() - 1).toModelNode());
node.get(NAME).set(CommonAttributes.SHOW_MODEL);
node.get(VALUE).set(false);
return node;
}
});
resolved.registerOperationTransformer(READ_ATTRIBUTE_OPERATION, new OperationTransformer() {
@Override
public TransformedOperation transformOperation(final TransformationContext context, final PathAddress address, final ModelNode operation) {
return new TransformedOperation(null, new OperationResultTransformer() {
@Override
public ModelNode transformResult(ModelNode result) {
if (operation.get(NAME).asString().equals(CommonAttributes.DOMAIN_NAME)) {
result.get(RESULT).set(CommonAttributes.DEFAULT_RESOLVED_DOMAIN);
}
result.get(OUTCOME).set(SUCCESS);
result.get(RESULT);
return result;
}
});
}
});
RejectExpressionValuesTransformer rejectTransformer = new RejectExpressionValuesTransformer(RemotingConnectorResource.USE_MANAGEMENT_ENDPOINT);
TransformersSubRegistration remoting = transformers.registerSubResource(RemotingConnectorResource.REMOTE_CONNECTOR_CONFIG_PATH,
(ResourceTransformer) rejectTransformer);
remoting.registerOperationTransformer(ADD, rejectTransformer);
remoting.registerOperationTransformer(WRITE_ATTRIBUTE_OPERATION, rejectTransformer.getWriteAttributeTransformer());
}