Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ve-dev] using JEM to introspect/reflect bean


Hi,

To use JEM, you need to have a project that is a Java project. It does introspection on a per Java project basis.

Note: The BeanInfo classes still are marked internal, but that is because they haven't been made API yet. They are stable and not likely to change very much except to be renamed to API classes sometime in the future.

To use:

... To setup for  a project do this once per session to initialize the BeanInfo process:

        IProject biProject = JavaProjectUtil.getProject("name of project");
        BeaninfoNature nature = BeaninfoNature.getRuntime(biProject);
        ResourceSet javarset = nature.getResourceSet();

... Now the javarset is a ResourceSet used for JEM for the project. So to actually do introspection:

        JavaClass jclass = JavaRefFactory.eINSTANCE.reflectType("fully-qualified classname", javarset);

From the jclass you can accessors to get the information you need. For example jclass.getAllProperties() returns all of the EStructuralFeatures that are BeanInfo properties.

There are two ways to access the actual BeanInfo such as PropertyDecorator (which corresponds to java.beans.PropertyDescriptor). The first is to get it from the EStructuralFeature. In that case you would do (Utilities is org.eclipse.jem.internal.beaninfo.core.Utilities):

        PropertyDecorator prop = Utilities.getPropertyDecorator(estructuralfeature);

Or to get all of the PropertyDecorators for a class:

        Iterator propertyItr = Utilities.getPropertiesIterator(jclass.getAllProperties());

and then use the iterator. It will return PropertyDecorator's from the iterator.

On JavaRefFactory there are various types of "reflectType" methods. You can choose which fits for you. The same goes for the Utilities. There are various methods that do different things to help you out.

Thanks,
Rich

Back to the top