You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2006/10/09 19:25:53 UTC

svn commit: r454433 [1/2] - in /jackrabbit/trunk/contrib/sanitycheck: ./ src/ src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/jackrabbit/ src/java/org/apache/jackrabbit/sanitycheck/ src/java/org/apache/jackrabbit/sanitycheck/check/ src...

Author: jukka
Date: Mon Oct  9 10:25:51 2006
New Revision: 454433

URL: http://svn.apache.org/viewvc?view=rev&rev=454433
Log:
JCR-76: Added contrib/sanitycheck as contributed by Edgar Poce.

Added:
    jackrabbit/trunk/contrib/sanitycheck/
    jackrabbit/trunk/contrib/sanitycheck/README.txt   (with props)
    jackrabbit/trunk/contrib/sanitycheck/project.xml   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/
    jackrabbit/trunk/contrib/sanitycheck/src/java/
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/SanityCheckException.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/SanityCheckHelper.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/AbstractNodeCheck.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/AbstractPropertyCheck.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/CheckParentsExist.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/CheckReferenceProperty.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/CheckTree.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/SanityCheckContext.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/package.html   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/console/
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/console/SanityCheckRunner.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/console/package.html   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/FixContext.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveChildNodeEntry.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveParentEntry.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveProperty.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemovePropertyEntry.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveValue.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/package.html   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/ChildNodeEntryInconsistency.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/NodeInconsistency.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/ParentEntryInconsistency.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/PropertyEntryInconsistency.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/PropertyInconsistency.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/ValueInconsistency.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/impl/
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/impl/AbstractChildNodeInconsistency.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/impl/AbstractChildPropertyInconsistency.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/impl/AbstractNodeInconsistency.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/impl/AbstractPropertyInconsistency.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/impl/AbstractValueInconsistency.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/impl/NoSuchChildInconsistency.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/impl/NoSuchParentInconsistency.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/impl/NoSuchPropertyInconsistency.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/impl/NoSuchReferencedNodeInconsistency.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/impl/NotReferenceableInconsistency.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/impl/UnableToReadNodeInconsistency.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/impl/UnableToReadPropertyInconsistency.java   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/impl/package.html   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/package.html   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/package.html   (with props)
    jackrabbit/trunk/contrib/sanitycheck/src/java/sanity-check-chain.xml   (with props)

Added: jackrabbit/trunk/contrib/sanitycheck/README.txt
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/README.txt?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/README.txt (added)
+++ jackrabbit/trunk/contrib/sanitycheck/README.txt Mon Oct  9 10:25:51 2006
@@ -0,0 +1,4 @@
+Documentation in javadocs.
+
+How to run (command line):
+See org.apache.jackrabbit.sanitycheck.console.SanityCheckRunner javadocs

Propchange: jackrabbit/trunk/contrib/sanitycheck/README.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/sanitycheck/project.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/project.xml?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/project.xml (added)
+++ jackrabbit/trunk/contrib/sanitycheck/project.xml Mon Oct  9 10:25:51 2006
@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+  <pomVersion>3</pomVersion>
+  <artifactId>jackrabbit</artifactId>
+  <name>Sanity Check</name>
+  <groupId>sanitycheck</groupId>
+  <currentVersion>1.0</currentVersion>
+  <inceptionYear>2005</inceptionYear>
+  <logo>/images/logo.gif</logo>
+  <mailingLists>
+    <mailingList>
+      <name>${pom.name} Dev List</name>
+    </mailingList>
+    <mailingList>
+      <name>${pom.name} User List</name>
+    </mailingList>
+  </mailingLists>
+  <dependencies>
+    <dependency>
+      <groupId>commons-chain</groupId>
+      <artifactId>commons-chain</artifactId>
+      <version>1.0</version>
+      <type>jar</type>
+    </dependency>
+    <dependency>
+      <groupId>jackrabbit</groupId>
+      <artifactId>jackrabbit</artifactId>
+      <version>0.16.4.1-dev</version>
+      <type>jar</type>
+    </dependency>
+    <dependency>
+      <groupId>commons-collections</groupId>
+      <artifactId>commons-collections</artifactId>
+      <version>3.1</version>
+      <type>jar</type>
+    </dependency>
+    <dependency>
+      <groupId>commons-digester</groupId>
+      <artifactId>commons-digester</artifactId>
+      <version>1.6</version>
+      <type>jar</type>
+    </dependency>
+    <dependency>
+      <groupId>commons-beanutils</groupId>
+      <artifactId>commons-beanutils</artifactId>
+      <version>1.7.0</version>
+      <type>jar</type>
+    </dependency>
+    <dependency>
+      <groupId>geronimo-spec</groupId>
+      <artifactId>geronimo-spec-jta</artifactId>
+      <version>1.0-M1</version>
+      <type>jar</type>
+    </dependency>
+    <dependency>
+      <groupId>jsr170</groupId>
+      <artifactId>jcr</artifactId>
+      <version>0.16.4.1</version>
+      <type>jar</type>
+      <url>http://www.day.com/maven/jsr170/jars/jcr-0.16.2.jar</url>
+    </dependency>
+    <dependency>
+      <groupId>xerces</groupId>
+      <artifactId>xercesImpl</artifactId>
+      <version>2.6.2</version>
+      <type>jar</type>
+    </dependency>
+    <dependency>
+      <groupId>xml-apis</groupId>
+      <artifactId>xmlParserAPIs</artifactId>
+      <version>2.0.2</version>
+      <type>jar</type>
+    </dependency>
+    <dependency>
+      <groupId>cqfs</groupId>
+      <artifactId>cqfs-jackrabbit</artifactId>
+      <version>3.5.6</version>
+      <type>jar</type>
+      <url>http://www.day.com/maven/cqfs/jars/cqfs-jackrabbit-3.5.6.jar</url>
+    </dependency>
+    <dependency>
+      <groupId>geronimo-spec</groupId>
+      <artifactId>geronimo-spec-jta</artifactId>
+      <version>1.0-M1</version>
+      <type>jar</type>
+    </dependency>
+    <dependency>
+      <groupId>xerces</groupId>
+      <artifactId>xercesImpl</artifactId>
+      <version>2.6.2</version>
+      <type>jar</type>
+    </dependency>
+    <dependency>
+      <groupId>xml-apis</groupId>
+      <artifactId>xmlParserAPIs</artifactId>
+      <version>2.0.2</version>
+      <type>jar</type>
+    </dependency>
+    <dependency>
+      <groupId>cqfs</groupId>
+      <artifactId>cqfs-jackrabbit</artifactId>
+      <version>3.5.6</version>
+      <type>jar</type>
+      <url>http://www.day.com/maven/cqfs/jars/cqfs-jackrabbit-3.5.6.jar</url>
+    </dependency>
+  </dependencies>
+  <build>
+    <sourceDirectory>src/java</sourceDirectory>
+    <unitTestSourceDirectory>src/test</unitTestSourceDirectory>
+    <unitTest>
+      <includes>
+        <include>**/*Test.java</include>
+      </includes>
+    </unitTest>
+  </build>
+</project>

Propchange: jackrabbit/trunk/contrib/sanitycheck/project.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/SanityCheckException.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/SanityCheckException.java?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/SanityCheckException.java (added)
+++ jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/SanityCheckException.java Mon Oct  9 10:25:51 2006
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.sanitycheck;
+
+/**
+ * Sanity Check Exception
+ */
+public class SanityCheckException extends Exception
+{
+
+    /**
+     * Comment for <code>serialVersionUID</code>
+     */
+    private static final long serialVersionUID = 3763101855693484086L;
+
+    /**
+     * 
+     */
+    public SanityCheckException()
+    {
+        super();
+    }
+
+    /**
+     * @param message
+     */
+    public SanityCheckException(String message)
+    {
+        super(message);
+    }
+
+    /**
+     * @param message
+     * @param cause
+     */
+    public SanityCheckException(String message, Throwable cause)
+    {
+        super(message, cause);
+    }
+
+    /**
+     * @param cause
+     */
+    public SanityCheckException(Throwable cause)
+    {
+        super(cause);
+    }
+}

