public void save(final int operationType)
      throws AccessDeniedException, ItemExistsException, ConstraintViolationException,
          InvalidItemStateException, VersionException, LockException, NoSuchNodeTypeException,
          RepositoryException {
    if (!isSystem() && getLocale() != null) {
      for (JCRNodeWrapper node : newNodes.values()) {
        for (String s : node.getNodeTypes()) {
          ExtendedPropertyDefinition[] propDefs =
              NodeTypeRegistry.getInstance().getNodeType(s).getPropertyDefinitions();
          for (ExtendedPropertyDefinition propDef : propDefs) {
            if (propDef.isMandatory()
                && propDef.getRequiredType() != PropertyType.WEAKREFERENCE
                && propDef.getRequiredType() != PropertyType.REFERENCE
                && !propDef.isProtected()
                && !node.hasProperty(propDef.getName())) {
              throw new ConstraintViolationException("Mandatory field : " + propDef.getName());
            }
          }
        }
      }
    }
    newNodes.clear();

    JCRObservationManager.doWorkspaceWriteCall(
        this,
        operationType,
        new JCRCallback<Object>() {
          public Object doInJCR(JCRSessionWrapper thisSession) throws RepositoryException {
            for (Session session : sessions.values()) {
              session.save();
            }
            return null;
          }
        });
  }
 public boolean hasPendingChanges() throws RepositoryException {
   for (Session session : sessions.values()) {
     if (session.hasPendingChanges()) {
       return true;
     }
   }
   return false;
 }
 public String[] getLockTokens() {
   List<String> allTokens = new ArrayList<String>(tokens);
   for (Session session : sessions.values()) {
     String[] tokens = session.getLockTokens();
     for (String token : tokens) {
       if (!allTokens.contains(token)) {
         allTokens.add(token);
       }
     }
   }
   return allTokens.toArray(new String[allTokens.size()]);
 }
 public void logout() {
   for (Session session : sessions.values()) {
     session.logout();
   }
   if (credentials instanceof SimpleCredentials) {
     SimpleCredentials simpleCredentials = (SimpleCredentials) credentials;
     JahiaLoginModule.removeToken(
         simpleCredentials.getUserID(), new String(simpleCredentials.getPassword()));
   }
   isLive = false;
   activeSessions.decrementAndGet();
 }
 /**
  * Applies the namespace prefix to the appropriate sessions, including the underlying provider
  * sessions.
  *
  * @param prefix
  * @param uri
  * @throws NamespaceException
  * @throws RepositoryException
  */
 public void setNamespacePrefix(String prefix, String uri)
     throws NamespaceException, RepositoryException {
   nsToPrefix.put(uri, prefix);
   prefixToNs.put(prefix, uri);
   for (Session s : sessions.values()) {
     s.setNamespacePrefix(prefix, uri);
     try {
       NamespaceRegistry nsReg = s.getWorkspace().getNamespaceRegistry();
       if (nsReg != null) {
         nsReg.registerNamespace(prefix, uri);
       }
     } catch (RepositoryException e) {
       if (logger.isDebugEnabled()) {
         logger.debug(
             "Prefix/uri could not be registered in workspace's registry- " + prefix + "/" + uri,
             e);
       }
     }
   }
 }
 /**
  * Get sessions from all providers used in this wrapper.
  *
  * @return a <code>Collection</code> of <code>JCRSessionWrapper</code> objects
  */
 public Collection<Session> getAllSessions() {
   return sessions.values();
 }
 public void removeLockToken(String token) {
   tokens.remove(token);
   for (Session session : sessions.values()) {
     session.removeLockToken(token);
   }
 }
 /**
  * Adds the specified lock token to the wrapped sessions. Holding a lock token makes the <code>
  * Session</code> the owner of the lock specified by that particular lock token.
  *
  * @param token a lock token (a string).
  * @deprecated As of JCR 2.0, {@link LockManager#addLockToken(String)} should be used instead.
  */
 public void addLockToken(String token) {
   tokens.add(token);
   for (Session session : sessions.values()) {
     session.addLockToken(token);
   }
 }
 public void refresh(boolean b) throws RepositoryException {
   for (Session session : sessions.values()) {
     session.refresh(b);
   }
 }