Hiho!
The problem (as far as my still very limited understanding of the internals
goes) seems to be that there is no way to store immutable objects (like
primitive wrappers) in the XMLInjectionPointModel.
So currently XMLInjectableConstructor#doInject iterates over the parameter list
and performs
inject(model.getInjectionClassType(), model.getActualTypeArguments(), anns);
but naturally the InjectionResolver#implResolveByType will fail when it tries
to resolve a webbean of type java.lang.Integer (and which value should be taken
btw?)
The reason why I think arrays and enums are currently not allowed is because
came to this point while debugging:
XLMUtil#getTypeInjectionPointModel
> else if (clazz.isAnnotation() || clazz.isArray() || clazz.isEnum())
> {
> throw new WebBeansConfigurationException(errorMessage + "Java type
> with name : " + getElementJavaClassName(typeElement) + " must be class or
> interface type");
> }
Maybe I misinterpreted something. But you do basically also mean that enums and
<array>s should work according to the spec?
I pushed my changes to my git repo http://ns1.backwork.net/git
You can checkout the project with
$> git clone http://ns1.backwork.net/git/openwebbeans.git
Then simply move the .git directory to your SVN project folder.
Btw, an official apache git mirror for openwebbeans would be fine if other ones
like to use git on top of the SVN checkout too. This is really fine for sharing
experimental code branches which one do not like to checkin into SVN.
LieGrue,
strub
--- Gurkan Erdogdu <[email protected]> schrieb am Fr, 16.1.2009:
> Von: Gurkan Erdogdu <[email protected]>
> Betreff: Re: XML definition for constructor injection
> An: [email protected]
> Datum: Freitag, 16. Januar 2009, 7:50
> Hi Mark;
>
> >> E.g. we currently do not allow Enums,
> <Array> and primitive
> wrapper classes like java.lang.Integer in constructor
> injection.
>
> Did you look at the XML defined components definitions in
> the svn? I think we supported these issues. You can find the
> necessary artifacts in the following packages in the svn.
>
> XML Defined Beans -->
> java/org/apache/webbeans/component/xml
> XML Constructor Injection -->
> org/apache/webbeans/inject/xml/ ,
> XMLInjectableConstructor.java. In this class you will see
> the constructor parameters as a
> List<XMLInjectionPointModel> where each
> XMLInjectionPointModel holds the xml defined constructor
> parameters properties.
>
> I will create test cases about your concerns today.
>
> /Gurkan
>
>
>
>
> ________________________________
> From: Mark Struberg <[email protected]>
> To: [email protected]
> Sent: Thursday, January 15, 2009 9:28:35 PM
> Subject: Re: XML definition for constructor injection
>
> I had long night yesterday and like to share my outcome.
>
> First, big thanks to Gurkan again for being so patient with
> me yesterday ;)
>
> Oki, here is what I guess is the answer to my question in
> form of a patch. I reread the spec and somehow I have the
> gut feeling that either I still do not understand it fully
> (most probably) or the spec is still a bit inconsistent or
> we do have something missing in the implementation yet. E.g.
> we currently do not allow Enums, <Array> and
> primitive wrapper classes like java.lang.Integer in
> constructor injection. Whereas the spec states that
> > 10.3.3. Bean constructor declarations -> 10.6
> > 10.6 Injection point declarations -> 10.8
> > 10.8 Specifying bean types and bindings
> > • an element that represents a Java class or
> interface,
> > or <Array> ...
>
> The spec says nothing about real primitive types like int
> though. But this would perfectly make sense to me, like one
> may have an existing service which has to be filled. And all
> the needed functionality is already there for the field
> injection.
>
> Please review the XMLs in the patch if I interpreted the
> spec correctly!
>
> status so far:
> .) The example with invoking
> TstBeanConstructor(CtParameter) works
> .) I have a patch for making the
> TstBeanConstructor(Integer) work, but it's pretty ugly,
> so I will only work on this if you confirm that this use
> case should work according to the spec.
> .) I'm not sure if TstBeanConstructor(int,int) is ok
> for the spec. Doesn't work anyway ;)
>
>
> Another thing I was not really aware of:
> > XML-based bean declarations define additional
> beans—they do not
> > redefine or disable any bean that was declared via
> annotations.
> I always thought the XML based may redefine the beans
> behaviour. E.g. if one bean has a standard scope, I may
> override the scope via XML. Or I may change the injection of
> a service used on a production server. This would really be
> handy in praxis!
>
> txs,
> strub
>
> --- Mark Struberg <[email protected]> schrieb am Mi,
> 14.1.2009:
>
> > Von: Mark Struberg <[email protected]>
> > Betreff: Re: XML definition for constructor injection
> > An: [email protected]
> > Datum: Mittwoch, 14. Januar 2009, 22:56
> > Here is an example of what I like to have:
> >
> > Let's assume I have a _given_
> my.company.ConfigService
> > (and I don't even have the sources) which has NO
> default
> > constructor:
> >
> > public class ConfigService {
> > private int val1=0, val2=0;
> > public ConfigService(int ctParam) { val1=100*ctParam;
> }
> > public setVal2(int val2) { this.val2=val2; }
> > public getVal1...
> > }
> >
> > And I like to have the ConfigService as singleton with
> name
> > "cfgSvc" defined via XML (since there is
> > annotation in the given source).
> >
> > The initialisation should be:
> > 1.) create the ConfigService via it's constructor
> and
> > ctParam=42
> > 2.) call setVal2(666);
> >
> >
> > See what I mean? Is this even possible with the
> > 'flat' structure in the samples of the spec?
> This
> > would not allow to additionally set a value for val2,
> or did
> > I confuse something?
> >
> > How must the XML look like according to the spec?
> >
> > txs and LieGrue,
> > strub
> >
> >
> > --- Mark Struberg <[email protected]> schrieb am
> Mi,
> > 14.1.2009:
> >
> > > Von: Mark Struberg <[email protected]>
> > > Betreff: Re: XML definition for constructor
> injection
> > > An: [email protected]
> > > Datum: Mittwoch, 14. Januar 2009, 11:32
> > > Hi Gurkan!
> > >
> > > > the immediate children of the XML bean
> > declaration
> > > I also understood it this way when I first read
> the
> > spec.
> > >
> > > from the spec:
> > > > For a simple bean defined using XML, the
> bean
> > > constructor may be
> > > > specified by listing the parameter types of
> the
> > > constructer, in
> > > > order, as direct children of the element
> that
> > declares
> > > the bean.
> > >
> > > But on the other hand it was not really clear to
> me if
> > the
> > > examples given in the spec are _with_ or
> _without_ the
> > bean
> > > declaration itself (outer
> > <myapp:TstBeanConstructor>
> > > in my example)!
> > >
> > > If we interpret it your way, then no
> 'mixed'
> > > scenario like the following would work:
> > >
> > > I like to have a @Named(value="config")
> > > @SessionScoped TstBeanConstructor PLUS I like to
> > inject the
> > > value 7 in setI2.
> > >
> > > How can this be achieved if there is no
> separation
> > between
> > > the constructor parameters and the additionally
> > injected
> > > ones?
> > >
> > > Maybe this is not needed? Or it's a
> shortcoming of
> > the
> > > spec? Or I'm completely confused? :)
> > >
> > > How I would write the XML (assuming a ct public
> > > TstBeanConstructor(int ctParam) { ... ):
> > >
> > > <myapp:TstBeanConstructor>
> > > <Named>config</Named>
> > > <SessionScoped/>
> > > <myapp:TstBeanConstructor>
> > >
> <myapp:ctParam>42</myapp:ctParam>
> >
> > >
> > > </myapp:TstBeanConstructor>
> > > <myapp:i2>7</myapp:i1>
> > > </myapp:TstBeanConstructor>
> > >
> > > LieGrue,
> > > strub
> > >
> > >
> > > --- Gurkan Erdogdu
> <[email protected]>
> > schrieb
> > > am Mi, 14.1.2009:
> > >
> > > > Von: Gurkan Erdogdu
> > <[email protected]>
> > > > Betreff: Re: XML definition for constructor
> > injection
> > > > An: [email protected]
> > > > Datum: Mittwoch, 14. Januar 2009, 8:14
> > > > Hi Mark;
> > > >
> > > > Your XML definition is not correct, I think.
> > > Specification
> > > > says that, the immediate children of the XML
> bean
> > > > declaration which correspond to *Java Type*
> is
> > > captured as
> > > > a *parameters* of this constructor. So the
> > correct XML
> > > > definition may be written as;
> > > >
> > > > <myapp:TstBeanConstructor>
> > > > <RequestScoped/>
> > > > <lang: Integer/>
> > > > </myapp:TstBeanConstructor>
> > > >
> > > > where *lang* is the namespace that
> corresponds to
> > the
> > > > *java.lang* package. You are able to give
> any
> > > namespace
> > > > instead of *lang*.
> > > >
> > > > When the container creates this bean
> instance, it
> > will
> > > > inject the constructor parameter with
> looking the
> > > beans with
> > > > API type *Integer* and Binding Type
> *...@current*.
> > If it
> > > finds
> > > > the bean successfully, it injects its
> current
> > > instance.
> > > >
> > > > For example, lets say that we define
> producer
> > method
> > > in
> > > > other bean class (MyOtherBean) .
> > > >
> > > > class MyOtherBean
> > > > {
> > > >
> > > > @RequestScoped @Produces
> > > > public int
> getTstBeanConstructorInitialValue()
> > > > {
> > > > return 12;
> > > > }
> > > > }
> > > > Then, container calls this method via its
> parent
> > bean
> > > > instance (MyOtherBean) and injects the
> resulted
> > > instance
> > > > (Integer:12) into the TstBeanConstructor.
> > > >
> > > > I did not try to execute this sample, but I
> think
> > it
> > > works.
> > > >
> > > > Please look at the specification that
> contains
> > full
> > > > explanation of the XML defined constructor
> > > declaration.
> > > >
> > > > /Gurkan
> > > >
> > > >
> > > >
> > > >
> > > > ________________________________
> > > > From: Mark Struberg
> <[email protected]>
> > > > To: [email protected]
> > > > Sent: Tuesday, January 13, 2009 10:51:43 PM
> > > > Subject: XML definition for constructor
> injection
> >
> > > >
> > > > grr, my first mail got eaten by the spam
> daemon
> > > >
> > > >
> > > > --- Mark Struberg <[email protected]>
> > schrieb am
> > > Di,
> > > > 13.1.2009:
> > > >
> > > > > Von: Mark Struberg
> <[email protected]>
> > > > > Betreff:
> > > > > An:
> [email protected]
> > > > > Datum: Dienstag, 13. Januar 2009, 21:46
> > > > > Hi!
> > > > >
> > > > > I like to test the constructor
> injection via
> > XML
> > > > > definition.
> > > > >
> > > > > For what I understand after reading the
> > spec, the
> > > > following
> > > > > should work:
> > > > >
> > > > > Assume we have the WebBean, _without_
> any
> > > annotations:
> > > > >
> > > > > public class TstBeanConstructor
> > > > > {
> > > > >
> > > > > private int i1=0;
> > > > > private int i2=0;
> > > > >
> > > > > public TstBeanConstructor(int i1)
> > > > > {
> > > > > this.i1 = i1*100;
> > > > > }
> > > > >
> > > > > public int getI1()
> > > > > ...
> > > > >
> > > > >
> > > > > and the XML looks like:
> > > > >
> > > > > <myapp:TstBeanConstructor>
> > > > > <RequestScoped/>
> > > > >
> <myapp:TstBeanConstructor>
> > > > >
> > <myapp:i1>12</myapp:i1>
> > >
> > > >
> > > > >
> > > > >
> </myapp:TstBeanConstructor>
> > > > > </myapp:TstBeanConstructor>
> > > > >
> > > > >
> > > > > should this work? At first I was a bit
> > confused
> > > about
> > > > the 2
> > > > > <myapp:TstBeanConstructor>, is
> this
> > correct
> > > in
> > > > the
> > > > > XML?
> > > > >
> > > > > txs and LieGrue,
> > > > > strub