[
https://issues.apache.org/jira/browse/TUSCANY-1823?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12533362
]
Mark Combellack commented on TUSCANY-1823:
------------------------------------------
I've done some more investigation into this problem and I now have a patch that
fixes this bug.
I can get property injection to partly work if I add an entry into the
.composite file for the properties. Basically, I added:
<property name="location" type="xsd:string">RTP</property>
<property name="year" type="xsd:string">2006</property>
Once this is done, the ComponentContext.getProperty() method no longer returns
null. This matches what Raymond Feng said in one of the above comments.
Now the ComponentContext.getProperty() method is attempting to inject and
instance of DocumentImpl. The problem is that the ComponentContextImpl is not
using the JavaPropertyValueObjectFactory class to "de-marshal" the value out of
the XML Document object.
The existing code in ComponentContextImpl.getProperty() does:
return type.cast(p.getValue());
This will just return the relevant XML Document object. Changing this code to
use the JavaPropertyValueObjectFactory means that the correct value for the
property is returned.
One problem is that the ComponentContextImpl is in the core project so cannot
directly access the JavaPropertyValueObjectFactory class as it is in the
implementation-java-runtime project.
The full solution to is bug that I have implemented in the attached patches is
to:
* Create a new core-spi interface called PropertyValueFactory with a single
method of createPropertyValue()
* Add a setPropertyValueFactory(PropertyValueFactory) method to the
ComponentContextImpl
* When the JavaComponentContextProvider.start() method is called, it will
register its propertyValueFactory with the ComponentContextImpl by calling
setPropertyValueFactory(PropertyValueFactory)
* When the Application calls ComponentContext.getProperty(), the
ComponentContextImpl can call propertyFactory.createPropertyValue() to get the
correct value of the property
The above changes allow the failing ComponentContext.getProperty() test in the
Properties iTests to work as expected.
> The getProperty() method on ComponentContext does not work
> ----------------------------------------------------------
>
> Key: TUSCANY-1823
> URL: https://issues.apache.org/jira/browse/TUSCANY-1823
> Project: Tuscany
> Issue Type: Bug
> Components: Java SCA Core Runtime
> Affects Versions: Java-SCA-1.0
> Environment: SVN revision #579110
> Linux
> Reporter: Mark Combellack
> Assignee: Raymond Feng
> Priority: Minor
> Fix For: Java-SCA-Next
>
> Attachments: ComponentContextGetPropertyComparisonFix.patch,
> ComponentContextGetPropertyTest_FAILS.patch
>
>
> As far as I can tell, it should be possible to get a property via:
> * Injection using @Property
> * ComponentContext.getProperty() method (Java Annotations spec - line 807
> & 808)
> The value returned by both of these methods should be equal.
> The ComponentContext.getProperty() method currently does not work as detailed
> above.
> The code for the ComponentContext.getProperty() method can be found in the
> ComponentContextImpl class of the core project.
> There appears to be more than one problem:
> Incorrectly comparing property name:
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> The code contains the following:
> public <B> B getProperty(Class<B> type, String propertyName) {
> for (ComponentProperty p : component.getProperties()) {
> if (propertyName.equals(propertyName)) {
> Notice that the if statement is comparing property name with itself. They
> will always be equal! This means that the first property is always being used
> rather than finding the correct one based on it's name.
> The code should be updated so that the if statement reads (i.e. use the
> p.getName() method)
> if (propertyName.equals(p.getName())) {
> I have attached a patch to fix this comparison problem.
> Properties appear not to be working:
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> To test ComponentContext.getProperty(), I updated the properties iTest by
> adding a test that gets the location from the ComponentContext and compares
> it with the injected version.
> The problem is that the property value returned from the ComponentContext is
> null.
> I have attached a patch for this test but as it does not pass so I would not
> apply it yet until this bug is fixed.
> Unfortunately, I do not know the cause of this problem.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]