|
From: Colin S. <col...@ex...> - 2003-10-20 01:48:20
|
I think this would work, and is probably the least ambiguous. jürgen höller [werk3AT] wrote: >Colin, Rod, > >You're right regarding the term "external" for a different XML file, not only a different context. On second thought, I consider "bean-id" unclear too, as beans in other XML files also have an "id". Thus, a slightly refined suggestion: > >- <ref bean="..."/> can reference any bean by any name (equal to current "external", similar to current "bean" but without XML idref check); > >- <ref external="..."/> stays as it is for the time being, but in its final incarnation, it should check that the reference is really outside the current XML file; > >- <ref local="..."/> can reference a bean id in the same XML file (equal to the formerly proposed "bean-id", with an XML idref check). > >That's probably as easy to explain as possible: "bean" is the general one that can reference anything, "external" is for beans outside the current file, "local" for beans inside the current file -- and it's still backward-compatible. What do you think? > >Juergen > > > > -----Ursprüngliche Nachricht----- > Von: Colin Sampaleanu [mailto:col...@ex...] > Gesendet: So 19.10.2003 16:20 > An: jürgen höller [werk3AT] > Cc: spr...@li... > Betreff: Re: [Springframework-developer] XML bean references > > > > jürgen höller [werk3AT] wrote: > > >Everybody, > > > >On the occasion of allowing a single application context to be loaded from multiple XML files, I've reconsidered a detail of our XML syntax: The "ref" tag currently has two different attributes: > >- "bean" to reference a bean in the same application context via its id attribute (the XML id); > >- "external" to reference a bean in a parent context. > >The latter can basically address any bean, be it in the same context or a parent, an id or an alias name. > > > >The main rationale behind the "bean"/"external" separation was simply separating between XML validation of id refs (by the XML parser) and referencing any kind of name (validated by the bean factory). The latter was mainly necessary for referencing beans outside of the current XML file, at that time a parent context. In the mean time, a single context can be defined by multiple XML files; thus I don't consider the "bean"/"external" naming appropriate anymore. > > > >Instead, let me suggest different attribute names: > >- keep a "bean" attribute to reference *any* kind of name, be it id or alias, just like the current "external" attribute; > >- introduce a new "bean-id" attribute to reference a bean in the same XML file via its XML id, like the current "bean" attribute. > > > >If we keep the "external" attribute for the moment as an equivalent of the proposed "bean" attribute, this would be fully compatible with existing bean definition files. Of course, "bean" attributes would not get validated by the XML parser anymore, but that would not break the files in any way. "external" attributes would still work too, the same as before. > > > >We should recommend migrating to the new pattern though, i.e.: > >- rename "bean" to "bean-id"; > >- rename "external" to "bean". > >That should be easy to do; and as the old pattern still works, there is no need to migrate existing bean definition files immediately. > > > >I've thought about this for a while, and I consider it very important to clarify the attributes in a way like the above. Else, it will be pretty hard to explain the rationale behind "bean" and "external", especially when using multiple XML files for a single context. "bean" and "bean-id" are far easier to explain: "bean" always works, "bean-id" adds validation by the XML parser if specifying a bean id in the same context. > > > >Any thoughts on this, any strong objections? I would actually like to get this into M2, although it's pretty close already. As the change is trivial to implement and fully backward compatible, that shouldn't matter too much. > > > > > Even the current 'external' can be considered to still make sense if you > ust consider it to mean the bean you are refering to is 'external' to > the current xml file, as opposed to the current definition, that is it > external to the current context. > > However, I do agree that it's probably cleaner and makes more sense to > just go with 'bean' and 'bean-id', and emphasize that the latter should > be used if possible for extra validation... That point should definitely > be documented properly (and used in the examples), so people don't > accidentally throw away this free validation by using just 'bean'. > > |