Propchange: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/SanityCheckException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/SanityCheckHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/SanityCheckHelper.java?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/SanityCheckHelper.java (added)
+++ jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/SanityCheckHelper.java Mon Oct  9 10:25:51 2006
@@ -0,0 +1,339 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.sanitycheck;
+
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Properties;
+
+import org.apache.commons.chain.Catalog;
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.config.ConfigParser;
+import org.apache.commons.chain.impl.CatalogFactoryBase;
+import org.apache.commons.collections.BeanMap;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.core.config.ConfigurationException;
+import org.apache.jackrabbit.core.config.RepositoryConfig;
+import org.apache.jackrabbit.core.config.VersioningConfig;
+import org.apache.jackrabbit.core.config.WorkspaceConfig;
+import org.apache.jackrabbit.core.state.PMContext;
+import org.apache.jackrabbit.core.state.PersistenceManager;
+import org.apache.jackrabbit.sanitycheck.check.SanityCheckContext;
+import org.apache.jackrabbit.sanitycheck.fix.FixContext;
+import org.apache.jackrabbit.sanitycheck.inconsistency.NodeInconsistency;
+
+/**
+ * Helper class
+ */
+public class SanityCheckHelper
+{
+    /** Logger */
+    private static Log log = LogFactory.getLog(SanityCheckHelper.class);
+
+    /** fix catalog */
+    private static final String FIX_CATALOG_NAME = "fixes";
+
+    /** versioning catalog */
+    private static final String CHAIN_CONFIG = "sanity-check-chain.xml";
+
+    /** versioning catalog */
+    private static final String VERSIONING_CHAIN = "versioning";
+
+    /** workspace catalog */
+    private static final String WORKSPACE_CHAIN = "workspace";
+
+    /** root uuid */
+    private static final String WORKSPACE_ROOT_UUID = "cafebabe-cafe-babe-cafe-babecafebabe";
+
+    /** versioning uuid */
+    private static final String VERSIONING_ROOT_UUID = "deadbeef-face-babe-cafe-babecafebabe";
+
+    /** Versioning pm name */
+    private static final String VERSIONING_PM_NAME = "versioning";
+
+    /** Workspace pm name */
+    private static final String WORKSPACE_PM_NAME = "workspace";
+
+    /** Catalog name */
+    private static final String CATALOG_NAME = "sanitycheck";
+
+    /**
+     * Repairs the given Inconsistency. It gets the command that matchs the
+     * class name of the Inconsistency implementor.
+     * 
+     * @param inconsistency
+     *            to repair
+     * @throws SanityCheckException
+     */
+    public static void repair(NodeInconsistency inconsistency)
+            throws SanityCheckException
+    {
+        FixContext ctx = new FixContext();
+        ctx.setInconsistency(inconsistency);
+        Catalog catalog = CatalogFactoryBase.getInstance().getCatalog(
+            FIX_CATALOG_NAME);
+        try
+        {
+            Command fix = catalog.getCommand(inconsistency.getClass().getName());
+            log.info("Trying to repair inconsistency "
+                    + inconsistency.getDescription() + " with "
+                    + fix.getClass().getName());
+            fix.execute(ctx);
+        } catch (Exception e)
+        {
+            throw new SanityCheckException("Unable to fix "
+                    + inconsistency.getDescription(), e);
+        }
+    }
+
+    /**
+     * Gets the inconsistencies for the given repository
+     * 
+     * @param config
+     * @return
+     * @throws SanityCheckException
+     */
+    public static Collection getInconsistencies(File configFile, String homePath)
+            throws SanityCheckException
+    {
+        try
+        {
+            // inconsistencies Collection
+            Collection inconsistencies = new ArrayList();
+
+            // parse the config
+            URL catalogURL = SanityCheckHelper.class.getClassLoader()
+                                                    .getResource(CHAIN_CONFIG);
+            ConfigParser parser = new ConfigParser();
+            parser.parse(catalogURL);
+            Catalog catalog = CatalogFactoryBase.getInstance().getCatalog(
+                CATALOG_NAME);
+
+            // Create a repositoryConfig instance
+            RepositoryConfig rConfig = getRepositoryConfig(configFile, homePath);
+
+            // versioning PersistenceManager
+            PersistenceManager vPm = getPersistenceManager(
+                rConfig.getVersioningConfig(),
+                rConfig);
+
+            // workspaces Collection
+            Collection workspacesPm = new ArrayList();
+
+            // Run the chain agains the workspaces PM
+            Iterator iter = rConfig.getWorkspaceConfigs().iterator();
+            while (iter.hasNext())
+            {
+                // Config
+                WorkspaceConfig wConfig = (WorkspaceConfig) iter.next();
+                // PersistenceManager
+                PersistenceManager wPm = getPersistenceManager(wConfig, rConfig);
+                // Log inconsistencies
+                inconsistencies.addAll(getInconsistencies(
+                    wPm,
+                    wConfig.getName(),
+                    vPm));
+                workspacesPm.add(wPm);
+            }
+
+            // Log versioning inconsistencies
+            // inconsistencies.addAll(getInconsistencies(vPm, workspacesPm));
+
+            // return inconsistencies
+            return inconsistencies;
+        } catch (Exception e)
+        {
+            throw new SanityCheckException("Unable to get inconsistencies.", e);
+        }
+    }
+
+    /**
+     * @param workspace
+     * @param versioning
+     * @return the inconsistencies for the given workspace PersistenceManage
+     */
+    public static Collection getInconsistencies(
+        PersistenceManager workspace,
+        String name,
+        PersistenceManager versioning) throws SanityCheckException
+    {
+        try
+        {
+            // Create sanity check context
+            SanityCheckContext wCtx = new SanityCheckContext();
+
+            // Set root node
+            wCtx.setRootUUID(WORKSPACE_ROOT_UUID);
+
+            // Add workspaces's PersistenceManagers
+            wCtx.setPersistenceManager(workspace);
+            wCtx.setPersistenceManagerName(WORKSPACE_PM_NAME + " " + name);
+
+            // Set versioning PM
+            wCtx.setVersioningPM(versioning);
+
+            // Run chain
+            Catalog catalog = CatalogFactoryBase.getInstance().getCatalog(
+                CATALOG_NAME);
+            catalog.getCommand(WORKSPACE_CHAIN).execute(wCtx);
+
+            // return inconsistencies
+            return wCtx.getInconsistencies();
+        } catch (Exception e)
+        {
+            throw new SanityCheckException("Unable to get inconsistencies.", e);
+        }
+    }
+
+    /**
+     * @param workspace
+     * @param versioning
+     * @return the inconsistencies for the given versioning PersistenceManager
+     * @throws SanityCheckException
+     */
+    public static Collection getInconsistencies(
+        PersistenceManager versioning,
+        Collection workspaces) throws SanityCheckException
+    {
+        try
+        {
+            // Create context
+            SanityCheckContext vCtx = new SanityCheckContext();
+            vCtx.setRootUUID(VERSIONING_ROOT_UUID);
+            vCtx.setPersistenceManager(versioning);
+            vCtx.setPersistenceManagerName(VERSIONING_PM_NAME);
+            // Run chain
+            Catalog catalog = CatalogFactoryBase.getInstance().getCatalog(
+                CATALOG_NAME);
+            catalog.getCommand(VERSIONING_CHAIN).execute(vCtx);
+            return vCtx.getInconsistencies();
+        } catch (Exception e)
+        {
+            throw new SanityCheckException(
+                "Unable to get inconsistencies from the versioning PersistenceManager.",
+                e);
+        }
+    }
+
+    /**
+     * @param configFile
+     * @param homePath
+     * @return the RepositoryConfig
+     * @throws SanityCheckException
+     */
+    private static RepositoryConfig getRepositoryConfig(
+        File configFile,
+        String homePath) throws SanityCheckException
+    {
+        RepositoryConfig config = null;
+        try
+        {
+            config = RepositoryConfig.create(
+                configFile.getAbsolutePath(),
+                homePath);
+        } catch (ConfigurationException e)
+        {
+            throw new SanityCheckException(e);
+        }
+        return config;
+    }
+
+    /**
+     * @return the Workspace Persistence Manager
+     * @throws SanityCheckException
+     */
+    private static PersistenceManager getPersistenceManager(
+        WorkspaceConfig wConfig,
+        RepositoryConfig rConfig) throws SanityCheckException
+    {
+        try
+        {
+            // FIXME: create instances of NodeTyperegistry and NameSpaceRegistry
+            PersistenceManager pm = (PersistenceManager) Class.forName(
+                                                                  wConfig.getPersistenceManagerConfig()
+                                                                         .getClassName())
+                                                              .newInstance();
+            PMContext ctx = new PMContext(
+                new File(wConfig.getHomeDir()),
+                wConfig.getFileSystem(),
+                WORKSPACE_ROOT_UUID,
+                null,
+                null);
+            addParameters(pm, wConfig.getPersistenceManagerConfig()
+                                     .getParameters());
+            pm.init(ctx);
+            return pm;
+        } catch (Exception e)
+        {
+            throw new SanityCheckException(e);
+        }
+    }
+
+    /**
+     * @return the Versioning Persistence Manager
+     * @throws SanityCheckException
+     */
+    private static PersistenceManager getPersistenceManager(
+        VersioningConfig vConfig,
+        RepositoryConfig rConfig) throws SanityCheckException
+    {
+        try
+        {
+            // FIXME: create instances of NodeTyperegistry and NameSpaceRegistry
+            PersistenceManager pm = (PersistenceManager) Class.forName(
+                                                                  vConfig.getPersistenceManagerConfig()
+                                                                         .getClassName())
+                                                              .newInstance();
+            PMContext ctx = new PMContext(
+                vConfig.getHomeDir(),
+                vConfig.getFileSystem(),
+                VERSIONING_ROOT_UUID,
+                null,
+                null);
+            addParameters(pm, vConfig.getPersistenceManagerConfig()
+                                     .getParameters());
+            pm.init(ctx);
+            return pm;
+        } catch (Exception e)
+        {
+            throw new SanityCheckException(e);
+        }
+    }
+
+    /**
+     * Add config parameters to the given PersistenceManager
+     * 
+     * @param pm
+     * @param params
+     */
+    private static void addParameters(PersistenceManager pm, Properties params)
+    {
+        BeanMap bm = new BeanMap(pm);
+        Iterator iter = params.keySet().iterator();
+        while (iter.hasNext())
+        {
+            Object paramName = iter.next();
+            Object paramValue = params.get(paramName);
+            bm.put(paramName, paramValue);
+        }
+    }
+
+}

