jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r653575 [1/2] - in /jackrabbit/sandbox/jackrabbit-jcr-mapping/spring: ./ src/java/ src/main/java/org/apache/jackrabbit/ocm/spring/ src/spring-config/ src/test-config/ src/test/ src/test/java/org/apache/jackrabbit/ocm/spring/ src/test/java/o...
Date Mon, 05 May 2008 19:59:14 GMT
Author: clombart
Date: Mon May  5 12:59:14 2008
New Revision: 653575

URL: http://svn.apache.org/viewvc?rev=653575&view=rev
Log:
Update the project to support Spring 2.5 thanks to the contribution made by Padraic Hannon and S├ębastien Deleuze (sorry for the delay on this issue). 
The project structure has been also reorganized. 
I will continue to enhance the code by using the Spring annotations.

Added:
    jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/exception/
    jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/exception/PersistenceException.java
    jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/resources/nodetypes/
    jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/resources/nodetypes/custom_nodetypes.xml
Removed:
    jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/java/
    jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/spring-config/
    jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test-config/
    jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/log4j.properties
    jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/org/
Modified:
    jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/pom.xml
    jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/JackrabbitSessionFactory.java
    jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/JcrMappingCallback.java
    jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/JcrMappingOperations.java
    jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/JcrMappingTemplate.java
    jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/MappingDescriptorFactoryBean.java
    jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/RepositoryUtil.java
    jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/SimpleTest.java
    jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/components/ArticleService.java
    jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/components/NewsService.java
    jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/components/impl/ArticleServiceImpl.java
    jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/components/impl/NewsServiceImpl.java

Modified: jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/pom.xml?rev=653575&r1=653574&r2=653575&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/pom.xml (original)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/pom.xml Mon May  5 12:59:14 2008
@@ -1,146 +1,192 @@
-<?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.
--->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
-                             http://maven.apache.org/maven-v4_0_0.xsd ">
-	<modelVersion>4.0.0</modelVersion>
-
-	<!-- ====================================================================== -->
-	<!-- P R O J E C T  D E S C R I P T I O N                                   -->
-	<!-- ====================================================================== -->
-	<parent>
-		<groupId>org.apache.jackrabbit</groupId>
-		<artifactId>jackrabbit</artifactId>
-		<version>1.4-SNAPSHOT</version>
-	</parent>
-	<artifactId>jackrabbit-ocm-spring</artifactId>
-	<packaging>jar</packaging>
-	<name>Jackrabbit Object Content Mapping Spring Integration</name>
-	<description>
-		This Jackrabbit subproject is an object/JCR persistence and
-		query service. This tools provides the ability to configure
-        Jackrabbit OCM services via Spring.
-	</description>
-	<inceptionYear>2007</inceptionYear>
-
-	<!-- ====================================================================== -->
-	<!-- B U I L D                                                              -->
-	<!-- ====================================================================== -->
-	<build>
-		<plugins>
-			<plugin>
-				<inherited>true</inherited>
-				<artifactId>maven-compiler-plugin</artifactId>
-				<configuration>
-					<target>1.5</target>
-					<source>1.5</source>
-				</configuration>
-			</plugin>
-			<plugin>
-				<groupId>org.apache.maven.plugins</groupId>
-				<artifactId>maven-surefire-plugin</artifactId>
-				<configuration>
-					<argLine>-Xmx256m</argLine>
-				</configuration>
-			</plugin>
-		</plugins>
-	</build>
-
-	<!-- ====================================================================== -->
-	<!-- P R O F I L E S                                                        -->
-	<!-- ====================================================================== -->
-    <profiles>
-        <profile>
-            <id>jdk1.4</id>
-            <build>
-                <plugins>
-                    <plugin>
-                        <inherited>true</inherited>
-                        <artifactId>maven-compiler-plugin</artifactId>
-                        <configuration>                            
-                            <target>1.4</target>
-                            <source>1.4</source>
-                        </configuration>
-                    </plugin>
-                    <plugin>
-                        <groupId>org.apache.maven.plugins</groupId>
-                        <artifactId>maven-jar-plugin</artifactId>
-                        <configuration>
-                            <classifier>jdk1.4</classifier>
-                        </configuration>
-                    </plugin>
-                </plugins>
-            </build>
-        </profile>
-    </profiles>
-
-	<!-- ====================================================================== -->
-	<!-- D E P E N D E N C I E S                                                -->
-	<!-- ====================================================================== -->
-	<dependencies>
-		<dependency>
-			<groupId>javax.jcr</groupId>
-			<artifactId>jcr</artifactId>
-			<version>1.0</version>
-		</dependency>
-        <dependency>
-			<groupId>org.apache.jackrabbit</groupId>
-			<artifactId>jackrabbit-ocm</artifactId>
-			<version>1.4-SNAPSHOT</version>
-	</dependency>
-        <dependency>
-            <groupId>org.springframework</groupId>
-            <artifactId>spring</artifactId>
-            <version>2.0.7</version>
-        </dependency>
-        <dependency>
-            <groupId>org.springmodules</groupId>
-            <artifactId>spring-modules-jcr</artifactId>
-            <version>0.8</version>
-        </dependency>
-        <dependency>
-            <groupId>commons-logging</groupId>
-            <artifactId>commons-logging</artifactId>
-            <version>1.1</version>
-        </dependency>
-
-
-		<!-- Test -->
-		<dependency>
-			<groupId>junit</groupId>
-			<artifactId>junit</artifactId>
-			<version>3.8.1</version>
-			<scope>test</scope>
-		</dependency>
-	</dependencies>
-
-	<scm>
-		<connection>
-			scm:svn:http://svn.apache.org/repos/asf/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring
-		</connection>
-		<developerConnection>
-			scm:svn:https://svn.apache.org/repos/asf/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring
-		</developerConnection>
-		<url>
-			http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring
-		</url>
-	</scm>
-</project>
+<?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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+                             http://maven.apache.org/maven-v4_0_0.xsd ">
+	<modelVersion>4.0.0</modelVersion>
+
+	<!-- ====================================================================== -->
+	<!-- P R O J E C T  D E S C R I P T I O N                                   -->
+	<!-- ====================================================================== -->
+	<parent>
+		<groupId>org.apache.jackrabbit</groupId>
+		<artifactId>jackrabbit</artifactId>
+		<version>1.5-SNAPSHOT</version>
+	</parent>
+	<artifactId>jackrabbit-ocm-spring</artifactId>
+	<packaging>jar</packaging>
+	<version>1.5-SNAPSHOT</version>
+	<name>Jackrabbit OCM Spring</name>
+	<description>
+		This project provides Spring support for Jackrabbit OCM
+	</description>
+	<inceptionYear>2007</inceptionYear>
+
+	<!-- ====================================================================== -->
+	<!-- B U I L D                                                              -->
+	<!-- ====================================================================== -->
+	<build>
+		<plugins>
+			<plugin>
+				<inherited>true</inherited>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<target>1.5</target>
+					<source>1.5</source>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-surefire-plugin</artifactId>
+				<version>2.3</version>
+				<configuration>
+					<argLine>-Xmx256m</argLine>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+
+	<!-- ====================================================================== -->
+	<!-- P R O F I L E S                                                        -->
+	<!-- ====================================================================== -->
+	<profiles>
+		<profile>
+			<id>jdk1.4</id>
+			<build>
+				<plugins>
+					<plugin>
+						<inherited>true</inherited>
+						<artifactId>maven-compiler-plugin</artifactId>
+						<configuration>
+							<target>1.4</target>
+							<source>1.4</source>
+						</configuration>
+					</plugin>
+					<plugin>
+						<groupId>org.apache.maven.plugins</groupId>
+						<artifactId>maven-jar-plugin</artifactId>
+						<configuration>
+							<classifier>jdk1.4</classifier>
+						</configuration>
+					</plugin>
+				</plugins>
+			</build>
+		</profile>
+	</profiles>
+
+	<!-- ====================================================================== -->
+	<!-- D E P E N D E N C I E S                                                -->
+	<!-- ====================================================================== -->
+	<dependencies>
+		<dependency>
+		    <groupId>org.springmodules</groupId>
+		    <artifactId>spring-modules-jcr</artifactId>
+		    <version>0.8b</version>
+		    <exclusions>
+		    	<exclusion>
+		    		<groupId>aparzev</groupId>
+		    		<artifactId>commons</artifactId>
+		    	</exclusion>
+		    	<exclusion>
+		    		<groupId>aparzev</groupId>
+		    		<artifactId>doka</artifactId>
+		    	</exclusion>
+		    	<exclusion>
+		    		<groupId>jeceira</groupId>
+		    		<artifactId>jeceira</artifactId>
+		    	</exclusion>
+		    	<exclusion>
+		    		<groupId>jsr170</groupId>
+		    		<artifactId>jsr170</artifactId>
+		    	</exclusion>
+		    	<exclusion>
+		    		<groupId>jug</groupId>
+		    		<artifactId>jug-asl</artifactId>
+		    	</exclusion>
+		    	<exclusion>
+		    		<groupId>org.apache.jackrabbit</groupId>
+		    		<artifactId>jackrabbit-jca</artifactId>
+		    	</exclusion>
+		    </exclusions>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.jackrabbit</groupId>
+			<artifactId>jackrabbit-api</artifactId>
+			<version>1.5-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.jackrabbit</groupId>
+			<artifactId>jackrabbit-core</artifactId>
+			<version>1.5-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.jackrabbit</groupId>
+			<artifactId>jackrabbit-jcr-commons</artifactId>
+			<version>1.5-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.jackrabbit</groupId>
+			<artifactId>jackrabbit-ocm</artifactId>
+			<version>1.5-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.jackrabbit</groupId>
+			<artifactId>jackrabbit-jcr-rmi</artifactId>
+			<version>1.5-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.jackrabbit</groupId>
+			<artifactId>jackrabbit-jca</artifactId>
+			<version>1.5-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.jackrabbit</groupId>
+			<artifactId>jackrabbit-ocm</artifactId>
+			<version>1.5-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>javax.jcr</groupId>
+			<artifactId>jcr</artifactId>
+			<version>1.0</version>
+		</dependency>
+
+		<!-- Test -->
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>3.8.1</version>
+			<scope>test</scope>
+		</dependency>
+
+	</dependencies>
+
+	<scm>
+		<connection>
+			scm:svn:http://svn.apache.org/repos/asf/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring
+		</connection>
+		<developerConnection>
+			scm:svn:https://svn.apache.org/repos/asf/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring
+		</developerConnection>
+		<url>
+			http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring
+		</url>
+	</scm>
+</project>

