jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r578997 - in /jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping: ./ src/main/java/org/apache/jackrabbit/ocm/manager/collectionconverter/impl/ src/main/java/org/apache/jackrabbit/ocm/manager/impl/ src/main/java/org/apache/jackrabbi...
Date Mon, 24 Sep 2007 22:20:16 GMT
Author: clombart
Date: Mon Sep 24 15:19:48 2007
New Revision: 578997

URL: http://svn.apache.org/viewvc?rev=578997&view=rev
Log:
Reorganise the ocm project - second step : Remove all Jackrabbit dependencies. 
right now, Jackrabbit is only used for the unit tests. 
RepositoryUtil has been split into 2 distincts classes : 
1/ NodeUtil : utility class for managing jcr nodes. 
2/ RepositoryUtil : utility class to connect & setup a Jackrabbit repo. This could be rename into JackrabbitRepoUtil :-)

Added:
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/repository/NodeUtil.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/repository/NodeUtilTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/repository/RepositoryUtil.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/security/
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/security/SimpleAccessManager.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/security/SimpleLoginModule.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/transaction/
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/transaction/jackrabbit/
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/transaction/jackrabbit/UserTransactionImpl.java
Removed:
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/repository/RepositoryUtil.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/security/
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/transaction/
Modified:
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/pom.xml
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/collectionconverter/impl/NTCollectionConverterImpl.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/impl/ObjectContentManagerImpl.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/TestBase.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/repository/AllTests.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/repository/RepositoryUtilTest.java

