public static NodeLocationWithParentImpl getNodeLocationWithParentUsingCache( Node node, String id, boolean cacheIfPossible, NodeCacheRegistryImpl nodeCache) { // nodeCache NO puede ser nulo // Se supone que el nodo no ha sido cacheado en el cliente todavía aunque tenga // un id asignado en el servidor (este id puede ser null si no ha sido cacheado en el servidor) // por lo que hay que obtener un path, absoluto o relativo respecto a un padre cacheado. // Buscamos un nodo padre que esté cacheado para evitar formar un path // absoluto que lleva tiempo. String parentId = null; Node parent = node; do { parent = parent.getParentNode(); parentId = nodeCache.getId(parent); // si cachedParent es null devuelve null } while ((parentId == null) && (parent != null)); ClientDocumentStfulDelegateImpl clientDoc = nodeCache.getClientDocumentStfulDelegate(); String path = clientDoc.getStringPathFromNode( node, parent); // Si cachedParent es null (cachedParentId es null) devuelve un path absoluto return new NodeLocationWithParentImpl( node, id, path, parent, parentId, cacheIfPossible, clientDoc); }
public static NodeLocationWithParentImpl getNodeLocationWithParent( Node node, boolean cacheIfPossible, ClientDocumentStfulDelegateImpl clientDoc) { // Si cacheIfPossible es true y se cachea el nodo, el location DEBE enviarse al cliente y // resolverse para cachear en el cliente NodeCacheRegistryImpl nodeCache = clientDoc.getNodeCacheRegistry(); if (nodeCache != null) { String id = nodeCache.getId(node); if (id != null) { return new NodeLocationWithParentImpl( node, id, null, cacheIfPossible, clientDoc); // Sólo se necesita el id del nodo, cuando está en la caché no necesitamos // el string path que es una tarea que consume mucho tiempo tanto en el // servidor como en el cliente } else // No cacheado { if (cacheIfPossible) { id = nodeCache.addNode( node); // Si el nodo no es cacheable o la caché está bloqueada (sólo lectural) // devuelve null, no pasa nada por no poder cachear return getNodeLocationWithParentUsingCache(node, id, true, nodeCache); } else { String path = clientDoc.getStringPathFromNode(node); return new NodeLocationWithParentImpl( node, null, path, false, clientDoc); // cacheIfPossible es false } } } else // El documento tiene el cache desactivado { String path = clientDoc.getStringPathFromNode(node); return new NodeLocationWithParentImpl(node, null, path, cacheIfPossible, clientDoc); } }