[exo-jcr-commits] exo-jcr SVN: r2727 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core: version and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Jul 1 02:53:54 EDT 2010


Author: nzamosenchuk
Date: 2010-07-01 02:53:53 -0400 (Thu, 01 Jul 2010)
New Revision: 2727

Modified:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionImpl.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/VersionHistoryImpl.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/VersionImpl.java
Log:
EXOJCR-768: Checks added in ItemImpl and it's descendants, also sessionImpl.

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java	2010-06-30 13:23:12 UTC (rev 2726)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java	2010-07-01 06:53:53 UTC (rev 2727)
@@ -191,6 +191,7 @@
     */
    public Item getAncestor(int degree) throws ItemNotFoundException, AccessDeniedException, RepositoryException
    {
+      checkValid();
       try
       {
          // 6.2.8 If depth > n is specified then an ItemNotFoundException is
@@ -789,6 +790,7 @@
     */
    public NodeData parentData() throws RepositoryException
    {
+      checkValid();
       NodeData parent = (NodeData)dataManager.getItemData(getData().getParentIdentifier());
       if (parent == null)
       {
@@ -873,6 +875,7 @@
 
    public boolean hasPermission(String action) throws RepositoryException
    {
+      checkValid();
       NodeData ndata;
       if (isNode())
       {

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java	2010-06-30 13:23:12 UTC (rev 2726)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java	2010-07-01 06:53:53 UTC (rev 2727)
@@ -190,7 +190,9 @@
       checkValid();
 
       if (LOG.isDebugEnabled())
+      {
          LOG.debug("Node.addMixin " + mixinName + " " + getPath());
+      }
 
       InternalQName name = locationFactory.parseJCRName(mixinName).getInternalName();
 
@@ -209,23 +211,33 @@
 
       // Mixin or not
       if (type == null || !type.isMixin())
+      {
          throw new NoSuchNodeTypeException("Nodetype " + mixinName + " not found or not mixin type.");
+      }
 
       // Validate
       if (session.getWorkspace().getNodeTypesHolder().isNodeType(type.getName(), nodeData().getPrimaryTypeName(),
          nodeData().getMixinTypeNames()))
+      {
          throw new ConstraintViolationException("Can not add mixin type " + mixinName + " to " + getPath());
+      }
 
       if (definition.isProtected())
+      {
          throw new ConstraintViolationException("Can not add mixin type. Node is protected " + getPath());
+      }
 
       // Check if versionable ancestor is not checked-in
       if (!checkedOut())
+      {
          throw new VersionException("Node " + getPath() + " or its nearest ancestor is checked-in");
+      }
 
       // Check locking
       if (!checkLocking())
+      {
          throw new LockException("Node " + getPath() + " is locked ");
+      }
 
       doAddMixin(type);
    }
@@ -239,23 +251,31 @@
 
       checkValid();
       if (JCRPath.THIS_RELPATH.equals(relPath))
+      {
          throw new RepositoryException("Can't add node to the path '" + relPath + "'");
+      }
 
       // Parent can be not the same as this node
       JCRPath itemPath = locationFactory.parseRelPath(relPath);
 
       // Check if there no final index
       if (itemPath.isIndexSetExplicitly())
+      {
          throw new RepositoryException("The relPath provided must not have an index on its final element. "
             + itemPath.getAsString(false));
+      }
 
       ItemImpl parentItem =
          dataManager.getItem(nodeData(), itemPath.makeParentPath().getInternalPath().getEntries(), false);
 
       if (parentItem == null)
+      {
          throw new PathNotFoundException("Parent not found for " + itemPath.getAsString(true));
+      }
       if (!parentItem.isNode())
+      {
          throw new ConstraintViolationException("Parent item is not a node " + parentItem.getPath());
+      }
 
       NodeImpl parent = (NodeImpl)parentItem;
       InternalQName name = itemPath.getName().getInternalName();
@@ -266,12 +286,15 @@
             nodeData().getMixinTypeNames());
 
       if (nodeDef == null)
+      {
          throw new ConstraintViolationException("Can not define node type for " + name.getAsString());
+      }
       InternalQName primaryTypeName = nodeDef.getName();
 
       if (nodeDef.getName().equals(name) || primaryTypeName.equals(Constants.JCR_ANY_NAME))
-
+      {
          primaryTypeName = nodeDef.getDefaultPrimaryType();
+      }
       // try to make new node
       return doAddNode(parent, name, primaryTypeName);
 
@@ -287,23 +310,31 @@
       checkValid();
 
       if (JCRPath.THIS_RELPATH.equals(relPath))
+      {
          throw new RepositoryException("Can't add node to the path '" + relPath + "'");
+      }
 
       // Parent can be not the same as this node
       JCRPath itemPath = locationFactory.parseRelPath(relPath);
 
       // Check if there no final index
       if (itemPath.isIndexSetExplicitly())
+      {
          throw new RepositoryException("The relPath provided must not have an index on its final element. "
             + itemPath.getAsString(false));
+      }
 
       ItemImpl parentItem =
          dataManager.getItem(nodeData(), itemPath.makeParentPath().getInternalPath().getEntries(), false);
 
       if (parentItem == null)
+      {
          throw new PathNotFoundException("Parent not found for " + itemPath.getAsString(true));
+      }
       if (!parentItem.isNode())
+      {
          throw new ConstraintViolationException("Parent item is not a node " + parentItem.getPath());
+      }
       NodeImpl parent = (NodeImpl)parentItem;
 
       InternalQName name = itemPath.getName().getInternalName();
@@ -326,20 +357,30 @@
             locationFactory.parseJCRName(mixinName).getInternalName());
 
       if (type == null)
+      {
          throw new NoSuchNodeTypeException("Nodetype not found (mixin) " + mixinName);
+      }
 
       if (session.getWorkspace().getNodeTypesHolder().isNodeType(type.getName(), nodeData().getPrimaryTypeName(),
          nodeData().getMixinTypeNames()))
+      {
          return false;
+      }
 
       if (definition.isProtected())
+      {
          return false;
+      }
 
       if (!checkedOut())
+      {
          return false;
+      }
 
       if (!checkLocking())
+      {
          return false;
+      }
 
       return true;
    }
@@ -371,7 +412,7 @@
     */
    public boolean checkedOut() throws UnsupportedRepositoryOperationException, RepositoryException
    {
-
+      // this will also check if item is valid
       NodeData vancestor = getVersionableAncestor();
       if (vancestor != null)
       {
@@ -401,8 +442,10 @@
       checkValid();
 
       if (!this.isNodeType(Constants.MIX_VERSIONABLE))
+      {
          throw new UnsupportedRepositoryOperationException(
             "Node.checkin() is not supported for not mix:versionable node ");
+      }
 
       if (!this.checkedOut())
       {
@@ -410,13 +453,19 @@
       }
 
       if (session.getTransientNodesManager().hasPendingChanges(getInternalPath()))
+      {
          throw new InvalidItemStateException("Node has pending changes " + getPath());
+      }
 
       if (hasProperty(Constants.JCR_MERGEFAILED))
+      {
          throw new VersionException("Node has jcr:mergeFailed " + getPath());
+      }
 
       if (!parent().checkLocking())
+      {
          throw new LockException("Node " + parent().getPath() + " is locked ");
+      }
 
       // the new version identifier
       String verIdentifier = IdGenerator.generate();
@@ -452,11 +501,15 @@
       checkValid();
 
       if (!this.isNodeType(Constants.MIX_VERSIONABLE))
+      {
          throw new UnsupportedRepositoryOperationException(
             "Node.checkout() is not supported for not mix:versionable node ");
+      }
 
       if (checkedOut())
+      {
          return;
+      }
 
       SessionChangesLog changesLog = new SessionChangesLog(session.getId());
 
@@ -493,10 +546,11 @@
     */
    public void clearACL() throws RepositoryException, AccessControlException
    {
-
       if (!isNodeType(Constants.EXO_PRIVILEGEABLE))
+      {
          throw new AccessControlException("Node is not exo:privilegeable " + getPath());
-
+      }
+      // this will also check if item is valid
       checkPermission(PermissionType.CHANGE_PERMISSION);
 
       List<AccessControlEntry> aces = new ArrayList<AccessControlEntry>();
@@ -526,7 +580,7 @@
     * @throws RepositoryException
     *           if any other error occurs
     */
-   public void doAddMixin(NodeTypeData type) throws NoSuchNodeTypeException, ConstraintViolationException,
+   private void doAddMixin(NodeTypeData type) throws NoSuchNodeTypeException, ConstraintViolationException,
       VersionException, LockException, RepositoryException
    {
 
@@ -598,7 +652,9 @@
       session.getActionHandler().postAddMixin(this, type.getName());
 
       if (LOG.isDebugEnabled())
+      {
          LOG.debug("Node.addMixin Property " + prop.getQPath().getAsString() + " values " + mixinTypes.length);
+      }
    }
 
    /**
@@ -625,7 +681,9 @@
          NodeImpl otherNode = (NodeImpl)obj;
 
          if (!otherNode.isValid() || !this.isValid())
+         {
             return false;
+         }
 
          try
          {
@@ -674,7 +732,9 @@
       checkValid();
 
       if (!this.isNodeType(Constants.MIX_VERSIONABLE))
+      {
          throw new UnsupportedRepositoryOperationException("Node is not versionable " + getPath());
+      }
 
       PropertyData bvProp =
          (PropertyData)dataManager.getItemData(nodeData(), new QPathEntry(Constants.JCR_BASEVERSION, 1));
@@ -727,13 +787,17 @@
             {
                NodeData corrAncestor = (NodeData)corrDataManager.getItemData(ancestor.getIdentifier());
                if (corrAncestor == null)
+               {
                   throw new ItemNotFoundException("No corresponding path for ancestor "
                      + ancestor.getQPath().getAsString() + " in " + corrSession.getWorkspace().getName());
+               }
 
                NodeData corrNode =
                   (NodeData)corrDataManager.getItemData(corrAncestor, myPath.getRelPath(myPath.getDepth() - i));
                if (corrNode != null)
+               {
                   return corrNode;
+               }
             }
          }
       }
@@ -1051,7 +1115,9 @@
          {
             Item primaryItem = dataManager.getItem(nodeData(), new QPathEntry(ntData.getPrimaryItemName(), 0), true);
             if (primaryItem != null)
+            {
                return primaryItem;
+            }
 
          }
       }
@@ -1078,7 +1144,9 @@
 
       long start = System.currentTimeMillis();
       if (LOG.isDebugEnabled())
+      {
          LOG.debug("getProperties() >>>>>");
+      }
 
       checkValid();
 
@@ -1193,11 +1261,15 @@
       JCRPath itemPath = locationFactory.parseRelPath(relPath);
 
       if (LOG.isDebugEnabled())
+      {
          LOG.debug("getProperty() " + getLocation().getAsString(false) + " " + relPath);
+      }
 
       ItemImpl prop = dataManager.getItem(nodeData(), itemPath.getInternalPath().getEntries(), true);
       if (prop == null || prop.isNode())
+      {
          throw new PathNotFoundException("Property not found " + itemPath.getAsString(false));
+      }
 
       return (Property)prop;
    }
@@ -1240,6 +1312,7 @@
     */
    public NodeData getVersionableAncestor() throws RepositoryException
    {
+      checkValid();
       NodeData node = nodeData();
       NodeTypeDataManager ntman = session.getWorkspace().getNodeTypesHolder();
 
@@ -1255,11 +1328,15 @@
             // check on deeper ancestor
             NodeData ancestor = (NodeData)dataManager.getItemData(node.getParentIdentifier());
             if (ancestor == null)
+            {
                throw new RepositoryException("Parent not found for "
                   + locationFactory.createJCRPath(node.getQPath()).getAsString(false) + ". Parent id "
                   + node.getParentIdentifier());
+            }
             else
+            {
                node = ancestor;
+            }
          }
       }
 
@@ -1407,6 +1484,7 @@
    /**
     * {@inheritDoc}
     */
+   @Override
    public void loadData(ItemData data, NodeData parent) throws RepositoryException, InvalidItemStateException,
       ConstraintViolationException
    {
@@ -1484,6 +1562,7 @@
    /**
     * {@inheritDoc}
     */
+   @Override
    public ItemDefinitionData getItemDefinitionData()
    {
       return definition;
@@ -1499,10 +1578,14 @@
       checkValid();
 
       if (!isNodeType(Constants.MIX_LOCKABLE))
+      {
          throw new LockException("Node is not lockable " + getPath());
+      }
 
       if (dataManager.hasPendingChanges(getInternalPath()))
+      {
          throw new InvalidItemStateException("Node has pending unsaved changes " + getPath());
+      }
 
       Lock newLock = session.getLockManager().addLock(this, isDeep, isSessionScoped, -1);
 
@@ -1535,10 +1618,14 @@
       checkValid();
 
       if (!isNodeType(Constants.MIX_LOCKABLE))
+      {
          throw new LockException("Node is not lockable " + getPath());
+      }
 
       if (dataManager.hasPendingChanges(getInternalPath()))
+      {
          throw new InvalidItemStateException("Node has pending unsaved changes " + getPath());
+      }
 
       Lock newLock = session.getLockManager().addLock(this, isDeep, false, timeOut);
 
@@ -1572,7 +1659,9 @@
       checkValid();
 
       if (session.hasPendingChanges())
+      {
          throw new InvalidItemStateException("Session has pending changes ");
+      }
 
       Map<String, String> failed = new HashMap<String, String>();
 
@@ -1588,7 +1677,9 @@
       EntityCollection failedIter = createMergeFailed(failed, changes);
 
       if (changes.getSize() > 0)
+      {
          dataManager.getTransactManager().save(changes);
+      }
 
       return failedIter;
    }
@@ -1603,8 +1694,10 @@
       checkValid();
 
       if (!getPrimaryNodeType().hasOrderableChildNodes())
+      {
          throw new UnsupportedRepositoryOperationException("Node does not support child ordering "
             + getPrimaryNodeType().getName());
+      }
 
       JCRPath sourcePath = locationFactory.createJCRPath(getLocation(), srcName);
       JCRPath destenationPath = destName != null ? locationFactory.createJCRPath(getLocation(), destName) : null;
@@ -1647,7 +1740,9 @@
 
       // no mixin found
       if (removedName == null)
+      {
          throw new NoSuchNodeTypeException("No mixin type found " + mixinName + " for node " + getPath());
+      }
 
       // A ConstraintViolationException will be thrown either
       // immediately or on save if the removal of a mixin is not
@@ -1701,8 +1796,10 @@
       {
          ItemData p = dataManager.getItemData(nodeData(), new QPathEntry(pd.getName(), 1));
          if (p != null && !p.isNode())
+         {
             // remove it
             dataManager.delete(p, ancestorToSave);
+         }
       }
 
       for (NodeDefinitionData nd : ntmanager.getAllChildNodeDefinitions(removedName))
@@ -1760,7 +1857,9 @@
       checkValid();
 
       if (!isNodeType(Constants.EXO_PRIVILEGEABLE))
+      {
          throw new AccessControlException("Node is not exo:privilegeable " + getPath());
+      }
 
       checkPermission(PermissionType.CHANGE_PERMISSION);
 
@@ -1791,20 +1890,30 @@
       checkValid();
 
       if (!this.isNodeType(Constants.MIX_VERSIONABLE))
+      {
          throw new UnsupportedRepositoryOperationException("Node is not versionable " + getPath());
+      }
 
       if (session.hasPendingChanges())
+      {
          throw new InvalidItemStateException("Session has pending changes ");
+      }
 
       if (((VersionImpl)version).getInternalName().equals(Constants.JCR_ROOTVERSION))
+      {
          throw new VersionException("It is illegal to call restore() on jcr:rootVersion");
+      }
 
       if (!versionHistory(false).isVersionBelongToThis(version))
+      {
          throw new VersionException("Bad version " + version.getPath());
+      }
 
       // Check locking
       if (!checkLocking())
+      {
          throw new LockException("Node " + getPath() + " is locked ");
+      }
 
       NodeData destParent = (NodeData)dataManager.getItemData(nodeData().getParentIdentifier());
       ((VersionImpl)version).restore(this.getSession(), destParent, nodeData().getQPath().getName(), removeExisting);
@@ -1831,18 +1940,26 @@
          checkValid();
 
          if (session.hasPendingChanges())
+         {
             throw new InvalidItemStateException("Session has pending changes ");
+         }
 
          if (((VersionImpl)version).getInternalName().equals(Constants.JCR_ROOTVERSION))
+         {
             throw new VersionException("It is illegal to call restore() on jcr:rootVersion");
+         }
 
          QPath destPath = locationFactory.parseRelPath(relPath).getInternalPath();
          NodeImpl destParent = (NodeImpl)dataManager.getItem(nodeData(), destPath.makeParentPath().getEntries(), false);
          if (destParent == null)
+         {
             throw new PathNotFoundException("Parent not found for " + relPath);
+         }
 
          if (!destParent.isNode())
+         {
             throw new ConstraintViolationException("Parent item is not a node. Rel path " + relPath);
+         }
 
          NodeImpl destNode =
             (NodeImpl)dataManager.getItem(destParent.nodeData(),
@@ -1853,25 +1970,35 @@
             // Dest node exists
 
             if (!destNode.isNode())
+            {
                throw new ConstraintViolationException("Item at relPath is not a node " + destNode.getPath());
+            }
 
             if (!destNode.isNodeType(Constants.MIX_VERSIONABLE))
+            {
                throw new UnsupportedRepositoryOperationException("Node at relPath is not versionable "
                   + destNode.getPath());
+            }
 
             if (!destNode.versionHistory(false).isVersionBelongToThis(version))
+            {
                throw new VersionException("Bad version " + version.getPath());
+            }
 
             // Check locking
             if (!destNode.parent().checkLocking())
+            {
                throw new LockException("Node " + destNode.getPath() + " is locked ");
+            }
          }
          else
          {
             // Dest node not found
             if (!destParent.checkedOut())
+            {
                throw new VersionException("Parent of a node at relPath is versionable and checked-in "
                   + destParent.getPath());
+            }
          }
 
          ((VersionImpl)version).restore(session, destParent.nodeData(), destPath.getName(), removeExisting);
@@ -1955,11 +2082,15 @@
       {
          String identity = i.next();
          if (identity == null)
+         {
             throw new RepositoryException("Identity cannot be null");
+         }
 
          String[] perm = (String[])permissions.get(identity);
          if (perm == null)
+         {
             throw new RepositoryException("Permissions cannot be null");
+         }
 
          for (int j = 0; j < perm.length; j++)
          {
@@ -2187,13 +2318,19 @@
       checkValid();
 
       if (!session.getLockManager().holdsLock((NodeData)this.getData()))
+      {
          throw new LockException("The node not locked " + getPath());
+      }
 
       if (!session.getLockManager().isLockHolder(this.nodeData()))
+      {
          throw new LockException("There are no permission to unlock the node " + getPath());
+      }
 
       if (dataManager.hasPendingChanges(getInternalPath()))
+      {
          throw new InvalidItemStateException("Node has pending unsaved changes " + getPath());
+      }
 
       doUnlock();
 
@@ -2211,11 +2348,15 @@
 
       // Check pending changes
       if (session.hasPendingChanges())
+      {
          throw new InvalidItemStateException("Session has pending changes ");
+      }
 
       // Check locking
       if (!checkLocking())
+      {
          throw new LockException("Node " + getPath() + " is locked ");
+      }
 
       SessionChangesLog changes = new SessionChangesLog(session.getId());
 
@@ -2257,12 +2398,16 @@
       NodeTypeDataManager nodeTypeDataManager = session.getWorkspace().getNodeTypesHolder();
       NodeTypeData nodeType = nodeTypeDataManager.getNodeType(primaryTypeName);
       if (nodeType == null)
+      {
          throw new NoSuchNodeTypeException("Nodetype not found "
             + sysLocFactory.createJCRName(primaryTypeName).getAsString());
+      }
 
       if (nodeType.isMixin())
+      {
          throw new ConstraintViolationException("Add Node failed, "
             + sysLocFactory.createJCRName(primaryTypeName).getAsString() + " is MIXIN type!");
+      }
 
       // Check if new node's node type is allowed by its parent definition
 
@@ -2279,20 +2424,28 @@
          session.getWorkspace().getNodeTypesHolder().getChildNodeDefinition(name, nodeData().getPrimaryTypeName(),
             nodeData().getMixinTypeNames());
       if (childNodeDefinition == null)
+      {
          throw new ConstraintViolationException("Can't find child node definition for "
             + sysLocFactory.createJCRName(name).getAsString() + " in " + getPath());
+      }
 
       if (childNodeDefinition.isProtected())
+      {
          throw new ConstraintViolationException("Can't add protected node "
             + sysLocFactory.createJCRName(name).getAsString() + " to " + getPath());
+      }
 
       // Check if versionable ancestor is not checked-in
       if (!checkedOut())
+      {
          throw new VersionException("Node " + getPath() + " or its nearest ancestor is checked-in");
+      }
 
       if (!checkLocking())
+      {
          // Check locking
          throw new LockException("Node " + getPath() + " is locked ");
+      }
 
    }
 
@@ -2320,7 +2473,9 @@
       PropertyData vhProp =
          (PropertyData)dataManager.getItemData(nodeData(), new QPathEntry(Constants.JCR_VERSIONHISTORY, 1));
       if (vhProp == null)
+      {
          throw new UnsupportedRepositoryOperationException("Node does not have jcr:versionHistory " + getPath());
+      }
 
       try
       {
@@ -2463,11 +2618,15 @@
 
          // calculating same name index
          if (sdata.getQPath().getName().getAsString().equals(srcPath.getName().getAsString()))
+         {
             ++sameNameIndex;
+         }
 
          // skeep unchanged
          if (sdata.getOrderNumber() == j)
+         {
             continue;
+         }
 
          NodeData newData = sdata;
          // change same name index
@@ -2557,7 +2716,9 @@
    {
       PropertyImpl prop = (PropertyImpl)dataManager.getItem(nodeData(), new QPathEntry(name, 1), false);
       if (prop == null || prop.isNode())
+      {
          throw new PathNotFoundException("Property not found " + name);
+      }
       return prop;
    }
 
@@ -2568,7 +2729,9 @@
          // locked, should be unlocked
 
          if (!session.getLockManager().isLockHolder(this.nodeData()))
+         {
             throw new LockException("There are no permission to unlock the node " + getPath());
+         }
 
          // remove mix:lockable properties (as the node is locked)
          doUnlock();
@@ -2606,8 +2769,10 @@
       PropertyData existed = (PropertyData)dataManager.getItemData(nodeData(), new QPathEntry(name, 0));
 
       if (existed == null)
+      {
          throw new RepositoryException("Property data is not found " + name.getAsString() + " for node "
             + nodeData().getQPath().getAsString());
+      }
 
       TransientPropertyData tdata =
          new TransientPropertyData(QPath.makeChildPath(getInternalPath(), name), existed.getIdentifier(), existed
@@ -2806,8 +2971,10 @@
       // addAutoCreatedItems(node.nodeData(), primaryTypeName);
 
       if (LOG.isDebugEnabled())
+      {
          LOG.debug("new node : " + node.getPath() + " name: " + " primaryType: " + node.getPrimaryNodeType().getName()
             + " index: " + node.getIndex() + " parent: " + parentNode);
+      }
 
       // launch event
       session.getActionHandler().postAddNode(node);
@@ -2822,7 +2989,9 @@
          ItemData pdata = dataManager.getItemData(nodeData(), new QPathEntry(name, 1));
 
          if (pdata != null && !pdata.isNode())
+         {
             return true;
+         }
       }
       catch (RepositoryException e)
       {
@@ -2837,7 +3006,9 @@
          (PropertyData)dataManager.getItemData(nodeData(), new QPathEntry(Constants.JCR_MERGEFAILED, 0));
 
       if (mergeFailed == null)
+      {
          return;
+      }
 
       List<ValueData> mf = new ArrayList<ValueData>();
       for (ValueData mfvd : mergeFailed.getValues())
@@ -3009,7 +3180,7 @@
             // check read conditions 
             if (canRead(item))
             {
-               next = (ItemImpl)session.getTransientNodesManager().readItem(item, nodeData(), true, false);
+               next = session.getTransientNodesManager().readItem(item, nodeData(), true, false);
             }
             else
             {

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionImpl.java	2010-06-30 13:23:12 UTC (rev 2726)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionImpl.java	2010-07-01 06:53:53 UTC (rev 2727)
@@ -49,6 +49,8 @@
 import org.exoplatform.services.jcr.impl.xml.importing.ContentImporter;
 import org.exoplatform.services.jcr.impl.xml.importing.StreamImporter;
 import org.exoplatform.services.jcr.util.IdGenerator;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
 import org.exoplatform.services.security.ConversationState;
 import org.exoplatform.services.security.Identity;
 import org.xml.sax.ContentHandler;
@@ -99,6 +101,11 @@
 public class SessionImpl implements ExtendedSession, NamespaceAccessor
 {
 
+   /**
+    * Logger.
+    */
+   private static Log log = ExoLogger.getLogger("exo.jcr.component.core.SessionImpl");
+
    public static final int DEFAULT_LAZY_READ_THRESHOLD = 100;
 
    private final RepositoryImpl repository;
@@ -216,13 +223,14 @@
     */
    public void checkPermission(String absPath, String actions) throws AccessControlException
    {
-
       try
       {
          JCRPath jcrPath = locationFactory.parseAbsPath(absPath);
          AccessControlList acl = dataManager.getACL(jcrPath.getInternalPath());
          if (!accessManager.hasPermission(acl, actions, getUserState().getIdentity()))
+         {
             throw new AccessControlException("Permission denied " + absPath + " : " + actions);
+         }
       }
       catch (RepositoryException e)
       {
@@ -237,6 +245,8 @@
       throws InvalidSerializedDataException, PathNotFoundException, SAXException, RepositoryException
    {
 
+      checkLive();
+      
       LocationFactory factory = new LocationFactory(((NamespaceRegistryImpl)repository.getNamespaceRegistry()));
 
       WorkspaceEntry wsConfig = (WorkspaceEntry)container.getComponentInstanceOfType(WorkspaceEntry.class);
@@ -276,6 +286,8 @@
       throws InvalidSerializedDataException, IOException, PathNotFoundException, RepositoryException
    {
 
+      checkLive();
+      
       LocationFactory factory = new LocationFactory(((NamespaceRegistryImpl)repository.getNamespaceRegistry()));
 
       WorkspaceEntry wsConfig = (WorkspaceEntry)container.getComponentInstanceOfType(WorkspaceEntry.class);
@@ -317,6 +329,9 @@
    public void exportWorkspaceSystemView(OutputStream out, boolean skipBinary, boolean noRecurse) throws IOException,
       PathNotFoundException, RepositoryException
    {
+      
+      checkLive();
+      
       LocationFactory factory = new LocationFactory(((NamespaceRegistryImpl)repository.getNamespaceRegistry()));
 
       WorkspaceEntry wsConfig = (WorkspaceEntry)container.getComponentInstanceOfType(WorkspaceEntry.class);
@@ -356,6 +371,9 @@
    public void exportSystemView(String absPath, ContentHandler contentHandler, boolean skipBinary, boolean noRecurse)
       throws PathNotFoundException, SAXException, RepositoryException
    {
+      
+      checkLive();
+      
       LocationFactory factory = new LocationFactory(((NamespaceRegistryImpl)repository.getNamespaceRegistry()));
 
       WorkspaceEntry wsConfig = (WorkspaceEntry)container.getComponentInstanceOfType(WorkspaceEntry.class);
@@ -392,6 +410,8 @@
    public void exportSystemView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse)
       throws IOException, PathNotFoundException, RepositoryException
    {
+      checkLive();
+      
       LocationFactory factory = new LocationFactory(((NamespaceRegistryImpl)repository.getNamespaceRegistry()));
 
       WorkspaceEntry wsConfig = (WorkspaceEntry)container.getComponentInstanceOfType(WorkspaceEntry.class);
@@ -466,7 +486,9 @@
       String[] names = new String[attributes.size()];
       int i = 0;
       for (String name : attributes)
+      {
          names[i++] = name;
+      }
       return names;
    }
 
@@ -477,6 +499,7 @@
     * @deprecated use WorkspaceContainerFacade instead of using container
     *             directly
     */
+   @Deprecated
    public ExoContainer getContainer()
    {
       return container;
@@ -497,6 +520,7 @@
 
    PathNotFoundException, ConstraintViolationException, VersionException, RepositoryException
    {
+      checkLive();
       NodeImpl node = (NodeImpl)getItem(parentAbsPath);
       // checked-in check
       if (!node.checkedOut())
@@ -531,12 +555,14 @@
     */
    public ItemImpl getItem(String absPath) throws PathNotFoundException, RepositoryException
    {
-
+      checkLive();
       JCRPath loc = locationFactory.parseAbsPath(absPath);
 
       ItemImpl item = dataManager.getItem(loc.getInternalPath(), true);
       if (item != null)
+      {
          return item;
+      }
 
       throw new PathNotFoundException("Item not found " + absPath + " in workspace " + workspaceName);
    }
@@ -618,7 +644,9 @@
       {
          uri = namespaces.get(prefix);
          if (uri != null)
+         {
             return uri;
+         }
       }
 
       return workspace.getNamespaceRegistry().getURI(prefix);
@@ -637,9 +665,12 @@
     */
    public Node getNodeByIdentifier(String identifier) throws ItemNotFoundException, RepositoryException
    {
+      checkLive();
       Item item = dataManager.getItemByIdentifier(identifier, true);
       if (item != null && item.isNode())
+      {
          return (Node)item;
+      }
 
       throw new ItemNotFoundException("Node not found " + identifier + " at " + workspaceName);
    }
@@ -649,6 +680,7 @@
     */
    public Node getNodeByUUID(String uuid) throws ItemNotFoundException, RepositoryException
    {
+      checkLive();
       Item item = dataManager.getItemByIdentifier(uuid, true);
 
       if (item != null && item.isNode())
@@ -675,6 +707,7 @@
     */
    public Node getRootNode() throws RepositoryException
    {
+      checkLive();
       Item item = dataManager.getItemByIdentifier(Constants.ROOT_UUID, true);
       if (item != null && item.isNode())
       {
@@ -737,15 +770,17 @@
          name = ((SimpleCredentials)credentials).getUserID();
       }
       else
+      {
          throw new LoginException(
             "Credentials for the authentication should be CredentialsImpl or SimpleCredentials type");
+      }
 
       SessionFactory sessionFactory = (SessionFactory)container.getComponentInstanceOfType(SessionFactory.class);
 
       ConversationState newState =
          new ConversationState(new Identity(name, userState.getIdentity().getMemberships(), userState.getIdentity()
             .getRoles()));
-      return (Session)sessionFactory.createSession(newState);
+      return sessionFactory.createSession(newState);
 
    }
 
@@ -785,6 +820,7 @@
       throws IOException, PathNotFoundException, ItemExistsException, ConstraintViolationException,
       InvalidSerializedDataException, RepositoryException
    {
+      checkLive();
       NodeImpl node = (NodeImpl)getItem(parentAbsPath);
       if (!node.checkedOut())
       {
@@ -821,6 +857,21 @@
    }
 
    /**
+    * Checks if session is alive. Currently only logs a warning, but newer JCR versions will throw an exception. 
+    * @throws RepositoryException
+    */
+   public void checkLive() throws RepositoryException
+   {
+      if (!live)
+      {
+         log
+            .warn(
+               "This kind of operation is forbidden after a session.logout(), please note that an exception will be raised in the next jcr version.",
+               new Exception());
+      }
+   }
+
+   /**
     * {@inheritDoc}
     */
    public boolean itemExists(String absPath)
@@ -828,7 +879,9 @@
       try
       {
          if (getItem(absPath) != null)
+         {
             return true;
+         }
       }
       catch (RepositoryException e)
       {
@@ -855,13 +908,16 @@
    public void move(String srcAbsPath, String destAbsPath) throws ItemExistsException, PathNotFoundException,
       VersionException, LockException, RepositoryException
    {
+      checkLive();
       JCRPath srcNodePath = getLocationFactory().parseAbsPath(srcAbsPath);
 
       NodeImpl srcNode = (NodeImpl)dataManager.getItem(srcNodePath.getInternalPath(), false);
       JCRPath destNodePath = getLocationFactory().parseAbsPath(destAbsPath);
       if (destNodePath.isIndexSetExplicitly())
+      {
          throw new RepositoryException("The relPath provided must not have an index on its final element. "
             + destNodePath.getAsString(false));
+      }
 
       NodeImpl destParentNode = (NodeImpl)dataManager.getItem(destNodePath.makeParentPath().getInternalPath(), true);
 
@@ -889,10 +945,14 @@
 
       // Check if versionable ancestor is not checked-in
       if (!srcNode.parent().checkedOut())
+      {
          throw new VersionException("Parent or source Node or its nearest ancestor is checked-in");
+      }
 
       if (!srcNode.checkLocking())
+      {
          throw new LockException("Source parent node " + srcNode.getPath() + " is locked ");
+      }
 
       ItemDataMoveVisitor initializer =
          new ItemDataMoveVisitor((NodeData)destParentNode.getData(), destNodePath.getName().getInternalName(),
@@ -939,20 +999,27 @@
     */
    public void setNamespacePrefix(String prefix, String uri) throws NamespaceException, RepositoryException
    {
+      checkLive();
       NamespaceRegistryImpl nrg = (NamespaceRegistryImpl)workspace.getNamespaceRegistry();
       if (!nrg.isUriRegistered(uri))
+      {
          throw new NamespaceException("The specified uri:" + uri + " is not among "
             + "those registered in the NamespaceRegistry");
+      }
       if (nrg.isPrefixMaped(prefix))
+      {
          throw new NamespaceException("A prefix '" + prefix + "' is currently already mapped to " + nrg.getURI(prefix)
             + " URI persistently in the repository NamespaceRegistry "
             + "and cannot be remapped to a new URI using this method, since this would make any "
             + "content stored using the old URI unreadable.");
+      }
       if (namespaces.containsKey(prefix))
+      {
          throw new NamespaceException("A prefix '" + prefix + "' is currently already mapped to "
             + namespaces.get(prefix) + " URI transiently within this Session and cannot be "
             + "remapped to a new URI using this method, since this would make any "
             + "content stored using the old URI unreadable.");
+      }
       nrg.validateNamespace(prefix, uri);
       namespaces.put(prefix, uri);
       prefixes.put(uri, prefix);

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/VersionHistoryImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/VersionHistoryImpl.java	2010-06-30 13:23:12 UTC (rev 2726)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/VersionHistoryImpl.java	2010-07-01 06:53:53 UTC (rev 2727)
@@ -94,6 +94,7 @@
    /**
     * {@inheritDoc}
     */
+   @Override
    public VersionHistoryDataHelper getData()
    {
       return (VersionHistoryDataHelper)super.getData();
@@ -111,6 +112,7 @@
          (PropertyData)dataManager.getItemData(nodeData(), new QPathEntry(Constants.JCR_VERSIONABLEUUID, 0));
 
       if (versionableUuid != null)
+      {
          try
          {
             return new String(versionableUuid.getValues().get(0).getAsByteArray());
@@ -123,6 +125,7 @@
          {
             LOG.error("jcr:versionableUuid, error of read " + e + ". Version history " + getPath(), e);
          }
+      }
 
       throw new ItemNotFoundException("A property jcr:versionableUuid is not found. Version history " + getPath());
    }
@@ -138,7 +141,9 @@
       VersionImpl version =
          (VersionImpl)dataManager.getItem(nodeData(), new QPathEntry(Constants.JCR_ROOTVERSION, 0), true);
       if (version == null)
+      {
          throw new VersionException("There are no root version in the version history " + getPath());
+      }
 
       return version;
    }
@@ -184,8 +189,10 @@
       VersionImpl version =
          (VersionImpl)dataManager.getItem(nodeData(), new QPathEntry(jcrVersionName.getInternalName(), 1), pool);
       if (version == null)
+      {
          throw new VersionException("There are no version with name '" + versionName + "' in the version history "
             + getPath());
+      }
 
       return version;
    }
@@ -199,13 +206,17 @@
 
       NodeData versionData = getVersionDataByLabel(label);
       if (versionData == null)
+      {
          throw new RepositoryException("There are no label '" + label + "' in the version history " + getPath());
+      }
 
       VersionImpl version = (VersionImpl)dataManager.getItemByIdentifier(versionData.getIdentifier(), true);
 
       if (version == null)
+      {
          throw new VersionException("There are no version with label '" + label + "' in the version history "
             + getPath());
+      }
 
       return version;
 
@@ -219,7 +230,9 @@
       checkValid();
 
       if (this.getVersionDataByLabel(label) == null)
+      {
          return false;
+      }
 
       return true;
    }
@@ -233,7 +246,9 @@
 
       NodeData versionData = getVersionDataByLabel(label);
       if (versionData != null && version.getUUID().equals(versionData.getIdentifier()))
+      {
          return true;
+      }
 
       return false;
    }
@@ -296,7 +311,9 @@
 
       String[] res = new String[vlabels.size()];
       for (int i = 0; i < vlabels.size(); i++)
+      {
          res[i] = vlabels.get(i);
+      }
       return res;
    }
 
@@ -306,6 +323,7 @@
    public void removeVersion(String versionName) throws ReferentialIntegrityException, AccessDeniedException,
       UnsupportedRepositoryOperationException, VersionException, RepositoryException
    {
+      checkValid();
       // get version (pool it to be able to invalidate the version on final)
       VersionImpl version = (VersionImpl)version(versionName, true);
 
@@ -314,8 +332,10 @@
       // getReferences!
       List<PropertyData> refs = dataManager.getReferencesData(version.getInternalIdentifier(), true);
       if (refs.size() > 0)
+      {
          throw new ReferentialIntegrityException("There are Reference property pointed to this Version "
             + refs.get(0).getQPath().getAsString());
+      }
 
       PlainChangesLog changes = new PlainChangesLogImpl(session.getId());
 
@@ -359,7 +379,7 @@
             {// V2's successor
                if (successorsData != null)
                {// to redirect V2's successor
-                // case of VH graph merge
+                  // case of VH graph merge
                   for (ValueData svalue : successorsData.getValues())
                   {
                      predecessor.removeAddSuccessor(version.getInternalIdentifier(),
@@ -430,7 +450,9 @@
       NodeData version = getData().getVersionData(jcrPath.getName().getInternalName());
 
       if (version == null)
+      {
          throw new VersionException("Version is not found " + jcrPath.getAsString(false));
+      }
 
       return version;
    }
@@ -525,7 +547,9 @@
          dataManager.getTransactManager().save(changes);
       }
       else
+      {
          throw new VersionException("Label not found " + labelName);
+      }
 
    }
 
@@ -534,6 +558,7 @@
    public void addVersion(NodeData versionableNodeData, String uuid, SessionChangesLog changesLog)
       throws RepositoryException
    {
+      checkValid();
       // nt:version
       NodeData versionData =
          TransientNodeData.createNodeData(nodeData(), new InternalQName(null, nextVersionName()), Constants.NT_VERSION,
@@ -583,7 +608,7 @@
          }
          VersionImpl predecessor = (VersionImpl)dataManager.getItemByIdentifier(new String(pib), false);
          predecessor.addSuccessor(versionData.getIdentifier(), changesLog);
-         
+
          predecessorsNew.add(new TransientValueData(pib));
       }
 

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/VersionImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/VersionImpl.java	2010-06-30 13:23:12 UTC (rev 2726)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/VersionImpl.java	2010-07-01 06:53:53 UTC (rev 2727)
@@ -116,10 +116,14 @@
             String videntifier = new String(successorsValues.get(i).getAsByteArray());
             VersionImpl version = (VersionImpl)dataManager.getItemByIdentifier(videntifier, true);
             if (version != null)
+            {
                successors[i] = version;
+            }
             else
+            {
                throw new RepositoryException("Successor version is not found " + videntifier + ", this version "
                   + getPath());
+            }
          }
       }
       catch (IOException e)
@@ -175,6 +179,8 @@
 
    public void addSuccessor(String successorIdentifier, PlainChangesLog changesLog) throws RepositoryException
    {
+      checkValid();
+
       ValueData successorRef = new TransientValueData(new Identifier(successorIdentifier));
 
       PropertyData successorsProp =
@@ -219,6 +225,8 @@
 
    public void addPredecessor(String predeccessorIdentifier, PlainChangesLog changesLog) throws RepositoryException
    {
+      checkValid();
+
       ValueData predeccessorRef = new TransientValueData(new Identifier(predeccessorIdentifier));
 
       PropertyData predeccessorsProp =
@@ -442,9 +450,13 @@
       SessionImpl restoreSession, boolean removeExisting, SessionChangesLog delegatedLog) throws RepositoryException
    {
 
+      checkValid();
+
       if (LOG.isDebugEnabled())
+      {
          LOG.debug("Restore on parent " + destParent.getQPath().getAsString() + " as " + name.getAsString()
             + ", removeExisting=" + removeExisting);
+      }
 
       DataManager dmanager = restoreSession.getTransientNodesManager().getTransactManager();
 
@@ -462,6 +474,8 @@
       throws RepositoryException
    {
 
+      checkValid();
+
       DataManager dmanager = restoreSession.getTransientNodesManager().getTransactManager();
 
       NodeData vh = (NodeData)dmanager.getItemData(nodeData().getParentIdentifier()); // version
@@ -480,7 +494,9 @@
       {
          if (prds[i].getUUID().equals(anotherVersion.getUUID())
             || ((VersionImpl)prds[i]).isSuccessorOrSameOf(anotherVersion))
+         {
             return true;
+         }
       }
       return false;
    }



More information about the exo-jcr-commits mailing list