Java Code Examples for javax.management.modelmbean.ModelMBeanAttributeInfo#getDescriptor()

The following examples show how to use javax.management.modelmbean.ModelMBeanAttributeInfo#getDescriptor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractJmxAssemblerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testAttributeInfoHasDescriptors() throws Exception {
	ModelMBeanInfo info = getMBeanInfoFromAssembler();

	ModelMBeanAttributeInfo attr = info.getAttribute(NAME_ATTRIBUTE);
	Descriptor desc = attr.getDescriptor();
	assertNotNull("getMethod field should not be null",
			desc.getFieldValue("getMethod"));
	assertNotNull("setMethod field should not be null",
			desc.getFieldValue("setMethod"));
	assertEquals("getMethod field has incorrect value", "getName",
			desc.getFieldValue("getMethod"));
	assertEquals("setMethod field has incorrect value", "setName",
			desc.getFieldValue("setMethod"));
}
 
Example 2
Source File: AbstractJmxAssemblerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testAttributeInfoHasDescriptors() throws Exception {
	ModelMBeanInfo info = getMBeanInfoFromAssembler();

	ModelMBeanAttributeInfo attr = info.getAttribute(NAME_ATTRIBUTE);
	Descriptor desc = attr.getDescriptor();
	assertNotNull("getMethod field should not be null",
			desc.getFieldValue("getMethod"));
	assertNotNull("setMethod field should not be null",
			desc.getFieldValue("setMethod"));
	assertEquals("getMethod field has incorrect value", "getName",
			desc.getFieldValue("getMethod"));
	assertEquals("setMethod field has incorrect value", "setName",
			desc.getFieldValue("setMethod"));
}
 
Example 3
Source File: AbstractJmxAssemblerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testAttributeInfoHasDescriptors() throws Exception {
	ModelMBeanInfo info = getMBeanInfoFromAssembler();

	ModelMBeanAttributeInfo attr = info.getAttribute(NAME_ATTRIBUTE);
	Descriptor desc = attr.getDescriptor();
	assertNotNull("getMethod field should not be null",
			desc.getFieldValue("getMethod"));
	assertNotNull("setMethod field should not be null",
			desc.getFieldValue("setMethod"));
	assertEquals("getMethod field has incorrect value", "getName",
			desc.getFieldValue("getMethod"));
	assertEquals("setMethod field has incorrect value", "setName",
			desc.getFieldValue("setMethod"));
}
 
Example 4
Source File: AbstractReflectiveMBeanInfoAssembler.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Iterate through all properties on the MBean class and gives subclasses
 * the chance to vote on the inclusion of both the accessor and mutator.
 * If a particular accessor or mutator is voted for inclusion, the appropriate
 * metadata is assembled and passed to the subclass for descriptor population.
 * @param managedBean the bean instance (might be an AOP proxy)
 * @param beanKey the key associated with the MBean in the beans map
 * of the {@code MBeanExporter}
 * @return the attribute metadata
 * @throws JMException in case of errors
 * @see #populateAttributeDescriptor
 */
@Override
protected ModelMBeanAttributeInfo[] getAttributeInfo(Object managedBean, String beanKey) throws JMException {
	PropertyDescriptor[] props = BeanUtils.getPropertyDescriptors(getClassToExpose(managedBean));
	List<ModelMBeanAttributeInfo> infos = new ArrayList<>();

	for (PropertyDescriptor prop : props) {
		Method getter = prop.getReadMethod();
		if (getter != null && getter.getDeclaringClass() == Object.class) {
			continue;
		}
		if (getter != null && !includeReadAttribute(getter, beanKey)) {
			getter = null;
		}

		Method setter = prop.getWriteMethod();
		if (setter != null && !includeWriteAttribute(setter, beanKey)) {
			setter = null;
		}

		if (getter != null || setter != null) {
			// If both getter and setter are null, then this does not need exposing.
			String attrName = JmxUtils.getAttributeName(prop, isUseStrictCasing());
			String description = getAttributeDescription(prop, beanKey);
			ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(attrName, description, getter, setter);

			Descriptor desc = info.getDescriptor();
			if (getter != null) {
				desc.setField(FIELD_GET_METHOD, getter.getName());
			}
			if (setter != null) {
				desc.setField(FIELD_SET_METHOD, setter.getName());
			}

			populateAttributeDescriptor(desc, getter, setter, beanKey);
			info.setDescriptor(desc);
			infos.add(info);
		}
	}

	return infos.toArray(new ModelMBeanAttributeInfo[0]);
}
 
Example 5
Source File: AbstractReflectiveMBeanInfoAssembler.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Iterate through all properties on the MBean class and gives subclasses
 * the chance to vote on the inclusion of both the accessor and mutator.
 * If a particular accessor or mutator is voted for inclusion, the appropriate
 * metadata is assembled and passed to the subclass for descriptor population.
 * @param managedBean the bean instance (might be an AOP proxy)
 * @param beanKey the key associated with the MBean in the beans map
 * of the {@code MBeanExporter}
 * @return the attribute metadata
 * @throws JMException in case of errors
 * @see #populateAttributeDescriptor
 */
