# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: /home/al/cvs-apps/jackrabbit/trunk/jackrabbit-ocm
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: pom.xml
--- pom.xml Base (BASE)
+++ pom.xml Locally Modified (Based On LOCAL)
@@ -109,13 +109,12 @@
       <groupId>commons-beanutils</groupId>
       <artifactId>commons-beanutils</artifactId>
     </dependency>
-
-    <!-- Test -->
     <dependency>
       <groupId>org.apache.jackrabbit</groupId>
       <artifactId>jackrabbit-core</artifactId>
-      <scope>test</scope>
     </dependency>
+
+    <!-- Test -->
     <dependency>
       <groupId>org.apache.geronimo.specs</groupId>
       <artifactId>geronimo-jta_1.0.1B_spec</artifactId>
Index: src/main/java/org/apache/jackrabbit/ocm/manager/impl/ObjectContentManagerImpl.java
--- src/main/java/org/apache/jackrabbit/ocm/manager/impl/ObjectContentManagerImpl.java Base (BASE)
+++ src/main/java/org/apache/jackrabbit/ocm/manager/impl/ObjectContentManagerImpl.java Locally Modified (Based On LOCAL)
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.ocm.manager.impl;
 
+import java.io.FileInputStream;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -34,6 +35,7 @@
 import javax.jcr.Workspace;
 import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.query.InvalidQueryException;
 import javax.jcr.query.QueryResult;
 import javax.jcr.version.VersionHistory;
@@ -64,6 +66,10 @@
 import org.apache.jackrabbit.ocm.repository.NodeUtil;
 import org.apache.jackrabbit.ocm.version.Version;
 import org.apache.jackrabbit.ocm.version.VersionIterator;
+import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
+import org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl;
+import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.core.nodetype.xml.NodeTypeReader;
 
 /**
  *
@@ -77,6 +83,15 @@
  * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
  */
 public class ObjectContentManagerImpl implements ObjectContentManager {
+     /** namespace prefix constant */
+    public static final String OCM_NAMESPACE_PREFIX   = "ocm";
+
+    /** namespace constant */
+    public static final String OCM_NAMESPACE   = "http://jackrabbit.apache.org/ocm";    
+    
+    /** Item path separator */
+    public static final String PATH_SEPARATOR = "/";
+   
     /**
      * Logger.
      */
@@ -207,6 +222,89 @@
     }
 
     /**
+     * Creates the ocm namespace, must be executed at least once 
+     * for new repository.
+     */
+    private static void createNamespace(Session session) throws RepositoryException
+    {
+         try
+         {
+            log.info("Jcr session setup ...");
+        	
+            String[] jcrNamespaces = session.getWorkspace().getNamespaceRegistry().getPrefixes();
+            boolean createNamespace = true;
+            for (int i = 0; i < jcrNamespaces.length; i++)
+            {
+                if (jcrNamespaces[i].equals(OCM_NAMESPACE_PREFIX))
+                {
+                    createNamespace = false;
+                    log.debug("Jackrabbit OCM namespace exists.");
+                }
+            }
+             
+            if (createNamespace)
+            {
+                session.getWorkspace().getNamespaceRegistry().registerNamespace(OCM_NAMESPACE_PREFIX, OCM_NAMESPACE);
+                log.info("Successfully created Jackrabbit OCM namespace.");
+            }
+            
+            if (session.getRootNode() != null)
+            {
+                log.info("Jcr session setup successfull.");
+            }
+            
+
+        }
+        catch (Exception e)
+        {
+            log.error("Error while setting up the jcr session.", e);
+            throw new RepositoryException(e.getMessage());
+        }
+    }
+/**
+ * Creates OCM namespace if not created before and registers additioanl node
+ * types needed for OCM. May be executed once for new repository.
+ * @param session Active JCR session with 
+ * @param xml input stream with nodetype definition xml
+ */
+    public static void registerOCMNodeTypes(Session session, InputStream xml) throws RepositoryException
+    {
+        try {
+                        createNamespace(session);
+                        
+			NodeTypeDef[] types = NodeTypeReader.read(xml);
+
+			Workspace workspace = session.getWorkspace();
+			NodeTypeManager ntMgr = workspace.getNodeTypeManager();
+			NodeTypeRegistry ntReg = ((NodeTypeManagerImpl) ntMgr).getNodeTypeRegistry();
+
+			for (int j = 0; j < types.length; j++) {
+			    NodeTypeDef def = types[j];
+
+			    try {
+			        ntReg.getNodeTypeDef(def.getName());
+			    }
+			    catch (NoSuchNodeTypeException nsne) {
+			        // HINT: if not already registered than register custom node type
+			        ntReg.registerNodeType(def);
+			    }
+
+			}
+		} 
+        catch (Exception e) 
+		{
+        	throw new RepositoryException("Impossible to register node types", e);
+		}
+    }   
+/** 
+ * Checks repository ready for usage with simple annoation-based OCM
+ * @param session Active JCR session with  * 
+ */   
+    public static void checkRepositorySetup(Session session) throws RepositoryException{
+      registerOCMNodeTypes(session, ObjectContentManagerImpl.class.getResourceAsStream("nodetypes-discriminator.xml"));  
+    }
+    
+    /**
      * Sets the <code>Mapper</code> used by this object content manager.
      *
      * @param mapper
Index: src/main/java/org/apache/jackrabbit/ocm/manager/impl/nodetypes-dicsriminator.xml
--- src/main/java/org/apache/jackrabbit/ocm/manager/impl/nodetypes-dicsriminator.xml Locally New
+++ src/main/java/org/apache/jackrabbit/ocm/manager/impl/nodetypes-dicsriminator.xml Locally New
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+ 
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<nodeTypes xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
+	xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal"
+	xmlns:sv="http://www.jcp.org/jcr/sv/1.0"
+	xmlns:test="http://www.apache.org/jackrabbit/test"
+	xmlns:mix="http://www.jcp.org/jcr/mix/1.0"
+	xmlns:ocm="http://jackrabbit.apache.org/ocm">
+	
+   <nodeType name="ocm:discriminator" isMixin="true">
+    <supertypes>
+      <supertype>nt:base</supertype>
+    </supertypes>
+    <propertyDefinition name="ocm:classname" requiredType="String" autoCreated="false" mandatory="true" onParentVersion="COPY" protected="false" multiple="false" />    
+  </nodeType>
+</nodeTypes>
