Hi,
Am Montag, den 10.12.2007, 14:06 +0100 schrieb Carsten Ziegeler:
> This would be symmetrical to the resource interface - but I'm not sure
> if we might run into implementation problems with this approach over
> time. Let's assume we have more than one extension for the
> ResourceResolver, the ObjectMapper and the YetUnknownExtension - to
> support both extensions you need to create an implementation hierarchy
> between the implementations (either ObjectMapper extends
> YetUnknownExtension or vice versa). Or you can only have one or the other.
>
> When over time another extension is added you get into the typical multi
> inheritance problem.
>
> On the other hand all these extensions might not be possible to be
> implemented independently from the resource resolver...difficult.
Not sure whether I understand you correctly. Thing is that the adaptTo
method just returns an object of the requested class (or null if not
possible). It is by no means required, that the adaptTo method returns
this cast to the correct type. So, the implementation may possible by:
public <T> T adaptTo(Class<T> type) {
if (type == Session.class) {
return (T) getSession();
} else if (type == ObjectMapper.class) {
return (T) getObjectMapper();
}
return null;
}
private ObjectMapper getObjectMapper() {
if (objectMapper == null) {
objectMapper = new ObjectMapper(getSession());
}
return objectMapper;
}
I do not think, that we run into any extension problems using this
approach because the ObjectMapper and the ResourceResolver are not
necessairily the same.
Regards
Felix