Exemplo n.º 1
0
 /**
  * The method <code>getAncestors</code>
  *
  * @param contextId an <code>int</code> value
  * @param includeSelf a <code>boolean</code> value
  * @return a <code>NodeSet</code> value
  */
 public NodeSet getAncestors(int contextId, boolean includeSelf) {
   ExtArrayNodeSet ancestors = new ExtArrayNodeSet();
   for (Iterator i = iterator(); i.hasNext(); ) {
     NodeProxy current = (NodeProxy) i.next();
     if (includeSelf) {
       if (Expression.NO_CONTEXT_ID != contextId) current.addContextNode(contextId, current);
       ancestors.add(current);
     }
     NodeId parentID = current.getNodeId().getParentId();
     while (parentID != null) {
       // Filter out the temporary nodes wrapper element
       if (parentID != NodeId.DOCUMENT_NODE
           && !(parentID.getTreeLevel() == 1
               && current.getDocument().getCollection().isTempCollection())) {
         NodeProxy parent = new NodeProxy(current.getDocument(), parentID, Node.ELEMENT_NODE);
         if (Expression.NO_CONTEXT_ID != contextId) parent.addContextNode(contextId, current);
         else parent.copyContext(current);
         ancestors.add(parent);
       }
       parentID = parentID.getParentId();
     }
   }
   ancestors.mergeDuplicates();
   return ancestors;
 }
Exemplo n.º 2
0
 public NodeProxy parentWithChild(
     DocumentImpl doc, NodeId nodeId, boolean directParent, boolean includeSelf) {
   NodeProxy temp = get(doc, nodeId);
   if (includeSelf && temp != null) return temp;
   nodeId = nodeId.getParentId();
   while (nodeId != null) {
     temp = get(doc, nodeId);
     if (temp != null) return temp;
     else if (directParent) return null;
     nodeId = nodeId.getParentId();
   }
   return null;
 }
Exemplo n.º 3
0
  /**
   * Return a new node set containing the parent nodes of all nodes in the current set.
   *
   * @param contextId an <code>int</code> value
   * @return a <code>NodeSet</code> value
   */
  public NodeSet getParents(int contextId) {
    NodeSet parents = new NewArrayNodeSet();
    NodeProxy parent = null;
    for (Iterator i = iterator(); i.hasNext(); ) {
      NodeProxy current = (NodeProxy) i.next();
      NodeId parentID = current.getNodeId().getParentId();
      // Filter out the temporary nodes wrapper element
      // Moved the parentID != NodeId.DOCUMENT_NODE test inside for /a/parent::node() to work
      // correctly.
      // Added the needed test parentID != null, detected in org.exist.xquery.OptimizerTest
      // "//node()[parent::mods:title &= 'ethnic']" which caused an NPE here
      // since I dont know when. /ljo
      if (parentID != null
          && !(parentID.getTreeLevel() == 1
              && current.getDocument().getCollection().isTempCollection())) {
        if (parent == null
            || parent.getDocument().getDocId() != current.getDocument().getDocId()
            || !parent.getNodeId().equals(parentID)) {
          if (parentID != NodeId.DOCUMENT_NODE) {
            parent =
                new NodeProxy(
                    current.getDocument(),
                    parentID,
                    Node.ELEMENT_NODE,
                    StoredNode.UNKNOWN_NODE_IMPL_ADDRESS);
          } else {
            parent =
                new NodeProxy(
                    current.getDocument(),
                    parentID,
                    Node.DOCUMENT_NODE,
                    StoredNode.UNKNOWN_NODE_IMPL_ADDRESS);
          }
        }
        if (Expression.NO_CONTEXT_ID != contextId) {
          parent.addContextNode(contextId, current);
        } else {
          parent.copyContext(current);
        }
        parent.addMatches(current);
        parents.add(parent);
      }
    }

    return parents;
  }
Exemplo n.º 4
0
 public static StoredNode deserialize(
     byte[] data, int start, int len, DocumentImpl doc, boolean pooled) {
   TextImpl text;
   if (pooled) text = (TextImpl) NodePool.getInstance().borrowNode(Node.TEXT_NODE);
   //            text = (TextImpl)NodeObjectPool.getInstance().borrowNode(TextImpl.class);
   else text = new TextImpl();
   int pos = start;
   pos += LENGTH_SIGNATURE_LENGTH;
   int dlnLen = ByteConversion.byteToShort(data, pos);
   pos += NodeId.LENGTH_NODE_ID_UNITS;
   NodeId dln = doc.getBroker().getBrokerPool().getNodeFactory().createFromData(dlnLen, data, pos);
   text.setNodeId(dln);
   int nodeIdLen = dln.size();
   pos += nodeIdLen;
   text.cdata =
       UTF8.decode(
           data, pos, len - (LENGTH_SIGNATURE_LENGTH + nodeIdLen + NodeId.LENGTH_NODE_ID_UNITS));
   return text;
 }