Modified: jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/JackrabbitSessionFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/JackrabbitSessionFactory.java?rev=653575&r1=653574&r2=653575&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/JackrabbitSessionFactory.java (original)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/JackrabbitSessionFactory.java Mon May  5 12:59:14 2008
@@ -1,80 +1,127 @@
-/*
- * 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.
- */
-package org.apache.jackrabbit.ocm.spring;
-
-import javax.jcr.NamespaceException;
-import javax.jcr.NamespaceRegistry;
-import javax.jcr.RepositoryException;
-
-import org.springmodules.jcr.JcrSessionFactory;
-
-/**
- *  JCR session factory specific to Jaclrabbit for Graffito. Until now, Jackrabbit cannot unregister a namespace. 
- *  So, the JcrSessionFactory provided by the spring module is not usefull when namespace management are needed. 
- *  This class extends the JcrSessionFactory in order to add the namespace graffito
- *
- * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
- */
-public class JackrabbitSessionFactory extends JcrSessionFactory 
-{
-
-	/**
-	 * Register the namespaces.
-	 * @throws RepositoryException
-	 */
-    protected void registerNamespaces() throws Exception {
-        NamespaceRegistry registry =
-            getSession().getWorkspace().getNamespaceRegistry();
-
-        // Keep trying until the Graffito namespace has been registered
-        int n = 0;
-        String prefix = null;
-        while (prefix == null) {
-            try {
-                // Is the Graffito namespace registered?
-                prefix = registry.getPrefix(RepositoryUtil.OCM_NAMESPACE);
-            } catch (NamespaceException e1) {
-                // No, try to register it with the default prefix
-                prefix = RepositoryUtil.OCM_NAMESPACE_PREFIX;
-                // ... and a sequence number if the first attempt failed 
-                if (n++ > 0) {
-                    prefix = prefix + n;
-                }
-                try {
-                    // Is this prefix registered to the Graffito namespace?
-                    if (!RepositoryUtil.OCM_NAMESPACE.equals(
-                            registry.getURI(prefix))) {
-                        // No, but it *is* registered. Try the next prefix...
-                        prefix = null;
-                    }
-                } catch (NamespaceException e2) {
-                    try {
-                        // No, and it's not registered. Try registering it:
-                        registry.registerNamespace(
-                                prefix, RepositoryUtil.OCM_NAMESPACE);
-                    } catch (NamespaceException e3) {
-                        // Registration failed. Try the next prefix...
-                        prefix = null;
-                    }
-                }
-            }
-        }
-
-        super.registerNamespaces();
-    }
-
-}
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.ocm.spring;
+
+import java.io.InputStream;
+
+import javax.jcr.NamespaceException;
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.RepositoryException;
+import javax.jcr.Workspace;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.nodetype.NodeTypeManager;
+
+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;
+import org.springframework.core.io.Resource;
+import org.springmodules.jcr.JcrSessionFactory;
+
+/**
+ *  JCR session factory specific to Jackrabbit OCM.
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class JackrabbitSessionFactory extends JcrSessionFactory
+{
+
+	private Resource nodeTypes2Import;
+
+	public Resource getNodeTypes2Import()
+	{
+		return nodeTypes2Import;
+	}
+
+	public void setNodeTypes2Import(Resource nodeTypes2Import)
+	{
+		this.nodeTypes2Import = nodeTypes2Import;
+	}
+
+	/**
+	 * Register the namespaces.
+	 * @throws RepositoryException
+	 */
+    protected void registerNamespaces() throws Exception {
+        NamespaceRegistry registry =
+            getSession().getWorkspace().getNamespaceRegistry();
+
+
+        int n = 0;
+        String prefix = null;
+        while (prefix == null) {
+            try {
+                prefix = registry.getPrefix(RepositoryUtil.OCM_NAMESPACE);
+            } catch (NamespaceException e1) {
+                // No, try to register it with the default prefix
+                prefix = RepositoryUtil.OCM_NAMESPACE_PREFIX;
+                // ... and a sequence number if the first attempt failed
+                if (n++ > 0) {
+                     prefix = prefix + n;
+                }
+                try {
+                    // Is this prefix registered to the Graffito namespace?
+                    if (!RepositoryUtil.OCM_NAMESPACE.equals(
+                            registry.getURI(prefix))) {
+                        // No, but it *is* registered. Try the next prefix...
+                        prefix = null;
+                    }
+                } catch (NamespaceException e2) {
+                    try {
+                        // No, and it's not registered. Try registering it:
+                        registry.registerNamespace(
+                                prefix, RepositoryUtil.OCM_NAMESPACE);
+                    } catch (NamespaceException e3) {
+                        // Registration failed. Try the next prefix...
+                        prefix = null;
+                    }
+                }
+            }
+        }
+
+        super.registerNamespaces();
+    }
+
+
+
+    protected void registerNodeTypes() throws Exception
+    {
+        if (nodeTypes2Import == null) return;
+    	InputStream xml = nodeTypes2Import.getInputStream();
+
+        // HINT: throws InvalidNodeTypeDefException, IOException
+        NodeTypeDef[] types = NodeTypeReader.read(xml);
+
+        Workspace workspace = getSession().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);
+            }
+
+        }
+    }
+
+}

