TransientApplicationState<S> state = (TransientApplicationState<S>) existing;
return new TransientApplicationState<S>(state.getContentId(), state.getContentState(), state.getOwnerType(),
state.getOwnerId());
} else {
// Hate doing this, but it's the only way to deal with persistent application state...
ExoContainer container = ExoContainerContext.getCurrentContainer();
if (container instanceof PortalContainer) {
DataStorage ds = (DataStorage) container.getComponentInstanceOfType(DataStorage.class);
try {
S s = ds.load(existing, type);
String contentId = ds.getId(existing);
return new TransientApplicationState<S>(contentId, s);