You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by tr...@apache.org on 2006/07/20 21:05:18 UTC
svn commit: r424021 - in
/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core: ./
version/
Author: tripod
Date: Thu Jul 20 12:05:17 2006
New Revision: 424021
URL: http://svn.apache.org/viewvc?rev=424021&view=rev
Log:
Removing superfluous AbstractVersion and AbstractVersionHistory
Added:
jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java (with props)
jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionImpl.java (with props)
Removed:
jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/AbstractVersion.java
jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionHistory.java
jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersion.java
jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionHistory.java
Modified:
jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemManager.java
jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java
jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemManager.java?rev=424021&r1=424020&r2=424021&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemManager.java (original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemManager.java Thu Jul 20 12:05:17 2006
@@ -29,10 +29,6 @@
import org.apache.jackrabbit.core.state.NodeState;
import org.apache.jackrabbit.core.state.PropertyState;
import org.apache.jackrabbit.core.util.Dumpable;
-import org.apache.jackrabbit.core.version.AbstractVersion;
-import org.apache.jackrabbit.core.version.AbstractVersionHistory;
-import org.apache.jackrabbit.core.version.InternalVersion;
-import org.apache.jackrabbit.core.version.InternalVersionHistory;
import org.apache.jackrabbit.core.version.VersionHistoryImpl;
import org.apache.jackrabbit.core.version.VersionImpl;
import org.apache.jackrabbit.name.NoPrefixDeclaredException;
@@ -533,12 +529,11 @@
* @return version instance
* @throws RepositoryException if an error occurs
*/
- protected AbstractVersion createVersionInstance(
+ protected VersionImpl createVersionInstance(
NodeId id, NodeState state, NodeDefinition def,
ItemLifeCycleListener[] listeners) throws RepositoryException {
- InternalVersion version = session.getVersionManager().getVersion(id);
- return new VersionImpl(this, session, id, state, def, listeners, version);
+ return new VersionImpl(this, session, id, state, def, listeners);
}
/**
@@ -550,13 +545,11 @@
* @return version instance
* @throws RepositoryException if an error occurs
*/
- protected AbstractVersionHistory createVersionHistoryInstance(
+ protected VersionHistoryImpl createVersionHistoryInstance(
NodeId id, NodeState state, NodeDefinition def,
ItemLifeCycleListener[] listeners) throws RepositoryException {
- InternalVersionHistory history =
- session.getVersionManager().getVersionHistory(id);
- return new VersionHistoryImpl(this, session, id, state, def, listeners, history);
+ return new VersionHistoryImpl(this, session, id, state, def, listeners);
}
//---------------------------------------------------< item cache methods >
Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?rev=424021&r1=424020&r2=424021&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java (original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java Thu Jul 20 12:05:17 2006
@@ -38,8 +38,8 @@
import org.apache.jackrabbit.core.version.InternalFrozenNode;
import org.apache.jackrabbit.core.version.InternalFrozenVersionHistory;
import org.apache.jackrabbit.core.version.VersionSelector;
-import org.apache.jackrabbit.core.version.AbstractVersion;
import org.apache.jackrabbit.core.version.DateVersionSelector;
+import org.apache.jackrabbit.core.version.VersionImpl;
import org.apache.jackrabbit.core.lock.LockManager;
import org.apache.jackrabbit.name.IllegalNameException;
import org.apache.jackrabbit.name.MalformedPathException;
@@ -3085,7 +3085,7 @@
NodeImpl node;
try {
// check if versionable node exists
- InternalFrozenNode fn = ((AbstractVersion) version).getFrozenNode();
+ InternalFrozenNode fn = ((VersionImpl) version).getFrozenNode();
node = (NodeImpl) session.getNodeByUUID(fn.getFrozenUUID());
if (removeExisting) {
try {
@@ -3105,7 +3105,7 @@
}
} catch (ItemNotFoundException e) {
// not found, create new one
- node = addNode(relPath, ((AbstractVersion) version).getFrozenNode());
+ node = addNode(relPath, ((VersionImpl) version).getFrozenNode());
}
// recreate node from frozen state
@@ -3302,8 +3302,8 @@
return null;
}
// test versions
- AbstractVersion v = (AbstractVersion) getBaseVersion();
- AbstractVersion vp = (AbstractVersion) srcNode.getBaseVersion();
+ VersionImpl v = (VersionImpl) getBaseVersion();
+ VersionImpl vp = (VersionImpl) srcNode.getBaseVersion();
if (vp.isMoreRecent(v) && !isCheckedOut()) {
// I f V' is a successor (to any degree) of V, then the merge result for
// N is update. This case can be thought of as the case where N' is
@@ -3732,7 +3732,7 @@
throws UnsupportedRepositoryOperationException, RepositoryException {
try {
- internalRestore((AbstractVersion) version, vsel, removeExisting);
+ internalRestore((VersionImpl) version, vsel, removeExisting);
} catch (RepositoryException e) {
// revert session
try {
@@ -3755,7 +3755,7 @@
* @param removeExisting
* @throws RepositoryException
*/
- protected Version[] internalRestore(AbstractVersion version, VersionSelector vsel,
+ protected Version[] internalRestore(VersionImpl version, VersionSelector vsel,
boolean removeExisting)
throws RepositoryException {
@@ -3933,7 +3933,7 @@
}
}
// get desired version from version selector
- AbstractVersion v = (AbstractVersion) vsel.select(history);
+ VersionImpl v = (VersionImpl) vsel.select(history);
// check existing version of item exists
if (!itemMgr.itemExists(nodeId)) {
@@ -3947,7 +3947,7 @@
log.error(msg);
throw new VersionException(msg);
}
- v = (AbstractVersion) vs[0];
+ v = (VersionImpl) vs[0];
}
restoredChild = addNode(child.getName(), v.getFrozenNode());
} else {
Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java?rev=424021&r1=424020&r2=424021&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java (original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java Thu Jul 20 12:05:17 2006
@@ -26,7 +26,7 @@
import org.apache.jackrabbit.core.query.QueryManagerImpl;
import org.apache.jackrabbit.core.state.LocalItemStateManager;
import org.apache.jackrabbit.core.state.SharedItemStateManager;
-import org.apache.jackrabbit.core.version.AbstractVersion;
+import org.apache.jackrabbit.core.version.VersionImpl;
import org.apache.jackrabbit.core.version.DateVersionSelector;
import org.apache.jackrabbit.core.version.VersionSelector;
import org.apache.jackrabbit.core.xml.ImportHandler;
@@ -597,7 +597,7 @@
// add all versions to map of versions to restore
final HashMap toRestore = new HashMap();
for (int i = 0; i < versions.length; i++) {
- AbstractVersion v = (AbstractVersion) versions[i];
+ VersionImpl v = (VersionImpl) versions[i];
VersionHistory vh = v.getContainingHistory();
// check for collision
if (toRestore.containsKey(vh.getUUID())) {
@@ -633,7 +633,7 @@
Version[] restored = null;
Iterator iter = toRestore.values().iterator();
while (iter.hasNext()) {
- AbstractVersion v = (AbstractVersion) iter.next();
+ VersionImpl v = (VersionImpl) iter.next();
try {
NodeImpl node = (NodeImpl) session.getNodeByUUID(v.getFrozenNode().getFrozenUUID());
restored = node.internalRestore(v, vsel, removeExisting);
Added: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java?rev=424021&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java (added)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java Thu Jul 20 12:05:17 2006
@@ -0,0 +1,320 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.version;
+
+import org.apache.jackrabbit.core.ItemLifeCycleListener;
+import org.apache.jackrabbit.core.ItemManager;
+import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.NodeImpl;
+import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.name.IllegalNameException;
+import org.apache.jackrabbit.name.NoPrefixDeclaredException;
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.name.UnknownPrefixException;
+import org.apache.jackrabbit.name.NameFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.Item;
+import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.NodeIterator;
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.nodetype.NodeDefinition;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionException;
+import javax.jcr.version.VersionHistory;
+import javax.jcr.version.VersionIterator;
+
+/**
+ * Base implementation of the {@link javax.jcr.version.VersionHistory} interface.
+ */
+public class VersionHistoryImpl extends NodeImpl implements VersionHistory {
+
+ /**
+ * Logger instance.
+ */
+ private static Logger log = LoggerFactory.getLogger(VersionHistoryImpl.class);
+
+ /**
+ * Create a new instance of this class.
+ * @param itemMgr item manager
+ * @param session session
+ * @param id node id
+ * @param state node state
+ * @param definition node definition
+ * @param listeners life cycle listeners
+ */
+ public VersionHistoryImpl(ItemManager itemMgr, SessionImpl session, NodeId id,
+ NodeState state, NodeDefinition definition,
+ ItemLifeCycleListener[] listeners) {
+ super(itemMgr, session, id, state, definition, listeners);
+ }
+
+ /**
+ * Returns the internal version history. Subclass responsibility.
+ *
+ * @return internal version history
+ * @throws RepositoryException if the internal version history is not available
+ */
+ protected InternalVersionHistory getInternalVersionHistory()
+ throws RepositoryException {
+ InternalVersionHistory history =
+ session.getVersionManager().getVersionHistory((NodeId) id);
+ if (history == null) {
+ throw new InvalidItemStateException(id + ": the item does not exist anymore");
+ }
+ return history;
+ }
+
+ /**
+ * @see javax.jcr.version.VersionHistory#getRootVersion()
+ */
+ public Version getRootVersion() throws RepositoryException {
+ return (Version) session.getNodeById(
+ getInternalVersionHistory().getRootVersion().getId());
+ }
+
+ /**
+ * @see javax.jcr.version.VersionHistory#getAllVersions()
+ */
+ public VersionIterator getAllVersions() throws RepositoryException {
+ return new VersionIteratorImpl(session,
+ getInternalVersionHistory().getRootVersion());
+ }
+
+ /**
+ * @see javax.jcr.version.VersionHistory#getVersion(String)
+ */
+ public Version getVersion(String versionName)
+ throws VersionException, RepositoryException {
+ try {
+ QName name = NameFormat.parse(versionName, session.getNamespaceResolver());
+ InternalVersion v = getInternalVersionHistory().getVersion(name);
+ if (v == null) {
+ throw new VersionException("No version with name '" + versionName + "' exists in this version history.");
+ }
+ return (Version) session.getNodeById(v.getId());
+ } catch (IllegalNameException e) {
+ throw new VersionException(e);
+ } catch (UnknownPrefixException e) {
+ throw new VersionException(e);
+ }
+ }
+
+ /**
+ * @see javax.jcr.version.VersionHistory#getVersionByLabel(String)
+ */
+ public Version getVersionByLabel(String label) throws RepositoryException {
+ try {
+ QName qLabel = NameFormat.parse(label, session.getNamespaceResolver());
+ InternalVersion v = getInternalVersionHistory().getVersionByLabel(qLabel);
+ if (v == null) {
+ throw new VersionException("No version with label '" + label + "' exists in this version history.");
+ }
+ return (Version) session.getNodeById(v.getId());
+ } catch (IllegalNameException e) {
+ throw new VersionException(e);
+ } catch (UnknownPrefixException e) {
+ throw new VersionException(e);
+ }
+ }
+
+ /**
+ * @see javax.jcr.version.VersionHistory#addVersionLabel(String, String, boolean)
+ */
+ public void addVersionLabel(String versionName, String label, boolean move)
+ throws VersionException, RepositoryException {
+ try {
+ session.getVersionManager().setVersionLabel(this,
+ NameFormat.parse(versionName, session.getNamespaceResolver()),
+ NameFormat.parse(label, session.getNamespaceResolver()),
+ move);
+ } catch (IllegalNameException e) {
+ throw new VersionException(e);
+ } catch (UnknownPrefixException e) {
+ throw new VersionException(e);
+ }
+ }
+
+ /**
+ * @see javax.jcr.version.VersionHistory#removeVersionLabel(String)
+ */
+ public void removeVersionLabel(String label) throws RepositoryException {
+ try {
+ Version existing = session.getVersionManager().setVersionLabel(this,
+ null,
+ NameFormat.parse(label, session.getNamespaceResolver()),
+ true);
+ if (existing == null) {
+ throw new VersionException("No version with label '" + label + "' exists in this version history.");
+ }
+ } catch (IllegalNameException e) {
+ throw new VersionException(e);
+ } catch (UnknownPrefixException e) {
+ throw new VersionException(e);
+ }
+ }
+
+
+ /**
+ * @see javax.jcr.version.VersionHistory#getVersionLabels
+ */
+ public String[] getVersionLabels() throws RepositoryException {
+ try {
+ QName[] labels = getInternalVersionHistory().getVersionLabels();
+ String[] ret = new String[labels.length];
+ for (int i = 0; i < labels.length; i++) {
+ ret[i] = NameFormat.format(labels[i], session.getNamespaceResolver());
+ }
+ return ret;
+ } catch (NoPrefixDeclaredException e) {
+ throw new IllegalArgumentException("Unable to resolve label name: " + e.toString());
+ }
+ }
+
+ /**
+ * @see javax.jcr.version.VersionHistory#getVersionLabels(javax.jcr.version.Version)
+ */
+ public String[] getVersionLabels(Version version)
+ throws VersionException, RepositoryException {
+ checkOwnVersion(version);
+ try {
+ QName[] labels = ((VersionImpl) version).getInternalVersion().getLabels();
+ String[] ret = new String[labels.length];
+ for (int i = 0; i < labels.length; i++) {
+ ret[i] = NameFormat.format(labels[i], session.getNamespaceResolver());
+ }
+ return ret;
+ } catch (NoPrefixDeclaredException e) {
+ throw new IllegalArgumentException("Unable to resolve label name: " + e.toString());
+ }
+ }
+
+ /**
+ * @see javax.jcr.version.VersionHistory#hasVersionLabel(String)
+ */
+ public boolean hasVersionLabel(String label) throws RepositoryException {
+ try {
+ QName qLabel = NameFormat.parse(label, session.getNamespaceResolver());
+ return getInternalVersionHistory().getVersionByLabel(qLabel) != null;
+ } catch (IllegalNameException e) {
+ throw new IllegalArgumentException("Unable to resolve label: " + e);
+ } catch (UnknownPrefixException e) {
+ throw new IllegalArgumentException("Unable to resolve label: " + e);
+ }
+ }
+
+ /**
+ * @see javax.jcr.version.VersionHistory#hasVersionLabel(javax.jcr.version.Version, String)
+ */
+ public boolean hasVersionLabel(Version version, String label)
+ throws VersionException, RepositoryException {
+ checkOwnVersion(version);
+ try {
+ QName qLabel = NameFormat.parse(label, session.getNamespaceResolver());
+ return ((VersionImpl) version).getInternalVersion().hasLabel(qLabel);
+ } catch (IllegalNameException e) {
+ throw new VersionException(e);
+ } catch (UnknownPrefixException e) {
+ throw new VersionException(e);
+ }
+ }
+
+ /**
+ * @see javax.jcr.version.VersionHistory#removeVersion(String)
+ */
+ public void removeVersion(String versionName)
+ throws UnsupportedRepositoryOperationException, VersionException,
+ RepositoryException {
+ try {
+ session.getVersionManager().removeVersion(this,
+ NameFormat.parse(versionName, session.getNamespaceResolver()));
+ } catch (IllegalNameException e) {
+ throw new RepositoryException(e);
+ } catch (UnknownPrefixException e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ /**
+ * @see javax.jcr.Item#isSame(javax.jcr.Item)
+ */
+ public boolean isSame(Item otherItem) {
+ if (otherItem instanceof VersionHistoryImpl) {
+ // since all version histories live in the same workspace, we can compare the uuids
+ try {
+ InternalVersionHistory other = ((VersionHistoryImpl) otherItem).getInternalVersionHistory();
+ return other.getId().equals(getInternalVersionHistory().getId());
+ } catch (RepositoryException e) {
+ log.warn("Unable to retrieve internal version history objects: " + e.getMessage());
+ log.debug("Stack dump:", e);
+ }
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getVersionableUUID() throws RepositoryException {
+ return getInternalVersionHistory().getVersionableUUID().toString();
+ }
+
+ /**
+ * Checks if the given version belongs to this history
+ *
+ * @param version
+ * @throws javax.jcr.version.VersionException
+ * @throws javax.jcr.RepositoryException
+ */
+ private void checkOwnVersion(Version version)
+ throws VersionException, RepositoryException {
+ if (!version.getParent().isSame(this)) {
+ throw new VersionException("Specified version not contained in this history.");
+ }
+ }
+
+ //--------------------------------------< Overwrite "protected" methods >---
+
+ /**
+ * Always throws a {@link javax.jcr.nodetype.ConstraintViolationException} since this node
+ * is protected.
+ *
+ * @throws javax.jcr.nodetype.ConstraintViolationException
+ */
+ public void update(String srcWorkspaceName) throws ConstraintViolationException {
+ String msg = "update operation not allowed on a version history node: " + safeGetJCRPath();
+ log.debug(msg);
+ throw new ConstraintViolationException(msg);
+ }
+
+ /**
+ * Always throws a {@link javax.jcr.nodetype.ConstraintViolationException} since this node
+ * is protected.
+ *
+ * @throws javax.jcr.nodetype.ConstraintViolationException
+ */
+ public NodeIterator merge(String srcWorkspace, boolean bestEffort)
+ throws ConstraintViolationException {
+ String msg = "merge operation not allowed on a version history node: " + safeGetJCRPath();
+ log.debug(msg);
+ throw new ConstraintViolationException(msg);
+ }
+}
Propchange: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java
------------------------------------------------------------------------------
svn:keywords = author date id revision url rev
Added: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionImpl.java?rev=424021&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionImpl.java (added)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionImpl.java Thu Jul 20 12:05:17 2006
@@ -0,0 +1,194 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.version;
+
+import org.apache.jackrabbit.core.ItemLifeCycleListener;
+import org.apache.jackrabbit.core.ItemManager;
+import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.NodeImpl;
+import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.state.NodeState;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.Item;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NodeDefinition;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionHistory;
+import java.util.Calendar;
+
+/**
+ * Base implementation of the {@link javax.jcr.version.Version} interface.
+ */
+public class VersionImpl extends NodeImpl implements Version {
+
+ /**
+ * Logger instance.
+ */
+ private static Logger log = LoggerFactory.getLogger(VersionImpl.class);
+
+ /**
+ * Create a new instance of this class.
+ * @param itemMgr item manager
+ * @param session session
+ * @param id node id
+ * @param state node state
+ * @param definition node definition
+ * @param listeners life cycle listeners
+ */
+ public VersionImpl(ItemManager itemMgr, SessionImpl session, NodeId id,
+ NodeState state, NodeDefinition definition,
+ ItemLifeCycleListener[] listeners) {
+ super(itemMgr, session, id, state, definition, listeners);
+ }
+
+ /**
+ * Returns the internal version. Subclass responsibility.
+ * @return internal version
+ * @throws RepositoryException if the internal version is not available
+ */
+ protected InternalVersion getInternalVersion() throws RepositoryException {
+ InternalVersion version =
+ session.getVersionManager().getVersion((NodeId) id);
+ if (version == null) {
+ throw new InvalidItemStateException(id + ": the item does not exist anymore");
+ }
+ return version;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Calendar getCreated() throws RepositoryException {
+ return getInternalVersion().getCreated();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Version[] getSuccessors() throws RepositoryException {
+ // need to wrap it around proper node
+ InternalVersion[] suc = getInternalVersion().getSuccessors();
+ Version[] ret = new Version[suc.length];
+ for (int i = 0; i < suc.length; i++) {
+ ret[i] = (Version) session.getNodeById(suc[i].getId());
+ }
+ return ret;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Version[] getPredecessors() throws RepositoryException {
+ // need to wrap it around proper node
+ InternalVersion[] pred = getInternalVersion().getPredecessors();
+ Version[] ret = new Version[pred.length];
+ for (int i = 0; i < pred.length; i++) {
+ ret[i] = (Version) session.getNodeById(pred[i].getId());
+ }
+ return ret;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public VersionHistory getContainingHistory() throws RepositoryException {
+ return (VersionHistory) getParent();
+ }
+
+ /**
+ * Returns the frozen node of this version
+ *
+ * @return
+ * @throws javax.jcr.RepositoryException
+ */
+ public InternalFrozenNode getFrozenNode() throws RepositoryException {
+ return getInternalVersion().getFrozenNode();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isSame(Item otherItem) {
+ if (otherItem instanceof VersionImpl) {
+ // since all versions live in the same workspace, we can compare the uuids
+ try {
+ InternalVersion other = ((VersionImpl) otherItem).getInternalVersion();
+ return other.getId().equals(getInternalVersion().getId());
+ } catch (RepositoryException e) {
+ log.warn("Unable to retrieve internal version objects: " + e.getMessage());
+ log.debug("Stack dump:", e);
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Checks if this version is more recent than the given version <code>v</code>.
+ * A version is more recent if and only if it is a successor (or a successor
+ * of a successor, etc., to any degree of separation) of the compared one.
+ *
+ * @param v the version to check
+ * @return <code>true</code> if the version is more recent;
+ * <code>false</code> otherwise.
+ */
+ public boolean isMoreRecent(VersionImpl v) throws RepositoryException {
+ return getInternalVersion().isMoreRecent(v.getInternalVersion());
+ }
+
+ /**
+ * Checks if this is the root version.
+ * @return <code>true</code> if this version is the root version;
+ * <code>false</code> otherwise.
+ */
+ public boolean isRootVersion() throws RepositoryException {
+ return getInternalVersion().isRootVersion();
+ }
+
+ //--------------------------------------< Overwrite "protected" methods >---
+
+
+ /**
+ * Always throws a {@link javax.jcr.nodetype.ConstraintViolationException} since this node
+ * is protected.
+ *
+ * @throws javax.jcr.nodetype.ConstraintViolationException
+ */
+ public void update(String srcWorkspaceName) throws ConstraintViolationException {
+ String msg = "update operation not allowed on a version node: " + safeGetJCRPath();
+ log.debug(msg);
+ throw new ConstraintViolationException(msg);
+ }
+
+ /**
+ * Always throws a {@link javax.jcr.nodetype.ConstraintViolationException} since this node
+ * is protected.
+ *
+ * @throws javax.jcr.nodetype.ConstraintViolationException
+ */
+ public NodeIterator merge(String srcWorkspace, boolean bestEffort)
+ throws ConstraintViolationException {
+ String msg = "merge operation not allowed on a version node: " + safeGetJCRPath();
+ log.debug(msg);
+ throw new ConstraintViolationException(msg);
+ }
+
+}
Propchange: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionImpl.java
------------------------------------------------------------------------------
svn:keywords = author date id revision url rev
Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java?rev=424021&r1=424020&r2=424021&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java (original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java Thu Jul 20 12:05:17 2006
@@ -282,7 +282,7 @@
}
});
- return (AbstractVersion)
+ return (VersionImpl)
((SessionImpl) node.getSession()).getNodeById(version.getId());
}
@@ -295,7 +295,7 @@
public void removeVersion(VersionHistory history, final QName name)
throws VersionException, RepositoryException {
- final AbstractVersionHistory historyImpl = (AbstractVersionHistory) history;
+ final VersionHistoryImpl historyImpl = (VersionHistoryImpl) history;
if (!historyImpl.hasNode(name)) {
throw new VersionException("Version with name " + name.toString()
+ " does not exist in this VersionHistory");
@@ -326,7 +326,7 @@
escFactory.doSourced((SessionImpl) history.getSession(), new SourcedTarget(){
public Object run() throws RepositoryException {
InternalVersionHistoryImpl vh = (InternalVersionHistoryImpl)
- ((AbstractVersionHistory) history).getInternalVersionHistory();
+ ((VersionHistoryImpl) history).getInternalVersionHistory();
return setVersionLabel(vh, version, label, move);
}
});
Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java?rev=424021&r1=424020&r2=424021&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java (original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java Thu Jul 20 12:05:17 2006
@@ -167,7 +167,7 @@
if (isInXA()) {
InternalVersionHistoryImpl vh = (InternalVersionHistoryImpl)
- ((AbstractVersionHistory) history).getInternalVersionHistory();
+ ((VersionHistoryImpl) history).getInternalVersionHistory();
removeVersion(vh, versionName);
return;
}
@@ -183,7 +183,7 @@
if (isInXA()) {
InternalVersionHistoryImpl vh = (InternalVersionHistoryImpl)
- ((AbstractVersionHistory) history).getInternalVersionHistory();
+ ((VersionHistoryImpl) history).getInternalVersionHistory();
InternalVersion v = setVersionLabel(vh, version, label, move);
if (v == null) {
return null;