Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33288
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2015-12-03 03:33 -0800 |
| Message-ID | <64d27264-1b2d-49cb-8492-71306709f92e@googlegroups.com> (permalink) |
| Subject | Oo questions |
| From | mike <mikaelpetterson@hotmail.com> |
This is the code users have:
<code>
ObjectAttribute attr = retriever.getAttr("name");
</code>
ObjectAttribute is an abstract class with a method called getValue().
We found a fault, when we had a sequence with one element, that getAttr(String) returned wrong type for certain "name".
Before getAttr() returned ValueAttribute but so after fix we return
SequenceAttribute which is the correct type. Both ValueAttribute and SequenceAttribute are implementations of ObjectAttribute.
When this was fixed we could see that the impact for end-user would be huge so we would like to give them a grace period, since users do
<code>
attr.getValue()
</code>
which now gives a different outputformat SequenceAttribute is used.
So we created a SequenceAttributeProxy ( since SequenceAttribute is used in other libraries that don't need this) that extends SequenceAttribute and returns the old value like:
<code>
public class SequenceAttributeProxy extends SequenceAttribute {
public SequenceAttributeProxy (String name) {
super(name);
}
@Override
public String getValue() {
if (sequence.size() == 1) {
String correctFormat = getValueAsJson().toString();
String incorrectFormat = sequence.get(0).getValue();
//Do some logging
return sequence.get(0).getValue();
}
return getValueAsJson().toString();
}
}
</code>
When we checked user code we discovered that some user have done it correct:
<code>
SequenceAttribute attr = (SequenceAttribute)retriever.getAttr("name");
</code>
So users have both:
1. ObjectAttribute attr = retriever.getAttr("name");
2. SequenceAttribute attr = (SequenceAttribute)retriever.getAttr("name");
But we only want users of 1. to see logging and return the old value.
Problem is that getAttr() now returns SequenceAttribute for both 1 and 2.
And we have not found a way to distinguish between them so we can use that in our Proxy.
Any ideas?
//mike
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread
Oo questions mike <mikaelpetterson@hotmail.com> - 2015-12-03 03:33 -0800 Re: Oo questions Arne Vajhøj <arne@vajhoej.dk> - 2015-12-03 19:04 -0500 Re: Oo questions mike <mikaelpetterson@hotmail.com> - 2015-12-04 00:22 -0800
csiph-web