Propchange: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/SanityCheckHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/AbstractNodeCheck.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/AbstractNodeCheck.java?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/AbstractNodeCheck.java (added)
+++ jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/AbstractNodeCheck.java Mon Oct  9 10:25:51 2006
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.sanitycheck.check;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.state.NoSuchItemStateException;
+import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.core.state.PersistenceManager;
+import org.apache.jackrabbit.sanitycheck.SanityCheckException;
+
+/**
+ * SanityCheck Superclass. It assumens the tree is consistent.
+ */
+public abstract class AbstractNodeCheck implements Command
+{
+
+    /**
+     * @inheritDoc
+     */
+    public boolean execute(Context ctx) throws Exception
+    {
+        SanityCheckContext sanityCtx = (SanityCheckContext) ctx;
+        PersistenceManager pm = sanityCtx.getPersistenceManager();
+        NodeState root = pm.load(NodeId.valueOf(sanityCtx.getRootUUID()));
+        execute(root, sanityCtx);
+        return false;
+    }
+
+    /**
+     * Traverses the tree and perform the sanity checks
+     * 
+     * @param node
+     * @param ctx
+     * @throws Exception
+     */
+    private void execute(NodeState node, SanityCheckContext ctx)
+            throws Exception
+    {
+        PersistenceManager pm = ctx.getPersistenceManager();
+        // perform NodeState Sanity check
+        internalExecute(node, ctx);
+
+        // Recurse if children are present
+        Collection children = node.getChildNodeEntries();
+        if (children.size() > 0)
+        {
+            Iterator iter = children.iterator();
+            while (iter.hasNext())
+            {
+                NodeState.ChildNodeEntry childEntry = (NodeState.ChildNodeEntry) iter.next();
+                try
+                {
+                    NodeState child = pm.load(new NodeId(childEntry.getUUID()));
+                    this.execute(child, ctx);
+                } catch (NoSuchItemStateException e)
+                {
+                    throw new SanityCheckException(
+                        "Unable o traverse tree. Run a tree check before this check.",
+                        e);
+                }
+            }
+        }
+    }
+
+    /**
+     * Sanity check implementation
+     * 
+     * @param state
+     */
+    protected abstract void internalExecute(
+        NodeState state,
+        SanityCheckContext ctx) throws Exception;
+
+
+}

