complexValueType.get("bigdecimal-value", DESCRIPTION).set("A bigdecimal value");
complexValueType.get("bigdecimal-value", TYPE).set(ModelType.BIG_DECIMAL);
final SubsystemRegistration subsystem = context.registerSubsystem("test", 1, 0);
final ManagementResourceRegistration registration = subsystem.registerSubsystemModel(new DescriptionProvider() {
@Override
public ModelNode getModelDescription(Locale locale) {
ModelNode node = new ModelNode();
node.get(DESCRIPTION).set("A test subsystem");
addAttribute(node, "ro-int", ModelType.INT, "A read-only int");
addAttribute(node, "undefined-int", ModelType.INT, "A read-only int");
addAttribute(node, "int", ModelType.INT, "A int");
addAttribute(node, "bigint", ModelType.BIG_INTEGER, "A big int");
addAttribute(node, "bigdec", ModelType.BIG_DECIMAL, "A big dec");
addAttribute(node, "boolean", ModelType.BOOLEAN, "A boolean");
addAttribute(node, "bytes", ModelType.BYTES, "A bytes");
addAttribute(node, "double", ModelType.DOUBLE, "A double");
addAttribute(node, "string", ModelType.STRING, "A string");
addValueTypeAttribute(node, "list", ModelType.LIST, new ModelNode().set(ModelType.INT), "A list");
addAttribute(node, "long", ModelType.LONG, "A long");
addAttribute(node, "type", ModelType.TYPE, "A type");
addValueTypeAttribute(node, "map", ModelType.OBJECT, new ModelNode().set(ModelType.INT), "A map");
addValueTypeAttribute(node, "complex", ModelType.OBJECT, complexValueType, "A complex value");
// TODO also add the types mentioned in
// MBeanInfoFactory.convertToMBeanType()
return node;
}
private ModelNode addAttribute(ModelNode node, String name, ModelType type, String description) {
ModelNode tgt = node.get(ATTRIBUTES, name);
tgt.get(TYPE).set(type);
tgt.get(DESCRIPTION).set(description);
return node;
}
private void addValueTypeAttribute(ModelNode node, String name, ModelType type, ModelNode valueType, String description) {
ModelNode tgt = addAttribute(node, name, type, description);
tgt.get(ATTRIBUTES, name, VALUE_TYPE).set(valueType);
}
});
// We always need to add an 'add' operation
registration.registerOperationHandler(ADD, TestSubystemAdd.INSTANCE, TestSubystemAdd.INSTANCE, false);
//Register the attributes
registration.registerReadOnlyAttribute("ro-int", null, Storage.CONFIGURATION);
registration.registerReadWriteAttribute("undefined-int", null, new WriteAttributeHandlers.ModelTypeValidatingHandler(
ModelType.INT), Storage.CONFIGURATION);
registration.registerReadWriteAttribute("int", null, new WriteAttributeHandlers.ModelTypeValidatingHandler(
ModelType.INT), Storage.CONFIGURATION);
registration.registerReadWriteAttribute("bigint", null, new WriteAttributeHandlers.ModelTypeValidatingHandler(
ModelType.BIG_INTEGER), Storage.CONFIGURATION);
registration.registerReadWriteAttribute("bigdec", null, new WriteAttributeHandlers.ModelTypeValidatingHandler(
ModelType.BIG_DECIMAL), Storage.CONFIGURATION);
registration.registerReadWriteAttribute("boolean", null, new WriteAttributeHandlers.ModelTypeValidatingHandler(
ModelType.BOOLEAN), Storage.CONFIGURATION);
registration.registerReadWriteAttribute("bytes", null, new WriteAttributeHandlers.ModelTypeValidatingHandler(
ModelType.BYTES), Storage.CONFIGURATION);
registration.registerReadWriteAttribute("double", null, new WriteAttributeHandlers.ModelTypeValidatingHandler(
ModelType.DOUBLE), Storage.CONFIGURATION);
registration.registerReadWriteAttribute("string", null, new WriteAttributeHandlers.ModelTypeValidatingHandler(
ModelType.STRING), Storage.CONFIGURATION);
registration.registerReadWriteAttribute("list", null, new WriteAttributeHandlers.ModelTypeValidatingHandler(
ModelType.LIST), Storage.CONFIGURATION);
registration.registerReadWriteAttribute("long", null, new WriteAttributeHandlers.ModelTypeValidatingHandler(
ModelType.LONG), Storage.CONFIGURATION);
registration.registerReadWriteAttribute("type", null, new WriteAttributeHandlers.ModelTypeValidatingHandler(
ModelType.TYPE), Storage.CONFIGURATION);
registration.registerReadWriteAttribute("map", null, new WriteAttributeHandlers.ModelTypeValidatingHandler(
ModelType.OBJECT), Storage.CONFIGURATION);
registration.registerReadWriteAttribute("complex", null, new ComplexWriteAttributeHandler(), Storage.CONFIGURATION);
//Register the operation handlers
registration.registerOperationHandler(VoidOperationNoParams.OPERATION_NAME, VoidOperationNoParams.INSTANCE, VoidOperationNoParams.INSTANCE, EnumSet.of(OperationEntry.Flag.READ_ONLY));
registration.registerOperationHandler(IntOperationWithParams.OPERATION_NAME, IntOperationWithParams.INSTANCE, IntOperationWithParams.INSTANCE);
ComplexOperation op = new ComplexOperation(complexValueType);
registration.registerOperationHandler(ComplexOperation.OPERATION_NAME, op, op);
// subsystem.registerXMLElementWriter(parser);
}