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/08 19:34:34 UTC
cvs commit: jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core NodeImpl.java
stefan 2004/07/08 10:34:34
Modified: proposals/jcrri/src/org/apache/slide/jcr/core NodeImpl.java
Log:
jcrri
Revision Changes Path
1.18 +104 -4 jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/NodeImpl.java
Index: NodeImpl.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/NodeImpl.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- NodeImpl.java 7 Jul 2004 16:05:24 -0000 1.17
+++ NodeImpl.java 8 Jul 2004 17:34:34 -0000 1.18
@@ -734,8 +734,108 @@
public void orderBefore(String srcName, String destName)
throws UnsupportedOperationException, ConstraintViolationException,
ItemNotFoundException, RepositoryException {
- // @todo implement orderBefore(String, String)
- throw new UnsupportedOperationException();
+ if (!nodeType.hasOrderableChildNodes()) {
+ throw new UnsupportedRepositoryOperationException("child node ordering not supported on node " + safeGetJCRPath());
+ }
+
+ // check arguments
+ if (srcName.equals(destName)) {
+ throw new ConstraintViolationException("source and destination have to be different");
+ }
+
+ Path.PathElement insertName;
+ try {
+ Path p = Path.create(srcName, ticket.getNamespaceResolver(), false);
+ if (p.getAncestorCount() > 0) {
+ throw new RepositoryException("invalid name: " + srcName);
+ }
+ insertName = p.getNameElement();
+ } catch (MalformedPathException e) {
+ String msg = "invalid name: " + srcName;
+ log.error(msg, e);
+ throw new RepositoryException(msg, e);
+ }
+
+ Path.PathElement beforeName;
+ if (destName != null) {
+ try {
+ Path p = Path.create(destName, ticket.getNamespaceResolver(), false);
+ if (p.getAncestorCount() > 0) {
+ throw new RepositoryException("invalid name: " + destName);
+ }
+ beforeName = p.getNameElement();
+ } catch (MalformedPathException e) {
+ String msg = "invalid name: " + destName;
+ log.error(msg, e);
+ throw new RepositoryException(msg, e);
+ }
+ } else {
+ beforeName = null;
+ }
+
+ // check existence
+ if (!hasNode(srcName)) {
+ throw new ItemNotFoundException(safeGetJCRPath() + " has no child node with name " + srcName);
+ }
+ if (destName != null && !hasNode(destName)) {
+ throw new ItemNotFoundException(safeGetJCRPath() + " has no child node with name " + destName);
+ }
+
+ ArrayList list = new ArrayList(((NodeState) state).getChildNodeEntries());
+ int srcInd = -1, destInd = -1;
+ for (int i = 0; i < list.size(); i++) {
+ NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) list.get(i);
+ if (srcInd == -1) {
+ if (entry.getName().equals(insertName.getName()) &&
+ (entry.getIndex() == insertName.getIndex() ||
+ insertName.getIndex() == 0 && entry.getIndex() == 1)) {
+ srcInd = i;
+ }
+ }
+ if (destInd == -1 && beforeName != null) {
+ if (entry.getName().equals(beforeName.getName()) &&
+ (entry.getIndex() == beforeName.getIndex() ||
+ beforeName.getIndex() == 0 && entry.getIndex() == 1)) {
+ destInd = i;
+ if (srcInd != -1) {
+ break;
+ }
+ }
+ } else {
+ if (srcInd != -1) {
+ break;
+ }
+ }
+ }
+
+ // check if resulting order would be different to current order
+ if (destInd == -1) {
+ if (srcInd == list.size() - 1) {
+ // no change, we're done
+ return;
+ }
+ } else {
+ if ((destInd - srcInd) == 1) {
+ // no change, we're done
+ return;
+ }
+ }
+
+ // reorder list
+ if (destInd == -1) {
+ list.add(list.remove(srcInd));
+ } else {
+ if (srcInd < destInd) {
+ list.add(destInd, list.get(srcInd));
+ list.remove(srcInd);
+ } else {
+ list.add(destInd, list.remove(srcInd));
+ }
+ }
+
+ // modify the state of 'this', i.e. the parent node
+ NodeState thisState = (NodeState) getOrCreateTransientItemState();
+ thisState.setChildNodeEntries(list);
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org