Propchange: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/AbstractNodeCheck.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/AbstractPropertyCheck.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/AbstractPropertyCheck.java?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/AbstractPropertyCheck.java (added)
+++ jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/AbstractPropertyCheck.java Mon Oct  9 10:25:51 2006
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.sanitycheck.check;
+
+import java.util.Iterator;
+
+import org.apache.jackrabbit.core.PropertyId;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.sanitycheck.SanityCheckException;
+
+/**
+ * Superclass of property checks. It assumens the tree is consistent.
+ */
+public abstract class AbstractPropertyCheck extends AbstractNodeCheck
+{
+
+    /**
+     * @inheritDoc
+     */
+    protected void internalExecute(NodeState node, SanityCheckContext ctx)
+            throws SanityCheckException
+    {
+        Iterator propsIter = node.getPropertyEntries().iterator();
+        while (propsIter.hasNext())
+        {
+            NodeState.PropertyEntry propEntry = (NodeState.PropertyEntry) propsIter.next();
+            try
+            {
+                PropertyState property = ctx.getPersistenceManager().load(
+                    new PropertyId(node.getUUID(), propEntry.getName()));
+                // perform PropertyState SanityCheck
+                internalExecute(node, property, ctx);
+            } catch (ItemStateException e)
+            {
+                throw new SanityCheckException(
+                    "Unable o traverse tree. Run a tree check before this check.",
+                    e);
+            }
+        }
+    }
+
+    /**
+     * Checks the given property
+     * 
+     * @param node
+     * @param property
+     * @param ctx
+     * @throws SanityCheckException
+     */
+    protected abstract void internalExecute(
+        NodeState node,
+        PropertyState property,
+        SanityCheckContext ctx) throws SanityCheckException;
+
+}

Propchange: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/AbstractPropertyCheck.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/CheckParentsExist.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/CheckParentsExist.java?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/CheckParentsExist.java (added)
+++ jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/CheckParentsExist.java Mon Oct  9 10:25:51 2006
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.sanitycheck.check;
+
+import java.util.Iterator;
+
+import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.NoSuchItemStateException;
+import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.core.state.PersistenceManager;
+import org.apache.jackrabbit.sanitycheck.SanityCheckException;
+import org.apache.jackrabbit.sanitycheck.inconsistency.impl.NoSuchParentInconsistency;
+
+/**
+ * Checks that all the referenced parents exists in the PersistenceManager
+ */
+public class CheckParentsExist extends AbstractNodeCheck
+{
+    /**
+     * @inheritDoc
+     */
+    protected void internalExecute(
+        NodeState node,
+        SanityCheckContext ctx) throws SanityCheckException
+    {
+        PersistenceManager pm = ctx.getPersistenceManager();
+        Iterator iter = node.getParentUUIDs().iterator() ;
+        while (iter.hasNext())
+        {
+            String uuid = (String) iter.next();
+            try {
+                pm.load(NodeId.valueOf(uuid));
+            } catch (NoSuchItemStateException ve)
+            {
+                NoSuchParentInconsistency inc = new NoSuchParentInconsistency();
+                inc.setPersistenceManager(pm);
+                inc.setPersistenceManagerName(ctx.getPersistenceManagerName());
+                inc.setNode(node);
+                inc.setParentUUID(uuid);
+                ctx.addInconsistency(inc);
+            } catch (ItemStateException ise)
+            {
+                throw new SanityCheckException(
+                    "An error while running the check.",
+                    ise);
+            }
+            
+        }
+    }
+}

Propchange: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/CheckParentsExist.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/CheckReferenceProperty.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/CheckReferenceProperty.java?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/CheckReferenceProperty.java (added)
+++ jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/CheckReferenceProperty.java Mon Oct  9 10:25:51 2006
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.sanitycheck.check;
+
+import javax.jcr.PropertyType;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.core.value.InternalValue;
+import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.NoSuchItemStateException;
+import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.core.state.PersistenceManager;
+import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.core.util.uuid.UUID;
+import org.apache.jackrabbit.sanitycheck.SanityCheckException;
+import org.apache.jackrabbit.sanitycheck.inconsistency.impl.NoSuchReferencedNodeInconsistency;
+
+/**
+ * This class is responsible of
+ * <ul>
+ * <li>checking the existence of all the referenced nodes in the workspace PM
+ * or the versioning PM</li>
+ * <li>TODO: checking that the referenced node is referenceable.
+ * </li>
+ * </ul>
+ */
+public class CheckReferenceProperty extends AbstractPropertyCheck
+{
+    private static Log log = LogFactory.getLog(CheckReferenceProperty.class);
+
+    /**
+     * @inheritDoc
+     */
+    protected void internalExecute(
+        NodeState node,
+        PropertyState property,
+        SanityCheckContext ctx) throws SanityCheckException
+    {
+        PersistenceManager pm = ctx.getPersistenceManager();
+        PersistenceManager vPm = ctx.getVersioningPersistenceManager();
+
+        if (property.getType() == PropertyType.REFERENCE)
+        {
+            InternalValue[] values = property.getValues();
+            for (int i = 0; i < values.length; i++)
+            {
+                InternalValue value = values[i];
+                UUID uuid = (UUID) value.internalValue();
+                NodeId id = new NodeId(uuid.toString());
+                try
+                {
+                    // Load referenced node
+                    NodeState referencedNode = pm.load(id);
+
+                    // FIXME: It's not possible to check id the state is
+                    // referenceable without a NodeTypeRegistry instance.
+                    // 
+                    // if (!referencedNode.getMixinTypeNames().contains(
+                    // Constants.MIX_REFERENCEABLE))
+                    // {
+                    // // Add inconsistency
+                    // NotReferenceableInconsistency inc = new
+                    // NotReferenceableInconsistency();
+                    // inc.setPersistenceManager(ctx.getPersistenceManager());
+                    // inc.setPersistenceManagerName(ctx.getPersistenceManagerName());
+                    // inc.setNode(node);
+                    // inc.setProperty(property);
+                    // inc.setIndex(i);
+                    // inc.setReferencedNode(referencedNode);
+                    // ctx.addInconsistency(inc);
+                    // }
+                    //
+                } catch (NoSuchItemStateException e)
+                {
+                    // Try to load it from the versioning PM
+                    try
+                    {
+                        vPm.load(id);
+                        log.info("Reference " + node.getUUID() + "/"
+                                + property.getName()
+                                + " points to a versioning node ("
+                                + id.getUUID() + ")");
+                    } catch (NoSuchItemStateException ve)
+                    {
+                        NoSuchReferencedNodeInconsistency inc = new NoSuchReferencedNodeInconsistency();
+                        inc.setIndex(i);
+                        inc.setPersistenceManager(pm);
+                        inc.setPersistenceManagerName(ctx.getPersistenceManagerName());
+                        inc.setNode(node);
+                        inc.setProperty(property);
+                        ctx.addInconsistency(inc);
+                    } catch (ItemStateException ise)
+                    {
+                        throw new SanityCheckException(
+                            "An error while running the check.",
+                            ise);
+                    }
+                } catch (ItemStateException e)
+                {
+                    throw new SanityCheckException(
+                        "An error while running the check.",
+                        e);
+                }
+            }
+        }
+    }
+}

