Monday, June 27, 2011

Java Language Puzzle 2

Given the following source listing, explain why InstantiationException is thrown when running (via the main method entry point) and how the code should be fixed.

package puzzle;

public class Entity
    private Entity()
    public class Factory
        public Entity create()
            return new Entity();
    public static void main( String[] args ) throws Exception
Exception in thread "main" java.lang.InstantiationException: puzzle.Entity$Factory
	at java.lang.Class.newInstance0(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at puzzle.Entity.main(

ANSWER:  It looks like everyone who responded correctly identified the fact that Factory class is not defined as static as the cause of this exception. The solution is to add the static keyword. I would imagine that vast majority of Java developers are pretty comfortable with static/non-static inner classes semantics. What raises this to a puzzle level is a rather unhelpful exception.

Wednesday, June 22, 2011

Announcing Sapphire 0.3 Release

It is with great pleasure that I announce on-time availability of Sapphire 0.3 release. This release includes numerous enhancements, some of which I will briefly describe. Current users of 0.2.x line will want to consult the migration guide.

Before we get to the new features, it is important to take a few minutes to thank all the people who made this release possible. Shenxue Zhou is a new committer on the project and has been working hard to bring us diagram editing support. A key new features in this release. The community around Sapphire has grown substantially in the last few months. Many of the enhancements that you will find in this release are based on ideas and requirements brought by the new adopters. All of the adopters deserve a thank you, but I will call out one by name. Greg Amerson (Liferay) has progressed very quickly from an adopter to a contributors. Five patches from Greg are in the 0.3 release. Greg has the distinction of being the first non-Oracle contributor to Sapphire. Last but not least, several members of Oracle QA has pitched in to verify enhancements and fixed bugs.

Without further ado, I present the enhancements in the 0.3 release…

Diagram Editing – Define diagram UI just as easily as a form. Sapphire declarative UI language has been expanded to cover basic diagram concepts. This feature opens the door for very sophisticated editors that provide diagram, form and source views on the same data. Yet, no matter how many diagram, form and source views on the data you define, Sapphire keeps everything in sync with n-way synchronization.

Properties View Integration – Easily attach properties view content to diagram nodes, connections, form outline nodes, etc. using the same UI definition facilities as the editor. Sapphire will automatically inject that content into the standard Eclipse properties view when that part has selection.

UI Definition Editor – Spend less time trying to get sdef syntax right with the new form-based editor for Sapphire UI Definition files. The editor is, of course, itself built using Sapphire.

Expression Language Enhancements – Use EL in more areas of model and UI specification than before. The EL itself is now even more powerful with better handling of collections and support for custom type casts among other features.

Modularity Improvements – Use Sapphire in more scenarios than before. The core modeling framework now only requires Java. Add integration with OSGi, Eclipse platform resources, JDT, etc. by installing separate modules.

Miscellaneous Enhancements – Embed snippets of HTML into a form, show related content next to a property editor, choose from three layouts for a checkbox, specify editor header image, define collapsible sections, the list goes on. Head over to the enhancements guide for all the details.

Of course, no release of a UI framework would be complete without screen captures. Here are a few to wet your appetite…




Migration Guide
Developer Guide

Concurrently with 0.3, we are also shipping 0.2.3 release to bring support for Indigo to adopters who still rely on the 0.2.x line.

Friday, June 17, 2011

Java EE Module Configuration Editors Draft Proposal

I am working on a proposal for Java EE Module Configuration Editors project. The goal is to create a new project under WTP Java EE Tools project and build there editors for web.xml, application.xml, ejb-jar.xml and possibly all the rest of the module configuration files. The editors would be built using Sapphire and work across various versions of Java EE spec. For Java EE 5 or newer, the editors would be able to also edit Java annotations instead of the XML configuration file from the same interface.

Draft Proposal

While I am working on the getting the new project created to hold this work, I’ve started implementing the web.xml editor in Sapphire repository as a sample. You can get a feel for what’s there now and what the final result will look like in the screencast that I put together.


To take the editor for a spin yourself, install everything from the following repository. Don't try to go to a newer build as this plugin has been removed from the Sapphire build in preparation for the 0.3 release.

To access the source code, point your Eclipse at the following location in CVS. Note that you will need WTP + Sapphire in your target platform and Sapphire SDK in your dev eclipse. The latter part is very important as the Sapphire SDK contains the code generate necessary to build this plugin.

Source Code

If you are interested in this work, leave a comment with your name on this blog post or send a note to wtp-dev mailing list so that I can add you to the list of interested parties in the project proposal. If you are interested in helping to implement these editors, state as much as well and we will discuss.