Modified: jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/JcrMappingCallback.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/JcrMappingCallback.java?rev=653575&r1=653574&r2=653575&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/JcrMappingCallback.java (original)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/JcrMappingCallback.java Mon May  5 12:59:14 2008
@@ -1,45 +1,45 @@
-/*
- * 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.
- */
-package org.apache.jackrabbit.ocm.spring;
-
-import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
-import org.apache.jackrabbit.ocm.exception.JcrMappingException;
-
-/**
- * Callback interface for Jcr mapping code. To be used with JcrMappingTemplate's execute method, 
- * assumably often as anonymous classes within a method implementation. The typical 
- * implementation will call PersistenceManager.get/insert/remove/update to perform some operations on 
- * the repository.
- * 
- * @author Costin Leau
- *
- */
-public interface JcrMappingCallback {
-
-    /**
-     * Called by {@link JcrMappingTemplate#execute} within an active PersistenceManager
-     * {@link org.apache.jackrabbit.ocm.manager.ObjectContentManager}.
-     * It is not responsible for logging out of the <code>Session</code> or handling transactions.
-     *
-     * Allows for returning a result object created within the
-     * callback, i.e. a domain object or a collection of domain
-     * objects. A thrown {@link RuntimeException} is treated as an
-     * application exeception; it is propagated to the caller of the
-     * template.
-     */
-    public Object doInJcrMapping(ObjectContentManager manager) throws JcrMappingException;
-}
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.ocm.spring;
+
+import org.apache.jackrabbit.ocm.exception.JcrMappingException;
+import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
+
+/**
+ * Callback interface for Jcr mapping code. To be used with JcrMappingTemplate's execute method,
+ * assumably often as anonymous classes within a method implementation. The typical
+ * implementation will call PersistenceManager.get/insert/remove/update to perform some operations on
+ * the repository.
+ *
+ * @author Costin Leau
+ *
+ */
+public interface JcrMappingCallback {
+
+    /**
+     * Called by {@link JcrMappingTemplate#execute} within an active PersistenceManager
+     * {@link org.apache.jackrabbit.ocm.manager.ObjectContentManager}.
+     * It is not responsible for logging out of the <code>Session</code> or handling transactions.
+     *
+     * Allows for returning a result object created within the
+     * callback, i.e. a domain object or a collection of domain
+     * objects. A thrown {@link RuntimeException} is treated as an
+     * application exeception; it is propagated to the caller of the
+     * template.
+     */
+    public Object doInJcrMapping(ObjectContentManager manager) throws JcrMappingException;
+}

