if (within instanceof Container) {
return (Container) within;
} else if (within instanceof Contained) {
return ((Contained) within).getContainer();
} else {
throw new Kite9ProcessingException("Cannot find container for " + within);
}
} else {
// object must exist outside context
if (within instanceof Contained) {
return ((Contained) within).getContainer();
} else {
throw new Kite9ProcessingException("Cannot find container for " + within);
}
}
}