public Object unmarshal(Object obj, IUnmarshallingContext ictx)
throws JiBXException {
// make sure we're at the appropriate start tag
UnmarshallingContext ctx = (UnmarshallingContext)ictx;
if (isPresent(ctx)) {
// make sure there's a name for the document being parsed
if (ctx.getDocumentName() == null) {
throw new JiBXException("Unable to process include without " +
"base document name " + ctx.buildPositionString());
} else {
// check for conditionals on include
boolean use = true;
String name = ctx.attributeText(ATTR_NAMESPACE,
IFDEF_NAME, null);
if (name != null) {
use = getValue(name, ctx) != null;
}
name = ctx.attributeText(ATTR_NAMESPACE, IFNDEF_NAME, null);
if (use && name != null) {
use = getValue(name, ctx) == null;
}
// get the remaining attribute values and ditch element
String path = ctx.attributeText(ATTR_NAMESPACE, PATH_NAME);
String access =
ctx.attributeText(ATTR_NAMESPACE, ACCESSDIR_NAME);
String label = ctx.attributeText(ATTR_NAMESPACE,
LABEL_NAME, null);
ctx.parsePastElement(ELEMENT_NAMESPACE, INCLUDE_NAME);
// check if this include is active
if (use) {
// find the file to be included
int index = ctx.getStackDepth() - 1;
Builder build = (Builder)ctx.getStackObject(index);
File config = Component.
applyFilePath(build.getSourceRoot(), path);
File root = config.getParentFile();
// create new unmarshalling context for included file
UnmarshallingContext inctx = (UnmarshallingContext)
BindingDirectory.getFactory(Site.class).
createUnmarshallingContext();
try {
inctx.setDocument(new FileInputStream
(new File(root, path)), path, null);
} catch (FileNotFoundException e) {
throw new JiBXException("Include file " + path +
" not found " + ctx.buildPositionString());
}
// unmarshal the included document
obj = inctx.unmarshalElement();
if (obj instanceof Site) {
return new Menu((Site)obj, root, access, label);
} else if (obj instanceof Menu) {
return new Menu((Menu)obj, root, access, label);
} else {