/* (non-Javadoc)
* @see org.exist.xquery.BasicFunction#eval(org.exist.xquery.value.Sequence[], org.exist.xquery.value.Sequence)
*/
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
Metas metas = null;
Meta meta = null;
if (getSignature().getName().equals(NAME))
if (args.length == 1) {
meta = MetaData.get().getMeta(args[0].getStringValue());
} else {
if (args[0] instanceof DocumentImpl) {
metas = MetaData.get().getMetas(((DocumentImpl)args[0]));
} else
throw new XPathException(this, "Unsupported type "+args[0].getItemType());
}
else if (getSignature().getName().equals(NAME_URL))
metas = MetaData.get().getMetas(XmldbURI.create(args[0].getStringValue()));
if (metas == null && meta == null)
throw new XPathException(this, "No metadata found.");
if (meta == null)
meta = metas.get(args[1].getStringValue());
if (meta == null)
return Sequence.EMPTY_SEQUENCE;
ValueSequence returnSeq = new ValueSequence();
if (meta.getValue() instanceof DocumentImpl) {
returnSeq.add( new NodeProxy( (DocumentImpl) meta.getValue() ) );
} else {
returnSeq.add(new StringValue(meta.getValue().toString()));
}
return returnSeq;
}