On Dec 20, 2008, at 10:12 PM, Gavin King wrote:
I would like to open up a discussion about the XML format defined in
chapter 10.
Mike is concerned that the XML format is different to the style used
in other Java EE specifications, where class/method names are
generally specified as strings in the body of XML elements, and that
the XML format may turn out to be confusing to users.
On the other hand, the format currently defined by the specification
is typesafe, allowing tooling to provide validation and
auto-completion of all class/method names, and is also less verbose.
It's also consistent with the approach used by existing solutions in
the spec (Spring, Seam).
I've recently discovered that it's possible to write a Java 6
Processor that would generate the XML schema for a package containing
web beans as part of the compilation process. (This is an awesome new
feature of javac, that used to be provided by the APT plugin.)
One possible path to take would be to use hyphenated names in the XML
(i.e. <foo-bar> instead of <FooBar>) to make the XML more visually
consistent with other EE descriptors.
I love the new format. The urn:java:package namespace is brilliant,
to the extent that I'd go postal if it reverted to the earlier draft.
Among other advantages, it makes the XML so much more readable by
emphasizing the bean's name. The name change to <foo-bar> would be a
good change, for consistency.
Specifically, I just went through the process of changing our security
tag/bean configuration to the new format, and the improvement is
dramatic. With the new format, the XML expresses exactly what the
configuration means, and with no extraneous verbiage. It's brilliant.
There are a few things that I'd like tweaked, though:
1) The inline bean vs property needs to be simplified. (9.5
injection point declarations), specifically the existence of a child
element should not affect the parsing. Instead, it should follow the
method model (9.2.6) where "has a direct child <Initializer>, ..., or
binding type." 9.5 should be rewritten as:
a) If the Java type is a parameterized type .... is a type
declaration
b) Otherwise if ... binding type ... is a type declaration
c) Otherwise, the injection point declaration is an inline Web
Bean declaration, and the declared type ...
i.e. removing the old 3rd rule because it was making things more
confusing. The slight extra verbosity by requiring <Current/> for an
injected type is outweighed by the simplification, and consistency
with 9.2.6.
The specific problem is: when does an XML element refer to a type and
when does it refer to a bean to be instantiated (9.6 vs 9.7), which
isn't obvious from the spec (it's well-defined, but can be simplified.)
2) Property injection (bean-style setters) really need to be
supported. The bean pattern is historic and embedded in essentially
all specifications, so it's not really something WebBeans can avoid.
Aside from the historic value, property injection lets you validate
input easily at the configuration point, which is very nice.
3) Argument vs field is somewhat visually confusing. The spec
logic works, but it's easy to confuse a constructor arg for a field
and waste time. I'm not sure it needs to be changed, but something to
think about. You could have field/property as <myapp:foo-bar> and
types/annotations as <myapp:FooBar> or add an <arg> (I'm not sure
these are good ideas or even if there needs to be a change. I'm just
throwing the idea out.)
4) Annotation declaration is great. I would like the ability to
add non-webbeans annotations (for service declarations/introspection),
but that non-critical and could certainly be put off until a later spec.
-- Scott
I would like to get everyone's thoughts on this issue:
Do you like the existing format?
Do you find it confusing? In what way?
Have you used this approach in Spring or Seam? If so, how did it
compare?
How important is typesafety?
--
Gavin King
gavin.king(a)gmail.com
http://in.relation.to/Bloggers/Gavin
http://hibernate.org
http://seamframework.org