Modified: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/pom.xml?rev=578997&r1=578996&r2=578997&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/pom.xml (original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/pom.xml Mon Sep 24 15:19:48 2007
@@ -1,178 +1,193 @@
 <?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.
-  -->
+	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
+	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>
+	<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</artifactId>
-  <packaging>jar</packaging>
-  <name>Jackrabbit Object Content Mapping</name>
-  <description>This Jackrabbit subproject is an object/JCR persistence and query service. This tools lets you to persist java objects into a JCR compliant repository - including association, inheritance, polymorphism, composition, and the Java collections framework. Furthermore, this jcr-mapping allows you to express queries in Java-based Criteria, as well as in JCR query language. It offers also features like version support and object locking.</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>
-
-  <!-- ====================================================================== -->
-  <!-- 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-api</artifactId>
-      <version>1.4-SNAPSHOT</version>
-    </dependency>
-    <dependency>
-	    <groupId>org.apache.jackrabbit</groupId>
-	    <artifactId>jackrabbit-core</artifactId>
-	    <version>1.4-SNAPSHOT</version>
-    </dependency>    
-    <dependency>
-      <groupId>org.apache.jackrabbit</groupId>
-      <artifactId>jackrabbit-jcr-commons</artifactId>
-      <version>1.4-SNAPSHOT</version>
-    </dependency>
-      <dependency>
-        <groupId>org.apache.lucene</groupId>
-        <artifactId>lucene-core</artifactId>
-        <version>2.2.0</version>
-      </dependency>
-      <dependency>
-	    <groupId>commons-collections</groupId>
-	    <artifactId>commons-collections</artifactId>
-	    <version>3.1</version>
-    </dependency>
-    <dependency>
-	    <groupId>commons-logging</groupId>
-	    <artifactId>commons-logging</artifactId>	    
-	    <version>1.0.2</version>	    
-    </dependency>
-    <dependency>
-	    <groupId>commons-lang</groupId>
-	    <artifactId>commons-lang</artifactId>
-	    <version>2.1</version>
-    </dependency>    
- 
-    <dependency>
-	    <groupId>org.slf4j</groupId>
-	    <artifactId>slf4j-log4j12</artifactId>
-	    <version>1.0</version>
-    </dependency>
-    <dependency>
-	    <groupId>cglib</groupId>
-	    <artifactId>cglib</artifactId>
-	    <version>2.1_3</version>
-    </dependency> 	
-    <dependency>
-	    <groupId>commons-beanutils</groupId>	    
-	    <artifactId>commons-beanutils</artifactId>
-	    <version>1.7.0</version>
-    </dependency>  
-    <dependency>
-	    <groupId>log4j</groupId>
-	    <artifactId>log4j</artifactId>
-	    <version>1.2.8</version>	   
-    </dependency>
-    <!-- Test -->
-    <dependency>
-	    <groupId>geronimo-spec</groupId>
-	    <artifactId>geronimo-spec-jta</artifactId>
-	    <version>1.0-M1</version>
-	    <scope>test</scope>
-    </dependency>
-    <dependency>
-	    <groupId>xerces</groupId>
-	    <artifactId>xercesImpl</artifactId>
-	    <version>2.6.2</version>
-	    <scope>test</scope>
-    </dependency>
-    <dependency>
-	    <groupId>xerces</groupId>
-	    <artifactId>xmlParserAPIs</artifactId>
-	    <version>2.0.2</version>
-	    <scope>test</scope>
-    </dependency>
-    <dependency>
-	    <groupId>org.apache.derby</groupId>
-	    <artifactId>derby</artifactId>
-	    <version>10.2.1.6</version>
-	    <scope>test</scope>
-    </dependency>
-    <dependency>
-	    <groupId>commons-digester</groupId>
-	    <artifactId>commons-digester</artifactId>
-	    <version>1.7</version>	    
-    </dependency>
-    <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/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping
-    </connection>
-    <developerConnection>
-      scm:svn:https://svn.apache.org/repos/asf/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping
-    </developerConnection>
-    <url>
-      http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping
-    </url>
-  </scm>
+	<!-- ====================================================================== -->
+	<!-- 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</artifactId>
+	<packaging>jar</packaging>
+	<name>Jackrabbit Object Content Mapping</name>
+	<description>
+		This Jackrabbit subproject is an object/JCR persistence and
+		query service. This tools lets you to persist java objects into
+		a JCR compliant repository - including association, inheritance,
+		polymorphism, composition, and the Java collections framework.
+		Furthermore, this jcr-mapping allows you to express queries in
+		Java-based Criteria, as well as in JCR query language. It offers
+		also features like version support and object locking.
+	</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>
+
+	<!-- ====================================================================== -->
+	<!-- 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>commons-collections</groupId>
+			<artifactId>commons-collections</artifactId>
+			<version>3.1</version>
+		</dependency>
+		<dependency>
+			<groupId>commons-logging</groupId>
+			<artifactId>commons-logging</artifactId>
+			<version>1.0.2</version>
+		</dependency>
+		<dependency>
+			<groupId>commons-lang</groupId>
+			<artifactId>commons-lang</artifactId>
+			<version>2.1</version>
+		</dependency>
+
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-log4j12</artifactId>
+			<version>1.0</version>
+		</dependency>
+		<dependency>
+			<groupId>cglib</groupId>
+			<artifactId>cglib</artifactId>
+			<version>2.1_3</version>
+		</dependency>
+		<dependency>
+			<groupId>commons-beanutils</groupId>
+			<artifactId>commons-beanutils</artifactId>
+			<version>1.7.0</version>
+		</dependency>
+		<dependency>
+			<groupId>log4j</groupId>
+			<artifactId>log4j</artifactId>
+			<version>1.2.8</version>
+		</dependency>
+
+		<!-- Test -->
+
+		<dependency>
+			<groupId>org.apache.jackrabbit</groupId>
+			<artifactId>jackrabbit-api</artifactId>
+			<version>1.4-SNAPSHOT</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.jackrabbit</groupId>
+			<artifactId>jackrabbit-core</artifactId>
+			<version>1.4-SNAPSHOT</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.jackrabbit</groupId>
+			<artifactId>jackrabbit-jcr-commons</artifactId>
+			<version>1.4-SNAPSHOT</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.lucene</groupId>
+			<artifactId>lucene-core</artifactId>
+			<version>2.2.0</version>
+			<scope>test</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>geronimo-spec</groupId>
+			<artifactId>geronimo-spec-jta</artifactId>
+			<version>1.0-M1</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>xerces</groupId>
+			<artifactId>xercesImpl</artifactId>
+			<version>2.6.2</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>xerces</groupId>
+			<artifactId>xmlParserAPIs</artifactId>
+			<version>2.0.2</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.derby</groupId>
+			<artifactId>derby</artifactId>
+			<version>10.2.1.6</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>commons-digester</groupId>
+			<artifactId>commons-digester</artifactId>
+			<version>1.7</version>
+		</dependency>
+		<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/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping
+		</connection>
+		<developerConnection>
+			scm:svn:https://svn.apache.org/repos/asf/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping
+		</developerConnection>
+		<url>
+			http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping
+		</url>
+	</scm>
 
 </project>

Modified: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/collectionconverter/impl/NTCollectionConverterImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/collectionconverter/impl/NTCollectionConverterImpl.java?rev=578997&r1=578996&r2=578997&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/collectionconverter/impl/NTCollectionConverterImpl.java (original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/collectionconverter/impl/NTCollectionConverterImpl.java Mon Sep 24 15:19:48 2007
@@ -18,8 +18,6 @@
 package org.apache.jackrabbit.ocm.manager.collectionconverter.impl;
 
 
-import java.util.ArrayList;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -47,7 +45,6 @@
 import org.apache.jackrabbit.ocm.mapper.model.ClassDescriptor;
 import org.apache.jackrabbit.ocm.mapper.model.CollectionDescriptor;
 import org.apache.jackrabbit.ocm.reflection.ReflectionUtils;
-import org.apache.jackrabbit.util.ISO9075;
 
 /**
  * Collection Mapping/convertion based on node type.

Modified: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/impl/ObjectContentManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/impl/ObjectContentManagerImpl.java?rev=578997&r1=578996&r2=578997&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/impl/ObjectContentManagerImpl.java (original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/impl/ObjectContentManagerImpl.java Mon Sep 24 15:19:48 2007
@@ -61,7 +61,6 @@
 import org.apache.jackrabbit.ocm.query.Query;
 import org.apache.jackrabbit.ocm.query.QueryManager;
 import org.apache.jackrabbit.ocm.query.impl.QueryManagerImpl;
-import org.apache.jackrabbit.ocm.repository.RepositoryUtil;
 import org.apache.jackrabbit.ocm.version.Version;
 import org.apache.jackrabbit.ocm.version.VersionIterator;
 /**
@@ -120,7 +119,6 @@
 			this.requestObjectCache = new RequestObjectCacheImpl();        
 			this.objectConverter = new ObjectConverterImpl(mapper, converterProvider, new ProxyManagerImpl(), requestObjectCache);
 			
-			RepositoryUtil.setupSession(session);
 		} 
         catch (RepositoryException e) 
         {
@@ -148,8 +146,7 @@
 			this.queryManager = new QueryManagerImpl(mapper, atomicTypeConverters, session.getValueFactory());
 			this.requestObjectCache = new RequestObjectCacheImpl();        
 			this.objectConverter = new ObjectConverterImpl(mapper, converterProvider, new ProxyManagerImpl(), requestObjectCache);
-			
-			RepositoryUtil.setupSession(session);
+						
 		} 
         catch (RepositoryException e) 
         {
@@ -178,7 +175,6 @@
 			this.requestObjectCache = new RequestObjectCacheImpl();        
 			this.objectConverter = new ObjectConverterImpl(mapper, converterProvider, new ProxyManagerImpl(), requestObjectCache);
 			
-			RepositoryUtil.setupSession(session);
 		} 
         catch (RepositoryException e) 
         {
@@ -207,8 +203,7 @@
         this.objectConverter = converter;
         this.queryManager = queryManager;
         this.requestObjectCache = requestObjectCache;
-        
-        RepositoryUtil.setupSession(session);
+                
     }
     
     /**

Modified: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java?rev=578997&r1=578996&r2=578997&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java (original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java Mon Sep 24 15:19:48 2007
@@ -49,7 +49,7 @@
 import org.apache.jackrabbit.ocm.mapper.model.CollectionDescriptor;
 import org.apache.jackrabbit.ocm.mapper.model.FieldDescriptor;
 import org.apache.jackrabbit.ocm.reflection.ReflectionUtils;
-import org.apache.jackrabbit.ocm.repository.RepositoryUtil;
+import org.apache.jackrabbit.ocm.repository.NodeUtil;
 
 /**
  * Default implementation for {@link ObjectConverterImpl}
@@ -139,8 +139,8 @@
 	public void insert(Session session, Object object) {
 		String path = this.getPath(session, object);
 		try {
-			String parentPath = RepositoryUtil.getParentPath(path);
-			String nodeName = RepositoryUtil.getNodeName(path);
+			String parentPath = NodeUtil.getParentPath(path);
+			String nodeName = NodeUtil.getNodeName(path);
 			Node parentNode = (Node) session.getItem(parentPath);
 			this.insert(session, parentNode, nodeName, object);
 
@@ -227,8 +227,8 @@
 	public void update(Session session, Object object) {
 		String path = this.getPath(session, object);
 		try {
-			String parentPath = RepositoryUtil.getParentPath(path);
-			String nodeName = RepositoryUtil.getNodeName(path);
+			String parentPath = NodeUtil.getParentPath(path);
+			String nodeName = NodeUtil.getNodeName(path);
 			Node parentNode = (Node) session.getItem(parentPath);
 			this.update(session, parentNode, nodeName, object);
 		} catch (PathNotFoundException pnfe) {

Added: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/repository/NodeUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/repository/NodeUtil.java?rev=578997&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/repository/NodeUtil.java (added)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/repository/NodeUtil.java Mon Sep 24 15:19:48 2007
@@ -0,0 +1,116 @@
+/*
+ * 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.repository;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.ocm.exception.JcrMappingException;
+import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException;
+
+/**
+* Utility class for managing JCR nodes.
+* 
+*
+* @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+* @version $Id: Exp $
+*/
+public class NodeUtil
+{
+    
+      
+    /** Item path separator */
+    public static final String PATH_SEPARATOR = "/";
+    
+    private final static Log log = LogFactory.getLog(NodeUtil.class);
+    
+      
+    /**
+     * Check if a path is valid 
+     * 
+     * @param path The path to validate
+     * @return true if the path is valid, else false
+     */
+    public static boolean isValidPath(String path)
+    {
+        if ((path == null) ||
+            (path.equals(PATH_SEPARATOR)) ||
+            (path.endsWith(PATH_SEPARATOR)) ||
+            (! path.startsWith(PATH_SEPARATOR)) || 
+            (path.equals("")))
+        {
+            return false; 
+        }
+        return true;
+    }    
+    
+    /**
+     * Get the parent path
+     * @param path The path from wich the parent path has to be returned
+     * @return The parent path
+     * 
+     * @throws ObjectContentManagerException when the path is invalid
+     */
+    public static String getParentPath(String path) throws ObjectContentManagerException
+    {
+        String parentPath = "";
+        
+        if (!isValidPath(path))
+        {
+            throw new JcrMappingException("Invalid path : " + path);
+        }
+        
+        String[] pathElements = path.split(PATH_SEPARATOR);         
+        
+        // Firts path element should be = empty string because a uri always start with '/'
+        // So, if len=2, means it is a root folder like '/foo'. 
+        // In this case the uri has not parent folder => return "/"
+        if (pathElements.length == 2)
+        {
+            return PATH_SEPARATOR;
+        }
+        
+        for(int i=0; i < pathElements.length -1; i++)
+        {   
+            if (! pathElements[i].equals(""))
+            {    
+               parentPath += PATH_SEPARATOR + pathElements[i];
+            }
+        }                  
+        return parentPath;
+    }
+
+    /**
+     * Get the node name
+     * @param path  The path from which the node name has to be retrieved
+     * @return The node name
+     * 
+     * @throws ObjectContentManagerException when the path is invalid
+     */
+    public static String getNodeName(String path)  throws ObjectContentManagerException
+    {
+        
+        String[] pathElements = path.split(PATH_SEPARATOR);
+        
+        if (! isValidPath(path))
+        {
+            throw new JcrMappingException("Invalid path : " + path);
+        }        
+        return pathElements[pathElements.length-1];
+    }
+    
+  
+}

Modified: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/TestBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/TestBase.java?rev=578997&r1=578996&r2=578997&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/TestBase.java (original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/TestBase.java Mon Sep 24 15:19:48 2007
@@ -98,6 +98,7 @@
 	        
 	        if (!isInit) {
 	            initObjectContentManager();
+	            RepositoryUtil.setupSession(getSession());
 	            registerNodeTypes(getSession());
 	            isInit = true;
 	        }
@@ -129,6 +130,7 @@
 			if (ocm == null)
 			{
 				initObjectContentManager();
+				RepositoryUtil.setupSession(getSession());
                 registerNodeTypes(getSession());
 			}
 			return ocm;

Modified: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/repository/AllTests.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/repository/AllTests.java?rev=578997&r1=578996&r2=578997&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/repository/AllTests.java (original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/repository/AllTests.java Mon Sep 24 15:19:48 2007
@@ -37,6 +37,7 @@
         TestSuite suite= new TestSuite("Test for org.apache.jackrabbit.ocm.repository");
         //$JUnit-BEGIN$
         suite.addTestSuite(RepositoryUtilTest.class);
+        suite.addTestSuite(NodeUtilTest.class);
        
         
         //$JUnit-END$

Added: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/repository/NodeUtilTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/repository/NodeUtilTest.java?rev=578997&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/repository/NodeUtilTest.java (added)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/repository/NodeUtilTest.java Mon Sep 24 15:19:48 2007
@@ -0,0 +1,125 @@
+/*
+ * 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.repository;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/** Testcase for RepositoryUtil.
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
+ */
+public class NodeUtilTest extends TestCase
+{
+
+    /**
+     * <p>Defines the test case name for junit.</p>
+     * @param testName The test case name.
+     */
+    public NodeUtilTest(String testName)
+    {
+        super(testName);
+    }
+
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+    }
+
+    /**
+     * @see junit.framework.TestCase#tearDown()
+     */
+    public void tearDown() throws Exception
+    {
+        super.tearDown();
+    }
+
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite(NodeUtilTest.class); 
+        // All methods starting with "test" will be executed in the test suite.
+        return new TestSetup(suite) {
+            protected void setUp() throws Exception {
+                super.setUp();
+                RepositoryUtil.registerRepository("repositoryTest", "./src/test/test-config/repository-derby.xml", "target/repository");
+            }
+
+            protected void tearDown() throws Exception {
+                RepositoryUtil.unRegisterRepository("repositoryTest");
+                super.tearDown();
+            }
+            
+        };
+    }
+
+
+    /**
+     * Test for getParentPath() 
+     *
+     */
+    public void testGetParentPath()
+    {
+        try
+        {
+            String parentPath = NodeUtil.getParentPath("/test");
+            assertNotNull("parent path is null for /test", parentPath);
+            assertTrue("parent path is incorrect for /test", parentPath.equals("/"));
+
+            parentPath = NodeUtil.getParentPath("/test/test2");
+            assertNotNull("parent path is null for /test/test2", parentPath);
+            assertTrue("parent path is incorrect for /test/test2", parentPath.equals("/test"));
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Unable to find the repository : " + e);
+        }
+    }
+    
+    /**
+     * Test for getNodeName() 
+     *
+     */
+    public void testGetNodeName()
+    {
+        try
+        {
+            String nodeName = NodeUtil.getNodeName("/test");
+            assertNotNull("node name is null for /test", nodeName);
+            assertTrue("node name is incorrect for /test", nodeName.equals("test"));
+            
+            nodeName = NodeUtil.getNodeName("/test/test2");
+            assertNotNull("node name is null for /test/test2", nodeName);
+            assertTrue("node name is incorrect for /test/test2", nodeName.equals("test2"));
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Unable to find the repository : " + e);
+        }
+    }   
+    
+     
+}
\ No newline at end of file

Added: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/repository/RepositoryUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/repository/RepositoryUtil.java?rev=578997&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/repository/RepositoryUtil.java (added)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/repository/RepositoryUtil.java Mon Sep 24 15:19:48 2007
@@ -0,0 +1,227 @@
+/*
+ * 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.repository;
+
+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.JcrMappingException;
+import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException;
+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, "/");
+    }
+}

Modified: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/repository/RepositoryUtilTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/repository/RepositoryUtilTest.java?rev=578997&r1=578996&r2=578997&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/repository/RepositoryUtilTest.java (original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/repository/RepositoryUtilTest.java Mon Sep 24 15:19:48 2007
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.ocm.repository;
 
-import javax.jcr.ItemNotFoundException;
 import javax.jcr.Node;
 import javax.jcr.Repository;
 import javax.jcr.Session;
@@ -30,7 +29,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.jackrabbit.ocm.repository.RepositoryUtil;
 import org.apache.jackrabbit.ocm.transaction.jackrabbit.UserTransactionImpl;
 
 /** Testcase for RepositoryUtil.
@@ -140,53 +138,7 @@
         }
     }
 
-    /**
-     * Test for getParentPath() 
-     *
-     */
-    public void testGetParentPath()
-    {
-        try
-        {
-            String parentPath = RepositoryUtil.getParentPath("/test");
-            assertNotNull("parent path is null for /test", parentPath);
-            assertTrue("parent path is incorrect for /test", parentPath.equals("/"));
-
-            parentPath = RepositoryUtil.getParentPath("/test/test2");
-            assertNotNull("parent path is null for /test/test2", parentPath);
-            assertTrue("parent path is incorrect for /test/test2", parentPath.equals("/test"));
-            
-        }
-        catch (Exception e)
-        {
-            e.printStackTrace();
-            fail("Unable to find the repository : " + e);
-        }
-    }
     
-    /**
-     * Test for getNodeName() 
-     *
-     */
-    public void testGetNodeName()
-    {
-        try
-        {
-            String nodeName = RepositoryUtil.getNodeName("/test");
-            assertNotNull("node name is null for /test", nodeName);
-            assertTrue("node name is incorrect for /test", nodeName.equals("test"));
-            
-            nodeName = RepositoryUtil.getNodeName("/test/test2");
-            assertNotNull("node name is null for /test/test2", nodeName);
-            assertTrue("node name is incorrect for /test/test2", nodeName.equals("test2"));
-            
-        }
-        catch (Exception e)
-        {
-            e.printStackTrace();
-            fail("Unable to find the repository : " + e);
-        }
-    }   
     
     public void testEncodePath()
     {

Added: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/security/SimpleAccessManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/security/SimpleAccessManager.java?rev=578997&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/security/SimpleAccessManager.java (added)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/security/SimpleAccessManager.java Mon Sep 24 15:19:48 2007
@@ -0,0 +1,164 @@
+/*
+ * 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.security;
+
+import javax.jcr.AccessDeniedException;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.RepositoryException;
+import javax.security.auth.Subject;
+
+import org.apache.jackrabbit.core.HierarchyManager;
+import org.apache.jackrabbit.core.ItemId;
+import org.apache.jackrabbit.core.security.AMContext;
+import org.apache.jackrabbit.core.security.AccessManager;
+import org.apache.jackrabbit.core.security.AnonymousPrincipal;
+import org.apache.jackrabbit.core.security.SystemPrincipal;
+import org.apache.log4j.Logger;
+
+/**
+ * <code>SimpleAccessManager</code> ...
+ */
+public class SimpleAccessManager implements AccessManager
+{
+
+	private static Logger log = Logger.getLogger(SimpleAccessManager.class);
+
+	/**
+	 * Subject whose access rights this AccessManager should reflect
+	 */
+	protected Subject subject;
+
+	/**
+	 * hierarchy manager used for ACL-based access control model
+	 */
+	protected HierarchyManager hierMgr;
+
+	private boolean initialized;
+
+	protected boolean system;
+
+	protected boolean anonymous;
+
+	/**
+	 * Empty constructor
+	 */
+	public SimpleAccessManager()
+	{
+		initialized = false;
+		anonymous = false;
+		system = false;
+	}
+
+	//--------------------------------------------------------< AccessManager >
+	/**
+	 * {@inheritDoc}
+	 */
+	public void init(AMContext context) throws AccessDeniedException, Exception
+	{
+		if (initialized)
+		{
+			throw new IllegalStateException("already initialized");
+		}
+
+		subject = context.getSubject();
+		hierMgr = context.getHierarchyManager();
+		anonymous = !subject.getPrincipals(AnonymousPrincipal.class).isEmpty();
+		system = !subject.getPrincipals(SystemPrincipal.class).isEmpty();
+
+		// @todo check permission to access given workspace based on principals
+		initialized = true;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public synchronized void close() throws Exception
+	{
+		if (!initialized)
+		{
+			throw new IllegalStateException("not initialized");
+		}
+
+		initialized = false;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public void checkPermission(ItemId id, int permissions) throws AccessDeniedException, ItemNotFoundException, RepositoryException
+	{
+		if (!initialized)
+		{
+			throw new IllegalStateException("not initialized");
+		}
+
+		if (system)
+		{
+			// system has always all permissions
+			return;
+		}
+		else if (anonymous)
+		{
+			// anonymous is always denied WRITE & REMOVE premissions
+			if ((permissions & WRITE) == WRITE || (permissions & REMOVE) == REMOVE)
+			{
+				throw new AccessDeniedException();
+			}
+		}
+		// @todo check permission based on principals
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public boolean isGranted(ItemId id, int permissions) throws ItemNotFoundException, RepositoryException
+	{
+		if (!initialized)
+		{
+			throw new IllegalStateException("not initialized");
+		}
+
+		if (system)
+		{
+			// system has always all permissions
+			return true;
+		}
+		else if (anonymous)
+		{
+			// anonymous is always denied WRITE & REMOVE premissions
+			if ((permissions & WRITE) == WRITE || (permissions & REMOVE) == REMOVE)
+			{
+				return false;
+			}
+		}
+
+		// @todo check permission based on principals
+		return true;
+	
+		
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public boolean canAccess(String workspaceName) throws NoSuchWorkspaceException, RepositoryException
+	{
+		// @todo check permission to access given workspace based on principals
+		return true;
+	}
+}

Added: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/security/SimpleLoginModule.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/security/SimpleLoginModule.java?rev=578997&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/security/SimpleLoginModule.java (added)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/security/SimpleLoginModule.java Mon Sep 24 15:19:48 2007
@@ -0,0 +1,221 @@
+/*
+ * 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.security;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.jcr.Credentials;
+import javax.jcr.SimpleCredentials;
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.FailedLoginException;
+import javax.security.auth.login.LoginException;
+import javax.security.auth.spi.LoginModule;
+
+import org.apache.jackrabbit.core.security.AnonymousPrincipal;
+import org.apache.jackrabbit.core.security.CredentialsCallback;
+import org.apache.jackrabbit.core.security.SecurityConstants;
+import org.apache.jackrabbit.core.security.UserPrincipal;
+import org.apache.log4j.Logger;
+
+/**
+ * A <code>SimpleLoginModule</code> ...
+ */
+public class SimpleLoginModule implements LoginModule
+{
+
+	private static Logger log = Logger.getLogger(SimpleLoginModule.class);
+
+	/**
+	 * Name of the anonymous user id option in the LoginModule configuration
+	 */
+	private static final String OPT_ANONYMOUS = "anonymousId";
+
+	/**
+	 * The default user id for anonymous login
+	 */
+	private static final String DEFAULT_ANONYMOUS_ID = "anonymous";
+
+	// initial state
+	private Subject subject;
+
+	private CallbackHandler callbackHandler;
+
+	private Map sharedState;
+
+	private Map options;
+
+	// configurable options
+	//private boolean someOpt = false;
+
+	// local authentication state:
+	// the principals, i.e. the authenticated identities
+	private final Set principals = new HashSet();
+
+	/**
+	 * Id of an anonymous user login
+	 */
+	private String anonymousUserId = DEFAULT_ANONYMOUS_ID;
+
+	/**
+	 * Constructor
+	 */
+	public SimpleLoginModule()
+	{
+	}
+
+	//----------------------------------------------------------< LoginModule >
+	/**
+	 * {@inheritDoc}
+	 */
+	public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options)
+	{
+		this.subject = subject;
+		this.callbackHandler = callbackHandler;
+		this.sharedState = sharedState;
+		this.options = options;
+
+		// initialize any configured options
+		//someOpt = "true".equalsIgnoreCase((String)options.get("someOpt"));
+		String userId = (String) options.get(OPT_ANONYMOUS);
+		if (userId != null)
+		{
+			anonymousUserId = userId;
+		}
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public boolean login() throws LoginException
+	{
+		// prompt for a user name and password
+		if (callbackHandler == null)
+		{
+			throw new LoginException("no CallbackHandler available");
+		}
+
+		Callback[] callbacks = new Callback[]
+		{ new CredentialsCallback() };
+
+		boolean authenticated = false;
+		principals.clear();
+		try
+		{
+			callbackHandler.handle(callbacks);
+			// credentials
+			CredentialsCallback ccb = (CredentialsCallback) callbacks[0];
+			Credentials creds = ccb.getCredentials();
+			if (creds != null)
+			{
+				if (creds instanceof SimpleCredentials)
+				{
+					SimpleCredentials sc = (SimpleCredentials) creds;
+					// authenticate
+
+					Object attr = sc.getAttribute(SecurityConstants.IMPERSONATOR_ATTRIBUTE);
+					if (attr != null && attr instanceof Subject)
+					{
+						Subject impersonator = (Subject) attr;
+						// @todo check privileges to 'impersonate' the user represented by the supplied credentials
+					}
+					else
+					{
+						// @todo implement simple username/password authentication
+					}
+
+					if (anonymousUserId.equals(sc.getUserID()))
+					{
+						principals.add(new AnonymousPrincipal());
+					}
+					else
+					{
+						// else assume the user we authenticated is the UserPrincipal
+						principals.add(new UserPrincipal(sc.getUserID()));
+					}
+					authenticated = true;
+				}
+			}
+		}
+		catch (java.io.IOException ioe)
+		{
+			throw new LoginException(ioe.toString());
+		}
+		catch (UnsupportedCallbackException uce)
+		{
+			throw new LoginException(uce.getCallback().toString() + " not available");
+		}
+
+		if (authenticated)
+		{
+			return !principals.isEmpty();
+		}
+		else
+		{
+			// authentication failed: clean out state
+			principals.clear();
+			throw new FailedLoginException();
+		}
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public boolean commit() throws LoginException
+	{
+		if (principals.isEmpty())
+		{
+			return false;
+		}
+		else
+		{
+			// add a principals (authenticated identities) to the Subject
+			subject.getPrincipals().addAll(principals);
+			return true;
+		}
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public boolean abort() throws LoginException
+	{
+		if (principals.isEmpty())
+		{
+			return false;
+		}
+		else
+		{
+			logout();
+		}
+		return true;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public boolean logout() throws LoginException
+	{
+		subject.getPrincipals().removeAll(principals);
+		principals.clear();
+		return true;
+	}
+}

Added: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/transaction/jackrabbit/UserTransactionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/transaction/jackrabbit/UserTransactionImpl.java?rev=578997&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/transaction/jackrabbit/UserTransactionImpl.java (added)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/transaction/jackrabbit/UserTransactionImpl.java Mon Sep 24 15:19:48 2007
@@ -0,0 +1,213 @@
+/*
+ * 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.transaction.jackrabbit;
+
+import javax.jcr.Session;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.SystemException;
+import javax.transaction.UserTransaction;
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+
+import org.apache.jackrabbit.core.XASession;
+
+/**
+ * Internal {@link javax.transaction.UserTransaction} implementation.
+ */
+public class UserTransactionImpl implements UserTransaction {
+
+    /**
+     * Global transaction id counter
+     */
+    private static byte counter = 0;
+
+    /**
+     * XAResource
+     */
+    private final XAResource xares;
+
+    /**
+     * Xid
+     */
+    private Xid xid;
+
+    /**
+     * Status
+     */
+    private int status = Status.STATUS_NO_TRANSACTION;
+
+    /**
+     * Create a new instance of this class. Takes a session as parameter.
+     * @param session session. If session is not of type
+     * {@link XASession}, an <code>IllegalArgumentException</code>
+     * is thrown
+     */
+    public UserTransactionImpl(Session session) {
+        if (session instanceof XASession) {
+            xares = ((XASession) session).getXAResource();
+        } else {
+            throw new IllegalArgumentException("Session not of type XASession");
+        }
+    }
+
+    /**
+     * @see javax.transaction.UserTransaction#begin
+     */
+    public void begin() throws NotSupportedException, SystemException {
+        if (status != Status.STATUS_NO_TRANSACTION) {
+            throw new IllegalStateException("Transaction already active");
+        }
+
+        try {
+            xid = new XidImpl(counter++);
+            xares.start(xid, XAResource.TMNOFLAGS);
+            status = Status.STATUS_ACTIVE;
+
+        } catch (XAException e) {
+
+            throw new SystemException("Unable to begin transaction: " +
+                    "XA_ERR=" + e.errorCode);
+        }
+    }
+
+    /**
+     * @see javax.transaction.UserTransaction#commit
+     */
+    public void commit() throws HeuristicMixedException,
+            HeuristicRollbackException, IllegalStateException,
+            RollbackException, SecurityException, SystemException {
+
+        if (status != Status.STATUS_ACTIVE) {
+            throw new IllegalStateException("Transaction not active");
+        }
+
+        try {
+            xares.end(xid, XAResource.TMSUCCESS);
+
+            status = Status.STATUS_PREPARING;
+            xares.prepare(xid);
+            status = Status.STATUS_PREPARED;
+
+            status = Status.STATUS_COMMITTING;
+            xares.commit(xid, false);
+            status = Status.STATUS_COMMITTED;
+
+        } catch (XAException e) {
+
+            if (e.errorCode >= XAException.XA_RBBASE &&
+                    e.errorCode <= XAException.XA_RBEND) {
+                throw new RollbackException();
+            } else {
+                throw new SystemException("Unable to commit transaction: " +
+                    "XA_ERR=" + e.errorCode);
+            }
+        }
+    }
+
+    /**
+     * @see javax.transaction.UserTransaction#getStatus
+     */
+    public int getStatus() throws SystemException {
+        return status;
+    }
+
+    /**
+     * @see javax.transaction.UserTransaction#rollback
+     */
+    public void rollback() throws IllegalStateException, SecurityException,
+            SystemException {
+
+        if (status != Status.STATUS_ACTIVE &&
+                status != Status.STATUS_MARKED_ROLLBACK) {
+
+            throw new IllegalStateException("Transaction not active");
+        }
+
+        try {
+            xares.end(xid, XAResource.TMFAIL);
+
+            status = Status.STATUS_ROLLING_BACK;
+            xares.rollback(xid);
+            status = Status.STATUS_ROLLEDBACK;
+
+        } catch (XAException e) {
+
+            throw new SystemException("Unable to rollback transaction: " +
+                    "XA_ERR=" + e.errorCode);
+        }
+    }
+
+    /**
+     * @see javax.transaction.UserTransaction#setRollbackOnly()
+     */
+    public void setRollbackOnly() throws IllegalStateException, SystemException {
+        if (status != Status.STATUS_ACTIVE) {
+            throw new IllegalStateException("Transaction not active");
+        }
+        status = Status.STATUS_MARKED_ROLLBACK;
+    }
+
+    /**
+     * @see javax.transaction.UserTransaction#setTransactionTimeout
+     */
+    public void setTransactionTimeout(int seconds) throws SystemException {}
+
+
+    /**
+     * Internal {@link Xid} implementation.
+     */
+    class XidImpl implements Xid {
+
+        /** Global transaction id */
+        private final byte[] globalTxId;
+
+        /**
+         * Create a new instance of this class. Takes a global
+         * transaction number as parameter
+         * @param globalTxNumber global transaction number
+         */
+        public XidImpl(byte globalTxNumber) {
+            this.globalTxId = new byte[] { globalTxNumber };
+        }
+
+        /**
+         * @see javax.transaction.xa.Xid#getFormatId()
+         */
+        public int getFormatId() {
+            return 0;
+        }
+
+        /**
+         * @see javax.transaction.xa.Xid#getBranchQualifier()
+         */
+        public byte[] getBranchQualifier() {
+            return new byte[0];
+        }
+
+        /**
+         * @see javax.transaction.xa.Xid#getGlobalTransactionId()
+         */
+        public byte[] getGlobalTransactionId() {
+            return globalTxId;
+        }
+    }
+}



Mime
View raw message