Propchange: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/CheckReferenceProperty.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/CheckTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/CheckTree.java?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/CheckTree.java (added)
+++ jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/CheckTree.java Mon Oct  9 10:25:51 2006
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.sanitycheck.check;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.PropertyId;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.NoSuchItemStateException;
+import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.core.state.PersistenceManager;
+import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.sanitycheck.inconsistency.impl.NoSuchChildInconsistency;
+import org.apache.jackrabbit.sanitycheck.inconsistency.impl.NoSuchPropertyInconsistency;
+import org.apache.jackrabbit.sanitycheck.inconsistency.impl.UnableToReadNodeInconsistency;
+import org.apache.jackrabbit.sanitycheck.inconsistency.impl.UnableToReadPropertyInconsistency;
+
+/**
+ * Checks the tree integrity by checking the existence of every child node and
+ * property. If any inconsistency is found the context processing is completed
+ * and no further checks will be performed.
+ */
+public class CheckTree implements Command
+{
+    /**
+     * @inheritDoc
+     */
+    public boolean execute(Context ctx) throws Exception
+    {
+        SanityCheckContext sanityCtx = (SanityCheckContext) ctx;
+        PersistenceManager pm = sanityCtx.getPersistenceManager();
+        NodeState root = pm.load(NodeId.valueOf(sanityCtx.getRootUUID()));
+        int incs = sanityCtx.getInconsistencies().size();
+        execute(root, sanityCtx);
+        if (sanityCtx.getInconsistencies().size() > incs)
+        {
+            return true;
+        } else
+        {
+            return false;
+        }
+    }
+
+    /**
+     * 
+     * @param node
+     * @param ctx
+     * @throws Exception
+     */
+    private void execute(NodeState node, SanityCheckContext ctx)
+            throws Exception
+    {
+        PersistenceManager pm = ctx.getPersistenceManager();
+        Iterator propsIter = node.getPropertyEntries().iterator();
+        while (propsIter.hasNext())
+        {
+            NodeState.PropertyEntry propEntry = (NodeState.PropertyEntry) propsIter.next();
+            try
+            {
+                PropertyState property = pm.load(new PropertyId(
+                    node.getUUID(),
+                    propEntry.getName()));
+            } catch (NoSuchItemStateException e)
+            {
+                // Property doesn't exist
+                NoSuchPropertyInconsistency inc = new NoSuchPropertyInconsistency();
+                inc.setPersistenceManager(pm);
+                inc.setPersistenceManagerName(ctx.getPersistenceManagerName());
+                inc.setNode(node);
+                inc.setPropertyEntry(propEntry.getName());
+                ctx.addInconsistency(inc);
+            } catch (ItemStateException e)
+            {
+                // Unable to retrieve node
+                UnableToReadPropertyInconsistency inc = new UnableToReadPropertyInconsistency() ;
+                inc.setPersistenceManager(pm);
+                inc.setPersistenceManagerName(ctx.getPersistenceManagerName()) ;
+                inc.setNode(node);
+                inc.setPropertyEntry(propEntry.getName());
+                ctx.addInconsistency(inc);
+
+
+            }
+        }
+
+        // Recurse if children are present
+        Collection children = node.getChildNodeEntries();
+        if (children.size() > 0)
+        {
+            Iterator iter = children.iterator();
+            while (iter.hasNext())
+            {
+                NodeState.ChildNodeEntry childEntry = (NodeState.ChildNodeEntry) iter.next();
+                try
+                {
+                    NodeState child = pm.load(new NodeId(childEntry.getUUID()));
+                    this.execute(child, ctx);
+                } catch (NoSuchItemStateException e)
+                {
+                    // node doesn't exist
+                    NoSuchChildInconsistency inc = new NoSuchChildInconsistency();
+                    inc.setNode(node);
+                    inc.setChild(childEntry.getUUID());
+                    inc.setPersistenceManager(pm);
+                    inc.setPersistenceManagerName(ctx.getPersistenceManagerName());
+                    ctx.addInconsistency(inc);
+                } catch (ItemStateException e)
+                {
+                    // Unable to retrieve node
+                    UnableToReadNodeInconsistency inc = new UnableToReadNodeInconsistency() ;
+                    inc.setPersistenceManager(pm);
+                    inc.setPersistenceManagerName(ctx.getPersistenceManagerName()) ;
+                    inc.setNode(node);
+                    inc.setChild(childEntry.getUUID()) ;
+                    ctx.addInconsistency(inc);
+                }
+            }
+        }
+    }
+
+}

