From commits-return-8805-apmail-jackrabbit-commits-archive=jackrabbit.apache.org@jackrabbit.apache.org Tue Sep 08 16:11:22 2009 Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 1414 invoked from network); 8 Sep 2009 16:11:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 8 Sep 2009 16:11:22 -0000 Received: (qmail 66508 invoked by uid 500); 8 Sep 2009 16:11:22 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 66463 invoked by uid 500); 8 Sep 2009 16:11:22 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 66454 invoked by uid 99); 8 Sep 2009 16:11:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Sep 2009 16:11:22 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Sep 2009 16:11:10 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 9357E23889FD; Tue, 8 Sep 2009 16:09:54 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r812570 [22/24] - in /jackrabbit/sandbox/JCR-1456: ./ jackrabbit-api/ jackrabbit-api/src/main/appended-resources/ jackrabbit-api/src/main/appended-resources/META-INF/ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/ jackrabb... Date: Tue, 08 Sep 2009 16:09:45 -0000 To: commits@jackrabbit.apache.org From: jukka@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090908160954.9357E23889FD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractRepositoryService.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractRepositoryService.java?rev=812570&r1=812569&r2=812570&view=diff ============================================================================== --- jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractRepositoryService.java (original) +++ jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractRepositoryService.java Tue Sep 8 16:09:28 2009 @@ -16,18 +16,69 @@ */ package org.apache.jackrabbit.spi.commons; +import java.io.InputStream; +import java.io.Reader; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.jcr.AccessDeniedException; +import javax.jcr.Credentials; +import javax.jcr.InvalidItemStateException; +import javax.jcr.ItemExistsException; +import javax.jcr.ItemNotFoundException; +import javax.jcr.LoginException; +import javax.jcr.MergeException; +import javax.jcr.NamespaceException; +import javax.jcr.NoSuchWorkspaceException; +import javax.jcr.PathNotFoundException; +import javax.jcr.PropertyType; +import javax.jcr.ReferentialIntegrityException; +import javax.jcr.Repository; +import javax.jcr.RepositoryException; +import javax.jcr.SimpleCredentials; +import javax.jcr.UnsupportedRepositoryOperationException; +import javax.jcr.ValueFormatException; +import javax.jcr.lock.LockException; +import javax.jcr.nodetype.ConstraintViolationException; +import javax.jcr.nodetype.InvalidNodeTypeDefinitionException; +import javax.jcr.nodetype.NoSuchNodeTypeException; +import javax.jcr.nodetype.NodeTypeExistsException; +import javax.jcr.query.InvalidQueryException; +import javax.jcr.version.VersionException; + +import org.apache.jackrabbit.spi.Batch; +import org.apache.jackrabbit.spi.EventBundle; +import org.apache.jackrabbit.spi.EventFilter; import org.apache.jackrabbit.spi.IdFactory; +import org.apache.jackrabbit.spi.ItemId; +import org.apache.jackrabbit.spi.LockInfo; +import org.apache.jackrabbit.spi.Name; import org.apache.jackrabbit.spi.NameFactory; +import org.apache.jackrabbit.spi.NodeId; +import org.apache.jackrabbit.spi.Path; import org.apache.jackrabbit.spi.PathFactory; +import org.apache.jackrabbit.spi.PropertyId; +import org.apache.jackrabbit.spi.QNodeDefinition; +import org.apache.jackrabbit.spi.QNodeTypeDefinition; +import org.apache.jackrabbit.spi.QPropertyDefinition; +import org.apache.jackrabbit.spi.QValue; import org.apache.jackrabbit.spi.QValueFactory; +import org.apache.jackrabbit.spi.QueryInfo; import org.apache.jackrabbit.spi.RepositoryService; +import org.apache.jackrabbit.spi.SessionInfo; +import org.apache.jackrabbit.spi.Subscription; import org.apache.jackrabbit.spi.commons.identifier.IdFactoryImpl; import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl; import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl; +import org.apache.jackrabbit.spi.commons.namespace.NamespaceMapping; +import org.apache.jackrabbit.spi.commons.nodetype.NodeTypeStorage; +import org.apache.jackrabbit.spi.commons.nodetype.NodeTypeStorageImpl; +import org.apache.jackrabbit.spi.commons.nodetype.compact.CompactNodeTypeDefReader; +import org.apache.jackrabbit.spi.commons.nodetype.compact.ParseException; import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl; -import javax.jcr.RepositoryException; - /** * AbstractRepositoryService provides an abstract base class for * repository service implementations. This class provides default @@ -42,6 +93,26 @@ public abstract class AbstractRepositoryService implements RepositoryService { /** + * The repository descriptors. + */ + protected final Map descriptors = new HashMap(); + + /** + * The fixed set of namespaces known to the repository service. + */ + protected final NamespaceMapping namespaces = new NamespaceMapping(); + + /** + * The fixed set of node type definitions known to the repository service. + */ + protected final NodeTypeStorage nodeTypeDefs = new NodeTypeStorageImpl(); + + /** + * The node definition of the root node. + */ + protected QNodeDefinition rootNodeDefinition; + + /** * @return {@link IdFactoryImpl#getInstance()}. * @throws RepositoryException if an error occurs. */ @@ -72,4 +143,726 @@ public QValueFactory getQValueFactory() throws RepositoryException { return QValueFactoryImpl.getInstance(); } + + protected AbstractRepositoryService() throws RepositoryException { + QValueFactory qvf = QValueFactoryImpl.getInstance(); + QValue[] vFalse = new QValue[] {qvf.create(false)}; + + descriptors.put(Repository.WRITE_SUPPORTED, vFalse); + descriptors.put(Repository.IDENTIFIER_STABILITY, + new QValue[] {qvf.create(Repository.IDENTIFIER_STABILITY_SAVE_DURATION, PropertyType.STRING)}); + descriptors.put(Repository.OPTION_XML_IMPORT_SUPPORTED, vFalse); + descriptors.put(Repository.OPTION_XML_EXPORT_SUPPORTED, vFalse); + descriptors.put(Repository.OPTION_UNFILED_CONTENT_SUPPORTED, vFalse); + descriptors.put(Repository.OPTION_VERSIONING_SUPPORTED, vFalse); + descriptors.put(Repository.OPTION_SIMPLE_VERSIONING_SUPPORTED, vFalse); + descriptors.put(Repository.OPTION_ACCESS_CONTROL_SUPPORTED, vFalse); + descriptors.put(Repository.OPTION_LOCKING_SUPPORTED, vFalse); + descriptors.put(Repository.OPTION_OBSERVATION_SUPPORTED, vFalse); + descriptors.put(Repository.OPTION_JOURNALED_OBSERVATION_SUPPORTED, vFalse); + descriptors.put(Repository.OPTION_RETENTION_SUPPORTED, vFalse); + descriptors.put(Repository.OPTION_LIFECYCLE_SUPPORTED, vFalse); + descriptors.put(Repository.OPTION_TRANSACTIONS_SUPPORTED, vFalse); + descriptors.put(Repository.OPTION_WORKSPACE_MANAGEMENT_SUPPORTED, vFalse); + descriptors.put(Repository.OPTION_UPDATE_PRIMARY_NODE_TYPE_SUPPORTED, vFalse); + descriptors.put(Repository.OPTION_UPDATE_MIXIN_NODE_TYPES_SUPPORTED, vFalse); + descriptors.put(Repository.OPTION_SHAREABLE_NODES_SUPPORTED, vFalse); + descriptors.put(Repository.OPTION_NODE_TYPE_MANAGEMENT_SUPPORTED, vFalse); + + descriptors.put(Repository.QUERY_LANGUAGES, new QValue[0]); + descriptors.put(Repository.QUERY_STORED_QUERIES_SUPPORTED, vFalse); + descriptors.put(Repository.QUERY_FULL_TEXT_SEARCH_SUPPORTED, vFalse); + descriptors.put(Repository.QUERY_JOINS, + new QValue[] {qvf.create(Repository.QUERY_JOINS_NONE, PropertyType.STRING)}); + + descriptors.putAll(descriptors); + } + + public AbstractRepositoryService(Map descriptors, + Map namespaces, + QNodeTypeDefinition[] nodeTypeDefs) + throws RepositoryException { + + this(); + this.descriptors.putAll(descriptors); + + for (Map.Entry entry : namespaces.entrySet()) { + this.namespaces.setMapping(entry.getKey(), entry.getValue()); + } + + this.nodeTypeDefs.registerNodeTypes(nodeTypeDefs, true); + } + + public AbstractRepositoryService(Map descriptors, + Map namespaces, + Reader cnd) + throws RepositoryException { + + this(); + this.descriptors.putAll(descriptors); + + for (Map.Entry entry : namespaces.entrySet()) { + this.namespaces.setMapping(entry.getKey(), entry.getValue()); + } + + CompactNodeTypeDefReader reader; + try { + reader = new CompactNodeTypeDefReader(cnd, "", this.namespaces); + List ntds = reader.getNodeTypeDefinitions(); + nodeTypeDefs.registerNodeTypes(ntds.toArray(new QNodeTypeDefinition[ntds.size()]), true); + } + catch (ParseException e) { + throw new RepositoryException("Error reading node type definitions", e); + } + } + + //---------------------------< subclass responsibility >-------------------- + + /** + * Create the root node definition. + * + * @return the root node definition for a workspace. + * @throws RepositoryException if an error occurs. + */ + protected abstract QNodeDefinition createRootNodeDefinition() throws RepositoryException; + + //---------------------< may be overwritten by subclasses>------------------ + + /** + * Checks if the given credentials are valid. This default + * implementation is empty thus allowing all credentials. + * + * @param credentials the credentials to check. + * @param workspaceName the workspace to access. + * @throws LoginException if the credentials are invalid. + */ + protected void checkCredentials(Credentials credentials, String workspaceName) throws LoginException { + // empty + } + + /** + * Checks if the given workspace is available. The default implementation is empty + * thus admitting every workspace name. + * @param workspaceName Name of the workspace to check + * @throws NoSuchWorkspaceException If workspaceName is not available. + */ + protected void checkWorkspace(String workspaceName) throws NoSuchWorkspaceException { + // empty + } + + /** + * Creates a session info instance for the given credentials and + * workspaceName. This default implementation creates a + * {@link SessionInfoImpl} instance and sets the userId and + * workspaceName. The user userId is null or the + * userId from credentials if it is of type + * {@link SimpleCredentials}. + * + * @param credentials the credentials. + * @param workspaceName the name of the workspace to access or null + * for the default workspace. + * @return a session info instance for the given credentials and + * workspaceName. + * @throws RepositoryException + */ + protected SessionInfo createSessionInfo(Credentials credentials, String workspaceName) + throws RepositoryException { + + String userId = null; + if (credentials instanceof SimpleCredentials) { + userId = ((SimpleCredentials) credentials).getUserID(); + } + + SessionInfoImpl s = new SessionInfoImpl(); + s.setUserID(userId); + s.setWorkspacename(workspaceName); + return s; + } + + /** + * Creates a session info instance for the given sessionInfo and + * workspaceName. This default implementation creates a + * {@link SessionInfoImpl} instance and sets the userId and + * workspaceName. The user userId is set to the return value of + * {@link SessionInfo#getUserID()}. + * + * @param sessionInfo the sessionInfo. + * @param workspaceName the name of the workspace to access. + * @return a session info instance for the given credentials and + * workspaceName. + * @throws RepositoryException + */ + protected SessionInfo createSessionInfo(SessionInfo sessionInfo, String workspaceName) + throws RepositoryException { + + String userId = sessionInfo.getUserID(); + + SessionInfoImpl s = new SessionInfoImpl(); + s.setUserID(userId); + s.setWorkspacename(workspaceName); + return s; + } + + /** + * Checks the type of the sessionInfo instance. This default + * implementation checks if sessionInfo is of type + * {@link SessionInfoImpl}, otherwise throws a {@link RepositoryException}. + * + * @param sessionInfo the session info to check. + * @throws RepositoryException if the given sessionInfo is not + * of the required type for this repository + * service implementation. + */ + protected void checkSessionInfo(SessionInfo sessionInfo) + throws RepositoryException { + if (sessionInfo instanceof SessionInfoImpl) { + return; + } + throw new RepositoryException("SessionInfo not of type " + + SessionInfoImpl.class.getName()); + } + + //--------------------------< descriptors >--------------------------------- + + /** + * This default implementation returns the descriptors that were passed + * to the constructor of this repository service. + */ + public Map getRepositoryDescriptors() throws RepositoryException { + return descriptors; + } + + //----------------------------< login >------------------------------------- + + /** + * This default implementation does: + *
    + *
  • calls {@link #checkCredentials(Credentials, String)}
  • + *
  • calls {@link #checkWorkspace(String)}
  • + *
  • calls {@link #createSessionInfo(Credentials, String)}
  • . + *
+ * @param credentials the credentials for the login. + * @param workspaceName the name of the workspace to log in. + * @return the session info. + * @throws LoginException if the credentials are invalid. + * @throws NoSuchWorkspaceException if workspaceName is unknown. + * @throws RepositoryException if another error occurs. + */ + public SessionInfo obtain(Credentials credentials, String workspaceName) + throws LoginException, NoSuchWorkspaceException, RepositoryException { + checkCredentials(credentials, workspaceName); + checkWorkspace(workspaceName); + return createSessionInfo(credentials, workspaceName); + } + + /** + * This default implementation returns the session info returned by the call + * to {@link #createSessionInfo(SessionInfo, String)}. + */ + public SessionInfo obtain(SessionInfo sessionInfo, String workspaceName) + throws LoginException, NoSuchWorkspaceException, RepositoryException { + return createSessionInfo(sessionInfo, workspaceName); + } + + + /** + * This default implementation returns the session info returned by the call + * to {@link #obtain(Credentials, String)} with the workspaceName taken from + * the passed sessionInfo. + */ + public SessionInfo impersonate(SessionInfo sessionInfo, Credentials credentials) + throws LoginException, RepositoryException { + return obtain(credentials, sessionInfo.getWorkspaceName()); + } + + /** + * This default implementation does nothing. + */ + public void dispose(SessionInfo sessionInfo) throws RepositoryException { + // do nothing + } + + //-----------------------------< node types >------------------------------- + + /** + * This default implementation first calls {@link #checkSessionInfo(SessionInfo)} + * with the sessionInfo, + */ + public Iterator getQNodeTypeDefinitions(SessionInfo sessionInfo) throws + RepositoryException { + + checkSessionInfo(sessionInfo); + return nodeTypeDefs.getAllDefinitions(); + } + + /** + * This default implementation first calls {@link #checkSessionInfo(SessionInfo)} + * with the sessionInfo, then gathers the {@link QNodeTypeDefinition}s + * with the given nodetypeNames. If one of the nodetypeNames + * is not a valid node type definition then a {@link RepositoryException} + * is thrown. + */ + public Iterator getQNodeTypeDefinitions(SessionInfo sessionInfo, Name[] nodetypeNames) + throws RepositoryException { + + checkSessionInfo(sessionInfo); + return nodeTypeDefs.getDefinitions(nodetypeNames); + } + + /** + * This default implementation first calls {@link #checkSessionInfo(SessionInfo)} + * with the sessionInfo, then lazily initializes {@link #rootNodeDefinition} + * if nodeId denotes the root node; otherwise throws a + * {@link UnsupportedRepositoryOperationException}. + */ + public QNodeDefinition getNodeDefinition(SessionInfo sessionInfo, + NodeId nodeId) + throws RepositoryException { + checkSessionInfo(sessionInfo); + if (nodeId.getUniqueID() == null && nodeId.getPath().denotesRoot()) { + synchronized (this) { + if (rootNodeDefinition == null) { + rootNodeDefinition = createRootNodeDefinition(); + } + return rootNodeDefinition; + } + } + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public QPropertyDefinition getPropertyDefinition(SessionInfo sessionInfo, + PropertyId propertyId) + throws RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void registerNodeTypes(SessionInfo sessionInfo, QNodeTypeDefinition[] nodeTypeDefinitions, boolean allowUpdate) throws InvalidNodeTypeDefinitionException, NodeTypeExistsException, UnsupportedRepositoryOperationException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void unregisterNodeTypes(SessionInfo sessionInfo, Name[] nodeTypeNames) throws UnsupportedRepositoryOperationException, NoSuchNodeTypeException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + //-----------------------------< namespaces >------------------------------- + + /** + * This default implementation first calls {@link #checkSessionInfo(SessionInfo)} + * with the sessionInfo, then returns the prefix to namespace + * URL mapping that was provided in the constructor of this repository + * service. + */ + public Map getRegisteredNamespaces(SessionInfo sessionInfo) throws + RepositoryException { + checkSessionInfo(sessionInfo); + return namespaces.getPrefixToURIMapping(); + } + + /** + * This default implementation first calls {@link #checkSessionInfo(SessionInfo)} + * with the sessionInfo, then returns the namepsace URI for the + * given prefix. + */ + public String getNamespaceURI(SessionInfo sessionInfo, String prefix) + throws NamespaceException, RepositoryException { + checkSessionInfo(sessionInfo); + return namespaces.getURI(prefix); + } + + /** + * This default implementation first calls {@link #checkSessionInfo(SessionInfo)} + * with the sessionInfo, then return the namespace prefix for + * the given uri. + */ + public String getNamespacePrefix(SessionInfo sessionInfo, String uri) + throws NamespaceException, RepositoryException { + checkSessionInfo(sessionInfo); + return namespaces.getPrefix(uri); + } + + //-----------------------------< write methods >---------------------------- + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public Batch createBatch(SessionInfo sessionInfo, ItemId itemId) + throws RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void submit(Batch batch) throws PathNotFoundException, ItemNotFoundException, NoSuchNodeTypeException, ValueFormatException, VersionException, LockException, ConstraintViolationException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void importXml(SessionInfo sessionInfo, + NodeId parentId, + InputStream xmlStream, + int uuidBehaviour) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void move(SessionInfo sessionInfo, + NodeId srcNodeId, + NodeId destParentNodeId, + Name destName) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void copy(SessionInfo sessionInfo, + String srcWorkspaceName, + NodeId srcNodeId, + NodeId destParentNodeId, + Name destName) throws NoSuchWorkspaceException, ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, UnsupportedRepositoryOperationException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void update(SessionInfo sessionInfo, + NodeId nodeId, + String srcWorkspaceName) + throws NoSuchWorkspaceException, AccessDeniedException, LockException, InvalidItemStateException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void clone(SessionInfo sessionInfo, + String srcWorkspaceName, + NodeId srcNodeId, + NodeId destParentNodeId, + Name destName, + boolean removeExisting) throws NoSuchWorkspaceException, ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, UnsupportedRepositoryOperationException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public LockInfo lock(SessionInfo sessionInfo, + NodeId nodeId, + boolean deep, + boolean sessionScoped) + throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public LockInfo lock(SessionInfo sessionInfo, NodeId nodeId, boolean deep, + boolean sessionScoped, long timeoutHint, String ownerHint) + throws UnsupportedRepositoryOperationException, LockException, + AccessDeniedException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @return null. + */ + public LockInfo getLockInfo(SessionInfo sessionInfo, NodeId nodeId) + throws AccessDeniedException, RepositoryException { + return null; + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void refreshLock(SessionInfo sessionInfo, NodeId nodeId) + throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void unlock(SessionInfo sessionInfo, NodeId nodeId) + throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public NodeId checkin(SessionInfo sessionInfo, NodeId nodeId) + throws VersionException, UnsupportedRepositoryOperationException, InvalidItemStateException, LockException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void checkout(SessionInfo sessionInfo, NodeId nodeId) + throws UnsupportedRepositoryOperationException, LockException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void checkout(SessionInfo sessionInfo, NodeId nodeId, NodeId activityId) + throws UnsupportedRepositoryOperationException, LockException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public NodeId checkpoint(SessionInfo sessionInfo, NodeId nodeId) + throws UnsupportedRepositoryOperationException, LockException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void removeVersion(SessionInfo sessionInfo, + NodeId versionHistoryId, + NodeId versionId) + throws ReferentialIntegrityException, AccessDeniedException, UnsupportedRepositoryOperationException, VersionException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void restore(SessionInfo sessionInfo, + NodeId nodeId, + NodeId versionId, + boolean removeExisting) throws VersionException, PathNotFoundException, ItemExistsException, UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void restore(SessionInfo sessionInfo, + NodeId[] versionIds, + boolean removeExisting) throws ItemExistsException, UnsupportedRepositoryOperationException, VersionException, LockException, InvalidItemStateException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException + * always. + */ + public Iterator merge(SessionInfo sessionInfo, + NodeId nodeId, + String srcWorkspaceName, + boolean bestEffort) throws + NoSuchWorkspaceException, AccessDeniedException, MergeException, + LockException, InvalidItemStateException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException + * always. + */ + public Iterator merge(SessionInfo sessionInfo, + NodeId nodeId, + String srcWorkspaceName, + boolean bestEffort, + boolean isShallow) throws + NoSuchWorkspaceException, AccessDeniedException, MergeException, + LockException, InvalidItemStateException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void resolveMergeConflict(SessionInfo sessionInfo, + NodeId nodeId, + NodeId[] mergeFailedIds, + NodeId[] predecessorIds) + throws VersionException, InvalidItemStateException, UnsupportedRepositoryOperationException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void addVersionLabel(SessionInfo sessionInfo, + NodeId versionHistoryId, + NodeId versionId, + Name label, + boolean moveLabel) throws VersionException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void removeVersionLabel(SessionInfo sessionInfo, + NodeId versionHistoryId, + NodeId versionId, + Name label) throws VersionException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public NodeId createActivity(SessionInfo sessionInfo, String title) throws UnsupportedRepositoryOperationException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void removeActivity(SessionInfo sessionInfo, NodeId activityId) throws UnsupportedRepositoryOperationException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public Iterator mergeActivity(SessionInfo sessionInfo, NodeId activityId) throws UnsupportedRepositoryOperationException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public NodeId createConfiguration(SessionInfo sessionInfo, NodeId nodeId) throws UnsupportedRepositoryOperationException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + //-----------------------------< observation >------------------------------ + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public EventFilter createEventFilter(SessionInfo sessionInfo, + int eventTypes, + Path absPath, + boolean isDeep, + String[] uuid, + Name[] nodeTypeName, + boolean noLocal) + throws UnsupportedRepositoryOperationException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public Subscription createSubscription(SessionInfo sessionInfo, + EventFilter[] filters) + throws UnsupportedRepositoryOperationException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void updateEventFilters(Subscription subscription, + EventFilter[] filters) + throws RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public EventBundle[] getEvents(Subscription subscription, long timeout) + throws RepositoryException, InterruptedException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public EventBundle getEvents(SessionInfo sessionInfo, EventFilter filter, + long after) throws + RepositoryException, UnsupportedRepositoryOperationException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void dispose(Subscription subscription) throws RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + //-------------------------------------------------< namespace registry >--- + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void registerNamespace(SessionInfo sessionInfo, + String prefix, + String uri) throws NamespaceException, UnsupportedRepositoryOperationException, AccessDeniedException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void unregisterNamespace(SessionInfo sessionInfo, String uri) + throws NamespaceException, UnsupportedRepositoryOperationException, AccessDeniedException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + //-----------------------------------------------< Workspace Management >--- + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void createWorkspace(SessionInfo sessionInfo, String name, String srcWorkspaceName) throws AccessDeniedException, UnsupportedRepositoryOperationException, NoSuchWorkspaceException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + /** + * @throws UnsupportedRepositoryOperationException always. + */ + public void deleteWorkspace(SessionInfo sessionInfo, String name) throws AccessDeniedException, UnsupportedRepositoryOperationException, NoSuchWorkspaceException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + //-------------------------------< query >---------------------------------- + + public String[] getSupportedQueryLanguages(SessionInfo sessionInfo) throws RepositoryException { + checkSessionInfo(sessionInfo); + return new String[0]; + } + + public String[] checkQueryStatement(SessionInfo sessionInfo, String statement, + String language, Map namespaces) throws + InvalidQueryException, RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + + public QueryInfo executeQuery(SessionInfo sessionInfo, String statement, + String language, Map namespaces, long limit, + long offset, Map values) throws RepositoryException { + throw new UnsupportedRepositoryOperationException(); + } + } Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/EventFilterImpl.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/EventFilterImpl.java?rev=812570&r1=812569&r2=812570&view=diff ============================================================================== --- jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/EventFilterImpl.java (original) +++ jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/EventFilterImpl.java Tue Sep 8 16:09:28 2009 @@ -16,18 +16,20 @@ */ package org.apache.jackrabbit.spi.commons; -import org.apache.jackrabbit.spi.EventFilter; +import java.io.Serializable; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import javax.jcr.RepositoryException; + import org.apache.jackrabbit.spi.Event; +import org.apache.jackrabbit.spi.EventFilter; +import org.apache.jackrabbit.spi.Name; import org.apache.jackrabbit.spi.NodeId; import org.apache.jackrabbit.spi.Path; -import javax.jcr.RepositoryException; -import java.util.Set; -import java.util.HashSet; -import java.util.Arrays; -import java.util.Collections; -import java.io.Serializable; - /** * EventFilterImpl is the simple bean style implementation of an * {@link EventFilter}. @@ -40,9 +42,9 @@ private final Path absPath; - private final Set uuids; + private final Set uuids; - private final Set nodeTypeNames; + private final Set nodeTypeNames; private final boolean noLocal; @@ -61,13 +63,13 @@ Path absPath, boolean isDeep, String[] uuids, - Set nodeTypeNames, + Set nodeTypeNames, boolean noLocal) { this.eventTypes = eventTypes; this.absPath = absPath; this.isDeep = isDeep; - this.uuids = uuids != null ? new HashSet(Arrays.asList(uuids)) : null; - this.nodeTypeNames = nodeTypeNames != null ? new HashSet(nodeTypeNames) : null; + this.uuids = uuids != null ? new HashSet(Arrays.asList(uuids)) : null; + this.nodeTypeNames = nodeTypeNames != null ? new HashSet(nodeTypeNames) : null; this.noLocal = noLocal; } @@ -100,7 +102,7 @@ // check node types if (nodeTypeNames != null) { - Set eventTypes = new HashSet(); + Set eventTypes = new HashSet(); eventTypes.addAll(Arrays.asList(event.getMixinTypeNames())); eventTypes.add(event.getPrimaryNodeTypeName()); // create intersection @@ -154,7 +156,7 @@ if (uuids == null) { return null; } else { - return (String[]) uuids.toArray(new String[uuids.size()]); + return uuids.toArray(new String[uuids.size()]); } } @@ -162,7 +164,7 @@ * @return an unmodifiable set of node type names or null if * this filter does not care about node types. */ - public Set getNodeTypeNames() { + public Set getNodeTypeNames() { if (nodeTypeNames == null) { return null; } else { @@ -181,6 +183,7 @@ * Returns a string representation of this EventFilter instance. * {@inheritDoc} */ + @Override public String toString() { return new StringBuffer(getClass().getName()) .append("[") Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QNodeTypeDefinitionImpl.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QNodeTypeDefinitionImpl.java?rev=812570&r1=812569&r2=812570&view=diff ============================================================================== --- jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QNodeTypeDefinitionImpl.java (original) +++ jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QNodeTypeDefinitionImpl.java Tue Sep 8 16:09:28 2009 @@ -167,12 +167,31 @@ NamePathResolver resolver, QValueFactory qValueFactory) throws RepositoryException { - this(resolver.getQName(def.getName()), - getNames(def.getDeclaredSupertypeNames(), resolver), null, def.isMixin(), - def.isAbstract(), def.isQueryable(), def.hasOrderableChildNodes(), + this(resolver.getQName(def.getName()), def, resolver, qValueFactory); + } + + /** + * Internal constructor to avoid resolving def.getName() 3 times. + * @param name name of the definition + * @param def node type definition + * @param resolver resolver + * @param qValueFactory value factory + * @throws RepositoryException if an error occurs + */ + private QNodeTypeDefinitionImpl(Name name, NodeTypeDefinition def, + NamePathResolver resolver, + QValueFactory qValueFactory) + throws RepositoryException { + this(name, + getNames(def.getDeclaredSupertypeNames(), resolver), + null, + def.isMixin(), + def.isAbstract(), + def.isQueryable(), + def.hasOrderableChildNodes(), def.getPrimaryItemName() == null ? null : resolver.getQName(def.getPrimaryItemName()), - createQPropertyDefinitions(def.getDeclaredPropertyDefinitions(), resolver, qValueFactory), - createQNodeDefinitions(def.getDeclaredChildNodeDefinitions(), resolver)); + createQPropertyDefinitions(name, def.getDeclaredPropertyDefinitions(), resolver, qValueFactory), + createQNodeDefinitions(name, def.getDeclaredChildNodeDefinitions(), resolver)); } //------------------------------------------------< QNodeTypeDefinition >--- @@ -351,22 +370,37 @@ return names; } - private static QPropertyDefinition[] createQPropertyDefinitions(PropertyDefinition[] pds, + private static QPropertyDefinition[] createQPropertyDefinitions(Name declName, + PropertyDefinition[] pds, NamePathResolver resolver, QValueFactory qValueFactory) throws RepositoryException { + if (pds == null || pds.length == 0) { + return QPropertyDefinition.EMPTY_ARRAY; + } QPropertyDefinition[] declaredPropDefs = new QPropertyDefinition[pds.length]; for (int i = 0; i < pds.length; i++) { PropertyDefinition propDef = pds[i]; Name name = propDef.getName().equals(QItemDefinitionImpl.ANY_NAME.getLocalName()) ? QItemDefinitionImpl.ANY_NAME : resolver.getQName(propDef.getName()); - Name declName = resolver.getQName(propDef.getDeclaringNodeType().getName()); - QValue[] defVls = ValueFormat.getQValues(propDef.getDefaultValues(), resolver, qValueFactory); + // check if propDef provides declaring node type and if it matches 'this' one. + if (propDef.getDeclaringNodeType() != null) { + if (!declName.equals(resolver.getQName(propDef.getDeclaringNodeType().getName()))) { + throw new RepositoryException("Property definition specified invalid declaring nodetype: " + + propDef.getDeclaringNodeType().getName() + ", but should be " + declName); + } + } + QValue[] defVls = propDef.getDefaultValues() == null + ? QValue.EMPTY_ARRAY + : ValueFormat.getQValues(propDef.getDefaultValues(), resolver, qValueFactory); String[] jcrConstraints = propDef.getValueConstraints(); - QValueConstraint[] constraints = new QValueConstraint[jcrConstraints.length]; - for (int j=0; j 0) { + constraints = new QValueConstraint[jcrConstraints.length]; + for (int j=0; j { public void addNode(NodeId parentId, Name nodeName, Name nodetypeName, String uuid) throws RepositoryException { @@ -88,60 +80,5 @@ addOperation(Operations.setValue(propertyId, values)); } - public Batch apply(Batch batch) throws RepositoryException { - if (batch == null) { - throw new IllegalArgumentException("Batch must not be null"); - } - for (Iterator it = operations.iterator(); it.hasNext(); ) { - Operation op = (Operation) it.next(); - op.apply(batch); - } - return batch; - } - - /** - * This method is called when an operation is added to the list of {@link #operations} - * kept by this change log. - * @param op {@link Operation} to add - * @throws RepositoryException - */ - protected void addOperation(Operation op) throws RepositoryException { - operations.add(op); - } - - // -----------------------------------------------------< Object >--- - - public String toString() { - StringBuffer b = new StringBuffer(); - for (Iterator it = operations.iterator(); it.hasNext(); ) { - b.append(it.next()); - if (it.hasNext()) { - b.append(", "); - } - } - return b.toString(); - } - - public boolean equals(Object other) { - if (null == other) { - return false; - } - if (this == other) { - return true; - } - if (other instanceof ChangeLogImpl) { - return equals((ChangeLogImpl) other); - } - return false; - } - - public boolean equals(ChangeLogImpl other) { - return operations.equals(other.operations); - } - - public int hashCode() { - throw new IllegalArgumentException("Not hashable"); - } - } Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/ConsolidatingChangeLog.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/ConsolidatingChangeLog.java?rev=812570&r1=812569&r2=812570&view=diff ============================================================================== --- jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/ConsolidatingChangeLog.java (original) +++ jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/ConsolidatingChangeLog.java Tue Sep 8 16:09:28 2009 @@ -39,7 +39,7 @@ * {@link CancelableOperation CancelableOperation} implementations document their behavior * concerning cancellation. */ -public class ConsolidatingChangeLog extends ChangeLogImpl { +public class ConsolidatingChangeLog extends AbstractChangeLog { private static final PathFactory PATH_FACTORY = PathFactoryImpl.getInstance(); /** @@ -136,15 +136,11 @@ *
  • Otherwise add the current operation to the list of operations.
  • * */ - protected void addOperation(Operation op) throws RepositoryException { - if (!(op instanceof CancelableOperation)) { - throw new IllegalArgumentException("Operation not instance of " - + CancelableOperation.class.getName()); - } - - CancelableOperation otherOp = (CancelableOperation) op; - for (Iterator it = new OperationsBackwardWithSentinel(); it.hasNext(); ) { - CancelableOperation thisOp = (CancelableOperation) it.next(); + @Override + public void addOperation(CancelableOperation op) throws RepositoryException { + CancelableOperation otherOp = op; + for (OperationsBackwardWithSentinel it = new OperationsBackwardWithSentinel(); it.hasNext(); ) { + CancelableOperation thisOp = it.next(); switch (thisOp.cancel(otherOp)) { case CancelableOperation.CANCEL_THIS: it.remove(); @@ -165,8 +161,8 @@ // -----------------------------------------------------< private >--- - private class OperationsBackwardWithSentinel implements Iterator { - private final ListIterator it = operations.listIterator(operations.size()); + private class OperationsBackwardWithSentinel implements Iterator { + private final ListIterator it = operations.listIterator(operations.size()); private boolean last = !it.hasPrevious(); private boolean done; @@ -174,13 +170,13 @@ return it.hasPrevious() || last; } - public Object next() { + public CancelableOperation next() { if (last) { done = true; return CancelableOperations.empty(); } else { - Object o = it.previous(); + CancelableOperation o = it.previous(); last = !it.hasPrevious(); return o; } Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/Operations.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/Operations.java?rev=812570&r1=812569&r2=812570&view=diff ============================================================================== --- jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/Operations.java (original) +++ jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/Operations.java Tue Sep 8 16:09:28 2009 @@ -56,10 +56,12 @@ */ public void apply(Batch batch) throws RepositoryException { /* nothing to do */ } + @Override public String toString() { return "Empty[]"; } + @Override public boolean equals(Object other) { if (null == other) { return false; @@ -67,6 +69,7 @@ return other instanceof Empty; } + @Override public int hashCode() { return Empty.class.hashCode(); } @@ -115,10 +118,12 @@ batch.addNode(parentId, nodeName, nodetypeName, uuid); } + @Override public String toString() { return "AddNode[" + parentId + ", " + nodeName + ", " + nodetypeName + ", " + uuid + "]"; } + @Override public boolean equals(Object other) { if (null == other) { return false; @@ -139,6 +144,7 @@ && Operations.equals(uuid, other.uuid); } + @Override public int hashCode() { return 41 * ( 41 * ( @@ -221,10 +227,12 @@ } } + @Override public String toString() { return "AddProperty[" + parentId + ", " + propertyName + ", " + values + "]"; } + @Override public boolean equals(Object other) { if (null == other) { return false; @@ -245,6 +253,7 @@ && Arrays.equals(values, other.values); } + @Override public int hashCode() { return 41 * ( 41 * ( @@ -312,10 +321,12 @@ batch.move(srcNodeId, destParentNodeId, destName); } + @Override public String toString() { return "Move[" + srcNodeId + ", " + destParentNodeId + ", " + destName + "]"; } + @Override public boolean equals(Object other) { if (null == other) { return false; @@ -335,6 +346,7 @@ && Operations.equals(destName, other.destName); } + @Override public int hashCode() { return 41 * ( 41 * ( @@ -383,10 +395,12 @@ batch.remove(itemId); } + @Override public String toString() { return "Remove[" + itemId + "]"; } + @Override public boolean equals(Object other) { if (null == other) { return false; @@ -404,6 +418,7 @@ return Operations.equals(itemId, other.itemId); } + @Override public int hashCode() { return 41 + Operations.hashCode(itemId); } @@ -452,10 +467,12 @@ batch.reorderNodes(parentId, srcNodeId, beforeNodeId); } + @Override public String toString() { return "ReorderNodes[" + parentId + ", " + srcNodeId + ", " + beforeNodeId + "]"; } + @Override public boolean equals(Object other) { if (null == other) { return false; @@ -475,6 +492,7 @@ && Operations.equals(beforeNodeId, other.beforeNodeId); } + @Override public int hashCode() { return 41 * ( 41 * ( @@ -526,10 +544,12 @@ batch.setMixins(nodeId, mixinNodeTypeNames); } + @Override public String toString() { return "SetMixins[" + nodeId + ", " + mixinNodeTypeNames + "]"; } + @Override public boolean equals(Object other) { if (null == other) { return false; @@ -548,6 +568,7 @@ && Arrays.equals(mixinNodeTypeNames, other.mixinNodeTypeNames); } + @Override public int hashCode() { return 41 * ( 41 + Operations.hashCode(nodeId)) @@ -596,10 +617,12 @@ batch.setPrimaryType(nodeId, primaryTypeName); } + @Override public String toString() { return "SetPrimaryType[" + nodeId + ", " + primaryTypeName + "]"; } + @Override public boolean equals(Object other) { if (null == other) { return false; @@ -618,6 +641,7 @@ && primaryTypeName.equals(other.primaryTypeName); } + @Override public int hashCode() { return 41 * ( 41 + Operations.hashCode(nodeId)) @@ -689,10 +713,12 @@ } } + @Override public String toString() { return "SetValue[" + propertyId + ", " + values + "]"; } + @Override public boolean equals(Object other) { if (null == other) { return false; @@ -712,6 +738,7 @@ && Arrays.equals(values, other.values); } + @Override public int hashCode() { return 41 * ( 41 + Operations.hashCode(propertyId)) Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java?rev=812570&r1=812569&r2=812570&view=diff ============================================================================== --- jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java (original) +++ jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java Tue Sep 8 16:09:28 2009 @@ -109,8 +109,8 @@ }, "getQValueFactory()", new Object[]{}); } - public Map getRepositoryDescriptors() throws RepositoryException { - return (Map) execute(new Callable() { + public Map getRepositoryDescriptors() throws RepositoryException { + return (Map) execute(new Callable() { public Object call() throws RepositoryException { return service.getRepositoryDescriptors(); } @@ -398,6 +398,17 @@ }, "checkout(SessionInfo, NodeId)", new Object[]{unwrap(sessionInfo), nodeId}); } + public void checkout(final SessionInfo sessionInfo, final NodeId nodeId, final NodeId activityId) + throws RepositoryException { + + execute(new Callable() { + public Object call() throws RepositoryException { + service.checkout(unwrap(sessionInfo), nodeId, activityId); + return null; + } + }, "checkout(SessionInfo, NodeId, NodeId)", new Object[]{unwrap(sessionInfo), nodeId, activityId}); + } + public NodeId checkpoint(final SessionInfo sessionInfo, final NodeId nodeId) throws UnsupportedRepositoryOperationException, RepositoryException { return (NodeId) execute(new Callable() { public Object call() throws RepositoryException { @@ -526,12 +537,12 @@ }, "mergeActivity(SessionInfo, NodeId)", new Object[]{unwrap(sessionInfo), activityId}); } - public NodeId createConfiguration(final SessionInfo sessionInfo, final NodeId nodeId, final NodeId baselineId) throws UnsupportedRepositoryOperationException, RepositoryException { + public NodeId createConfiguration(final SessionInfo sessionInfo, final NodeId nodeId) throws UnsupportedRepositoryOperationException, RepositoryException { return (NodeId) execute(new Callable() { public Object call() throws RepositoryException { - return service.createConfiguration(unwrap(sessionInfo), nodeId, baselineId); + return service.createConfiguration(unwrap(sessionInfo), nodeId); } - }, "createConfiguration(SessionInfo, NodeId, NodeId)", new Object[]{unwrap(sessionInfo), nodeId, baselineId}); + }, "createConfiguration(SessionInfo, NodeId, NodeId)", new Object[]{unwrap(sessionInfo), nodeId}); } public String[] getSupportedQueryLanguages(final SessionInfo sessionInfo) throws RepositoryException { Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameConstants.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameConstants.java?rev=812570&r1=812569&r2=812570&view=diff ============================================================================== --- jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameConstants.java (original) +++ jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameConstants.java Tue Sep 8 16:09:28 2009 @@ -283,6 +283,18 @@ */ public static final Name JCR_ACTIVITY_TITLE = FACTORY.create(Name.NS_JCR_URI, "activityTitle"); + /** + * jcr:configurations + * @since 2.0 + */ + public static final Name JCR_CONFIGURATIONS = FACTORY.create(Name.NS_JCR_URI, "configurations"); + + /** + * jcr:configuration + * @since 2.0 + */ + public static final Name JCR_CONFIGURATION = FACTORY.create(Name.NS_JCR_URI, "configuration"); + //--------------------------------< node type related item name constants > @@ -543,6 +555,12 @@ */ public static final Name NT_ACTIVITY = FACTORY.create(Name.NS_NT_URI, "activity"); + /** + * nt:configuration + * @since 2.0 + */ + public static final Name NT_CONFIGURATION = FACTORY.create(Name.NS_NT_URI, "configuration"); + //-------------------------------------------------------------------------- /** * rep:root @@ -560,12 +578,22 @@ public static final Name REP_VERSIONSTORAGE = FACTORY.create(Name.NS_REP_URI, "versionStorage"); /** - * rep:activities + * rep:Activities + */ + public static final Name REP_ACTIVITIES = FACTORY.create(Name.NS_REP_URI, "Activities"); + + /** + * rep:Configurations + */ + public static final Name REP_CONFIGURATIONS = FACTORY.create(Name.NS_REP_URI, "Configurations"); + + /** + * rep:baseVersions */ - public static final Name REP_ACTIVITIES = FACTORY.create(Name.NS_REP_URI, "activities"); + public static final Name REP_BASEVERSIONS = FACTORY.create(Name.NS_REP_URI, "baseVersions"); /** - * rep:versionReference + * rep:VersionReference */ public static final Name REP_VERSION_REFERENCE = FACTORY.create(Name.NS_REP_URI, "VersionReference"); Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathMap.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathMap.java?rev=812570&r1=812569&r2=812570&view=diff ============================================================================== --- jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathMap.java (original) +++ jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathMap.java Tue Sep 8 16:09:28 2009 @@ -21,6 +21,7 @@ import org.apache.jackrabbit.spi.PathFactory; import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException; +import java.util.List; import java.util.Map; import java.util.ArrayList; import java.util.HashMap; @@ -31,14 +32,15 @@ * Generic path map that associates information with the individual path elements * of a path. */ -public class PathMap { +public class PathMap { private static final PathFactory PATH_FACTORY = PathFactoryImpl.getInstance(); /** * Root element */ - private final Element root = new Element(PATH_FACTORY.getRootPath().getNameElement()); + private final Element root = + new Element(PATH_FACTORY.getRootPath().getNameElement()); /** * Map a path to a child. If exact is false, @@ -48,12 +50,12 @@ * @return child, maybe null if exact is * true */ - public Element map(Path path, boolean exact) { + public Element map(Path path, boolean exact) { Path.Element[] elements = path.getElements(); - Element current = root; + Element current = root; for (int i = 1; i < elements.length; i++) { - Element next = current.getChild(elements[i]); + Element next = current.getChild(elements[i]); if (next == null) { if (exact) { return null; @@ -71,8 +73,8 @@ * @param path path to child * @param obj object to store at destination */ - public Element put(Path path, Object obj) { - Element element = put(path); + public Element put(Path path, T obj) { + Element element = put(path); element.obj = obj; return element; } @@ -83,12 +85,12 @@ * @param path path to child * @param element element to store at destination */ - public void put(Path path, Element element) { + public void put(Path path, Element element) { Path.Element[] elements = path.getElements(); - Element current = root; + Element current = root; for (int i = 1; i < elements.length - 1; i++) { - Element next = current.getChild(elements[i]); + Element next = current.getChild(elements[i]); if (next == null) { next = current.createChild(elements[i]); } @@ -101,12 +103,12 @@ * Create an empty child given by its path. * @param path path to child */ - public Element put(Path path) { + public Element put(Path path) { Path.Element[] elements = path.getElements(); - Element current = root; + Element current = root; for (int i = 1; i < elements.length; i++) { - Element next = current.getChild(elements[i]); + Element next = current.getChild(elements[i]); if (next == null) { next = current.createChild(elements[i]); } @@ -123,7 +125,7 @@ * or not; otherwise call back on non-empty children * only */ - public void traverse(ElementVisitor visitor, boolean includeEmpty) { + public void traverse(ElementVisitor visitor, boolean includeEmpty) { root.traverse(visitor, includeEmpty); } @@ -131,17 +133,17 @@ * Internal class holding the object associated with a certain * path element. */ - public final static class Element { + public final static class Element { /** * Parent element */ - private Element parent; + private Element parent; /** * Map of immediate children */ - private Map children; + private Map>> children; /** * Number of non-empty children @@ -151,7 +153,7 @@ /** * Object associated with this element */ - private Object obj; + private T obj; /** * Path.Element suitable for path construction associated with this @@ -185,8 +187,8 @@ * @param nameIndex position where child is created * @return child */ - private Element createChild(Path.Element nameIndex) { - Element element = new Element(nameIndex); + private Element createChild(Path.Element nameIndex) { + Element element = new Element(nameIndex); put(nameIndex, element); return element; } @@ -214,10 +216,10 @@ // convert 1-based index value to 0-base value int index = getZeroBasedIndex(nameIndex); if (children != null) { - ArrayList list = (ArrayList) children.get(nameIndex.getName()); + List> list = children.get(nameIndex.getName()); if (list != null && list.size() > index) { for (int i = index; i < list.size(); i++) { - Element element = (Element) list.get(i); + Element element = list.get(i); if (element != null) { element.index = element.getNormalizedIndex() + 1; element.updatePathElement(element.getName(), element.index); @@ -234,15 +236,15 @@ * @return element matching nameIndex or null if * none exists. */ - private Element getChild(Path.Element nameIndex) { + private Element getChild(Path.Element nameIndex) { // convert 1-based index value to 0-base value int index = getZeroBasedIndex(nameIndex); - Element element = null; + Element element = null; if (children != null) { - ArrayList list = (ArrayList) children.get(nameIndex.getName()); + List> list = children.get(nameIndex.getName()); if (list != null && list.size() > index) { - element = (Element) list.get(index); + element = list.get(index); } } return element; @@ -253,15 +255,15 @@ * @param nameIndex position where child should be located * @param element element to add */ - public void put(Path.Element nameIndex, Element element) { + public void put(Path.Element nameIndex, Element element) { // convert 1-based index value to 0-base value int index = getZeroBasedIndex(nameIndex); if (children == null) { - children = new HashMap(); + children = new HashMap>>(); } - ArrayList list = (ArrayList) children.get(nameIndex.getName()); + List> list = children.get(nameIndex.getName()); if (list == null) { - list = new ArrayList(); + list = new ArrayList>(); children.put(nameIndex.getName(), list); } while (list.size() < index) { @@ -289,7 +291,7 @@ * @param nameIndex child's path element * @return removed child, may be null */ - public Element remove(Path.Element nameIndex) { + public Element remove(Path.Element nameIndex) { return remove(nameIndex, true, true); } @@ -309,7 +311,7 @@ * an element * @return removed child, may be null */ - private Element remove(Path.Element nameIndex, boolean shift, + private Element remove(Path.Element nameIndex, boolean shift, boolean removeIfEmpty) { // convert 1-based index value to 0-base value @@ -317,14 +319,14 @@ if (children == null) { return null; } - ArrayList list = (ArrayList) children.get(nameIndex.getName()); + List> list = children.get(nameIndex.getName()); if (list == null || list.size() <= index) { return null; } - Element element = (Element) list.set(index, null); + Element element = list.set(index, null); if (shift) { for (int i = index + 1; i < list.size(); i++) { - Element sibling = (Element) list.get(i); + Element sibling = list.get(i); if (sibling != null) { sibling.index--; sibling.updatePathElement(sibling.getName(), sibling.index); @@ -386,19 +388,14 @@ * Path.PathElement and values * are of type Element */ - public void setChildren(Map children) { + public void setChildren(Map> children) { // Remove all children without removing the element itself this.children = null; childrenCount = 0; // Now add back all items - Iterator entries = children.entrySet().iterator(); - while (entries.hasNext()) { - Map.Entry entry = (Map.Entry) entries.next(); - - Path.Element nameIndex = (Path.Element) entry.getKey(); - Element element = (Element) entry.getValue(); - put(nameIndex, element); + for (Map.Entry> entry : children.entrySet()) { + put(entry.getKey(), entry.getValue()); } // Special case: if map was empty, handle like removeAll() @@ -411,7 +408,7 @@ * Return the object associated with this element * @return object associated with this element */ - public Object get() { + public T get() { return obj; } @@ -419,7 +416,7 @@ * Set the object associated with this element * @param obj object associated with this element */ - public void set(Object obj) { + public void set(T obj) { this.obj = obj; if (obj == null && childrenCount == 0 && parent != null) { @@ -542,16 +539,13 @@ * element regardless, whether the associated object is empty * or not; otherwise call back on non-empty children only */ - public void traverse(ElementVisitor visitor, boolean includeEmpty) { + public void traverse(ElementVisitor visitor, boolean includeEmpty) { if (includeEmpty || obj != null) { visitor.elementVisited(this); } if (children != null) { - Iterator iter = children.values().iterator(); - while (iter.hasNext()) { - ArrayList list = (ArrayList) iter.next(); - for (int i = 0; i < list.size(); i++) { - Element element = (Element) list.get(i); + for (List>list : children.values()) { + for (Element element : list) { if (element != null) { element.traverse(visitor, includeEmpty); } @@ -578,8 +572,8 @@ * child of this node. * @param other node to check */ - public boolean isAncestorOf(Element other) { - Element parent = other.parent; + public boolean isAncestorOf(Element other) { + Element parent = other.parent; while (parent != null) { if (parent == this) { return true; @@ -593,7 +587,7 @@ * Return the parent of this element * @return parent or null if this is the root element */ - public Element getParent() { + public Element getParent() { return parent; } @@ -609,15 +603,11 @@ * Return an iterator over all of this element's children. Every * element returned by this iterator is of type {@link Element}. */ - public Iterator getChildren() { - ArrayList result = new ArrayList(); - + public Iterator> getChildren() { + ArrayList> result = new ArrayList>(); if (children != null) { - Iterator iter = children.values().iterator(); - while (iter.hasNext()) { - ArrayList list = (ArrayList) iter.next(); - for (int i = 0; i < list.size(); i++) { - Element element = (Element) list.get(i); + for (List> list : children.values()) { + for (Element element : list) { if (element != null) { result.add(element); } @@ -637,12 +627,12 @@ * @return descendant, maybe null if exact is * true */ - public Element getDescendant(Path relPath, boolean exact) { + public Element getDescendant(Path relPath, boolean exact) { Path.Element[] elements = relPath.getElements(); - Element current = this; + Element current = this; for (int i = 0; i < elements.length; i++) { - Element next = current.getChild(elements[i]); + Element next = current.getChild(elements[i]); if (next == null) { if (exact) { return null; @@ -658,12 +648,12 @@ /** * Element visitor used in {@link PathMap#traverse} */ - public interface ElementVisitor { + public interface ElementVisitor { /** * Invoked for every element visited on a tree traversal * @param element element visited */ - void elementVisited(Element element); + void elementVisited(Element element); } } Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/AbstractItemDefinitionTemplate.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/AbstractItemDefinitionTemplate.java?rev=812570&r1=812569&r2=812570&view=diff ============================================================================== --- jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/AbstractItemDefinitionTemplate.java (original) +++ jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/AbstractItemDefinitionTemplate.java Tue Sep 8 16:09:28 2009 @@ -16,8 +16,18 @@ */ package org.apache.jackrabbit.spi.commons.nodetype; +import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver; +import org.apache.jackrabbit.spi.commons.name.NameConstants; +import org.apache.jackrabbit.spi.Name; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import javax.jcr.nodetype.ItemDefinition; import javax.jcr.nodetype.NodeType; +import javax.jcr.nodetype.ConstraintViolationException; +import javax.jcr.RepositoryException; +import javax.jcr.NamespaceException; +import javax.jcr.version.OnParentVersionAction; /** * AbstractItemDefinitionTemplate serves as base class for @@ -26,25 +36,40 @@ */ abstract class AbstractItemDefinitionTemplate implements ItemDefinition { - private String name; + private static final Logger log = LoggerFactory.getLogger(AbstractItemDefinitionTemplate.class); + + private Name name; private boolean autoCreated; private boolean mandatory; - private int opv; + private int opv = OnParentVersionAction.COPY; private boolean protectedStatus; + protected final NamePathResolver resolver; + /** * Package private constructor + * + * @param resolver */ - AbstractItemDefinitionTemplate() { + AbstractItemDefinitionTemplate(NamePathResolver resolver) { + this.resolver = resolver; } /** * Package private constructor * * @param def + * @param resolver + * @throws javax.jcr.nodetype.ConstraintViolationException */ - AbstractItemDefinitionTemplate(ItemDefinition def) { - name = def.getName(); + AbstractItemDefinitionTemplate(ItemDefinition def, NamePathResolver resolver) throws ConstraintViolationException { + this.resolver = resolver; + + if (def instanceof ItemDefinitionImpl) { + name = ((ItemDefinitionImpl) def).itemDef.getName(); + } else { + setName(def.getName()); + } autoCreated = def.isAutoCreated(); mandatory = def.isMandatory(); opv = def.getOnParentVersion(); @@ -56,9 +81,20 @@ * Sets the name of the child item. * * @param name a String. + * @throws ConstraintViolationException */ - public void setName(String name) { - this.name = name; + public void setName(String name) throws ConstraintViolationException { + if (ItemDefinitionImpl.ANY_NAME.equals(name)) { + // handle the * special case that isn't a valid JCR name but a valid + // name for a ItemDefinition (residual). + this.name = NameConstants.ANY_NAME; + } else { + try { + this.name = resolver.getQName(name); + } catch (RepositoryException e) { + throw new ConstraintViolationException(e); + } + } } /** @@ -83,8 +119,11 @@ * Sets the on-parent-version status of the child item. * * @param opv an int constant member of OnParentVersionAction. + * @throws IllegalArgumentException If the given opv flag isn't valid. */ public void setOnParentVersion(int opv) { + // validate the given opv-action + OnParentVersionAction.nameFromValue(opv); this.opv = opv; } @@ -102,7 +141,17 @@ * {@inheritDoc} */ public String getName() { - return name; + if (name == null) { + return null; + } else { + try { + return resolver.getJCRName(name); + } catch (NamespaceException e) { + // should never get here + log.error("encountered unregistered namespace in item definition name", e); + return name.toString(); + } + } } /** @@ -139,5 +188,4 @@ public boolean isProtected() { return protectedStatus; } - } Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/AbstractNodeTypeManager.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/AbstractNodeTypeManager.java?rev=812570&r1=812569&r2=812570&view=diff ============================================================================== --- jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/AbstractNodeTypeManager.java (original) +++ jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/AbstractNodeTypeManager.java Tue Sep 8 16:09:28 2009 @@ -19,6 +19,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.jackrabbit.spi.Name; +import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver; import javax.jcr.nodetype.NodeTypeManager; import javax.jcr.nodetype.NodeTypeTemplate; @@ -50,13 +51,22 @@ */ public abstract NodeType getNodeType(Name ntName) throws NoSuchNodeTypeException; + /** + * Returns the NamePathResolver used to validate JCR names. + * + * @return the NamePathResolver used to convert JCR names/paths to internal + * onces and vice versa. The resolver may also be used to validate names + * passed to the various templates. + */ + public abstract NamePathResolver getNamePathResolver(); + //----------------------------------------------------< NodeTypeManager >--- /** * @see javax.jcr.nodetype.NodeTypeManager#createNodeTypeTemplate() */ public NodeTypeTemplate createNodeTypeTemplate() throws UnsupportedRepositoryOperationException, RepositoryException { - return new NodeTypeTemplateImpl(); + return new NodeTypeTemplateImpl(getNamePathResolver()); } /** @@ -64,7 +74,7 @@ */ public NodeTypeTemplate createNodeTypeTemplate(NodeTypeDefinition ntd) throws UnsupportedRepositoryOperationException, RepositoryException { - return new NodeTypeTemplateImpl(ntd); + return new NodeTypeTemplateImpl(ntd, getNamePathResolver()); } /** @@ -72,7 +82,7 @@ */ public NodeDefinitionTemplate createNodeDefinitionTemplate() throws UnsupportedRepositoryOperationException, RepositoryException { - return new NodeDefinitionTemplateImpl(getNodeType(NodeType.NT_BASE)); + return new NodeDefinitionTemplateImpl(getNamePathResolver()); } /** @@ -80,7 +90,7 @@ */ public PropertyDefinitionTemplate createPropertyDefinitionTemplate() throws UnsupportedRepositoryOperationException, RepositoryException { - return new PropertyDefinitionTemplateImpl(); + return new PropertyDefinitionTemplateImpl(getNamePathResolver()); } /**