Modified: jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/JcrMappingOperations.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/JcrMappingOperations.java?rev=653575&r1=653574&r2=653575&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/JcrMappingOperations.java (original)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/JcrMappingOperations.java Mon May  5 12:59:14 2008
@@ -1,71 +1,71 @@
-/*
- * 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.
- */
-package org.apache.jackrabbit.ocm.spring;
-
-import java.util.Collection;
-
-import org.apache.jackrabbit.ocm.query.Query;
-import org.springframework.dao.DataAccessException;
-
-/**
- * Interface that specifies a basic set of JCR mapping operations. Not often used, but 
- * a useful option to enhance testability, as it can easily be mocked or stubbed.
- * 
- * <p>
- * Provides JcrMappingTemplate's data access methods that mirror various PersistenceManager
- * methods. See the required javadocs for details on those methods.
- * 
- * @author Costin Leau
- *
- */
-public interface JcrMappingOperations {
-
-    /**
-     * Execute a JcrMappingCallback.
-     * 
-     * @param callback callback to execute
-     * @return the callback result
-     * @throws DataAccessException
-     */
-    public Object execute(JcrMappingCallback callback) throws DataAccessException;
-
-    /**
-     * @see org.apache.jackrabbit.ocm.manager.ObjectContentManager#insert(java.lang.Object)
-     */
-    public void insert( final java.lang.Object object);
-
-    /**
-     * @see org.apache.jackrabbit.ocm.manager.ObjectContentManager#update(java.lang.Object)
-     */
-    public void update( final java.lang.Object object);
-
-    /**
-     * @see org.apache.jackrabbit.ocm.manager.ObjectContentManager#remove(java.lang.String)
-     */
-    public void remove(final java.lang.String path);
-
-    /**
-     * @see org.apache.jackrabbit.ocm.manager.ObjectContentManager#getObject(java.lang.String)
-     */
-    public Object getObject( final java.lang.String path);
-
-    /**
-     * @see org.apache.jackrabbit.ocm.manager.ObjectContentManager#getObjects(org.apache.jackrabbit.ocm.query.Query)
-     */
-    public Collection getObjects(final Query query);
-
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.ocm.spring;
+
+import java.util.Collection;
+
+import org.apache.jackrabbit.ocm.query.Query;
+import org.springframework.dao.DataAccessException;
+
+/**
+ * Interface that specifies a basic set of JCR mapping operations. Not often used, but
+ * a useful option to enhance testability, as it can easily be mocked or stubbed.
+ *
+ * <p>
+ * Provides JcrMappingTemplate's data access methods that mirror various PersistenceManager
+ * methods. See the required javadocs for details on those methods.
+ *
+ * @author Costin Leau
+ *
+ */
+public interface JcrMappingOperations {
+
+    /**
+     * Execute a JcrMappingCallback.
+     *
+     * @param callback callback to execute
+     * @return the callback result
+     * @throws DataAccessException
+     */
+    public Object execute(JcrMappingCallback callback) throws DataAccessException;
+
+    /**
+     * @see org.apache.jackrabbit.ocm.manager.ObjectContentManager#insert(java.lang.Object)
+     */
+    public void insert( final java.lang.Object object);
+
+    /**
+     * @see org.apache.jackrabbit.ocm.manager.ObjectContentManager#update(java.lang.Object)
+     */
+    public void update( final java.lang.Object object);
+
+    /**
+     * @see org.apache.jackrabbit.ocm.manager.ObjectContentManager#remove(java.lang.String)
+     */
+    public void remove(final java.lang.String path);
+
+    /**
+     * @see org.apache.jackrabbit.ocm.manager.ObjectContentManager#getObject(java.lang.String)
+     */
+    public Object getObject( final java.lang.String path);
+
+    /**
+     * @see org.apache.jackrabbit.ocm.manager.ObjectContentManager#getObjects(org.apache.jackrabbit.ocm.query.Query)
+     */
+    public Collection getObjects(final Query query);
+
 }
\ No newline at end of file

Modified: jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/JcrMappingTemplate.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/JcrMappingTemplate.java?rev=653575&r1=653574&r2=653575&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/JcrMappingTemplate.java (original)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/JcrMappingTemplate.java Mon May  5 12:59:14 2008
@@ -1,251 +1,251 @@
-/*
- * 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.
- */
-package org.apache.jackrabbit.ocm.spring;
-
-import java.io.InputStream;
-import java.sql.Timestamp;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
-import org.apache.jackrabbit.ocm.exception.JcrMappingException;
-import org.apache.jackrabbit.ocm.mapper.Mapper;
-import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
-import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.BinaryTypeConverterImpl;
-import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.BooleanTypeConverterImpl;
-import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.ByteArrayTypeConverterImpl;
-import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.CalendarTypeConverterImpl;
-import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.DoubleTypeConverterImpl;
-import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.IntTypeConverterImpl;
-import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.LongTypeConverterImpl;
-import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.StringTypeConverterImpl;
-import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.TimestampTypeConverterImpl;
-import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.UtilDateTypeConverterImpl;
-import org.apache.jackrabbit.ocm.manager.impl.ObjectContentManagerImpl;
-import org.apache.jackrabbit.ocm.query.Query;
-import org.apache.jackrabbit.ocm.query.QueryManager;
-import org.apache.jackrabbit.ocm.query.impl.QueryManagerImpl;
-import org.springframework.dao.DataAccessException;
-import org.springmodules.jcr.JcrCallback;
-import org.springmodules.jcr.JcrSystemException;
-import org.springmodules.jcr.JcrTemplate;
-import org.springmodules.jcr.SessionFactory;
-
-/**
- * Template whichs adds mapping support for the Java Content Repository.
- * <p/>
- * For PersistenceManagers the template creates internally the set of default converters.
- * 
- * 
- * @see org.apache.jackrabbit.ocm.manager.ObjectContentManager
- * @author Costin Leau
- * 
- */
-public class JcrMappingTemplate extends JcrTemplate implements JcrMappingOperations {
-
-    private Mapper mapper;
-    
-
-    /**
-     * Default constructor for JcrTemplate
-     */
-    public JcrMappingTemplate() {
-        super();
-
-    }
-
-    /**
-     * @param sessionFactory
-     */
-    public JcrMappingTemplate(SessionFactory sessionFactory, Mapper mapper) {
-        setSessionFactory(sessionFactory);
-        setMapper(mapper);
-        
-        afterPropertiesSet();
-    }
-
-    /**
-     * Add rule for checking the mapper.
-     * 
-     * @see org.springmodules.jcr.JcrAccessor#afterPropertiesSet()
-     */
-    public void afterPropertiesSet() {
-        super.afterPropertiesSet();
-        if (mapper == null)
-            throw new IllegalArgumentException("mapper can NOT be null");
-    }
-
-    /**
-     * Method for creating a query manager. It's unclear where this entity is stateless or not.
-     * 
-     * @return
-     */
-    public  QueryManager createQueryManager() {
-        try {
-            Map atomicTypeConverters = this.createDefaultConverters(this.getSession());
-            return new QueryManagerImpl(mapper, atomicTypeConverters, this.getSession().getValueFactory());
-        } catch (RepositoryException e) {
-            throw new JcrSystemException(e);
-        }
-    }
-
-    /**
-     * Creates a persistence manager. It's unclear if this object is stateless/thread-safe or not.
-     * However because it depends on session it has to be created per session and it's not per repository.
-     * 
-     * 
-     * @param session
-     * @return
-     * @throws JcrMappingException
-     */
-    protected ObjectContentManager createPersistenceManager(Session session) throws RepositoryException, JcrMappingException {
-        return new ObjectContentManagerImpl(session, mapper);
-    }
-
-    /**
-     * Due to the way the actual jcr-mapping is made we have to create the converters for
-     * each session.
-     * 
-     * @param session
-     * @return
-     */
-    protected Map createDefaultConverters(Session session) throws RepositoryException {
-        Map map = new HashMap(14);
-
-        map.put(String.class, new StringTypeConverterImpl());
-        map.put(InputStream.class, new BinaryTypeConverterImpl());
-        map.put(long.class, new LongTypeConverterImpl());
-        map.put(Long.class, new LongTypeConverterImpl());
-        map.put(int.class, new IntTypeConverterImpl());
-        map.put(Integer.class, new IntTypeConverterImpl());
-        map.put(double.class, new DoubleTypeConverterImpl());
-        map.put(Double.class, new DoubleTypeConverterImpl());
-        map.put(boolean.class, new BooleanTypeConverterImpl());
-        map.put(Boolean.class, new BooleanTypeConverterImpl());
-        map.put(Calendar.class, new CalendarTypeConverterImpl());
-        map.put(Date.class, new UtilDateTypeConverterImpl());
-        map.put(byte[].class, new ByteArrayTypeConverterImpl());
-        map.put(Timestamp.class, new TimestampTypeConverterImpl());
-
-        return map;
-    }
-
-    public Object execute(final JcrMappingCallback action, boolean exposeNativeSession) throws DataAccessException {
-        return execute(new JcrCallback() {
-            /**
-             * @see org.springmodules.jcr.JcrCallback#doInJcr(javax.jcr.Session)
-             */
-            public Object doInJcr(Session session) throws RepositoryException {
-                try {
-                    return action.doInJcrMapping(createPersistenceManager(session));
-                } catch (JcrMappingException e) {
-                    throw convertMappingAccessException(e);
-                }
-            }
-
-        }, exposeNativeSession);
-    }
-
-    public Object execute(JcrMappingCallback callback) throws DataAccessException {
-        return execute(callback, isExposeNativeSession());
-    }
-
-    // ----------------
-    // Delegate methods
-    // ----------------
-
-    public void insert(final java.lang.Object object) {
-        execute(new JcrMappingCallback() {
-            public Object doInJcrMapping(ObjectContentManager manager) throws JcrMappingException {
-                manager.insert(object);
-                return null;
-            }
-        }, true);
-    }
-
-    public void update( final java.lang.Object object) {
-        execute(new JcrMappingCallback() {
-            public Object doInJcrMapping(ObjectContentManager manager) throws JcrMappingException {
-                manager.update( object);
-                return null;
-            }
-        }, true);
-    }
-
-    public void remove(final java.lang.String path) {
-        execute(new JcrMappingCallback() {
-            public Object doInJcrMapping(ObjectContentManager manager) throws JcrMappingException {
-                manager.remove(path);
-                return null;
-            }
-        }, true);
-    }
-
-    public Object getObject(final java.lang.String path) {
-        return execute(new JcrMappingCallback() {
-            public Object doInJcrMapping(ObjectContentManager manager) throws JcrMappingException {
-                return manager.getObject(path);
-            }
-        }, true);
-    }
-
-    public Collection getObjects(final Query query) {
-        return (Collection) execute(new JcrMappingCallback() {
-            public Object doInJcrMapping(ObjectContentManager manager) throws JcrMappingException {
-                return manager.getObjects(query);
-            }
-        }, true);
-    }
-
-    /**
-     * Convert the given MappingException to an appropriate exception from
-     * the <code>org.springframework.dao</code> hierarchy.
-     * <p>
-     * Note that because we have no base specific exception we have to catch
-     * the generic Exception and translate it into JcrSystemException.
-     * <p>
-     * May be overridden in subclasses.
-     * 
-     * @param ex Exception that occured
-     * @return the corresponding DataAccessException instance
-     */
-    public DataAccessException convertMappingAccessException(Exception ex) {
-        // repository exception
-        if (ex instanceof RepositoryException)
-            return super.convertJcrAccessException((RepositoryException) ex);
-        return new JcrSystemException(ex);
-    }
-
-    /**
-     * @return Returns the mapper.
-     */
-    public Mapper getMapper() {
-        return mapper;
-    }
-
-    /**
-     * @param mapper The mapper to set.
-     */
-    public void setMapper(Mapper mapper) {
-        this.mapper = mapper;
-    }    
-}
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.ocm.spring;
+
+import java.io.InputStream;
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.ocm.exception.JcrMappingException;
+import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
+import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.BinaryTypeConverterImpl;
+import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.BooleanTypeConverterImpl;
+import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.ByteArrayTypeConverterImpl;
+import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.CalendarTypeConverterImpl;
+import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.DoubleTypeConverterImpl;
+import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.IntTypeConverterImpl;
+import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.LongTypeConverterImpl;
+import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.StringTypeConverterImpl;
+import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.TimestampTypeConverterImpl;
+import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.UtilDateTypeConverterImpl;
+import org.apache.jackrabbit.ocm.manager.impl.ObjectContentManagerImpl;
+import org.apache.jackrabbit.ocm.mapper.Mapper;
+import org.apache.jackrabbit.ocm.query.Query;
+import org.apache.jackrabbit.ocm.query.QueryManager;
+import org.apache.jackrabbit.ocm.query.impl.QueryManagerImpl;
+import org.springframework.dao.DataAccessException;
+import org.springmodules.jcr.JcrCallback;
+import org.springmodules.jcr.JcrSystemException;
+import org.springmodules.jcr.JcrTemplate;
+import org.springmodules.jcr.SessionFactory;
+
+/**
+ * Template whichs adds mapping support for the Java Content Repository.
+ * <p/>
+ * For PersistenceManagers the template creates internally the set of default converters.
+ *
+ *
+ * @see org.apache.jackrabbit.ocm.manager.ObjectContentManager
+ * @author Costin Leau
+ *
+ */
+public class JcrMappingTemplate extends JcrTemplate implements JcrMappingOperations {
+
+    private Mapper mapper;
+
+
+    /**
+     * Default constructor for JcrTemplate
+     */
+    public JcrMappingTemplate() {
+        super();
+
+    }
+
+    /**
+     * @param sessionFactory
+     */
+    public JcrMappingTemplate(SessionFactory sessionFactory, Mapper mapper) {
+        setSessionFactory(sessionFactory);
+        setMapper(mapper);
+
+        afterPropertiesSet();
+    }
+
+    /**
+     * Add rule for checking the mapper.
+     *
+     * @see org.apache.jackrabbit.spring.JcrAccessor#afterPropertiesSet()
+     */
+    public void afterPropertiesSet() {
+        super.afterPropertiesSet();
+        if (mapper == null)
+            throw new IllegalArgumentException("mapper can NOT be null");
+    }
+
+    /**
+     * Method for creating a query manager. It's unclear where this entity is stateless or not.
+     *
+     * @return
+     */
+    public  QueryManager createQueryManager() {
+        try {
+            Map atomicTypeConverters = this.createDefaultConverters(this.getSession());
+            return new QueryManagerImpl(mapper, atomicTypeConverters, this.getSession().getValueFactory());
+        } catch (RepositoryException e) {
+            throw new JcrSystemException(e);
+        }
+    }
+
+    /**
+     * Creates a persistence manager. It's unclear if this object is stateless/thread-safe or not.
+     * However because it depends on session it has to be created per session and it's not per repository.
+     *
+     *
+     * @param session
+     * @return
+     * @throws JcrMappingException
+     */
+    protected ObjectContentManager createPersistenceManager(Session session) throws RepositoryException, JcrMappingException {
+        return new ObjectContentManagerImpl(session, mapper);
+    }
+
+    /**
+     * Due to the way the actual jcr-mapping is made we have to create the converters for
+     * each session.
+     *
+     * @param session
+     * @return
+     */
+    protected Map createDefaultConverters(Session session) throws RepositoryException {
+        Map map = new HashMap(14);
+
+        map.put(String.class, new StringTypeConverterImpl());
+        map.put(InputStream.class, new BinaryTypeConverterImpl());
+        map.put(long.class, new LongTypeConverterImpl());
+        map.put(Long.class, new LongTypeConverterImpl());
+        map.put(int.class, new IntTypeConverterImpl());
+        map.put(Integer.class, new IntTypeConverterImpl());
+        map.put(double.class, new DoubleTypeConverterImpl());
+        map.put(Double.class, new DoubleTypeConverterImpl());
+        map.put(boolean.class, new BooleanTypeConverterImpl());
+        map.put(Boolean.class, new BooleanTypeConverterImpl());
+        map.put(Calendar.class, new CalendarTypeConverterImpl());
+        map.put(Date.class, new UtilDateTypeConverterImpl());
+        map.put(byte[].class, new ByteArrayTypeConverterImpl());
+        map.put(Timestamp.class, new TimestampTypeConverterImpl());
+
+        return map;
+    }
+
+    public Object execute(final JcrMappingCallback action, boolean exposeNativeSession) throws DataAccessException {
+        return execute(new JcrCallback() {
+            /**
+             * @see org.apache.jackrabbit.spring.JcrCallback#doInJcr(javax.jcr.Session)
+             */
+            public Object doInJcr(Session session) throws RepositoryException {
+                try {
+                    return action.doInJcrMapping(createPersistenceManager(session));
+                } catch (JcrMappingException e) {
+                    throw convertMappingAccessException(e);
+                }
+            }
+
+        }, exposeNativeSession);
+    }
+
+    public Object execute(JcrMappingCallback callback) throws DataAccessException {
+        return execute(callback, isExposeNativeSession());
+    }
+
+    // ----------------
+    // Delegate methods
+    // ----------------
+
+    public void insert(final java.lang.Object object) {
+        execute(new JcrMappingCallback() {
+            public Object doInJcrMapping(ObjectContentManager manager) throws JcrMappingException {
+                manager.insert(object);
+                return null;
+            }
+        }, true);
+    }
+
+    public void update( final java.lang.Object object) {
+        execute(new JcrMappingCallback() {
+            public Object doInJcrMapping(ObjectContentManager manager) throws JcrMappingException {
+                manager.update( object);
+                return null;
+            }
+        }, true);
+    }
+
+    public void remove(final java.lang.String path) {
+        execute(new JcrMappingCallback() {
+            public Object doInJcrMapping(ObjectContentManager manager) throws JcrMappingException {
+                manager.remove(path);
+                return null;
+            }
+        }, true);
+    }
+
+    public Object getObject(final java.lang.String path) {
+        return execute(new JcrMappingCallback() {
+            public Object doInJcrMapping(ObjectContentManager manager) throws JcrMappingException {
+                return manager.getObject(path);
+            }
+        }, true);
+    }
+
+    public Collection getObjects(final Query query) {
+        return (Collection) execute(new JcrMappingCallback() {
+            public Object doInJcrMapping(ObjectContentManager manager) throws JcrMappingException {
+                return manager.getObjects(query);
+            }
+        }, true);
+    }
+
+    /**
+     * Convert the given MappingException to an appropriate exception from
+     * the <code>org.springframework.dao</code> hierarchy.
+     * <p>
+     * Note that because we have no base specific exception we have to catch
+     * the generic Exception and translate it into JcrSystemException.
+     * <p>
+     * May be overridden in subclasses.
+     *
+     * @param ex Exception that occured
+     * @return the corresponding DataAccessException instance
+     */
+    public DataAccessException convertMappingAccessException(Exception ex) {
+        // repository exception
+        if (ex instanceof RepositoryException)
+            return super.convertJcrAccessException((RepositoryException) ex);
+        return new JcrSystemException(ex);
+    }
+
+    /**
+     * @return Returns the mapper.
+     */
+    public Mapper getMapper() {
+        return mapper;
+    }
+
+    /**
+     * @param mapper The mapper to set.
+     */
+    public void setMapper(Mapper mapper) {
+        this.mapper = mapper;
+    }
+}

Modified: jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/MappingDescriptorFactoryBean.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/MappingDescriptorFactoryBean.java?rev=653575&r1=653574&r2=653575&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/MappingDescriptorFactoryBean.java (original)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/MappingDescriptorFactoryBean.java Mon May  5 12:59:14 2008
@@ -1,110 +1,110 @@
-/*
- * 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.
- */
-package org.apache.jackrabbit.ocm.spring;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.jackrabbit.ocm.exception.JcrMappingException;
-import org.apache.jackrabbit.ocm.mapper.impl.digester.DigesterDescriptorReader;
-import org.apache.jackrabbit.ocm.mapper.model.ClassDescriptor;
-import org.apache.jackrabbit.ocm.mapper.model.MappingDescriptor;
-import org.springframework.beans.factory.FactoryBean;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.core.io.Resource;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Iterator;
-
-/**
- * Factory bean for loading mapping files. This factory beans can load several file descriptors
- * and assembles them into an overall class descriptor. 
- * 
- * @author Costin Leau
- *
- */
-public class MappingDescriptorFactoryBean implements FactoryBean, InitializingBean {
-
-    private static final Log log = LogFactory.getLog(MappingDescriptorFactoryBean.class);
-
-    private MappingDescriptor mappingDescriptor;
-
-    private Resource[] mappings;
-
-    /**
-     * @see org.springframework.beans.factory.FactoryBean#getObject()
-     */
-    public Object getObject() throws Exception {
-        return mappingDescriptor;
-    }
-
-    /**
-     * @see org.springframework.beans.factory.FactoryBean#getObjectType()
-     */
-    public Class getObjectType() {
-        return (this.mappingDescriptor != null) ? this.mappingDescriptor.getClass() : ClassDescriptor.class;
-    }
-
-    /**
-     * @see org.springframework.beans.factory.FactoryBean#isSingleton()
-     */
-    public boolean isSingleton() {
-        return true;
-    }
-
-    /**
-     * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
-     */
-    public void afterPropertiesSet() throws Exception {
-        if (mappings == null || mappings.length == 0)
-            throw new IllegalArgumentException("at least one mapping file is needed");
-
-        createMappingDescriptor();
-    }
-
-    /**
-     * Subclasses can extend this method to provide custom behavior when creating 
-     * the mapping descriptor
-     */
-    protected void createMappingDescriptor() throws IOException, JcrMappingException {
-        // load the descriptors step by step and concatenate everything in an over-all
-        // descriptor
-        InputStream[] streams = new InputStream[mappings.length];
-        for (int i = 0; i < streams.length; i++) {
-            if (mappings[i] != null) {
-                streams[i] = mappings[i].getInputStream();
-            }
-        }
-        DigesterDescriptorReader reader = new DigesterDescriptorReader(streams);
-        mappingDescriptor = reader.loadClassDescriptors();
-    }
-
-    /**
-     * @return Returns the descriptors.
-     */
-    public Resource[] getMappings() {
-        return mappings;
-    }
-
-    /**
-     * @param descriptors The descriptors to set.
-     */
-    public void setMappings(Resource[] descriptors) {
-        this.mappings = descriptors;
-    }
-
-}
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.ocm.spring;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.ocm.exception.JcrMappingException;
+import org.apache.jackrabbit.ocm.mapper.impl.digester.DigesterDescriptorReader;
+import org.apache.jackrabbit.ocm.mapper.model.ClassDescriptor;
+import org.apache.jackrabbit.ocm.mapper.model.MappingDescriptor;
+import org.springframework.beans.factory.FactoryBean;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.core.io.Resource;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
+
+/**
+ * Factory bean for loading mapping files. This factory beans can load several file descriptors
+ * and assembles them into an overall class descriptor.
+ *
+ * @author Costin Leau
+ *
+ */
+public class MappingDescriptorFactoryBean implements FactoryBean, InitializingBean {
+
+    private static final Log log = LogFactory.getLog(MappingDescriptorFactoryBean.class);
+
+    private MappingDescriptor mappingDescriptor;
+
+    private Resource[] mappings;
+
+    /**
+     * @see org.springframework.beans.factory.FactoryBean#getObject()
+     */
+    public Object getObject() throws Exception {
+        return mappingDescriptor;
+    }
+
+    /**
+     * @see org.springframework.beans.factory.FactoryBean#getObjectType()
+     */
+    public Class getObjectType() {
+        return (this.mappingDescriptor != null) ? this.mappingDescriptor.getClass() : ClassDescriptor.class;
+    }
+
+    /**
+     * @see org.springframework.beans.factory.FactoryBean#isSingleton()
+     */
+    public boolean isSingleton() {
+        return true;
+    }
+
+    /**
+     * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
+     */
+    public void afterPropertiesSet() throws Exception {
+        if (mappings == null || mappings.length == 0)
+            throw new IllegalArgumentException("at least one mapping file is needed");
+
+        createMappingDescriptor();
+    }
+
+    /**
+     * Subclasses can extend this method to provide custom behavior when creating
+     * the mapping descriptor
+     */
+    protected void createMappingDescriptor() throws IOException, JcrMappingException {
+        // load the descriptors step by step and concatenate everything in an over-all
+        // descriptor
+        InputStream[] streams = new InputStream[mappings.length];
+        for (int i = 0; i < streams.length; i++) {
+            if (mappings[i] != null) {
+                streams[i] = mappings[i].getInputStream();
+            }
+        }
+        DigesterDescriptorReader reader = new DigesterDescriptorReader(streams);
+        mappingDescriptor = reader.loadClassDescriptors();
+    }
+
+    /**
+     * @return Returns the descriptors.
+     */
+    public Resource[] getMappings() {
+        return mappings;
+    }
+
+    /**
+     * @param descriptors The descriptors to set.
+     */
+    public void setMappings(Resource[] descriptors) {
+        this.mappings = descriptors;
+    }
+
+}

Modified: jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/RepositoryUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/RepositoryUtil.java?rev=653575&r1=653574&r2=653575&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/RepositoryUtil.java (original)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/main/java/org/apache/jackrabbit/ocm/spring/RepositoryUtil.java Mon May  5 12:59:14 2008
@@ -1,225 +1,225 @@
-/*
- * 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.
- */
-package org.apache.jackrabbit.ocm.spring;
-
-import java.util.Hashtable;
-
-import javax.jcr.Repository;
-import javax.jcr.Session;
-import javax.jcr.SimpleCredentials;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.jackrabbit.core.jndi.RegistryHelper;
-import org.apache.jackrabbit.ocm.exception.RepositoryException;
-import org.apache.jackrabbit.util.ISO9075;
-import org.apache.jackrabbit.util.Text;
-
-/**
-* Utility class for managing JCR repositories.
-* <b>Note</b>: most of the utility methods in this class can be used only with Jackrabbit.
-*
-* @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
-* @version $Id: Exp $
-*/
-public class RepositoryUtil
-{
-    
-    /** 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 = "/";
-    
-    private final static Log log = LogFactory.getLog(RepositoryUtil.class);
-    
-    /**
-     * Register a new repository 
-     * 
-     * @param repositoryName The repository unique name
-     * @param configFile The JCR config file
-     * @param homeDir The directory containing the complete repository settings (workspace, node types, ...)
-     * 
-     * @throws RepositoryException when it is not possible to register the repository
-     */
-    public static void registerRepository(String repositoryName, String configFile, String homeDir) throws RepositoryException
-    {
-        try
-        {
-            Hashtable env = new Hashtable();
-            env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory");
-            env.put(Context.PROVIDER_URL, "localhost");
-            InitialContext ctx = new InitialContext(env);
-
-            RegistryHelper.registerRepository(ctx, repositoryName, configFile, homeDir, true);
-        }
-        catch (Exception e)
-        {        
-            throw new RepositoryException("Impossible to register the respository : " + 
-                                           repositoryName + " - config file : " + configFile, e);
-        }        
-        
-    }
-    
-    
-    /**
-     * Unregister a repository 
-     * 
-     * @param repositoryName The repository unique name
-     * 
-     * @throws RepositoryException when it is not possible to unregister the repository
-     */
-    public static void unRegisterRepository(String repositoryName) throws RepositoryException
-    {
-        try
-        {
-        	Hashtable env = new Hashtable();
-            env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory");
-            env.put(Context.PROVIDER_URL, "localhost");
-            InitialContext ctx = new InitialContext(env);
-
-            RegistryHelper.unregisterRepository(ctx, repositoryName);
-        }
-        catch (Exception e)
-        {
-            throw new RepositoryException("Impossible to unregister the respository : " + 
-                                           repositoryName , e);
-        }        
-        
-    }
-    
-    /**
-     * Get a repository
-     * 
-     * @param repositoryName The repository name
-     * @return a JCR repository reference
-     * 
-     * @throws RepositoryException when it is not possible to get the repository. 
-     *         Before calling this method, the repository has to be registered (@see RepositoryUtil#registerRepository(String, String, String)
-     */
-    public static Repository getRepository(String repositoryName) throws RepositoryException
-    {
-        try
-        {
-            Hashtable env = new Hashtable();
-            env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory");
-            env.put(Context.PROVIDER_URL, "localhost");
-            InitialContext ctx = new InitialContext(env);
-            
-            Repository repository = (Repository) ctx.lookup(repositoryName);
-            return repository;
-        }
-        catch (Exception e)
-        {
-            throw new RepositoryException("Impossible to get the repository : " + repositoryName, e);
-        }        
-    }
-    
-    /**
-     * Connect to a JCR repository
-     * 
-     * @param repository The JCR repository 
-     * @param user The user name
-     * @param password The password
-     * @return a valid JCR session 
-     * 
-     * @throws RepositoryException when it is not possible to connect to the JCR repository 
-     */
-    public static Session login(Repository repository, String user, String password) throws RepositoryException
-    {
-        try
-        {
-            Session session = repository.login(new SimpleCredentials(user, password.toCharArray()), null);
-            
-           
-            return session; 
-        }
-        catch (Exception e)
-        {
-            throw new RepositoryException("Impossible to login ", e);
-        }
-    }
-      
-    
-  
-
-    
-    /**
-     * Setup the session. 
-     * Until now, we check only if the namespace prefix exist in the repository
-     * 
-     */
-    public static void setupSession(Session session) throws RepositoryException
-    {
-         try
-         {
-        	log.info("Setup 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());
-        }
-    }
-
-    /**
-     * Encode a path 
-     * @TODO : drop Jackrabbit dependency
-     * 
-     * @param path the path to encode
-     * @return the encoded path 
-     * 
-     */
-    public static String encodePath(String path)
-    {
-    	String[] pathElements = Text.explode(path, '/');
-    	for (int i=0;i<pathElements.length;i++)
-    	{
-    		pathElements[i] = ISO9075.encode(pathElements[i]);
-    	}
-    	return "/" + Text.implode(pathElements, "/");
-    }
-}
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.ocm.spring;
+
+import java.util.Hashtable;
+
+import javax.jcr.Repository;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.core.jndi.RegistryHelper;
+import org.apache.jackrabbit.ocm.exception.RepositoryException;
+import org.apache.jackrabbit.util.ISO9075;
+import org.apache.jackrabbit.util.Text;
+
+/**
+* Utility class for managing JCR repositories.
+* <b>Note</b>: most of the utility methods in this class can be used only with Jackrabbit.
+*
+* @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+* @version $Id: Exp $
+*/
+public class RepositoryUtil
+{
+
+    /** 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 = "/";
+
+    private final static Log log = LogFactory.getLog(RepositoryUtil.class);
+
+    /**
+     * Register a new repository
+     *
+     * @param repositoryName The repository unique name
+     * @param configFile The JCR config file
+     * @param homeDir The directory containing the complete repository settings (workspace, node types, ...)
+     *
+     * @throws RepositoryException when it is not possible to register the repository
+     */
+    public static void registerRepository(String repositoryName, String configFile, String homeDir) throws RepositoryException
+    {
+        try
+        {
+            Hashtable env = new Hashtable();
+            env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory");
+            env.put(Context.PROVIDER_URL, "localhost");
+            InitialContext ctx = new InitialContext(env);
+
+            RegistryHelper.registerRepository(ctx, repositoryName, configFile, homeDir, true);
+        }
+        catch (Exception e)
+        {
+            throw new RepositoryException("Impossible to register the respository : " +
+                                           repositoryName + " - config file : " + configFile, e);
+        }
+
+    }
+
+
+    /**
+     * Unregister a repository
+     *
+     * @param repositoryName The repository unique name
+     *
+     * @throws RepositoryException when it is not possible to unregister the repository
+     */
+    public static void unRegisterRepository(String repositoryName) throws RepositoryException
+    {
+        try
+        {
+        	Hashtable env = new Hashtable();
+            env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory");
+            env.put(Context.PROVIDER_URL, "localhost");
+            InitialContext ctx = new InitialContext(env);
+
+            RegistryHelper.unregisterRepository(ctx, repositoryName);
+        }
+        catch (Exception e)
+        {
+            throw new RepositoryException("Impossible to unregister the respository : " +
+                                           repositoryName , e);
+        }
+
+    }
+
+    /**
+     * Get a repository
+     *
+     * @param repositoryName The repository name
+     * @return a JCR repository reference
+     *
+     * @throws RepositoryException when it is not possible to get the repository.
+     *         Before calling this method, the repository has to be registered (@see RepositoryUtil#registerRepository(String, String, String)
+     */
+    public static Repository getRepository(String repositoryName) throws RepositoryException
+    {
+        try
+        {
+            Hashtable env = new Hashtable();
+            env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory");
+            env.put(Context.PROVIDER_URL, "localhost");
+            InitialContext ctx = new InitialContext(env);
+
+            Repository repository = (Repository) ctx.lookup(repositoryName);
+            return repository;
+        }
+        catch (Exception e)
+        {
+            throw new RepositoryException("Impossible to get the repository : " + repositoryName, e);
+        }
+    }
+
+    /**
+     * Connect to a JCR repository
+     *
+     * @param repository The JCR repository
+     * @param user The user name
+     * @param password The password
+     * @return a valid JCR session
+     *
+     * @throws RepositoryException when it is not possible to connect to the JCR repository
+     */
+    public static Session login(Repository repository, String user, String password) throws RepositoryException
+    {
+        try
+        {
+            Session session = repository.login(new SimpleCredentials(user, password.toCharArray()), null);
+
+
+            return session;
+        }
+        catch (Exception e)
+        {
+            throw new RepositoryException("Impossible to login ", e);
+        }
+    }
+
+
+
+
+
+    /**
+     * Setup the session.
+     * Until now, we check only if the namespace prefix exist in the repository
+     *
+     */
+    public static void setupSession(Session session) throws RepositoryException
+    {
+         try
+         {
+        	log.info("Setup 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());
+        }
+    }
+
+    /**
+     * Encode a path
+     * @TODO : drop Jackrabbit dependency
+     *
+     * @param path the path to encode
+     * @return the encoded path
+     *
+     */
+    public static String encodePath(String path)
+    {
+    	String[] pathElements = Text.explode(path, '/');
+    	for (int i=0;i<pathElements.length;i++)
+    	{
+    		pathElements[i] = ISO9075.encode(pathElements[i]);
+    	}
+    	return "/" + Text.implode(pathElements, "/");
+    }
+}



Mime
View raw message