[ https://issues.apache.org/jira/browse/TUSCANY-1823?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12533733 ]
Mike Edwards commented on TUSCANY-1823: --------------------------------------- Raymond, you asked: "I think it requires the SCA spec clarification here. In the following case: @Property public String location = "RTP"; Do we take the "RTP" as the default value? Should ComponentContext.getProperty(String.class, "location") return "RTP"? If so, then it will be inconsistent with the setter method because it cannot access the default value. private String location ="RTP"; @Property public void setLocation(String location) { this.location = location; } It's not clear in the spec (assembly and java). " In your case above, "RTP" IS the default value for the property. So, if no value is provided for the property by its SCA component configuration, the default value applies. It is a different issue as to whether ComponentContext.getProperty(...) can correctly get at the property value. Clearly, if there is a getter method, all is well. If there is no getter method, then for a private field you would have to violate encapsulation in order to go fetch the value. I don't have an answer to that one. I suggest that it is the Java C&I spec that has the problem, since the default value is perfectly well defined, but that getting the value of the property is not at all clear in the case where the property field is private and there is no getter method. Yours, Mike. > 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: ComponentContextGetProperty.patch, > ComponentContextGetProperty_EnableTest.patch, > 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]