Propchange: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/CheckTree.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/SanityCheckContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/SanityCheckContext.java?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/SanityCheckContext.java (added)
+++ jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/SanityCheckContext.java Mon Oct  9 10:25:51 2006
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.sanitycheck.check;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.commons.chain.impl.ContextBase;
+import org.apache.jackrabbit.core.state.PersistenceManager;
+import org.apache.jackrabbit.sanitycheck.inconsistency.NodeInconsistency;
+
+/**
+ * Sanity Checks Context
+ */
+public class SanityCheckContext extends ContextBase
+{
+    /**
+     * Comment for <code>serialVersionUID</code>
+     */
+    private static final long serialVersionUID = 3691035482775564595L;
+
+    /** Inconsistencies key */
+    private Collection inconsistencies = new ArrayList();
+
+    /** workspace pm key */
+    private PersistenceManager persistenceManager;
+
+    /** versioning pm key */
+    public PersistenceManager versioningPM;
+
+    /** Root node uuid */
+    private String rootUUID;
+
+    /** Persistence Manager Name */
+    private String persistenceManagerName;
+
+    /**
+     * Adds an inconsistency to the context
+     * 
+     * @param inc
+     */
+    public void addInconsistency(NodeInconsistency inc)
+    {
+        this.getInconsistencies().add(inc);
+    }
+
+    /**
+     * Set versioning PM
+     * 
+     * @param pm
+     */
+    public void setVersioningPM(PersistenceManager pm)
+    {
+        this.versioningPM = pm;
+    }
+
+    /**
+     * Set workspace PM
+     * 
+     * @param pm
+     */
+    public void setPersistenceManager(PersistenceManager pm)
+    {
+        this.persistenceManager = pm;
+    }
+
+    /**
+     * @return inconsistencies
+     */
+    public Collection getInconsistencies()
+    {
+        return inconsistencies;
+    }
+
+    /**
+     * Gets the persistence manager to check
+     * 
+     * @return
+     */
+    public PersistenceManager getPersistenceManager()
+    {
+        return persistenceManager;
+    }
+
+    /**
+     * Gets the persistence manager to check
+     * 
+     * @return
+     */
+    public PersistenceManager getVersioningPersistenceManager()
+    {
+        return versioningPM;
+    }
+
+    /**
+     * Get the root node uuid
+     * 
+     * @return
+     */
+    public String getRootUUID()
+    {
+        return rootUUID;
+    }
+
+    /**
+     * Sets
+     * 
+     * @return
+     */
+    public void setRootUUID(String rootUUID)
+    {
+        this.rootUUID = rootUUID;
+    }
+
+    /**
+     * @return PersistenceManager name
+     */
+    public String getPersistenceManagerName()
+    {
+        return persistenceManagerName;
+    }
+
+    /**
+     * Sets the PersistenceManager name
+     * @param persistenceManagerName
+     */
+    public void setPersistenceManagerName(String persistenceManagerName)
+    {
+        this.persistenceManagerName = persistenceManagerName;
+    }
+}

Propchange: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/SanityCheckContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/package.html
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/package.html?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/package.html (added)
+++ jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/package.html Mon Oct  9 10:25:51 2006
@@ -0,0 +1,3 @@
+<body>
+	This package contains sanity checks.
+</body>
\ No newline at end of file

Propchange: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/check/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/console/SanityCheckRunner.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/console/SanityCheckRunner.java?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/console/SanityCheckRunner.java (added)
+++ jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/console/SanityCheckRunner.java Mon Oct  9 10:25:51 2006
@@ -0,0 +1,221 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.sanitycheck.console;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.jackrabbit.sanitycheck.SanityCheckException;
+import org.apache.jackrabbit.sanitycheck.SanityCheckHelper;
+import org.apache.jackrabbit.sanitycheck.inconsistency.NodeInconsistency;
+
+/**
+ * <p>
+ * Command line Sanity Check Runner.
+ * </p>
+ * <p>
+ * Arguments:
+ * <ul>
+ * <li>-repair prompts to repair the inconsistencies</li>
+ * <li>-config=[repository.xml path]</li>
+ * <li>-repository=[repository path]</li>
+ * </ul>
+ * 
+ * </p>
+ * 
+ */
+public class SanityCheckRunner
+{
+    private static final String REPAIR_OPTION = "-repair";
+
+    private static final String CONFIG_OPTION = "-config";
+
+    private static final String REPOSITORY_OPTION = "-repository";
+
+    /** Runner */
+    private static SanityCheckRunner runner = new SanityCheckRunner();
+
+    /**
+     * 
+     * @param args
+     * @throws SanityCheckException
+     */
+    public static void main(String[] args) throws Exception
+    {
+        runner.run(args);
+    }
+
+    /**
+     * Run all the SanityChecks for the given workspaces
+     * 
+     * @param args
+     * @throws Exception
+     */
+    private void run(String[] args) throws Exception
+    {
+        boolean repair = hasOption(args, REPAIR_OPTION);
+
+        Collection inconsistencies = SanityCheckHelper.getInconsistencies(new File(getConfigPath(args)),
+            getRepositoryPath(args));
+
+        // Execute report
+        this.report(inconsistencies);
+
+        // Execute repair
+        if (repair)
+        {
+            repair(inconsistencies);
+        }
+
+    }
+
+    /**
+     * Report the inconsistencies
+     * 
+     * @param log
+     */
+    private void report(Collection inconsistencies)
+    {
+        System.out.println("----- < REPORT STARTS > -----");
+        int i = 0;
+        Iterator iter = inconsistencies.iterator();
+        while (iter.hasNext())
+        {
+            i++;
+            NodeInconsistency inc = (NodeInconsistency) iter.next();
+            System.out.println(i + " - " + inc.getDescription());
+        }
+        System.out.println("----- < REPORT ENDS > -----");
+    }
+
+    /**
+     * Repair the inconsistencies
+     * 
+     * @param log
+     * @throws SanityCheckException
+     */
+    private void repair(Collection inconsistencies) throws SanityCheckException
+    {
+        int i = 0;
+        Iterator iter = inconsistencies.iterator();
+        while (iter.hasNext())
+        {
+            i++;
+            NodeInconsistency inc = (NodeInconsistency) iter.next();
+            try
+            {
+                BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
+                String str = "";
+                int tries = 0;
+                while (!str.equals("y") && !str.equals("n") && tries < 3)
+                {
+                    tries++;
+                    System.out.print(i + "> " + inc.getDescription() + ".\n do you want to fix it? [y/n] ");
+                    str = in.readLine();
+                }
+                if (str.equals("y"))
+                {
+                    SanityCheckHelper.repair(inc);
+                    System.out.println(i + "> [repaired]");
+                } else
+                {
+                    System.out.println(i + ">  [ignored]");
+                }
+            } catch (IOException e)
+            {
+                throw new SanityCheckException("Unable to prompt.", e);
+            }
+        }
+    }
+
+    private String getConfigPath(String[] args)
+    {
+        String configPath = getArgument(args, CONFIG_OPTION);
+        if (configPath == null)
+        {
+            throw new IllegalArgumentException("Set the config file. "
+                    + CONFIG_OPTION + "=[path]");
+        }
+        File file = new File(configPath);
+        if (!file.exists())
+        {
+            throw new IllegalArgumentException("Config file not found. "
+                    + configPath);
+        }
+        return configPath;
+    }
+
+    private String getRepositoryPath(String[] args)
+    {
+        String repoPath = getArgument(args, REPOSITORY_OPTION);
+        if (repoPath == null)
+        {
+            throw new IllegalArgumentException("Set the repository path. "
+                    + REPOSITORY_OPTION + "=[path]");
+        }
+        File repoFile = new File(repoPath);
+        if (!repoFile.exists())
+        {
+            throw new IllegalArgumentException("Repository path not found. "
+                    + repoPath);
+        }
+        return repoPath;
+    }
+
+    /**
+     * Gets the argument value
+     * 
+     * @param args
+     * @param key
+     * @return
+     */
+    private String getArgument(String[] args, String key)
+    {
+        String arg = null;
+        for (int i = 0; i < args.length; i++)
+        {
+            if (args[i].startsWith(key + "="))
+            {
+                arg = args[i].substring(key.length() + 1);
+            }
+        }
+        return arg;
+    }
+
+    /**
+     * @param args
+     * @param option
+     * @return true if the option exists
+     */
+    private boolean hasOption(String[] args, String option)
+    {
+        boolean retu = false;
+        for (int i = 0; i < args.length; i++)
+        {
+            if (args[i].equals(option))
+            {
+                retu = true;
+            }
+        }
+        return retu;
+    }
+
+}

