Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

JFace Data Binding/PojoBindable/PojoBindableSVN

Pojo Bindable SVN

For the last version of Pojo Bindable you can (for the moment) get it from the SVN on Dynaresume project. You can find the whole Pojo bindable project at http://dynaresume.googlecode.com/svn/trunk/JFace-Pojo-Bindable/ :

Pojo Bindable into OSGi context

You can find a basic sample with Pojo bindable into org.eclipse.core.examples.databinding.pojo.bindable.equinox bundle. This bundle has an Activator which create a basic PojoPerson coming from another bundle org.eclipse.core.examples.databinding.pojo.bindable.model:

package org.eclipse.core.examples.databinding.pojo.bindable.model;
 
public class PojoPerson {
 
	String name = "HelloWorld";
 
	public String getName() {
		return name;
	}
 
	public void setName(String name) {
		this.name = name;
	}
}

and add it a PropertyChangeListener listener :

public class Activator implements BundleActivator {
 
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext
	 * )
	 */
	public void start(BundleContext context) throws Exception {
 
		// Create Pojo instance
		PojoPerson person = new PojoPerson();
 
		PropertyChangeListener listener = new PropertyChangeListener() {
			public void propertyChange(PropertyChangeEvent event) {
				System.out.println("---------- Property User changed --------");
				System.out.println("  PropertyName=" + event.getPropertyName());
				System.out.println("  OldValue=" + event.getOldValue());
				System.out.println("  NewValue=" + event.getNewValue());
				System.out
						.println("------------------------------------------");
			}
		};
 
		// Add Listener
		try {
			Method m = person.getClass().getMethod("addPropertyChangeListener",
					String.class, PropertyChangeListener.class);
			m.invoke(person, "name", listener);
		} catch (Exception e) {
			e.printStackTrace();
		}
 
		// Change name property.
		person.setName("New name");
 
	}
...
}

When bundle is started, you will see on console :

---------- Property User changed --------
  PropertyName=name
  OldValue=HelloWorld
  NewValue=New name
------------------------------------------

You can notice that there is no dependencies to Pojo Bindable in this code. If Pojo Bindable is well configured into OSGi context, when PojoPersonn Class is used, the bytecode is updated when Class is loaded to add PropertyChangeSupport.

Pojo Bindable works into OSGi context only with Equinox. Indead Pojo bindable provides an OSGi fragment org.eclipse.core.databinding.pojo.bindable.equinox.weaving which is linked to org.eclipse.osgi and use Adaptor Hooks.

How test Pojo Bindable into OSGi context?

To test the bundle org.eclipse.core.examples.databinding.pojo.bindable.equinox, you must :

Import the projects from SVN

Import from SVN the projects :

  1. the 3 ASM projects stored into dependencies :
  2. Bundle org.eclipse.core.databinding.pojo.bindable: Pojo Bindable bundle.
  3. Bundle org.eclipse.core.databinding.pojo.bindable.equinox: bundle which publish a BindableWeaver service to transform Class to Pojo bindable (implements BindableAware interface).
  4. Fragment org.eclipse.core.databinding.pojo.bindable.equinox.weaving: bundle which consume a BindableWeaver service to transform Class to Pojo bindable (implements BindableAware interface).
  5. Bundle org.eclipse.core.examples.databinding.pojo.bindable.equinox: Pojo Bindable bundle example which use Pojo Bindable into OSgi context.
  6. Bundle org.eclipse.core.examples.databinding.pojo.bindable.model: bundle model wich contains PojoPerson.
  7. Bundle org.eclipse.core.examples.databinding.pojo.bindable.equinox.fragment: fragment linked to org.eclipse.core.databinding.pojo.bindable.equinox wich configure Pojo Bindable.

PojoBindableSVN OSGiContext Projects.png

Pojo Bindable Bundles

If you wish use Pojo Bindable into OSGi context, you must use Bundles/Fragments :

Pojo Bindable Configuration (bindable.properties)

To configure Pojo bindable like Bindable Java Agent, you must create an OSGi Fragment linked to org.eclipse.core.databinding.pojo.bindable.equinox bundle and create a file bindable.properties into the fragment project. Into our example Pojo bindable is configured with the org.eclipse.core.examples.databinding.pojo.bindable.equinox.fragment OSGi Fragment. This fragment contains bindable.properties with this content :

bindable.packages=org.eclipse.core.examples.databinding.pojo.bindable.model
bindable.debug=true

This configuration will transform the classes coming from org.eclipse.core.examples.databinding.pojo.bindable.model packages like our PojoPerson. Pojo bindable debug mode is set to true, so you will see each Classes wich must be loaded and check if your Class is transformed as explained here.

Pojo Bindable Examples

Import as binary project org.eclipse.osgi

Pojo Bindable use Equinox Adaptor Hooks but more precisly ClassLoadingHook (see class BindableWeaverRegistry). The bundle org.eclipse.core.databinding.pojo.bindable.equinox.weaving is OSGi Fragment attached to org.eclipse.osgi bundle. To work with PDE, import the bundle org.eclipse.osgi as binary project into your workspace. To do that, open the Plug-ins view (Window->Show View -> Other... => PDE/Plug-ins). Select the org.eclipse.osgi bundle into the Plug-ins view and choose menu "Import As->Binary Project" :

