private static MBeanParameterInfo CreateMBeanParameterInfo(ParameterInfo info) { Descriptor descriptor = new Descriptor(); OpenType openType = OpenType.CreateOpenType(info.ParameterType); descriptor.SetField(OpenTypeDescriptor.Field, openType); object[] tmp = info.GetCustomAttributes(typeof(OpenMBeanAttributeAttribute), false); if (tmp.Length > 0) { OpenMBeanAttributeAttribute attr = (OpenMBeanAttributeAttribute)tmp[0]; if (attr.LegalValues != null && (attr.MinValue != null || attr.MaxValue != null)) { throw new OpenDataException("Cannot specify both min/max values and legal values."); } IComparable defaultValue = (IComparable)attr.DefaultValue; OpenInfoUtils.ValidateDefaultValue(openType, defaultValue); descriptor.SetField(DefaultValueDescriptor.Field, defaultValue); if (attr.LegalValues != null) { OpenInfoUtils.ValidateLegalValues(openType, attr.LegalValues); descriptor.SetField(LegalValuesDescriptor.Field, attr.LegalValues); } else { OpenInfoUtils.ValidateMinMaxValue(openType, defaultValue, attr.MinValue, attr.MaxValue); descriptor.SetField(MinValueDescriptor.Field, attr.MinValue); descriptor.SetField(MaxValueDescriptor.Field, attr.MaxValue); } } return(new MBeanParameterInfo(info.Name, InfoUtils.GetDescrition(info.Member, info, "MBean operation parameter", info.Name), openType.Representation.AssemblyQualifiedName, descriptor)); }
public MBeanOperationInfo CreateMBeanOperationInfo(MethodInfo info) { Descriptor descriptor = new Descriptor(); object[] attrTmp = info.GetCustomAttributes(typeof(OpenMBeanOperationAttribute), false); if (attrTmp.Length == 0) { throw new OpenDataException("Open MBean operation have to have its impact specified."); } OpenMBeanOperationAttribute attr = (OpenMBeanOperationAttribute)attrTmp[0]; if (attr.Impact == OperationImpact.Unknown) { throw new OpenDataException("Open MBean operation have to have its impact specified."); } OpenType openType = info.ReturnType != null?OpenType.CreateOpenType(info.ReturnType) : SimpleType.Void; descriptor.SetField(OpenTypeDescriptor.Field, openType); return(new MBeanOperationInfo(info.Name, InfoUtils.GetDescrition(info, info, "MBean operation"), openType.Representation.AssemblyQualifiedName, info.GetParameters().Select(x => CreateMBeanParameterInfo(x)), attr.Impact, descriptor)); }