Metawidget inspects back-end metadata and creates front-end UI widgets. If your application is split over multiple tiers, however, sometimes the back-end metadata is not accessible from the front-end. For example, annotations (such as JPA ones) are designed to 'fall away' if the class is transferred to a tier without their JAR (such as ejb3-persistence.jar) in its classpath. Equally, configuration files may not be accessible across tiers.
Metawidget supports these situations. Because each remoting environment is different, however, you will need to add a little code yourself. Every Inspector returns an XML string, which is inherently serializable and safe to pass across tiers. Therefore, to run inspection remotely:
create a back-end class suited to your environment, such as an EJB Session Bean. Have the back-end class instantiate an Inspector - either programmatically:
XmlInspectorConfig config = new XmlInspectorConfig(); config.setInputStream( getClass().getResourceAsStream( "metawidget-backend-metadata.xml" )); Inspector inspector = new XmlInspector( config );
Or by using a metawidget.xml file and the ConfigReader helper class:
inspector = ConfigReader.configure( "backend-metawidget.xml", Inspector.class );
have the back-end class declare the Inspector interface. Implement the interface by delegating to the Inspector you just instantiated.
depending on your environment, it may futher be necessary to create a front-end class (a proxy). Have it declare the Inspector interface. Implement the interface by remoting to the back-end class and returning the XML string.
set the Inspector on the Metawidget by using the setInspector method.
An example of this technique can be seen in GwtRemoteInspectorProxy and GwtRemoteInspectorImpl.
|All Inspectors are immutable. Therefore you only need one Inspector for your entire application. Some remoting architectures support 'singletons' or 'service beans' well suited to this.|
If your architecture is strongly separated, some metadata may only be available in one tier (e.g. JPA annotations in the back-end) and some only available in another tier (e.g. struts-config.xml in the front-end).
For this, CompositeInspector supplies an overloaded method outside the normal Inspector interface. The overloaded CompositeInspector.inspect method takes an additional XML string of inspection results, and merges forthcoming inspection results with it.
Therefore, to combine metadata from different tiers:
create a front-end class that implements the Inspector interface
implement the interface by first remoting to the back-end class and returning the XML string, as before
next, delegate to a CompositeInspector to inspect the front-end, passing it the XML string from the back-end as a starting point