Propchange: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/console/SanityCheckRunner.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/console/package.html
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/console/package.html?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/console/package.html (added)
+++ jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/console/package.html Mon Oct  9 10:25:51 2006
@@ -0,0 +1,3 @@
+<body>
+	This package contains the a console runner.
+</body>
\ No newline at end of file

Propchange: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/console/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/FixContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/FixContext.java?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/FixContext.java (added)
+++ jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/FixContext.java Mon Oct  9 10:25:51 2006
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.sanitycheck.fix;
+
+import org.apache.commons.chain.impl.ContextBase;
+import org.apache.jackrabbit.sanitycheck.inconsistency.NodeInconsistency;
+
+/**
+ * This class contains the <code>Inconsistency</code> instances to fix.
+ */
+public class FixContext extends ContextBase
+{
+    /**
+     * Comment for <code>serialVersionUID</code>
+     */
+    private static final long serialVersionUID = 3763098578666928434L;
+
+    /**
+     * Inconsistency to repair
+     */
+    private NodeInconsistency inconsistency;
+
+    public NodeInconsistency getInconsistency()
+    {
+        return inconsistency;
+    }
+
+    public void setInconsistency(NodeInconsistency inconsistency)
+    {
+        this.inconsistency = inconsistency;
+    }
+}

Propchange: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/FixContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveChildNodeEntry.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveChildNodeEntry.java?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveChildNodeEntry.java (added)
+++ jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveChildNodeEntry.java Mon Oct  9 10:25:51 2006
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.sanitycheck.fix;
+
+import java.util.Iterator;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.core.QName;
+import org.apache.jackrabbit.core.state.ChangeLog;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.sanitycheck.SanityCheckException;
+import org.apache.jackrabbit.sanitycheck.inconsistency.ChildNodeEntryInconsistency;
+
+/**
+ * Fixes a <code>ChildNodeEntryInconsistency</code> by removing a the child node entry.
+ */
+public class RemoveChildNodeEntry implements Command
+{
+    
+    /**
+     * @inheritDoc
+     */
+    public boolean execute(Context ctx) throws Exception
+    {
+        FixContext fCtx = (FixContext) ctx ;
+        ChildNodeEntryInconsistency inc = (ChildNodeEntryInconsistency) fCtx.getInconsistency() ; 
+        Iterator iter = inc.getNode().getChildNodeEntries().iterator();
+        while (iter.hasNext())
+        {
+            NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) iter
+                    .next();
+            if (entry.getUUID().equals(inc.getChild()))
+            {
+                QName name = entry.getName();
+                int index = entry.getIndex();
+                inc.getNode().removeChildNodeEntry(name, index);
+                ChangeLog changeLog = new ChangeLog();
+                changeLog.modified(inc.getNode());
+                try
+                {
+                    inc.getPersistenceManager().store(changeLog);
+                    return true ;
+                } catch (ItemStateException e)
+                {
+                    throw new SanityCheckException(
+                            "Unable to store repaired state", e);
+                }
+            }
+        }
+        throw new SanityCheckException(
+                "Unable to repair. Unknown reason.");
+    }
+    
+}

Propchange: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveChildNodeEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveParentEntry.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveParentEntry.java?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveParentEntry.java (added)
+++ jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveParentEntry.java Mon Oct  9 10:25:51 2006
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.sanitycheck.fix;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.core.state.ChangeLog;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.sanitycheck.SanityCheckException;
+import org.apache.jackrabbit.sanitycheck.inconsistency.ParentEntryInconsistency;
+
+/**
+ * Fix a <code>PropertyEntryInconsistency</code> by removing the property entry.
+ */
+public class RemoveParentEntry implements Command
+{
+    
+    /**
+     * @inheritDoc
+     */
+    public boolean execute(Context ctx) throws Exception
+    {
+        FixContext fCtx = (FixContext) ctx ;
+        ParentEntryInconsistency inc = (ParentEntryInconsistency) fCtx.getInconsistency() ;
+        NodeState target = inc.getNode() ;
+        target.removeParentUUID(inc.getParentUUID()) ;
+        ChangeLog changeLog = new ChangeLog();
+        changeLog.modified(target);
+        try
+        {
+            inc.getPersistenceManager().store(changeLog);
+            return true ;
+        } catch (ItemStateException e)
+        {
+            throw new SanityCheckException(
+                    "Unable to store repaired state", e);
+        }
+    }
+    
+}

Propchange: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveParentEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveProperty.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveProperty.java?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveProperty.java (added)
+++ jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveProperty.java Mon Oct  9 10:25:51 2006
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.sanitycheck.fix;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.core.state.ChangeLog;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.sanitycheck.SanityCheckException;
+import org.apache.jackrabbit.sanitycheck.inconsistency.PropertyInconsistency;
+
+/**
+ * Fixes a <code>PropertyInconsistency</code> by removing the property.
+ */
+public class RemoveProperty implements Command
+{
+    
+    /**
+     * @inheritDoc
+     */
+    public boolean execute(Context ctx) throws Exception
+    {
+        FixContext fCtx = (FixContext) ctx ;
+        PropertyInconsistency inc = (PropertyInconsistency) fCtx.getInconsistency() ; 
+        PropertyState target = inc.getProperty() ; 
+        
+        ChangeLog changeLog = new ChangeLog();
+        changeLog.deleted(target);
+        try
+        {
+            inc.getPersistenceManager().store(changeLog);
+            return true ;
+        } catch (ItemStateException e)
+        {
+            throw new SanityCheckException(
+                    "Unable to store repaired state", e);
+        }
+    }
+    
+}