PojoBindableSVN OSGiContext ImportOrgEclipseOsiBundle.png

Your workspace look like this :

PojoBindableSVN OSGiContext workspace.png

Launch configuration

Start the bundle with Pojo Bindable OSGi.launch.

Bundle org.eclipse.core.databinding.pojo.bindable.equinox (Start Level=3)

If you edit the launch Pojo Bindable OSGi.launch, you can notice that into Bundles tab  :

  • bundle org.eclipse.osgi is selected into Workspace (node). The bundle org.eclipse.osgi from target Platform must not selected.
  • bundle org.eclipse.core.databinding.pojo.bindable.equinox must be started (Start Level=3) before the bundle which use PojoPerson.

PojoBindableSVN OSGiContext Launch Bundle.png

-Dosgi.framework.extensions=org.eclipse.core.databinding.pojo.bindable.equinox.weaving

Into Arguments tabs you can notice :

 -Dosgi.framework.extensions=org.eclipse.core.databinding.pojo.bindable.equinox.weaving

PojoBindableSVN OSGiContext Launch Arguments.png

Pojo Bindable & Bundles/Fragments

Here a schema wich explains how Pojo bindable works :

PojoBindableSVN OSGiContext PojoBindableBundles.png

We can resume Pojo bindable into OSGi context with 3 steps :

  1. (1) Publish BindableWeaver Service to transform Pojo Class.
  2. (2) Consume BindableWeaver Service to transform Pojo Class.
  3. (3) Create Pojo (bytecode is transformed) by using BindableWeaver Service.

Pojo Bindable & Equinox Aspects

You can do the same thing with Equinox Aspects. I adwice you to use Equinox Aspects Hook instead of Pojo bindable Hook, because Equinox Aspects Hook is more performant (cache...) and if you wish manage LoadTimeWeaver with JPA and Spring DM, you can use Load-Time Weaving for Spring-DM.

Equinox Aspects provides a bundle OSGi wich is an Equinox Hook Adapter org.eclipse.equinox.weaving.hook where you can download on Equinox Aspects - Downloads or get it from CVS Eclipse on equinox-incubator/aspects/org.eclipse.equinox.weaving.hook

This Hook depends NOT on AspectJ, so you NEED NOT install AspectJ bundles.

Pojo Bindable provides the bundle OSGi org.eclipse.equinox.weaving.pojo.bindable wich publish as OSGi service an implémentation of the factory org.eclipse.equinox.service.weaving.IWeavingServiceFactory (Interface coming from Equinox Aspects Hook) wich return an instance of org.eclipse.equinox.service.weaving.IWeavingService which transform bytecode to have Pojo Bindable capability.

To use Pojo Bindable with Equinox Aspects :

  1. Import org.eclipse.equinox.weaving.hook into your workspace.
  2. Import org.eclipse.osgi as Binary Project and select this bundle OSGi (org.eclipse.osgi from Workspace and NOT from Target Platform).
  3. Import org.eclipse.equinox.weaving.pojo.bindable into your workspace.
  4. Create a fragment OSGi attached to org.eclipse.equinox.weaving.pojo.bindable to configure Pojo Bindable with bindable.properties. You have a sample into the bundle org.eclipse.equinox.weaving.examples.pojo.bindable.fragment. bindable.properties has this content
    bindable.packages=org.eclipse.core.examples.databinding.pojo.bindable.model
    bindable.debug=true
    bindable.include_bundles=org.eclipse.core.examples.databinding.pojo.bindable.model

    bindable.include_bundles set the bundles ID (use ';' for several bundles) which contains Classes wich must be transformed by pojo bindable. This property is optionnal but it avoid to scan each classes of each bundles.

  5. Start the bundle org.eclipse.equinox.weaving.pojo.bindable on Start Level=3 (before Pojo Class bundles).
  6. Into Arguments of the OSGi Launch you must set:
    -Dosgi.framework.extensions=org.eclipse.equinox.weaving.hook

Pojo Bindable- Equinox Aspects & Bundles/Fragments

Here a schema wich explains how Pojo bindable & Equinox Aspects works :

PojoBindableSVN OSGiContext PojoBindableBundlesEquinoxAspects.png

We can resume Pojo bindable & Equinox Aspects into OSGi context with 3 steps :

  1. (1) Publish IWeavingServiceFactory Service wich is a factory wich create IWeavingService to transform Pojo Class.
  2. (2) Consume IWeavingServiceFactory Service to transform Pojo Class.
  3. (3) Create Pojo (bytecode is transformed) by using IWeavingServiceFactory Service.

Pojo Bindable & EclipseLink

EclipseLink provider Dynamic Weaving Fragment for Equinox into org.eclipse.persistence.jpa.equinox.weaving fragment to transform bytecode.

Back to the top