Exemplo n.º 5
0
  public static StoredNode deserialize(
      byte[] data, int start, int len, DocumentImpl doc, boolean pooled) {
    int pos = start;
    byte idSizeType = (byte) (data[pos] & 0x3);
    boolean hasNamespace = (data[pos] & 0x10) == 0x10;
    int attrType = (data[pos] & 0x4) >> 0x2;
    pos += StoredNode.LENGTH_SIGNATURE_LENGTH;
    int dlnLen = ByteConversion.byteToShort(data, pos);
    pos += NodeId.LENGTH_NODE_ID_UNITS;
    NodeId dln = doc.getBroker().getBrokerPool().getNodeFactory().createFromData(dlnLen, data, pos);
    pos += dln.size();
    short id = (short) Signatures.read(idSizeType, data, pos);
    pos += Signatures.getLength(idSizeType);
    String name = doc.getSymbols().getName(id);
    if (name == null) throw new RuntimeException("no symbol for id " + id);
    short nsId = 0;
    String prefix = null;
    if (hasNamespace) {
      nsId = ByteConversion.byteToShort(data, pos);
      pos += LENGTH_NS_ID;
      int prefixLen = ByteConversion.byteToShort(data, pos);
      pos += LENGTH_PREFIX_LENGTH;
      if (prefixLen > 0) prefix = UTF8.decode(data, pos, prefixLen).toString();
      pos += prefixLen;
    }
    String namespace = nsId == 0 ? "" : doc.getSymbols().getNamespace(nsId);
    XMLString value = UTF8.decode(data, pos, len - (pos - start));

    // OK : we have the necessary material to build the attribute
    AttrImpl attr;
    if (pooled) attr = (AttrImpl) NodePool.getInstance().borrowNode(Node.ATTRIBUTE_NODE);
    //            attr = (AttrImpl)NodeObjectPool.getInstance().borrowNode(AttrImpl.class);
    else attr = new AttrImpl();
    attr.setNodeName(doc.getSymbols().getQName(Node.ATTRIBUTE_NODE, namespace, name, prefix));
    attr.value = value;
    attr.setNodeId(dln);
    if (dln == null) throw new RuntimeException("no node id " + id);
    attr.setType(attrType);
    return attr;
  }
Exemplo n.º 6
0
 public static void addToList(DBBroker broker, byte[] data, int start, int len, AttrList list) {
   int pos = start;
   byte idSizeType = (byte) (data[pos] & 0x3);
   boolean hasNamespace = (data[pos] & 0x10) == 0x10;
   int attrType = (data[pos] & 0x4) >> 0x2;
   pos += StoredNode.LENGTH_SIGNATURE_LENGTH;
   int dlnLen = ByteConversion.byteToShort(data, pos);
   pos += NodeId.LENGTH_NODE_ID_UNITS;
   NodeId dln = broker.getBrokerPool().getNodeFactory().createFromData(dlnLen, data, pos);
   pos += dln.size();
   short id = (short) Signatures.read(idSizeType, data, pos);
   pos += Signatures.getLength(idSizeType);
   String name = broker.getSymbols().getName(id);
   if (name == null) throw new RuntimeException("no symbol for id " + id);
   short nsId = 0;
   String prefix = null;
   if (hasNamespace) {
     nsId = ByteConversion.byteToShort(data, pos);
     pos += LENGTH_NS_ID;
     int prefixLen = ByteConversion.byteToShort(data, pos);
     pos += LENGTH_PREFIX_LENGTH;
     if (prefixLen > 0) prefix = UTF8.decode(data, pos, prefixLen).toString();
     pos += prefixLen;
   }
   String namespace = nsId == 0 ? "" : broker.getSymbols().getNamespace(nsId);
   String value;
   try {
     value = new String(data, pos, len - (pos - start), "UTF-8");
   } catch (UnsupportedEncodingException uee) {
     LOG.warn(uee);
     value = new String(data, pos, len - (pos - start));
   }
   list.addAttribute(
       broker.getSymbols().getQName(Node.ATTRIBUTE_NODE, namespace, name, prefix),
       value,
       attrType);
 }
Exemplo n.º 7
0
 public static int getStringLength(NodeId nodeId, Value value) {
   final int nodeIdLen = nodeId.size();
   return value.getLength() - 3 - nodeIdLen;
 }
Exemplo n.º 8
0
 public static XMLString readData(NodeId nodeId, Value value, XMLString string) {
   final int nodeIdLen = nodeId.size();
   UTF8.decode(
       value.data(), value.start() + 3 + nodeIdLen, value.getLength() - 3 - nodeIdLen, string);
   return string;
 }