Propchange: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveProperty.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemovePropertyEntry.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemovePropertyEntry.java?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemovePropertyEntry.java (added)
+++ jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemovePropertyEntry.java Mon Oct  9 10:25:51 2006
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.sanitycheck.fix;
+
+import java.util.Iterator;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.core.state.ChangeLog;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.sanitycheck.SanityCheckException;
+import org.apache.jackrabbit.sanitycheck.inconsistency.PropertyEntryInconsistency;
+
+/**
+ * Fixes a <code>PropertyEntryInconsistency</code> by removing the property
+ * entry.
+ */
+public class RemovePropertyEntry implements Command
+{
+    private boolean completed = true;
+
+    /**
+     * @inheritDoc
+     */
+    public boolean execute(Context ctx) throws Exception
+    {
+        FixContext fCtx = (FixContext) ctx;
+        PropertyEntryInconsistency inc = (PropertyEntryInconsistency) fCtx.getInconsistency();
+
+        NodeState target = inc.getNode();
+        Iterator iter = target.getPropertyEntries().iterator();
+        while (iter.hasNext())
+        {
+            NodeState.PropertyEntry entry = (NodeState.PropertyEntry) iter.next();
+            if (entry.getName().equals(inc.getPropertyEntry()))
+            {
+                ((NodeState) target).removePropertyEntry(inc.getPropertyEntry());
+                ChangeLog changeLog = new ChangeLog();
+                changeLog.modified(target);
+                try
+                {
+                    inc.getPersistenceManager().store(changeLog);
+                    return this.completed ;
+                } catch (ItemStateException e)
+                {
+                    throw new SanityCheckException(
+                        "Unable to store repaired state",
+                        e);
+                }
+            }
+        }
+        throw new SanityCheckException("Unable to repair. Unknown reason.");
+    }
+
+    public boolean isCompleted()
+    {
+        return completed;
+    }
+
+    public void setCompleted(boolean completed)
+    {
+        this.completed = completed;
+    }
+}

Propchange: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemovePropertyEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveValue.java?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveValue.java (added)
+++ jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveValue.java Mon Oct  9 10:25:51 2006
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.sanitycheck.fix;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.core.value.InternalValue;
+import org.apache.jackrabbit.core.state.ChangeLog;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.sanitycheck.SanityCheckException;
+import org.apache.jackrabbit.sanitycheck.inconsistency.ValueInconsistency;
+
+/**
+ * Fixes a <code>ValueInconsistency</code> only in 
+ * multivalued properties by removing the value.
+ * It can't handle single value properties. If the property is
+ * single valued it delegates the call to the next command
+ * in the chain.
+ */
+public class RemoveValue implements Command
+{
+    
+    /**
+     * @inheritDoc
+     */
+    public boolean execute(Context ctx) throws Exception
+    {
+        FixContext fCtx = (FixContext) ctx ;
+        ValueInconsistency inc = (ValueInconsistency) fCtx.getInconsistency() ;
+        PropertyState prop = inc.getProperty() ;
+
+        // Check it's multivalues
+        if (prop.getValues().length==1) {
+            return false ;
+        }
+        
+        // Remove the value from the collection
+        InternalValue[] values =  prop.getValues() ;
+        Collection newValues = new ArrayList() ;
+        for (int i = 0; i < values.length; i++)
+        {
+            InternalValue value = values[i];
+            if (i!=inc.getIndex()) {
+                newValues.add(values[i]);
+            }
+        }
+        
+        // Modify and store the property
+        prop.setValues((InternalValue[]) newValues.toArray(new InternalValue[values.length-1]));
+        ChangeLog changeLog = new ChangeLog();
+        changeLog.modified(prop);
+        try
+        {
+            inc.getPersistenceManager().store(changeLog);
+        } catch (ItemStateException e)
+        {
+            throw new SanityCheckException(
+                    "Unable to store repaired property state", e);
+        }
+        
+        return true;
+    }
+    
+}

Propchange: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/RemoveValue.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/package.html
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/package.html?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/package.html (added)
+++ jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/package.html Mon Oct  9 10:25:51 2006
@@ -0,0 +1,3 @@
+<body>
+	This package contains fixes for inconsistencies.
+</body>
\ No newline at end of file

Propchange: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/fix/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/ChildNodeEntryInconsistency.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/ChildNodeEntryInconsistency.java?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/ChildNodeEntryInconsistency.java (added)
+++ jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/ChildNodeEntryInconsistency.java Mon Oct  9 10:25:51 2006
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.sanitycheck.inconsistency;
+
+
+
+/**
+ * Inconsistenct in child node entry value  
+ */
+public interface ChildNodeEntryInconsistency extends NodeInconsistency
+{
+    String getChild() ;
+}

Propchange: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/ChildNodeEntryInconsistency.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/NodeInconsistency.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/NodeInconsistency.java?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/NodeInconsistency.java (added)
+++ jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/NodeInconsistency.java Mon Oct  9 10:25:51 2006
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.sanitycheck.inconsistency;
+
+import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.core.state.PersistenceManager;
+
+/**
+ * <p>
+ * Inconsistency in a Node
+ * </p>
+ */
+public interface NodeInconsistency
+{
+
+    /**
+     * get the inconsistent node
+     * 
+     * @param state
+     */
+    public NodeState getNode();
+
+    /**
+     * @return Inconsistency's PersistenceManager name
+     */ 
+    public String getPersistenceManagerName();
+
+    /**
+     * @return Inconsistency's PersistenceManager
+     */
+    public PersistenceManager getPersistenceManager();
+
+    /**
+     * Inconsistency description
+     * 
+     * @return
+     */
+    public String getDescription();
+
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/NodeInconsistency.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/ParentEntryInconsistency.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/ParentEntryInconsistency.java?view=auto&rev=454433
==============================================================================
--- jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/ParentEntryInconsistency.java (added)
+++ jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/ParentEntryInconsistency.java Mon Oct  9 10:25:51 2006
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.sanitycheck.inconsistency;
+
+
+/**
+ * Inconsistency in a parent entry
+ */
+public interface ParentEntryInconsistency extends NodeInconsistency
+{
+    String getParentUUID() ;
+}

Propchange: jackrabbit/trunk/contrib/sanitycheck/src/java/org/apache/jackrabbit/sanitycheck/inconsistency/ParentEntryInconsistency.java
------------------------------------------------------------------------------
    svn:eol-style = native