@Override
protected ModelMBeanAttributeInfo[] getAttributeInfo(Object managedBean, String beanKey) throws JMException {
	PropertyDescriptor[] props = BeanUtils.getPropertyDescriptors(getClassToExpose(managedBean));
	List<ModelMBeanAttributeInfo> infos = new ArrayList<>();

	for (PropertyDescriptor prop : props) {
		Method getter = prop.getReadMethod();
		if (getter != null && getter.getDeclaringClass() == Object.class) {
			continue;
		}
		if (getter != null && !includeReadAttribute(getter, beanKey)) {
			getter = null;
		}

		Method setter = prop.getWriteMethod();
		if (setter != null && !includeWriteAttribute(setter, beanKey)) {
			setter = null;
		}

		if (getter != null || setter != null) {
			// If both getter and setter are null, then this does not need exposing.
			String attrName = JmxUtils.getAttributeName(prop, isUseStrictCasing());
			String description = getAttributeDescription(prop, beanKey);
			ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(attrName, description, getter, setter);

			Descriptor desc = info.getDescriptor();
			if (getter != null) {
				desc.setField(FIELD_GET_METHOD, getter.getName());
			}
			if (setter != null) {
				desc.setField(FIELD_SET_METHOD, setter.getName());
			}

			populateAttributeDescriptor(desc, getter, setter, beanKey);
			info.setDescriptor(desc);
			infos.add(info);
		}
	}

	return infos.toArray(new ModelMBeanAttributeInfo[0]);
}
 
Example 6
Source File: AbstractReflectiveMBeanInfoAssembler.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Iterate through all properties on the MBean class and gives subclasses
 * the chance to vote on the inclusion of both the accessor and mutator.
 * If a particular accessor or mutator is voted for inclusion, the appropriate
 * metadata is assembled and passed to the subclass for descriptor population.
 * @param managedBean the bean instance (might be an AOP proxy)
 * @param beanKey the key associated with the MBean in the beans map
 * of the {@code MBeanExporter}
 * @return the attribute metadata
 * @throws JMException in case of errors
 * @see #populateAttributeDescriptor
 */
@Override
protected ModelMBeanAttributeInfo[] getAttributeInfo(Object managedBean, String beanKey) throws JMException {
	PropertyDescriptor[] props = BeanUtils.getPropertyDescriptors(getClassToExpose(managedBean));
	List<ModelMBeanAttributeInfo> infos = new ArrayList<ModelMBeanAttributeInfo>();

	for (PropertyDescriptor prop : props) {
		Method getter = prop.getReadMethod();
		if (getter != null && getter.getDeclaringClass() == Object.class) {
			continue;
		}
		if (getter != null && !includeReadAttribute(getter, beanKey)) {
			getter = null;
		}

		Method setter = prop.getWriteMethod();
		if (setter != null && !includeWriteAttribute(setter, beanKey)) {
			setter = null;
		}

		if (getter != null || setter != null) {
			// If both getter and setter are null, then this does not need exposing.
			String attrName = JmxUtils.getAttributeName(prop, isUseStrictCasing());
			String description = getAttributeDescription(prop, beanKey);
			ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(attrName, description, getter, setter);

			Descriptor desc = info.getDescriptor();
			if (getter != null) {
				desc.setField(FIELD_GET_METHOD, getter.getName());
			}
			if (setter != null) {
				desc.setField(FIELD_SET_METHOD, setter.getName());
			}

			populateAttributeDescriptor(desc, getter, setter, beanKey);
			info.setDescriptor(desc);
			infos.add(info);
		}
	}

	return infos.toArray(new ModelMBeanAttributeInfo[infos.size()]);
}
 
Example 7
Source File: AbstractReflectiveMBeanInfoAssembler.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Iterate through all properties on the MBean class and gives subclasses
 * the chance to vote on the inclusion of both the accessor and mutator.
 * If a particular accessor or mutator is voted for inclusion, the appropriate
 * metadata is assembled and passed to the subclass for descriptor population.
 * @param managedBean the bean instance (might be an AOP proxy)
 * @param beanKey the key associated with the MBean in the beans map
 * of the {@code MBeanExporter}
 * @return the attribute metadata
 * @throws JMException in case of errors
 * @see #populateAttributeDescriptor
 */
@Override
protected ModelMBeanAttributeInfo[] getAttributeInfo(Object managedBean, String beanKey) throws JMException {
	PropertyDescriptor[] props = BeanUtils.getPropertyDescriptors(getClassToExpose(managedBean));
	List<ModelMBeanAttributeInfo> infos = new ArrayList<ModelMBeanAttributeInfo>();

	for (PropertyDescriptor prop : props) {
		Method getter = prop.getReadMethod();
		if (getter != null && getter.getDeclaringClass() == Object.class) {
			continue;
		}
		if (getter != null && !includeReadAttribute(getter, beanKey)) {
			getter = null;
		}

		Method setter = prop.getWriteMethod();
		if (setter != null && !includeWriteAttribute(setter, beanKey)) {
			setter = null;
		}

		if (getter != null || setter != null) {
			// If both getter and setter are null, then this does not need exposing.
			String attrName = JmxUtils.getAttributeName(prop, isUseStrictCasing());
			String description = getAttributeDescription(prop, beanKey);
			ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(attrName, description, getter, setter);

			Descriptor desc = info.getDescriptor();
			if (getter != null) {
				desc.setField(FIELD_GET_METHOD, getter.getName());
			}
			if (setter != null) {
				desc.setField(FIELD_SET_METHOD, setter.getName());
			}

			populateAttributeDescriptor(desc, getter, setter, beanKey);
			info.setDescriptor(desc);
			infos.add(info);
		}
	}

	return infos.toArray(new ModelMBeanAttributeInfo[infos.size()]);
}