You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by st...@apache.org on 2004/07/07 18:05:45 UTC

cvs commit: jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core ItemManager.java RepositoryImpl.java Test.java TicketImpl.java

stefan      2004/07/07 09:05:45

  Modified:    proposals/jcrri/src/org/apache/slide/jcr/core
                        ItemManager.java RepositoryImpl.java Test.java
                        TicketImpl.java
  Log:
  jcrri
  
  Revision  Changes    Path
  1.7       +65 -471   jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/ItemManager.java
  
  Index: ItemManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/ItemManager.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ItemManager.java	1 Jul 2004 18:29:41 -0000	1.6
  +++ ItemManager.java	7 Jul 2004 16:05:45 -0000	1.7
  @@ -25,10 +25,11 @@
   
   import org.apache.commons.collections.ReferenceMap;
   import org.apache.log4j.Logger;
  +import org.apache.slide.jcr.core.nodetype.NodeDefId;
   import org.apache.slide.jcr.core.nodetype.NodeTypeImpl;
  +import org.apache.slide.jcr.core.nodetype.PropDefId;
   import org.apache.slide.jcr.core.state.*;
   import org.apache.slide.jcr.util.IteratorHelper;
  -import org.apache.slide.jcr.util.MalformedPathException;
   
   import javax.jcr.*;
   import javax.jcr.access.AccessDeniedException;
  @@ -61,7 +62,7 @@
    * @author Stefan Guggisberg
    * @version $Revision$, $Date$
    */
  -public class ItemManager implements ItemLifeCycleListener, HierarchyManager {
  +public class ItemManager implements ItemLifeCycleListener {
   
       private static Logger log = Logger.getLogger(ItemManager.class);
   
  @@ -70,8 +71,8 @@
   
       private final TicketImpl ticket;
   
  -    private final PersistentItemStateManager persistentStateMgr;
  -    private final TransientItemStateManager transientStateMgr;
  +    private final ItemStateProvider itemStateProvider;
  +    private final HierarchyManager hierMgr;
   
       private NodeImpl root;
   
  @@ -83,17 +84,17 @@
       /**
        * Creates a new per-workspace instance <code>ItemManager</code> instance.
        *
  -     * @param persistentStateMgr the persistent state manager associated with
  -     *                           the new instance
  -     * @param ticket             the ticket associated with the new instance
  -     * @param rootNodeDef        the definition of the root node
  -     * @param rootNodeUUID       the UUID of the root node
  -     */
  -    ItemManager(PersistentItemStateManager persistentStateMgr, TicketImpl ticket,
  -		NodeDef rootNodeDef, String rootNodeUUID) {
  +     * @param itemStateProvider the item state provider associated with
  +     *                          the new instance
  +     * @param ticket            the ticket associated with the new instance
  +     * @param rootNodeDef       the definition of the root node
  +     * @param rootNodeUUID      the UUID of the root node
  +     */
  +    ItemManager(ItemStateProvider itemStateProvider, HierarchyManager hierMgr,
  +		TicketImpl ticket, NodeDef rootNodeDef, String rootNodeUUID) {
  +	this.itemStateProvider = itemStateProvider;
  +	this.hierMgr = hierMgr;
   	this.ticket = ticket;
  -	this.persistentStateMgr = persistentStateMgr;
  -	this.transientStateMgr = new TransientItemStateManager(getHierarchyMgr());
   	this.rootNodeDef = rootNodeDef;
   	rootNodeId = new NodeId(rootNodeUUID);
   	// setup item cache with soft references to items
  @@ -101,33 +102,6 @@
       }
   
       /**
  -     * Returns the persistent state manager
  -     *
  -     * @return the persistent state manager
  -     */
  -    PersistentItemStateManager getPersistentItemStateManager() {
  -	return persistentStateMgr;
  -    }
  -
  -    /**
  -     * Returns the transient state manager
  -     *
  -     * @return the transient state manager
  -     */
  -    TransientItemStateManager getTransientStateMgr() {
  -	return transientStateMgr;
  -    }
  -
  -    /**
  -     * Returns the hierarchy manager
  -     *
  -     * @return the hierarchy manager
  -     */
  -    HierarchyManager getHierarchyMgr() {
  -	return this;
  -    }
  -
  -    /**
        * Returns the root node instance of the repository.
        *
        * @return the root node.
  @@ -138,37 +112,16 @@
   	// to avoid chicken & egg kind of problems
   	if (root == null) {
   	    try {
  -		NodeState rootState = (NodeState) getItemState(rootNodeId);
  +		NodeState rootState = (NodeState) itemStateProvider.getItemState(rootNodeId);
   		// keep a hard reference to root node
   		root = createNodeInstance(rootState, rootNodeDef);
  -	    } catch (NoSuchItemStateException e) {
  -		String msg = "failed to retrieve state of root node";
  -		log.error(msg, e);
  -		throw new RepositoryException(msg, e);
  -	    }
  -	}
  -	return root;
  -    }
  -
  -    private synchronized ItemState getItemState(ItemId id)
  -	    throws NoSuchItemStateException, RepositoryException {
  -	// check if there's transient state for the specified item
  -	try {
  -	    return transientStateMgr.getItemState(id);
  -	} catch (NoSuchItemStateException nsise) {
  -	    // check if there's persistent state for the specified item
  -	    try {
  -		if (id.denotesNode()) {
  -		    return persistentStateMgr.getNodeState((NodeId) id);
  -		} else {
  -		    return persistentStateMgr.getPropertyState((PropertyId) id);
  -		}
   	    } catch (ItemStateException ise) {
  -		String msg = "failed to load persistent state of " + id;
  +		String msg = "failed to retrieve state of root node";
   		log.error(msg, ise);
   		throw new RepositoryException(msg, ise);
   	    }
   	}
  +	return root;
       }
   
       /**
  @@ -176,7 +129,6 @@
        * (used for diagnostic purposes).
        *
        * @param ps
  -     *
        * @throws RepositoryException
        */
       void dump(PrintStream ps) throws RepositoryException {
  @@ -193,10 +145,6 @@
   	    ps.println(id + "\t" + item.getPath() + " (" + item + ")");
   	}
   	ps.println();
  -	persistentStateMgr.dump(ps);
  -	ps.println();
  -	transientStateMgr.dump(ps);
  -	ps.println();
       }
   
       //--------------------------------------------------< item access methods >
  @@ -234,7 +182,7 @@
        */
       synchronized ItemImpl getItem(Path path)
   	    throws PathNotFoundException, AccessDeniedException, RepositoryException {
  -	ItemId id = resolvePath(path);
  +	ItemId id = hierMgr.resolvePath(path);
   
   	return getItem(id);
       }
  @@ -292,11 +240,15 @@
   
   	ItemState state = null;
   	try {
  -	    state = getItemState(parentId);
  +	    state = itemStateProvider.getItemState(parentId);
   	} catch (NoSuchItemStateException nsise) {
   	    String msg = "no such item: " + parentId;
   	    log.error(msg);
   	    throw new ItemNotFoundException(msg);
  +	} catch (ItemStateException ise) {
  +	    String msg = "failed to retrieve item state of node " + parentId;
  +	    log.error(msg);
  +	    throw new RepositoryException(msg);
   	}
   
   	if (!state.isNode()) {
  @@ -343,11 +295,15 @@
   
   	ItemState state = null;
   	try {
  -	    state = getItemState(parentId);
  +	    state = itemStateProvider.getItemState(parentId);
   	} catch (NoSuchItemStateException nsise) {
   	    String msg = "no such item: " + parentId;
   	    log.error(msg);
   	    throw new ItemNotFoundException(msg);
  +	} catch (ItemStateException ise) {
  +	    String msg = "failed to retrieve item state of node " + parentId;
  +	    log.error(msg);
  +	    throw new RepositoryException(msg);
   	}
   
   	if (!state.isNode()) {
  @@ -378,9 +334,13 @@
   	ItemImpl item = null;
   	ItemState state = null;
   	try {
  -	    state = getItemState(id);
  +	    state = itemStateProvider.getItemState(id);
   	} catch (NoSuchItemStateException ise) {
   	    throw new ItemNotFoundException(id.toString());
  +	} catch (ItemStateException ise) {
  +	    String msg = "failed to retrieve item state of item " + id;
  +	    log.error(msg);
  +	    throw new RepositoryException(msg);
   	}
   
   	if (state.isNode()) {
  @@ -410,19 +370,24 @@
   	NodeImpl parent = (NodeImpl) getItem(parentId);
   	// 2. get its node type
   	NodeTypeImpl ntParent = (NodeTypeImpl) parent.getPrimaryNodeType();
  -	// 3. get matching definition for the specified child node
  -
  -	// @todo need a cleaner way to determine matching definition; persist id of definition with node?
  -	NodeState parentState = (NodeState) parent.getItemState();
  -	List entries = parentState.getChildNodeEntries(state.getUUID());
  -	if (entries.isEmpty()) {
  -	    String msg = parentState.getUUID() + " has no child entry for " + state.getUUID();
  -	    log.error(msg);
  -	    throw new RepositoryException(msg);
  +	// 3. get definition for the specified child node
  +	NodeDef def = null;
  +	NodeDefId defId = state.getDefinitionId();
  +	if (defId != null) {
  +	    def = ticket.getNodeTypeManager().getNodeDef(defId);
  +	}
  +	if (def == null) {
  +	    // fallback: find matching definition in parent node's node type
  +	    NodeState parentState = (NodeState) parent.getItemState();
  +	    List entries = parentState.getChildNodeEntries(state.getUUID());
  +	    if (entries.isEmpty()) {
  +		String msg = parentState.getUUID() + " has no child entry for " + state.getUUID();
  +		log.error(msg);
  +		throw new RepositoryException(msg);
  +	    }
  +	    NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) entries.get(0);
  +	    def = ntParent.getApplicableChildNodeDef(entry.getName(), state.getNodeTypeName());
   	}
  -	NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) entries.get(0);
  -
  -	NodeDef def = ntParent.getApplicableChildNodeDef(entry.getName(), state.getNodeTypeName());
   
   	// create instance
   	return createNodeInstance(state, def);
  @@ -448,7 +413,15 @@
   	// 2. get its node type
   	NodeTypeImpl ntParent = (NodeTypeImpl) parent.getPrimaryNodeType();
   	// 3. get matching definition for the specified property
  -	PropertyDef def = ntParent.getApplicablePropertyDef(state.getName(), state.getType());
  +	PropertyDef def = null;
  +	PropDefId defId = state.getDefinitionId();
  +	if (defId != null) {
  +	    def = ticket.getNodeTypeManager().getPropDef(defId);
  +	}
  +	if (def == null) {
  +	    // fallback: find matching definition in parent node's node type
  +	    def = ntParent.getApplicablePropertyDef(state.getName(), state.getType());
  +	}
   
   	// create instance
   	return createPropertyInstance(state, def);
  @@ -526,6 +499,7 @@
       /**
        * Failsafe conversion of internal <code>Path</code> to JCR path for use in
        * error messages etc.
  +     *
        * @param path path to convert
        * @return JCR path
        */
  @@ -542,397 +516,17 @@
       /**
        * Failsafe translation of internal <code>ItemId</code> to JCR path for use in
        * error messages etc.
  +     *
        * @param id path to convert
        * @return JCR path
        */
       String safeGetJCRPath(ItemId id) {
   	try {
  -	    return safeGetJCRPath(getPath(id));
  +	    return safeGetJCRPath(hierMgr.getPath(id));
   	} catch (RepositoryException re) {
   	    log.error(id + ": failed to determine path to");
   	    // return string representation if id as a fallback
   	    return id.toString();
  -	}
  -    }
  -
  -    //-----------------------------------------------------< HierarchyManager >
  -    /**
  -     * @see HierarchyManager#listParents(ItemId)
  -     */
  -    public NodeId[] listParents(ItemId id) throws ItemNotFoundException, RepositoryException {
  -	ArrayList list = new ArrayList();
  -	try {
  -	    if (id.denotesNode()) {
  -		NodeState state = (NodeState) getItemState(id);
  -		Iterator iter = state.getParentUUIDs().iterator();
  -		while (iter.hasNext()) {
  -		    list.add(new NodeId((String) iter.next()));
  -		}
  -	    } else {
  -		PropertyState state = (PropertyState) getItemState(id);
  -		list.add(new NodeId(state.getParentUUID()));
  -	    }
  -	} catch (NoSuchItemStateException e) {
  -	    String msg = "failed to retrieve state of item " + id;
  -	    log.error(msg, e);
  -	    throw new ItemNotFoundException(msg, e);
  -	}
  -	return (NodeId[]) list.toArray(new NodeId[list.size()]);
  -    }
  -
  -    /**
  -     * @see HierarchyManager#listChildren(NodeId)
  -     */
  -    public ItemId[] listChildren(NodeId id) throws ItemNotFoundException, RepositoryException {
  -	NodeState parentState;
  -	try {
  -	    parentState = (NodeState) getItemState(id);
  -	} catch (NoSuchItemStateException e) {
  -	    String msg = "failed to retrieve state of parent node " + id;
  -	    log.error(msg, e);
  -	    throw new ItemNotFoundException(msg, e);
  -	}
  -	ArrayList list = new ArrayList();
  -	Iterator iter = parentState.getPropertyEntries().iterator();
  -	while (iter.hasNext()) {
  -	    // properties
  -	    NodeState.PropertyEntry pe = (NodeState.PropertyEntry) iter.next();
  -	    list.add(new PropertyId(id.getUUID(), pe.getName()));
  -	}
  -	iter = parentState.getChildNodeEntries().iterator();
  -	while (iter.hasNext()) {
  -	    // child nodes
  -	    NodeState.ChildNodeEntry cne = (NodeState.ChildNodeEntry) iter.next();
  -	    list.add(new NodeId(cne.getUUID()));
  -	}
  -	return (ItemId[]) list.toArray(new ItemId[list.size()]);
  -    }
  -
  -    /**
  -     * @see HierarchyManager#listZombieChildren(NodeId)
  -     */
  -    public ItemId[] listZombieChildren(NodeId id) throws ItemNotFoundException, RepositoryException {
  -	// FIXME messy code
  -	NodeState parentState;
  -	try {
  -	    // get transient/persistent state
  -	    parentState = (NodeState) getItemState(id);
  -	} catch (NoSuchItemStateException e) {
  -	    // try attic
  -	    try {
  -		parentState = (NodeState) transientStateMgr.getItemStateInAttic(id);
  -	    } catch (NoSuchItemStateException nsise) {
  -		String msg = "failed to retrieve state of parent node " + id;
  -		log.error(msg, nsise);
  -		throw new ItemNotFoundException(msg, nsise);
  -	    }
  -	}
  -
  -	ArrayList list = new ArrayList();
  -	Iterator iter = parentState.getRemovedPropertyEntries().iterator();
  -	while (iter.hasNext()) {
  -	    // removed properties
  -	    NodeState.PropertyEntry pe = (NodeState.PropertyEntry) iter.next();
  -	    list.add(new PropertyId(id.getUUID(), pe.getName()));
  -	}
  -	iter = parentState.getRemovedChildNodeEntries().iterator();
  -	while (iter.hasNext()) {
  -	    // removed child nodes
  -	    NodeState.ChildNodeEntry cne = (NodeState.ChildNodeEntry) iter.next();
  -	    list.add(new NodeId(cne.getUUID()));
  -	}
  -	return (ItemId[]) list.toArray(new ItemId[list.size()]);
  -    }
  -
  -    /**
  -     * @see HierarchyManager#resolvePath(Path)
  -     */
  -    public synchronized ItemId resolvePath(Path path)
  -	    throws PathNotFoundException, RepositoryException {
  -	// shortcut
  -	if (path.denotesRoot()) {
  -	    return rootNodeId;
  -	}
  -
  -	if (!path.isCanonical()) {
  -	    String msg = "path is not canonical";
  -	    log.error(msg);
  -	    throw new RepositoryException(msg);
  -	}
  -
  -	NodeState parentState;
  -	try {
  -	    parentState = (NodeState) getItemState(rootNodeId);
  -	} catch (NoSuchItemStateException e) {
  -	    String msg = "failed to retrieve state of root node";
  -	    log.error(msg, e);
  -	    throw new RepositoryException(msg, e);
  -	}
  -
  -	Path.PathElement[] elems = path.getElements();
  -	for (int i = 1; i < elems.length; i++) {
  -	    Path.PathElement elem = elems[i];
  -	    QName name = elem.getName();
  -	    int index = elem.getIndex();
  -	    if (parentState.hasChildNodeEntry(name, index == 0 ? 1 : index)) {
  -		// child node
  -		NodeState.ChildNodeEntry nodeEntry = parentState.getChildNodeEntry(name, index == 0 ? 1 : index);
  -		if (i == elems.length - 1) {
  -		    // last element in the path
  -		    return new NodeId(nodeEntry.getUUID());
  -		}
  -		try {
  -		    parentState = (NodeState) getItemState(new NodeId(nodeEntry.getUUID()));
  -		} catch (NoSuchItemStateException e) {
  -		    String msg = "failed to retrieve state of intermediary node";
  -		    log.error(msg, e);
  -		    throw new RepositoryException(msg, e);
  -		}
  -		continue;
  -	    } else if (parentState.hasPropertyEntry(name)) {
  -		// property
  -		if (index > 1) {
  -		    // properties can't have same name siblings
  -		    throw new PathNotFoundException(safeGetJCRPath(path));
  -		}
  -		if (i == elems.length - 1) {
  -		    return new PropertyId(parentState.getUUID(), name);
  -		} else {
  -		    // property is not the last element in the path
  -		    throw new PathNotFoundException(safeGetJCRPath(path));
  -		}
  -	    } else {
  -		// no such item
  -		throw new PathNotFoundException(safeGetJCRPath(path));
  -	    }
  -	}
  -
  -	throw new PathNotFoundException(safeGetJCRPath(path));
  -    }
  -
  -    /**
  -     * @see HierarchyManager#getPath(ItemId)
  -     */
  -    public synchronized Path getPath(ItemId id) throws ItemNotFoundException, RepositoryException {
  -	try {
  -	    Path.PathBuilder builder = new Path.PathBuilder();
  -
  -	    ItemState state = getItemState(id);
  -	    String parentUUID = state.getParentUUID();
  -	    if (parentUUID == null) {
  -		// specified id denotes the root node
  -		builder.addRoot();
  -		return builder.getPath();
  -	    }
  -
  -	    NodeState parent = (NodeState) getItemState(new NodeId(parentUUID));
  -	    do {
  -		if (state.isNode()) {
  -		    NodeState nodeState = (NodeState) state;
  -		    String uuid = nodeState.getUUID();
  -		    List entries = parent.getChildNodeEntries(uuid);
  -		    if (entries.isEmpty()) {
  -			String msg = "failed to build path of " + id + ": " + parent.getUUID() + " has no child entry for " + uuid;
  -			log.error(msg);
  -			throw new RepositoryException(msg);
  -		    }
  -		    // if the parent has more than one child node entries pointing
  -		    // to the same child node, always use the first one
  -		    NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) entries.get(0);
  -		    QName name = entry.getName();
  -		    // add to path
  -		    builder.addFirst(name.getNamespaceURI(), name.getLocalName(), entry.getIndex());
  -		} else {
  -		    PropertyState propState = (PropertyState) state;
  -		    QName name = propState.getName();
  -		    // add to path
  -		    builder.addFirst(name.getNamespaceURI(), name.getLocalName());
  -		}
  -		parentUUID = parent.getParentUUID();
  -		if (parentUUID != null) {
  -		    state = parent;
  -		    parent = (NodeState) getItemState(new NodeId(parentUUID));
  -		} else {
  -		    parent = null;
  -		    state = null;
  -		}
  -	    } while (parent != null);
  -
  -	    // add root to path
  -	    builder.addRoot();
  -	    return builder.getPath();
  -	} catch (NoSuchItemStateException nsise) {
  -	    String msg = "failed to build path of " + id;
  -	    log.error(msg, nsise);
  -	    throw new ItemNotFoundException(msg, nsise);
  -	} catch (MalformedPathException mpe) {
  -	    String msg = "failed to build path of " + id;
  -	    log.error(msg, mpe);
  -	    throw new RepositoryException(msg, mpe);
  -	}
  -    }
  -
  -    /**
  -     * @see HierarchyManager#getName(ItemId)
  -     */
  -    public QName getName(ItemId itemId) throws ItemNotFoundException, RepositoryException {
  -	if (itemId.denotesNode()) {
  -	    NodeId nodeId = (NodeId) itemId;
  -	    NodeState parentState;
  -	    try {
  -		NodeState nodeState = (NodeState) getItemState(nodeId);
  -		String parentUUID = nodeState.getParentUUID();
  -		if (parentUUID == null) {
  -		    // this is the root or an orphaned node
  -		    // FIXME
  -		    return new QName(NamespaceRegistryImpl.NS_DEFAULT_URI, "");
  -		}
  -		parentState = (NodeState) getItemState(new NodeId(parentUUID));
  -	    } catch (NoSuchItemStateException nsise) {
  -		String msg = "failed to resolve name of " + nodeId;
  -		log.error(msg, nsise);
  -		throw new RepositoryException(msg, nsise);
  -	    }
  -
  -	    List entries = parentState.getChildNodeEntries(nodeId.getUUID());
  -	    if (entries.size() == 0) {
  -		String msg = "failed to resolve name of " + nodeId;
  -		log.error(msg);
  -		throw new RepositoryException(msg);
  -	    }
  -	    NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) entries.get(0);
  -	    return entry.getName();
  -	} else {
  -	    PropertyId propId = (PropertyId) itemId;
  -	    return propId.getName();
  -	}
  -    }
  -
  -    /**
  -     * @see HierarchyManager#getAllPaths(ItemId)
  -     */
  -    public synchronized Path[] getAllPaths(ItemId id) throws ItemNotFoundException, RepositoryException {
  -	Path.PathBuilder builder = new Path.PathBuilder();
  -	ArrayList list = new ArrayList();
  -	list.add(builder);
  -
  -	NodeId nodeId = null;
  -	if (!id.denotesNode()) {
  -	    try {
  -		PropertyState propState = (PropertyState) getItemState(id);
  -		QName name = propState.getName();
  -		// add to path
  -		builder.addFirst(name.getNamespaceURI(), name.getLocalName());
  -		nodeId = new NodeId(propState.getParentUUID());
  -	    } catch (NoSuchItemStateException nsise) {
  -		String msg = "failed to build path of " + id;
  -		log.error(msg, nsise);
  -		throw new ItemNotFoundException(msg, nsise);
  -	    }
  -	} else {
  -	    nodeId = (NodeId) id;
  -	}
  -
  -	// recursively traverse parent nodes
  -	recursiveBuildPaths(nodeId, builder, list);
  -
  -	Path[] paths = new Path[list.size()];
  -	int i = 0;
  -	Iterator iter = list.iterator();
  -	while (iter.hasNext()) {
  -	    Path.PathBuilder pb = (Path.PathBuilder) iter.next();
  -	    try {
  -		paths[i++] = pb.getPath();
  -	    } catch (MalformedPathException mpe) {
  -		String msg = "failed to build all paths of " + id;
  -		log.error(msg, mpe);
  -		throw new RepositoryException(msg, mpe);
  -	    }
  -	}
  -	return paths;
  -    }
  -
  -    /**
  -     *
  -     * @param nodeId
  -     * @param builder
  -     * @param builders
  -     * @throws ItemNotFoundException
  -     * @throws RepositoryException
  -     */
  -    private void recursiveBuildPaths(NodeId nodeId, Path.PathBuilder builder, List builders)
  -	    throws ItemNotFoundException, RepositoryException {
  -	try {
  -	    NodeState nodeState = (NodeState) getItemState(nodeId);
  -
  -	    String uuid = nodeState.getUUID();
  -	    /**
  -	     * the parent uuid list contains an entry for every parent-child
  -	     * link to the specified node. this list may contain duplicate
  -	     * entries if the same parent node has more than one child link to
  -	     * the same target node. because the following code expects unique
  -	     * entries in the parent uuid list, we put them into a set. 
  -	     */
  -	    HashSet parentUUIDs = new HashSet(nodeState.getParentUUIDs());
  -	    if (parentUUIDs.size() == 0) {
  -		// nodeId denotes the root node
  -		builder.addRoot();
  -		return;
  -	    }
  -
  -	    // if the specified node has n parents,
  -	    // we need to create n - 1 path builder clones
  -	    LinkedList queue = new LinkedList();
  -	    queue.add(builder);
  -	    int n = parentUUIDs.size() - 1;
  -	    while (n-- > 0) {
  -		Path.PathBuilder clone = (Path.PathBuilder) builder.clone();
  -		queue.addLast(clone);
  -		// add to list of path builders
  -		builders.add(clone);
  -	    }
  -
  -
  -	    Iterator iter = parentUUIDs.iterator();
  -	    while (iter.hasNext()) {
  -		String parentUUID = (String) iter.next();
  -		NodeState parent = (NodeState) getItemState(new NodeId(parentUUID));
  -		List entries = parent.getChildNodeEntries(uuid);
  -		if (entries.isEmpty()) {
  -		    String msg = "failed to build path of " + nodeId + ": " + parent.getUUID() + " has no child entry for " + uuid;
  -		    log.error(msg);
  -		    throw new RepositoryException(msg);
  -		}
  -		n = entries.size() - 1;
  -		while (n-- > 0) {
  -		    // the same parent has multiple child references to
  -		    // this node, more path builder clones are needed
  -
  -		    // since we are consuming the queue of path builders
  -		    // starting at the tail, we can safely clone 'builder'
  -		    // because it will be consumed as the very last queue entry
  -		    Path.PathBuilder clone = (Path.PathBuilder) builder.clone();
  -		    queue.add(clone);
  -		    // add to list of path builders
  -		    builders.add(clone);
  -		}
  -		for (int i = 0; i < entries.size(); i++) {
  -		    NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) entries.get(i);
  -		    QName name = entry.getName();
  -
  -		    // get a path builder clone from the tail of the queue
  -		    Path.PathBuilder pb = (Path.PathBuilder) queue.removeLast();
  -		    // add entry to path
  -		    pb.addFirst(name.getNamespaceURI(), name.getLocalName(), entry.getIndex());
  -
  -		    // recurse
  -		    recursiveBuildPaths(new NodeId(parentUUID), pb, builders);
  -		}
  -	    }
  -	} catch (NoSuchItemStateException nsise) {
  -	    String msg = "failed to build path of " + nodeId;
  -	    log.error(msg, nsise);
  -	    throw new ItemNotFoundException(msg, nsise);
   	}
       }
   
  
  
  
  1.12      +9 -3      jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/RepositoryImpl.java
  
  Index: RepositoryImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/RepositoryImpl.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- RepositoryImpl.java	1 Jul 2004 18:29:41 -0000	1.11
  +++ RepositoryImpl.java	7 Jul 2004 16:05:45 -0000	1.12
  @@ -26,6 +26,7 @@
   import org.apache.commons.collections.BeanMap;
   import org.apache.log4j.Logger;
   import org.apache.slide.jcr.core.nodetype.NodeTypeRegistry;
  +import org.apache.slide.jcr.core.nodetype.NodeDefId;
   import org.apache.slide.jcr.core.observation.ObservationManagerFactory;
   import org.apache.slide.jcr.core.state.ItemStateException;
   import org.apache.slide.jcr.core.state.PersistenceManager;
  @@ -59,6 +60,7 @@
   	    new SimpleCredentials(ANONYMOUS_USER, new char[0]);
   
       private String rootNodeUUID;
  +    private NodeDefId rootNodeDefinitionId;
   
       private final NamespaceRegistryImpl nsReg;
       private final NodeTypeRegistry ntReg;
  @@ -225,6 +227,10 @@
   	nsReg = new NamespaceRegistryImpl(new BasedFileSystem(repStore, "/namespaces"));
   
   	ntReg = NodeTypeRegistry.create(nsReg, new BasedFileSystem(repStore, "/nodetypes"));
  +
  +	// FIXME relies on definition of nt:unstructured:
  +	// first (and only) child node definition is applied to root node
  +	rootNodeDefinitionId = new NodeDefId(ntReg.getNodeTypeDef(NodeTypeRegistry.NT_UNSTRUCTURED).getChildNodeDefs()[0]);
       }
   
       NamespaceRegistry getNamespaceRegistry() {
  @@ -261,7 +267,7 @@
   		StableWorkspaceDef swd = (StableWorkspaceDef) wd;
   		PersistenceManager persistMgr = createPersistenceManager(swd);
   		try {
  -		    stateMgr = new PersistentItemStateManager(persistMgr, rootNodeUUID);
  +		    stateMgr = new PersistentItemStateManager(persistMgr, rootNodeUUID, ntReg);
   		} catch (ItemStateException ise) {
   		    String msg = "failed to instantiate the persistent state manager";
   		    log.error(msg, ise);
  
  
  
  1.5       +2 -2      jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/Test.java
  
  Index: Test.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/Test.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Test.java	29 Jun 2004 17:11:47 -0000	1.4
  +++ Test.java	7 Jul 2004 16:05:45 -0000	1.5
  @@ -91,7 +91,7 @@
   	System.out.println();
   	dumpTree(root, System.out);
   
  -	root.setProperty("blob", new FileInputStream(new File("d:/temp/jcrri.zip")));
  +	//root.setProperty("blob", new FileInputStream(new File("d:/temp/jcrri.zip")));
   
   	root.setProperty("bla", 1);
   	root.setProperty("bla", 1.4);
  
  
  
  1.11      +38 -7     jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/TicketImpl.java
  
  Index: TicketImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/TicketImpl.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TicketImpl.java	1 Jul 2004 18:29:41 -0000	1.10
  +++ TicketImpl.java	7 Jul 2004 16:05:45 -0000	1.11
  @@ -26,6 +26,7 @@
   import org.apache.log4j.Logger;
   import org.apache.slide.jcr.core.nodetype.NodeTypeManagerImpl;
   import org.apache.slide.jcr.core.nodetype.NodeTypeRegistry;
  +import org.apache.slide.jcr.core.state.TicketItemStateManager;
   import org.apache.slide.jcr.util.MalformedPathException;
   import org.xml.sax.ContentHandler;
   
  @@ -76,6 +77,16 @@
       protected final AccessManagerImpl accessMgr;
   
       /**
  +     * the item state mgr associated with this ticket
  +     */
  +    protected final TicketItemStateManager itemStateMgr;
  +
  +    /**
  +     * the HierarchyManager associated with this ticket
  +     */
  +    protected final HierarchyManager hierMgr;
  +
  +    /**
        * the item mgr associated with this ticket
        */
       protected final ItemManager itemMgr;
  @@ -120,8 +131,10 @@
   
   	ntMgr = new NodeTypeManagerImpl(rep.getNodeTypeRegistry(), this);
   	wsp = new WorkspaceImpl(wd, rep.getWorkspaceStateManager(wd), rep, this);
  -	itemMgr = new ItemManager(wsp.getPersistentStateManager(), this, ntMgr.getRootNodeDefinition(), rep.getRootNodeUUID());
  -	accessMgr = new AccessManagerImpl(credentials, itemMgr.getHierarchyMgr(), getNamespaceResolver());
  +	itemStateMgr = new TicketItemStateManager(rep.getRootNodeUUID(), wsp.getPersistentStateManager(), getNamespaceResolver());
  +	hierMgr = itemStateMgr.getHierarchyMgr();
  +	itemMgr = new ItemManager(itemStateMgr, hierMgr, this, ntMgr.getRootNodeDefinition(), rep.getRootNodeUUID());
  +	accessMgr = new AccessManagerImpl(credentials, itemStateMgr.getHierarchyMgr(), getNamespaceResolver());
   
   	nsMappings = new TransientNamespaceMappings(rep.getNamespaceRegistry());
       }
  @@ -154,6 +167,24 @@
       }
   
       /**
  +     * Returns the <code>TicketItemStateManager</code> associated with this ticket.
  +     *
  +     * @return the <code>TicketItemStateManager</code> associated with this ticket
  +     */
  +    TicketItemStateManager getItemStateManager() {
  +	return itemStateMgr;
  +    }
  +
  +    /**
  +     * Returns the <code>HierarchyManager</code> associated with this ticket.
  +     *
  +     * @return the <code>HierarchyManager</code> associated with this ticket
  +     */
  +    HierarchyManager getHierarchyManager() {
  +	return hierMgr;
  +    }
  +
  +    /**
        * Dumps the state of this <code>Ticket</code> instance
        * (used for diagnostic purposes).
        *
  @@ -249,7 +280,7 @@
       public void refresh(boolean keepChanges) throws RepositoryException {
   	if (!keepChanges) {
   	    // optimization
  -	    itemMgr.getTransientStateMgr().disposeAllItemStates();
  +	    itemStateMgr.disposeAllTransientItemStates();
   	    return;
   	}
   	itemMgr.getRootNode().refresh(keepChanges);
  @@ -259,7 +290,7 @@
        * @see Ticket#hasPendingChanges
        */
       public boolean hasPendingChanges() throws RepositoryException {
  -	return itemMgr.getTransientStateMgr().hasAnyItemStates();
  +	return itemStateMgr.hasAnyTransientItemStates();
       }
   
       /**
  @@ -355,7 +386,7 @@
        */
       public void logout() {
   	// discard all transient changes
  -	itemMgr.getTransientStateMgr().disposeAllItemStates();
  +	itemStateMgr.disposeAllTransientItemStates();
   
   	log.debug("disposing workspace");
   	wsp.dispose();
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org