use of org.exist.dom.memtree.NodeImpl in project exist by eXist-db.
the class GetIndexStatistics method eval.
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
final IndexStatistics index = (IndexStatistics) context.getBroker().getBrokerPool().getIndexManager().getIndexById(IndexStatistics.ID);
if (index == null) {
// module may not be enabled
return Sequence.EMPTY_SEQUENCE;
}
final SAXAdapter adapter = new SAXAdapter(context);
try {
adapter.startDocument();
index.toSAX(adapter);
adapter.endDocument();
} catch (final SAXException e) {
throw new XPathException(this, "Error caught while retrieving statistics: " + e.getMessage(), e);
}
final DocumentImpl doc = (DocumentImpl) adapter.getDocument();
return (NodeImpl) doc.getFirstChild();
}
use of org.exist.dom.memtree.NodeImpl in project exist by eXist-db.
the class PIConstructor method eval.
/* (non-Javadoc)
* @see org.exist.xquery.Expression#eval(org.exist.xquery.StaticContext, org.exist.dom.persistent.DocumentSet, org.exist.xquery.value.Sequence, org.exist.xquery.value.Item)
*/
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
if (newDocumentContext) {
context.pushDocumentContext();
}
try {
final MemTreeBuilder builder = context.getDocumentBuilder();
final int nodeNr = builder.processingInstruction(target, data);
final NodeImpl node = builder.getDocument().getNode(nodeNr);
return node;
} finally {
if (newDocumentContext) {
context.popDocumentContext();
}
}
}
use of org.exist.dom.memtree.NodeImpl in project exist by eXist-db.
the class DynamicAttributeConstructor method eval.
/* (non-Javadoc)
* @see org.exist.xquery.Expression#eval(org.exist.xquery.value.Sequence, org.exist.xquery.value.Item)
*/
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
if (contextItem != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
}
}
if (newDocumentContext) {
context.pushDocumentContext();
}
NodeImpl node;
try {
final MemTreeBuilder builder = context.getDocumentBuilder();
builder.setReplaceAttributeFlag(replaceAttribute);
context.proceed(this, builder);
final Sequence nameSeq = qnameExpr.eval(contextSequence, contextItem);
if (!nameSeq.hasOne()) {
throw new XPathException(this, "The name expression should evaluate to a single value");
}
final Item qnItem = nameSeq.itemAt(0);
QName qn;
if (qnItem.getType() == Type.QNAME) {
qn = ((QNameValue) qnItem).getQName();
} else
try {
qn = QName.parse(context, nameSeq.getStringValue(), null);
} catch (final QName.IllegalQNameException e) {
throw new XPathException(this, ErrorCodes.XPTY0004, "'" + nameSeq.getStringValue() + "' is not a valid attribute name");
}
// Not in the specs but... makes sense
if (!XMLNames.isName(qn.getLocalPart())) {
throw new XPathException(this, ErrorCodes.XPTY0004, "'" + qn.getLocalPart() + "' is not a valid attribute name");
}
if ("xmlns".equals(qn.getLocalPart()) && qn.getNamespaceURI().isEmpty()) {
throw new XPathException(this, ErrorCodes.XQDY0044, "'" + qn.getLocalPart() + "' is not a valid attribute name");
}
String value;
final Sequence valueSeq = valueExpr.eval(contextSequence, contextItem);
if (valueSeq.isEmpty()) {
value = "";
} else {
final StringBuilder buf = new StringBuilder();
for (final SequenceIterator i = Atomize.atomize(valueSeq).iterate(); i.hasNext(); ) {
final Item next = i.nextItem();
buf.append(next.getStringValue());
if (i.hasNext()) {
buf.append(' ');
}
}
value = buf.toString();
}
value = DynamicAttributeConstructor.normalize(this, qn, value);
node = null;
try {
final int nodeNr = builder.addAttribute(qn, value);
node = builder.getDocument().getAttribute(nodeNr);
} catch (final DOMException e) {
throw new XPathException(this, ErrorCodes.XQDY0025, "element has more than one attribute '" + qn + "'");
}
} finally {
if (newDocumentContext) {
context.popDocumentContext();
}
}
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", node);
}
return node;
}
use of org.exist.dom.memtree.NodeImpl in project exist by eXist-db.
the class ArrayListValueSequence method expand.
/**
* Scan the sequence and check all in-memory documents.
* They may contains references to nodes stored in the database.
* Expand those references to get a pure in-memory DOM tree.
*/
private void expand() {
final Set<DocumentImpl> docs = new HashSet<>();
for (final Item value : values) {
final NodeImpl node = (NodeImpl) value;
final DocumentImpl ownerDoc = node.getNodeType() == Node.DOCUMENT_NODE ? (DocumentImpl) node : node.getOwnerDocument();
if (ownerDoc.hasReferenceNodes()) {
docs.add(ownerDoc);
}
}
for (final DocumentImpl doc : docs) {
doc.expand();
}
}
use of org.exist.dom.memtree.NodeImpl in project exist by eXist-db.
the class ArrayListValueSequence method getParents.
@Override
public Sequence getParents(final NodeTest test) throws XPathException {
final ArrayListValueSequence nodes = new ArrayListValueSequence();
for (final Item value : values) {
final NodeImpl node = (NodeImpl) value;
final NodeImpl parent = (NodeImpl) node.selectParentNode();
if (parent != null && test.matches(parent)) {
nodes.add(parent);
}
}
return nodes;
}
Aggregations