@Override public ModelMBeanAttributeInfo createAttributeInfo() { Descriptor desc = new DescriptorSupport(new String[] {"name=" + this.displayName, "descriptorType=attribute", "currencyTimeLimit=-1", // always stale "displayName=" + this.displayName, "getMethod=getJmxValue", "setMethod=setJmxValue"}); Assert.assertTrue(this.config != null, "Config target object is null!"); desc.setField("targetObject", this.config); ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(this.displayName, // name this.type, // type this.description, // description this.readable, // isReadable this.writeable, // isWritable this.is, // isIs desc); return info; }
@Override public ModelMBeanAttributeInfo createAttributeInfo() { Descriptor desc = new DescriptorSupport(new String[] {"name=" + this.displayName, "descriptorType=attribute", "currencyTimeLimit=-1", // always stale "displayName=" + this.displayName, "getMethod=getValue"}); Assert.assertTrue(this.stat != null, "Stat target object is null!"); desc.setField("targetObject", this.stat); ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(this.displayName, // name this.type, // type this.description, // description this.readable, // isReadable this.writeable, // isWritable this.is, // isIs desc); return info; }
public static void main(String[] args) throws Exception { boolean failed = false; String xmlDesc = "<DESCRIPTOR>" + "<FIELD name=\"field1\" value=\"dummy\">" + "</FIELD>" + "</DESCRIPTOR>"; Locale loc = Locale.getDefault(); try { Locale.setDefault(new Locale("tr", "TR")); new DescriptorSupport(xmlDesc); } catch (Exception e) { e.printStackTrace(System.out); failed = true; }finally{ Locale.setDefault(loc); } if (!failed) { System.out.println("OK: all tests passed"); } else { System.out.println("TEST FAILED"); throw new IllegalArgumentException("Test Failed"); } }
@Override public ModelMBeanAttributeInfo createAttributeInfo() { Descriptor desc = new DescriptorSupport( new String[] { "name=" + this.displayName, "descriptorType=attribute", "currencyTimeLimit=-1", // always stale "displayName=" + this.displayName, "getMethod=getJmxValue", "setMethod=setJmxValue" }); Assert.assertTrue(this.config != null, "Config target object is null!"); desc.setField("targetObject", this.config); ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo( this.displayName, // name this.type, // type this.description, // description this.readable, // isReadable this.writeable, // isWritable this.is, // isIs desc); return info; }
@Override public ModelMBeanAttributeInfo createAttributeInfo() { Descriptor desc = new DescriptorSupport( new String[] { "name=" + this.displayName, "descriptorType=attribute", "currencyTimeLimit=-1", // always stale "displayName=" + this.displayName, "getMethod=getValue" }); Assert.assertTrue(this.stat != null, "Stat target object is null!"); desc.setField("targetObject", this.stat); ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo( this.displayName, // name this.type, // type this.description, // description this.readable, // isReadable this.writeable, // isWritable this.is, // isIs desc); return info; }
/** * Test xml conversions, isValid() and toString() methods of * DescriptorSupport at end of each test case. */ public void commonCheck() throws Exception { assertTrue(descriptor.isValid()); DescriptorSupport descriptorSupport = new DescriptorSupport(descriptor .getFields()); // verify DescriptorSupport(String[]) constructor. compareArrays(descriptor.getFields(), descriptorSupport.getFields()); // verify DescriptorSupport(String xmlString) constructor. // System.out.println(descriptorSupport.toXMLString()); DescriptorSupport descriptorSupport2 = new DescriptorSupport( descriptorSupport.toXMLString()); assertTrue(compareArrays(descriptor.getFields(), descriptorSupport2 .getFields())); // verify toString() String[] fieldAndValues = trimForStringArrays(descriptorSupport .toString().split(",")); String[] fieldAndValues2 = trimForStringArrays(descriptorSupport .getFields()); assertTrue(compareArrays(fieldAndValues, fieldAndValues2)); }
/** * Builds an AttributeInfo in a default way * @param name * @param displayName * @param description * @param deflt * @param operName * @param signature * @return the default modelMBeanAttributeInfo object */ public static ModelMBeanAttributeInfo buildAttributeInfo(String name, String displayName, String description, String deflt, String operName, String signature){ Descriptor attrDesc = new DescriptorSupport(); attrDesc.setField("name", name); attrDesc.setField("descriptorType", "attribute"); attrDesc.setField("default", deflt); attrDesc.setField("displayName", displayName); attrDesc.setField( "getMethod", operName); ModelMBeanAttributeInfo result=new ModelMBeanAttributeInfo(name, signature, description, true, false, false, attrDesc); return result; }
@Override public MBeanInfo getMBeanInfo() { List<MBeanAttributeInfo> attributeInfos = new ArrayList<>(); for (ConfigItem item : serverConfigurationService.getConfigData().getItems()) { String type = item.getType(); switch (type) { case ServerConfigurationService.TYPE_BOOLEAN: type = "boolean"; break; case ServerConfigurationService.TYPE_INT: type = "int"; break; case ServerConfigurationService.TYPE_STRING: type = "java.lang.String"; break; } attributeInfos.add(new MBeanAttributeInfo(item.getName(), type, item.getDescription(), !item.isSecured(), true, false)); } List<MBeanOperationInfo> operationInfos = new ArrayList<>(); try { Method method = getClass().getMethod("addAttribute", String.class, String.class); operationInfos.add(new MBeanOperationInfo("addAttribute", method)); } catch (NoSuchMethodException e) { // Ignore } Descriptor descriptor = new DescriptorSupport(); descriptor.setField("immutableInfo", "false"); return new MBeanInfo(getClass().getName(), "Sakai Server Configuration", attributeInfos.toArray(new MBeanAttributeInfo[]{}), null, operationInfos.toArray(new MBeanOperationInfo[]{}), null, descriptor); }
/** * TODO: add comments. * * @throws Exception */ private void testFieldValue() throws Exception { String fieldName = "simple field"; ArrayList arrayList = new ArrayList(); String valueOfElement = "value"; arrayList.add(valueOfElement); DescriptorSupport descriptorSupport = new DescriptorSupport( new String[] { fieldName }, new Object[] { arrayList }); assertEquals(((ArrayList)descriptorSupport.getFieldValue(fieldName)) .get(0), valueOfElement); descriptor = descriptorSupport; // TODO: following line throws exception // descriptorSupport.toXMLString(); // commonCheck(); }
/** * Builds a default Descriptor object for getter operations * @param name the name of the getter * @param klass * @return the descriptor */ private static Descriptor buildGetterDescriptor( String name, String klass) { Descriptor resultDesc = new DescriptorSupport(); resultDesc.setField("name", name); resultDesc.setField("descriptorType", "operation"); resultDesc.setField("class", klass); resultDesc.setField("role", "getter"); return resultDesc; }
public static void main(String[] args) throws Exception { ImmutableDescriptor immutableEmpty = new ImmutableDescriptor(); DescriptorSupport mutableEmpty = new DescriptorSupport(); checkEmpty(union()); checkEmpty(union(immutableEmpty)); checkEmpty(union(mutableEmpty)); checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty)); checkEmpty(union(null, immutableEmpty, null)); ImmutableDescriptor immutableNumbers = new ImmutableDescriptor(new String[] {"one", "two", "three"}, new Object[] {1, 2, 3}); final String[] noNames = null; DescriptorSupport mutableNumbers = new DescriptorSupport(immutableNumbers.getFieldNames(), immutableNumbers.getFieldValues(noNames)); ImmutableDescriptor immutableOne = new ImmutableDescriptor(Collections.singletonMap("one", 1)); DescriptorSupport mutableOne = new DescriptorSupport(new String[] {"one"}, new Object[] {1}); ImmutableDescriptor immutableTwo = new ImmutableDescriptor(Collections.singletonMap("two", 2)); DescriptorSupport mutableTwo = new DescriptorSupport(new String[] {"two"}, new Object[] {2}); ImmutableDescriptor immutableOneTwo = new ImmutableDescriptor(new String[] {"one", "two"}, new Object[] {1, 2}); checkEqual(union(immutableNumbers), immutableNumbers); checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers); checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers); checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers, mutableNumbers, immutableOne), immutableNumbers); checkEqual(union(immutableOne, immutableTwo, immutableNumbers), immutableNumbers); checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers); checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo); checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo); if (failure != null) throw new Exception("TEST FAILED: " + failure); System.out.println("TEST PASSED"); }