incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r354166 [2/3] - in /incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr: exception/ mapper/ mapper/impl/ mapper/model/ persistence/ persistence/atomictypeconverter/ persistence/atomictypeconverter/impl/ persist...
Date Mon, 05 Dec 2005 20:36:34 GMT
Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverter.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverter.java?rev=354166&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverter.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverter.java Mon Dec  5 12:35:57 2005
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.portals.graffito.jcr.persistence.atomictypeconverter;
+
+import javax.jcr.Value;
+
+/**
+ * 
+ * AtomicTypeConverter interface.
+ * 
+ * The Object converter used atomic type converters to map atomic fields to JCR Value objects.
+ * Amotic fields are primitive java types and their wrapper classes.
+ * 
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ *
+ */
+public interface AtomicTypeConverter
+{
+
+	/**
+	 * Convert an object into a JCR value.
+	 * 
+	 * @param object The object to convert
+	 * @return the corresponding JCR value
+	 *  
+	 */
+	public Value getValue(Object object);
+
+	/**
+	 * Convert a jcr property value into an object
+	 * 
+	 * @param value The JCR property value
+	 * @return the corresponding object	
+	 */
+	public Object getObject(Value value);
+	
+	/**
+	 * Get the string converted value
+	 * @param object The object value
+	 * @return The string converted value	 
+	 */
+	public String getStringValue(Object object);
+
+}
\ No newline at end of file

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/AbstractAtomicTypeConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/AbstractAtomicTypeConverterImpl.java?rev=354166&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/AbstractAtomicTypeConverterImpl.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/AbstractAtomicTypeConverterImpl.java Mon Dec  5 12:35:57 2005
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl;
+
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter;
+
+/**
+ * Abstract implementation for {@link org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter}
+ *  
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ *
+ */
+public abstract class AbstractAtomicTypeConverterImpl implements AtomicTypeConverter
+{
+
+	private ValueFactory valueFactory;
+
+	/**
+	 * Constructor
+	 * @param factory The JCR Value factory to used
+	 */
+	public AbstractAtomicTypeConverterImpl(ValueFactory factory)
+	{
+		super();
+		valueFactory = factory;
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getValue(java.lang.Object)
+	 */
+	public abstract Value getValue(Object propValue);
+
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Value)
+     */
+	public abstract Object getObject(Value value);
+
+	/**
+	 * Set the JCR value factory
+	 * 
+	 * @param valueFactory The value factory to set
+	 */
+	void setValueFactory(ValueFactory valueFactory)
+	{
+		this.valueFactory = valueFactory;
+	}
+
+	/**	
+	 * @return the JCR value factory 
+	 */
+	public ValueFactory getValueFactory()
+	{
+		return this.valueFactory;
+	}
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/BinaryTypeConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/BinaryTypeConverterImpl.java?rev=354166&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/BinaryTypeConverterImpl.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/BinaryTypeConverterImpl.java Mon Dec  5 12:35:57 2005
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl;
+
+import java.io.InputStream;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+
+import org.apache.portals.graffito.jcr.exception.IncorrectAtomicTypeException;
+
+/**
+ * 
+ * Binary Type Converter
+ * 
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ *
+ */
+public class BinaryTypeConverterImpl extends AbstractAtomicTypeConverterImpl
+{
+	/**
+	 * Constructor
+	 * @param factory The JCR Value factory to used
+	 */
+	public BinaryTypeConverterImpl(ValueFactory factory)
+	{
+		super(factory);
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getValue(java.lang.Object)
+	 */
+    public Value getValue(Object propValue)
+    {
+        if (propValue == null)
+        {
+            return null;
+        }
+        return this.getValueFactory().createValue((InputStream) propValue);
+    }
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Value)
+     */
+    public Object getObject(Value value)
+    {
+    	try
+    	{
+		    return value.getStream();
+		}
+		catch (RepositoryException e)
+		{
+			throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString()  , e);
+		}
+    }
+
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object)
+     */
+	public String getStringValue(Object object)
+	{		
+		throw new IncorrectAtomicTypeException("Binary cannot be convert into string");
+	}
+
+    
+
+
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/BooleanTypeConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/BooleanTypeConverterImpl.java?rev=354166&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/BooleanTypeConverterImpl.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/BooleanTypeConverterImpl.java Mon Dec  5 12:35:57 2005
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl;
+
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+
+import org.apache.portals.graffito.jcr.exception.IncorrectAtomicTypeException;
+
+/**
+ * Boolean Type Converter
+ * 
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ *
+ */
+public class BooleanTypeConverterImpl extends AbstractAtomicTypeConverterImpl
+{
+	/**
+	 * Constructor
+	 * @param factory The JCR Value factory to used
+	 */
+	public BooleanTypeConverterImpl(ValueFactory factory)
+	{
+		super(factory);
+
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getValue(java.lang.Object)
+	 */
+	public Value getValue(Object propValue)
+	{
+		if (propValue == null)
+		{
+			return null;
+		}
+		boolean value = ((Boolean) propValue).booleanValue();
+		return this.getValueFactory().createValue(value);
+	}
+	
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Value)
+     */
+	public Object getObject(Value value)
+    {
+    	try
+    	{
+		    return new Boolean(value.getBoolean());
+		}
+		catch (Exception e)
+		{
+			throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString()  , e);
+		}
+    }
+	
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object)
+	 */
+	public String getStringValue(Object object)
+	{
+		
+		return ((Boolean) object).booleanValue() ? "true()" : "false()"; 
+	}
+
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/ByteArrayTypeConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/ByteArrayTypeConverterImpl.java?rev=354166&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/ByteArrayTypeConverterImpl.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/ByteArrayTypeConverterImpl.java Mon Dec  5 12:35:57 2005
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+
+import org.apache.portals.graffito.jcr.exception.IncorrectAtomicTypeException;
+
+/**
+ * 
+ * Byte Array Type Converter
+ * 
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ *
+ */
+public class ByteArrayTypeConverterImpl extends AbstractAtomicTypeConverterImpl
+{
+
+	/**
+	 * Constructor
+	 * @param factory The JCR Value factory to used
+	 */
+	public ByteArrayTypeConverterImpl(ValueFactory factory)
+	{
+		super(factory);
+
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getValue(java.lang.Object)
+	 */
+	public Value getValue(Object propValue)
+	{
+		if (propValue == null)
+		{
+			return null;
+		}
+		String value = new String((byte[]) propValue);
+		return getValueFactory().createValue(value);
+	}
+
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Value)
+	 */
+    public Object getObject(Value value)	
+    {
+		try
+		{
+			return value.getString().getBytes();
+		}
+		catch (RepositoryException e)
+		{
+			throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString() , e);
+		}
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object)
+	 */
+	public String getStringValue(Object object)
+	{
+		
+		return  "'" + object.toString() + "'";
+	}
+
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/CalendarTypeConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/CalendarTypeConverterImpl.java?rev=354166&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/CalendarTypeConverterImpl.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/CalendarTypeConverterImpl.java Mon Dec  5 12:35:57 2005
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl;
+
+import java.util.Calendar;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+
+import org.apache.portals.graffito.jcr.exception.IncorrectAtomicTypeException;
+
+/**
+ * Calendar Type Converter
+ * 
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ *
+ */
+public class CalendarTypeConverterImpl extends AbstractAtomicTypeConverterImpl
+{
+
+	/**
+	 * Constructor
+	 * @param factory The JCR Value factory to used
+	 */
+	public CalendarTypeConverterImpl(ValueFactory factory)
+	{
+		super(factory);
+
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getValue(java.lang.Object)
+	 */
+	public Value getValue(Object propValue)
+	{
+		if (propValue == null)
+		{
+			return null;
+		}
+		return this.getValueFactory().createValue(((Calendar) propValue).getTimeInMillis());
+
+	}
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Value)
+     */
+	public Object getObject(Value value)
+	{
+		try
+		{
+			
+			Calendar calendar = Calendar.getInstance();
+			calendar.setTimeInMillis(value.getLong());
+			return calendar;
+		}
+		catch (RepositoryException e)
+		{
+			throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString(), e);
+		}
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object)
+	 */
+	public String getStringValue(Object object)
+	{
+		
+		Calendar calendar = (Calendar) object;
+    	return new Long(calendar.getTimeInMillis()).toString();		
+	}
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/DoubleTypeConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/DoubleTypeConverterImpl.java?rev=354166&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/DoubleTypeConverterImpl.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/DoubleTypeConverterImpl.java Mon Dec  5 12:35:57 2005
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+
+import org.apache.portals.graffito.jcr.exception.IncorrectAtomicTypeException;
+
+/**
+ * Double Type Converter 
+ * 
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ *
+ */
+public class DoubleTypeConverterImpl extends AbstractAtomicTypeConverterImpl
+{
+	/**
+	 * Constructor
+	 * @param factory The JCR Value factory to used
+	 */
+
+	public DoubleTypeConverterImpl(ValueFactory factory)
+	{
+		super(factory);
+
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getValue(java.lang.Object)
+	 */
+	public Value getValue(Object propValue)
+	{
+		if (propValue == null)
+		{
+			return null;
+		}
+		double value = ((Double) propValue).doubleValue();
+		return this.getValueFactory().createValue(value);
+	}
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Value)
+     */
+	public Object getObject(Value value)
+    {
+		try
+		{
+			double beanPropValue = value.getDouble();
+			return new Double(beanPropValue);	
+		}
+		catch (RepositoryException e)
+		{
+			throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString(), e);
+		}
+	}
+	
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object)
+	 */
+	public String getStringValue(Object object)
+	{
+		
+		return object.toString();
+	}	
+
+
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/IntTypeConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/IntTypeConverterImpl.java?rev=354166&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/IntTypeConverterImpl.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/IntTypeConverterImpl.java Mon Dec  5 12:35:57 2005
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+
+import org.apache.portals.graffito.jcr.exception.IncorrectAtomicTypeException;
+
+/**
+ * Int Type Converter
+ * 
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ *
+ */
+public class IntTypeConverterImpl extends AbstractAtomicTypeConverterImpl
+{
+
+	/**
+	 * Constructor
+	 * @param factory The JCR Value factory to used
+	 */
+	public IntTypeConverterImpl(ValueFactory factory)
+	{
+		super(factory);
+
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getValue(java.lang.Object)
+	 */
+	public Value getValue(Object propValue)
+	{
+		if (propValue == null)
+		{
+			return null;
+		}
+		long value = ((Integer) propValue).intValue();
+		return this.getValueFactory().createValue(value);
+	}
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Value)
+     */
+	public Object getObject(Value value)
+    {
+		try
+		{
+			int beanPropValue = (int) value.getLong();
+			return new Integer(beanPropValue);
+		}
+		catch (RepositoryException e)
+		{
+			throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString(), e);
+		}
+	}
+	
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object)
+	 */
+	public String getStringValue(Object object)
+	{
+		
+		return object.toString();
+	}
+
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/LongTypeConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/LongTypeConverterImpl.java?rev=354166&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/LongTypeConverterImpl.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/LongTypeConverterImpl.java Mon Dec  5 12:35:57 2005
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+
+import org.apache.portals.graffito.jcr.exception.IncorrectAtomicTypeException;
+
+/**
+ * 
+ * Long Type Converter
+ * 
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ *
+ */
+public class LongTypeConverterImpl extends AbstractAtomicTypeConverterImpl
+{
+
+	/**
+	 * Constructor
+	 * @param factory The JCR Value factory to used
+	 */
+	public LongTypeConverterImpl(ValueFactory factory)
+	{
+		super(factory);
+
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getValue(java.lang.Object)
+	 */
+	public Value getValue(Object propValue)
+	{
+		if (propValue == null)
+		{
+			return null;
+		}
+
+		long value = ((Long) propValue).longValue();
+		return this.getValueFactory().createValue(value);
+	}
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Value)
+     */
+	public Object getObject(Value value)
+    {
+		try
+		{
+			long beanPropValue = value.getLong();
+			return new Long(beanPropValue);
+		}
+		catch (RepositoryException e)
+		{
+			throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString(), e);
+		}
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object)
+	 */
+	public String getStringValue(Object object)
+	{
+		
+		return object.toString();
+	}
+
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/StringTypeConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/StringTypeConverterImpl.java?rev=354166&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/StringTypeConverterImpl.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/StringTypeConverterImpl.java Mon Dec  5 12:35:57 2005
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+
+import org.apache.portals.graffito.jcr.exception.IncorrectAtomicTypeException;
+
+/**
+ * 
+ * String Type Converter 
+ * 
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ *
+ */
+public class StringTypeConverterImpl extends AbstractAtomicTypeConverterImpl
+{
+	/**
+	 * Constructor
+	 * @param factory The JCR Value factory to used
+	 */
+	public StringTypeConverterImpl(ValueFactory factory)
+	{
+		super(factory);
+
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getValue(java.lang.Object)
+	 */
+	public Value getValue(Object propValue)
+	{
+		if (propValue == null)
+		{
+			return null;
+		}
+		return this.getValueFactory().createValue((String) propValue);
+	}
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Value)
+     */
+	public Object getObject(Value value)
+    {
+		try
+		{
+			return value.getString();
+		}
+		catch (RepositoryException e)
+		{
+			throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString(), e);
+		}
+
+	}
+	
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object)
+	 */
+	public String getStringValue(Object object)
+	{
+		
+		return "'" + object.toString() + "'";
+	}	
+
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/TimestampTypeConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/TimestampTypeConverterImpl.java?rev=354166&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/TimestampTypeConverterImpl.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/TimestampTypeConverterImpl.java Mon Dec  5 12:35:57 2005
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl;
+
+import java.sql.Timestamp;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+
+import org.apache.portals.graffito.jcr.exception.IncorrectAtomicTypeException;
+
+/**
+ * 
+ * Timestamp Type Converter
+ * 
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ *
+ */
+public class TimestampTypeConverterImpl extends AbstractAtomicTypeConverterImpl
+{
+	/**
+	 * Constructor
+	 * @param factory The JCR Value factory to used
+	 */
+	public TimestampTypeConverterImpl(ValueFactory factory)
+	{
+		super(factory);
+
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getValue(java.lang.Object)
+	 */
+	public Value getValue(Object propValue)
+	{
+		if (propValue == null)
+			return null;
+		long value = ((Timestamp) propValue).getTime();
+		return this.getValueFactory().createValue(value);
+	}
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Value)
+     */
+	public Object getObject(Value value)
+    {
+		try
+		{
+			long beanPropValue = value.getLong();
+			return new Timestamp(beanPropValue);
+		}
+		catch (RepositoryException e)
+		{
+			throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString(), e);
+		}
+	}
+	
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object)
+	 */
+	public String getStringValue(Object object)
+	{
+		
+		return new Long(((Timestamp) object).getTime()).toString();
+	}	
+
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/UtilDateTypeConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/UtilDateTypeConverterImpl.java?rev=354166&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/UtilDateTypeConverterImpl.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/impl/UtilDateTypeConverterImpl.java Mon Dec  5 12:35:57 2005
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl;
+
+import java.util.Date;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+
+import org.apache.portals.graffito.jcr.exception.IncorrectAtomicTypeException;
+
+/**
+ * Util Date Converter
+ * 
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ * 
+ */
+public class UtilDateTypeConverterImpl extends AbstractAtomicTypeConverterImpl
+{
+
+	/**
+	 * Constructor
+	 * @param factory The JCR Value factory to used
+	 */
+	public UtilDateTypeConverterImpl(ValueFactory factory)
+	{
+		super(factory);
+
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getValue(java.lang.Object)
+	 */
+	public Value getValue(Object propValue)
+	{
+		if (propValue == null)
+		{
+			return null;
+		}
+		return this.getValueFactory().createValue(((java.util.Date) propValue).getTime());		
+	}
+
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Value)
+	 */
+	public Object getObject(Value value)
+    {
+		try
+		{
+			long time = value.getLong();
+			return new Date(time);
+
+		}
+		catch (RepositoryException e)
+		{
+			throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString(), e);
+		}
+
+	}
+	
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object)
+	 */
+	public String getStringValue(Object object)
+	{
+		
+		return new Long(((java.util.Date) object).getTime()).toString();
+	}	
+
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/CollectionConverter.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/CollectionConverter.java?rev=354166&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/CollectionConverter.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/CollectionConverter.java Mon Dec  5 12:35:57 2005
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2000-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.jcr.persistence.collectionconverter;
+
+import javax.jcr.Node;
+import javax.jcr.Session;
+
+import org.apache.portals.graffito.jcr.exception.PersistenceException;
+import org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor;
+
+/**
+ * Convert any kind of {@link ManageableCollection} into severals JCR nodes.
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * 
+ */
+public interface CollectionConverter
+{
+
+	/**
+	 * Insert/convert collection elements into some JCR nodes
+	 * @param session The JCR session 
+	 * @param parentNode the node which will contains the collection element
+	 * @param collectionDescriptor The collection descriptor
+	 * @param collection the collection to insert
+	 * 
+	 * @throws PersistenceException when it is not possible to insert the collection
+	 * 
+	 */
+	public void insertCollection(Session session, Node parentNode, 
+			                     CollectionDescriptor collectionDescriptor, ManageableCollection collection) throws PersistenceException;
+
+	/**
+	 * Update collection elements already present in the JCR repository
+	 * @param session The JCR session 
+	 * @param parentNode the node which will contains the collection element
+	 * @param collectionDescriptor The collection descriptor
+	 * @param collection the collection to update
+	 * 
+	 * @throws PersistenceException when it is not possible to update the collection
+	 */
+	public void updateCollection(Session session, Node parentNode, 
+			                     CollectionDescriptor collectionDescriptor, ManageableCollection collection) throws PersistenceException;
+
+	/**
+	 * Get a {@link ManageableCollection} from the JCR repository 
+	 * @param session The JCR session 
+	 * @param parentNode the node which contains the collection element
+	 * @param collectionDescriptor The collection descriptor
+	 * @param collectionFieldClass The collection class to used (ArrayList, Vector, ..) 
+	 * @return The collection populates with all elements found in the JCR repository
+	 * 
+	 * @throws PersistenceException when it is not possible to retrieve the collection 
+	 */
+	public ManageableCollection getCollection(Session session, Node parentNode, 
+			                                  CollectionDescriptor collectionDescriptor, Class collectionFieldClass) throws PersistenceException;
+
+}
\ No newline at end of file

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollection.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollection.java?rev=354166&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollection.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollection.java Mon Dec  5 12:35:57 2005
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2000-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.portals.graffito.jcr.persistence.collectionconverter;
+
+import java.util.Iterator;
+
+/** 
+ * Common interface used to persist any kind of Collection or Map.
+ * 
+ *
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ * 
+ */
+public interface ManageableCollection
+{
+    /**
+     * Add an object into this ManageableCollection
+     * @param object the object to add
+     */
+	public void addObject(Object object);
+   
+	/**
+	 * @return The ManageableCollection iterator
+	 */
+    public Iterator getIterator();
+    
+    /** 
+     * @return The ManageableCollection size
+     */
+    public int getSize();
+    
+    
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java?rev=354166&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java Mon Dec  5 12:35:57 2005
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.jcr.persistence.collectionconverter;
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Vector;
+
+import org.apache.portals.graffito.jcr.exception.PersistenceException;
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.ManageableArrayList;
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.ManageableVector;
+
+/**
+ * Utility class used to instantiate {@link ManageableCollection} 
+ *
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ *
+ */
+public class ManageableCollectionUtil
+{
+	
+	/**
+	 * Instantiate a new {@link ManageableCollection}
+	 * @param manageableCollectionClassName The manageable collection class name
+	 * @return an emtpy created {@link ManageableCollection}
+	 */
+    public static ManageableCollection getManageableCollection(String manageableCollectionClassName)
+    {
+        try
+        {
+            Class collectionClass = Class.forName(manageableCollectionClassName);
+            return (ManageableCollection) collectionClass.newInstance();
+        }
+        catch (Exception e)
+        {
+            throw new PersistenceException("Impossible to create the manageable collection : " + manageableCollectionClassName, e);
+        }
+    }
+
+	/**
+	 * Instantiate a new {@link ManageableCollection}
+	 * @param collectionClass the collection class name 
+	 * @return an emtpy created {@link ManageableCollection}
+	 */
+    
+    public static ManageableCollection getManageableCollection(Class collectionClass)
+    {
+        try
+        {
+
+            if (collectionClass.equals(ArrayList.class))
+            {
+                return new ManageableArrayList();
+            }
+
+            if (collectionClass.equals(Vector.class))
+            {
+                return new ManageableVector();
+            }
+
+            if (collectionClass.equals(Collection.class) || collectionClass.equals(List.class))
+            {
+                return new ManageableArrayList();
+            }
+            
+            Object collection  = collectionClass.newInstance();
+            if (! (collection instanceof ManageableCollection))
+            {
+               throw new PersistenceException("Unsupported collection type :" + collectionClass.getName());
+            }
+            else
+            {
+                return (ManageableCollection) collection;
+            }
+        }
+        catch (Exception e)
+        {
+            throw new PersistenceException("Impossible to create the manageable collection", e);
+        }
+    }
+
+    /**
+     * Convert a java Collection object into a {@link ManageableCollection}.
+     * Until now, only the following class are supported :
+     * Collection, List, ArrayList, Vector
+     * 
+     * If you need a Map, you have to write your own {@link ManageableCollection}.
+     * @param object the java collection or Map
+     * @return The converted {@link ManageableCollection}
+     *
+     */
+    public static ManageableCollection getManageableCollection(Object object)
+    {
+        try
+        {
+            if (object == null)
+            {
+                return null;
+            }
+
+            if (object instanceof ManageableCollection)
+            {
+                return (ManageableCollection) object;
+                
+            }
+            if (object.getClass().equals(ArrayList.class))
+            {
+                ManageableArrayList manageableArrayList =  new ManageableArrayList();
+                manageableArrayList.addAll((Collection) object);
+                return manageableArrayList;
+            }
+
+            if (object.getClass().equals(Vector.class))
+            {
+                ManageableVector manageableVector = new ManageableVector();
+                manageableVector.addAll((Collection) object);
+                return manageableVector;
+            }
+
+            if (object.getClass().equals(Collection.class) || object.getClass().equals(List.class))
+            {
+                ManageableArrayList manageableArrayList =  new ManageableArrayList();
+                manageableArrayList.addAll((Collection) object);
+                return manageableArrayList;
+            }
+
+            throw new PersistenceException("Unsupported collection type :" + object.getClass().getName());
+        }
+        catch (Exception e)
+        {
+            throw new PersistenceException("Impossible to create the manageable collection", e);
+        }
+    }
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/CustomNodeTypeCreatorImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/CustomNodeTypeCreatorImpl.java?rev=354166&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/CustomNodeTypeCreatorImpl.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/CustomNodeTypeCreatorImpl.java Mon Dec  5 12:35:57 2005
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.jcr.persistence.impl;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.portals.graffito.jcr.exception.CustomNodeTypeCreationException;
+import org.apache.portals.graffito.jcr.persistence.CustomNodeTypeCreator;
+import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
+
+/** Default implementation of the jackrabbit custom node creator.
+ *
+ * @author <a href="mailto:okiessler@apache.org">Oliver Kiessler</a>
+ * @version $Id: Exp $
+ */
+public class CustomNodeTypeCreatorImpl implements CustomNodeTypeCreator {
+    
+    /** Logger.
+     */
+    private final static Log log = LogFactory.getLog(CustomNodeTypeCreatorImpl.class); 
+    
+    /** Session to the jcr repository.
+     */
+    private PersistenceManagerImpl jcrSession;
+    
+    /** Creates a new instance of CustomNodeTypeCreatorImpl. */
+    public CustomNodeTypeCreatorImpl()
+    {
+    }
+    
+    /** Creates a new instance of CustomNodeTypeCreatorImpl with a jcr session. 
+     * @param jcrSession JcrSession
+     */
+    public CustomNodeTypeCreatorImpl(PersistenceManagerImpl jcrSession)
+    {
+        this.jcrSession = jcrSession;
+    }
+
+    /** This method is supposed to create custom node types on repository
+     * setup.
+     * 
+     * @throws org.apache.portals.graffito.jcr.exception.CustomNodeTypeCreationException 
+     * @return true/false
+     */
+    public boolean createInitialJcrCustomNodeTypes() throws CustomNodeTypeCreationException
+    {
+       
+        // TODO
+        
+        return true;
+    }
+
+    /** Method to add a jcr custom node type to an existing jcr repository.
+     * 
+     * @throws org.apache.portals.graffito.jcr.exception.CustomNodeTypeCreationException 
+     * @return true/false
+     */
+    public boolean addJcrCustomNodeType() throws CustomNodeTypeCreationException
+    {
+        
+        // TODO
+        
+        return false;
+    }
+    
+    /** Setter for property jcrSession.
+     * 
+     * @param jcrSession JcrSession
+     */
+    public void setJcrSession(PersistenceManagerImpl jcrSession)
+    {
+        this.jcrSession = jcrSession;
+    }
+
+    /** Getter for property jcrSession.
+     * 
+     * @return jcrSession
+     */
+    public PersistenceManager getJcrSession()
+    {
+        return jcrSession;
+    }
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/ObjectIterator.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/ObjectIterator.java?rev=354166&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/ObjectIterator.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/ObjectIterator.java Mon Dec  5 12:35:57 2005
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.portals.graffito.jcr.persistence.impl;
+
+import java.util.Iterator;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Session;
+
+import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
+
+
+/**
+ * ObjectIterator is a wrapper class for JCR NodeIterator
+ * 
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ *
+ */
+public class ObjectIterator implements Iterator
+{
+
+	private NodeIterator nodeIterator;
+
+	private Class objectClass;
+
+	private Session session;
+
+	private ObjectConverter objectConverter;
+
+	
+	/**
+	 * Constructor 
+	 * 
+	 * @param iterator JCR node iterator 
+	 * @param objectClass the object class used to instantiate the objects
+	 * @param converter The object converter
+	 * @param session the JCR session 
+	 */
+	public ObjectIterator(NodeIterator iterator, Class objectClass, ObjectConverter converter, Session session)
+	{
+		nodeIterator = iterator;
+		this.objectClass = objectClass;
+		objectConverter = converter;
+		this.session = session;
+	}
+
+	/**
+	 * 
+	 * @see java.util.Iterator#hasNext()
+	 */
+	public boolean hasNext()
+	{
+		return nodeIterator.hasNext();
+	}
+
+	/**
+	 * 
+	 * @see java.util.Iterator#next()
+	 */
+	public Object next() 
+	{
+
+		try
+		{
+			Node node = nodeIterator.nextNode();
+			return objectConverter.getObject(session, objectClass, node.getPath());
+		}
+		catch (Exception e)
+		{
+           return null;			
+		}
+
+	}
+
+	/**
+	 * 
+	 * @see java.util.Iterator#remove()
+	 */
+	public void remove()
+	{
+		nodeIterator.remove();
+	}
+
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java?rev=354166&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java Mon Dec  5 12:35:57 2005
@@ -0,0 +1,901 @@
+/*
+ * Copyright 2000-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.jcr.persistence.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.jcr.Item;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.lock.Lock;
+import javax.jcr.lock.LockException;
+import javax.jcr.query.QueryResult;
+import javax.jcr.version.VersionHistory;
+
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.jcr.exception.CannotUnlockException;
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.exception.LockedException;
+import org.apache.portals.graffito.jcr.exception.PersistenceException;
+import org.apache.portals.graffito.jcr.exception.VersionException;
+import org.apache.portals.graffito.jcr.mapper.Mapper;
+import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
+import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
+import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
+import org.apache.portals.graffito.jcr.persistence.objectconverter.impl.ObjectConverterImpl;
+import org.apache.portals.graffito.jcr.query.Query;
+import org.apache.portals.graffito.jcr.query.QueryManager;
+import org.apache.portals.graffito.jcr.version.Version;
+import org.apache.portals.graffito.jcr.version.VersionIterator;
+
+/** 
+ * 
+ * Default implementation for {@link org.apache.portals.graffito.jcr.persistence.PersistenceManager}
+ * 
+ * @author Sandro Boehme
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe</a>
+ * @author Martin Koci
+ * 
+ */
+public class PersistenceManagerImpl implements PersistenceManager
+{
+	/** 
+	 * Logger.
+	 */
+	private final static Log log = LogFactory
+			.getLog(PersistenceManagerImpl.class);
+
+	/** 
+	 * JCR session.
+	 */
+	protected Session session;
+
+	protected Mapper mapper;
+
+	/**
+	 * The Graffito query manager
+	 */
+	protected QueryManager queryManager;
+
+	/**
+	 * Object Converter
+	 */
+	protected ObjectConverter objectConverter;
+
+	/**
+	 * Contructor 
+	 * 
+	 * @param mapper the Mapper component
+	 * @param atomicTypeConverters Atomic type converters to used
+	 * @param queryManager the query manager to used
+	 * @param session The JCR session 
+	 * 
+	 */
+	public PersistenceManagerImpl(Mapper mapper, Map atomicTypeConverters,
+			QueryManager queryManager, Session session)
+	{
+		this.mapper = mapper;
+		this.session = session;
+		this.objectConverter = new ObjectConverterImpl(mapper,
+				atomicTypeConverters);
+		this.queryManager = queryManager;
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getObject(java.lang.Class, java.lang.String)
+	 */
+	public Object getObject(Class objectClass, String path)
+	{
+		try
+		{
+			if (!session.itemExists(path))
+			{
+				return null;
+			}
+
+		}
+		catch (Exception e)
+		{
+			throw new PersistenceException("Impossible to get the object at "
+					+ path, e);
+		}
+
+		return objectConverter.getObject(session, objectClass, path);
+
+	}
+
+	/**
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getObject(java.lang.Class, java.lang.String, java.lang.String)
+	 */
+	public Object getObject(Class objectClass, String path, String versionName)
+			throws PersistenceException
+	{
+		String pathVersion = null;
+		try
+		{
+			if (!session.itemExists(path))
+			{
+				return null;
+			}
+
+			Version version = this.getVersion(path, versionName);
+			pathVersion = version.getPath() + "/jcr:frozenNode";
+
+		}
+		catch (Exception e)
+		{
+			throw new PersistenceException("Impossible to get the object at "
+					+ path + " - version :" + versionName, e);
+		}
+
+		return objectConverter.getObject(session, objectClass, pathVersion);
+	}
+
+	/**
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#insert(java.lang.Object)
+	 */
+	public void insert(Object object)
+	{
+		String path = objectConverter.getPath(session, object);
+		
+		try
+		{
+
+			if (session.itemExists(path))
+			{
+				Item item = session.getItem(path);
+				if (item.isNode())
+				{
+					if (!((Node) item).getDefinition().allowsSameNameSiblings())
+					{
+						throw new PersistenceException(
+								"Path already exists and it is not supporting the same name sibling : "
+										+ path);
+					}
+				}
+				else
+				{
+					throw new PersistenceException(
+							"Path already exists and it is a property : "
+									+ path);
+				}
+
+			}
+		}
+		catch (RepositoryException e)
+		{
+			throw new PersistenceException(
+					"Impossible to insert the object at " + path, e);
+		}
+
+		objectConverter.insert(session, object);
+
+	}
+
+	/**
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#update(java.lang.Object)
+	 */
+	public void update(Object object)
+	{
+		String path = objectConverter.getPath(session, object);
+		try
+		{
+			if (!session.itemExists(path))
+			{
+				throw new PersistenceException("Path is not existing : " + path);
+			}
+			else
+			{
+				checkIfNodeLocked(path);
+			}
+		}
+		catch (RepositoryException e)
+		{
+			throw new PersistenceException("Impossible to update", e);
+		}
+
+		objectConverter.update(session, object);
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#remove(java.lang.String)
+	 */
+	public void remove(String path)
+	{
+
+		try
+		{
+			if (!session.itemExists(path))
+			{
+				throw new PersistenceException("Path is not existing : " + path);
+			}
+			else
+			{
+				checkIfNodeLocked(path);
+			}
+			
+			Item item = session.getItem(path);
+			item.remove();
+
+		}
+		catch (RepositoryException e)
+		{
+			throw new PersistenceException(
+					"Impossible to remove the object at " + path);
+		}
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#remove(java.lang.Object)
+	 */
+	public void remove(Object object) throws PersistenceException
+	{
+		this.remove(objectConverter.getPath(session, object));
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#remove(org.apache.portals.graffito.jcr.query.Query)
+	 */
+	public void remove(Query query)
+	{
+		try
+		{
+
+			String jcrExpression = this.queryManager.buildJCRExpression(query);
+			log.debug("Remove Objects with expression : " + jcrExpression);
+
+			javax.jcr.query.Query jcrQuery = session.getWorkspace().getQueryManager().createQuery(jcrExpression,javax.jcr.query.Query.XPATH);
+			QueryResult queryResult = jcrQuery.execute();
+			NodeIterator nodeIterator = queryResult.getNodes();
+			ArrayList nodes = new ArrayList();
+
+			while (nodeIterator.hasNext())
+			{
+				Node node = nodeIterator.nextNode();
+				log.debug("Remove node : " + node.getPath());
+				// it is not possible to remove nodes from an NodeIterator
+				// So, we add the node found in a collection to remove them after
+				nodes.add(node);
+			}
+
+			// Remove all collection nodes
+			for (int i = 0; i < nodes.size(); i++)
+			{				
+				Node node = (Node) nodes.get(i);
+				checkIfNodeLocked(node.getPath());
+				node.remove();
+			}
+
+		}
+		catch (RepositoryException e)
+		{
+			throw new PersistenceException("Impossible to get the object collection", e);
+		}
+
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#objectExists(java.lang.String)
+	 */
+	public boolean objectExists(String path)
+	{
+		try
+		{
+			//TODO : Check also if it is an object 
+			return session.itemExists(path);
+		}
+		catch (RepositoryException e)
+		{
+			throw new PersistenceException(
+					"Impossible to check if the object exist", e);
+		}
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#isPersistent(java.lang.Class)
+	 */
+	public boolean isPersistent(final Class clazz)
+	{
+		boolean isPersistent = false;
+		ClassDescriptor classDescriptor = mapper.getClassDescriptor(clazz);
+		if (classDescriptor != null)
+		{
+			isPersistent = true;
+		}
+		return isPersistent;
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getObject(org.apache.portals.graffito.jcr.query.Query)
+	 */
+	public Object getObject(Query query)
+	{
+
+		try
+		{
+
+			String jcrExpression = this.queryManager.buildJCRExpression(query);
+			log.debug("Get Object with expression : " + jcrExpression);
+
+			javax.jcr.query.Query jcrQuery = session.getWorkspace()
+					.getQueryManager().createQuery(jcrExpression,
+							javax.jcr.query.Query.XPATH);
+			QueryResult queryResult = jcrQuery.execute();
+			NodeIterator nodeIterator = queryResult.getNodes();
+
+			if (nodeIterator.getSize() > 1)
+			{
+				throw new PersistenceException(
+						"Impossible to get the object - the query returns more than one object");
+			}
+
+			Object object = null;
+			if (nodeIterator.hasNext())
+			{
+				Node node = nodeIterator.nextNode();
+				object = objectConverter.getObject(session, query.getFilter()
+						.getFilterClass(), node.getPath());
+			}
+
+			return object;
+		}
+		catch (RepositoryException e)
+		{
+			throw new PersistenceException(
+					"Impossible to get the object collection", e);
+		}
+
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getObjects(org.apache.portals.graffito.jcr.query.Query)
+	 */
+	public Collection getObjects(Query query)
+	{
+		try
+		{
+
+			String jcrExpression = this.queryManager.buildJCRExpression(query);
+			log.debug("Get Objects with expression : " + jcrExpression);
+
+			javax.jcr.query.Query jcrQuery = session.getWorkspace()
+					.getQueryManager().createQuery(jcrExpression,
+							javax.jcr.query.Query.XPATH);
+			QueryResult queryResult = jcrQuery.execute();
+			NodeIterator nodeIterator = queryResult.getNodes();
+
+			ArrayList result = new ArrayList();
+			while (nodeIterator.hasNext())
+			{
+				Node node = nodeIterator.nextNode();
+				log.debug("Node found : " + node.getPath());
+				result.add(objectConverter.getObject(session, query.getFilter()
+						.getFilterClass(), node.getPath()));
+			}
+
+			return result;
+		}
+		catch (RepositoryException e)
+		{
+			throw new PersistenceException(
+					"Impossible to get the object collection", e);
+		}
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getObjectIterator(org.apache.portals.graffito.jcr.query.Query)
+	 */
+	public Iterator getObjectIterator(Query query)
+	{
+		try
+		{
+
+			String jcrExpression = this.queryManager.buildJCRExpression(query);
+			log.debug("Get Object with expression : " + jcrExpression);
+
+			javax.jcr.query.Query jcrQuery = session.getWorkspace()
+					.getQueryManager().createQuery(jcrExpression,
+							javax.jcr.query.Query.XPATH);
+			QueryResult queryResult = jcrQuery.execute();
+			NodeIterator nodeIterator = queryResult.getNodes();
+			return new ObjectIterator(nodeIterator, query.getFilter()
+					.getFilterClass(), this.objectConverter, this.session);
+
+		}
+		catch (RepositoryException e)
+		{
+			throw new PersistenceException(
+					"Impossible to get the object collection", e);
+		}
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#checkin(java.lang.String)
+	 */
+	public void checkin(String path)
+	{
+		this.checkin(path, null);
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#checkin(java.lang.String, java.lang.String[])
+	 */
+	public void checkin(String path, String[] versionLabels)
+	{
+		try
+		{
+			Node node = (Node) session.getItem(path);
+			checkIfNodeLocked(node.getPath());
+			if (!node.isNodeType("mix:versionable"))
+			{
+				throw new VersionException("The object " + path
+						+ "is not versionable");
+			}
+			javax.jcr.version.Version newVersion = node.checkin();
+
+			if (versionLabels != null)
+			{
+				VersionHistory versionHistory = node.getVersionHistory();
+				for (int i = 0; i < versionLabels.length; i++)
+				{
+					versionHistory.addVersionLabel(newVersion.getName(),
+							versionLabels[i], false);
+				}
+			}
+		}
+		catch (RepositoryException e)
+		{
+			throw new VersionException("Impossible to checkin the object "
+					+ path, e);
+		}
+
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#checkout(java.lang.String)
+	 */
+	public void checkout(String path)
+	{
+		try
+		{
+			Node node = (Node) session.getItem(path);
+			if (!node.isNodeType("mix:versionable"))
+			{
+				throw new VersionException("The object " + path
+						+ "is not versionable");
+			}
+
+			node.checkout();
+
+		}
+		catch (RepositoryException e)
+		{
+			throw new VersionException("Impossible to checkout the object "
+					+ path, e);
+		}
+
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#addVersionLabel(java.lang.String, java.lang.String, java.lang.String)
+	 */
+	public void addVersionLabel(String path, String versionName,
+			String versionLabel)
+	{
+		try
+		{
+			Node node = (Node) session.getItem(path);
+			checkIfNodeLocked(path);
+			if (!node.isNodeType("mix:versionable"))
+			{
+				throw new VersionException("The object " + path
+						+ "is not versionable");
+			}
+
+			VersionHistory history = node.getVersionHistory();
+			history.addVersionLabel(versionName, versionLabel, false);
+		}
+		catch (RepositoryException e)
+		{
+			throw new VersionException(
+					"Impossible to add a new version label to  " + path
+							+ " - version name : " + versionName, e);
+		}
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getVersion(java.lang.String, java.lang.String)
+	 */
+	public Version getVersion(String path, String versionName)
+	{
+
+		try
+		{
+			Node node = (Node) session.getItem(path);
+			if (!node.isNodeType("mix:versionable"))
+			{
+				throw new VersionException("The object " + path
+						+ "is not versionable");
+			}
+
+			VersionHistory history = node.getVersionHistory();
+
+			return new Version(history.getVersion(versionName));
+		}
+		catch (RepositoryException e)
+		{
+			throw new PersistenceException("Impossible to get the version : "
+					+ path + " - version name : " + versionName, e);
+		}
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getVersionLabels(java.lang.String, java.lang.String)
+	 */
+	public String[] getVersionLabels(String path, String versionName)
+	{
+
+		try
+		{
+			Node node = (Node) session.getItem(path);
+			if (!node.isNodeType("mix:versionable"))
+			{
+				throw new VersionException("The object " + path
+						+ "is not versionable");
+			}
+
+			VersionHistory history = node.getVersionHistory();
+			javax.jcr.version.Version version = history.getVersion(versionName);
+			return history.getVersionLabels(version);
+
+		}
+		catch (RepositoryException e)
+		{
+			throw new PersistenceException(
+					"Impossible to get the version labels : " + path
+							+ " - version name : " + versionName, e);
+		}
+	}
+
+	/**
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getAllVersionLabels(java.lang.String)
+	 */
+	public String[] getAllVersionLabels(String path)
+			throws javax.jcr.version.VersionException
+	{
+
+		try
+		{
+			Node node = (Node) session.getItem(path);
+			if (!node.isNodeType("mix:versionable"))
+			{
+				throw new VersionException("The object " + path
+						+ "is not versionable");
+			}
+
+			VersionHistory history = node.getVersionHistory();
+			return history.getVersionLabels();
+
+		}
+		catch (RepositoryException e)
+		{
+			throw new PersistenceException(
+					"Impossible to get the all version labels : " + path, e);
+		}
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getAllVersions(java.lang.String)
+	 */
+	public VersionIterator getAllVersions(String path)
+	{
+		try
+		{
+			Node node = (Node) session.getItem(path);
+			if (!node.isNodeType("mix:versionable"))
+			{
+				throw new VersionException("The object " + path
+						+ "is not versionable");
+			}
+
+			VersionHistory history = node.getVersionHistory();
+			return new VersionIterator(history.getAllVersions());
+		}
+		catch (RepositoryException e)
+		{
+			throw new PersistenceException("Impossible to checkin the object "
+					+ path, e);
+		}
+
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getRootVersion(java.lang.String)
+	 */
+	public Version getRootVersion(String path)
+	{
+		try
+		{
+			Node node = (Node) session.getItem(path);
+			if (!node.isNodeType("mix:versionable"))
+			{
+				throw new VersionException("The object " + path
+						+ "is not versionable");
+			}
+
+			VersionHistory history = node.getVersionHistory();
+
+			return new Version(history.getRootVersion());
+		}
+		catch (RepositoryException e)
+		{
+			throw new PersistenceException(
+					"Impossible to get the root version  for the object "
+							+ path, e);
+		}
+
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getBaseVersion(java.lang.String)
+	 */
+	public Version getBaseVersion(String path)
+	{
+		try
+		{
+			Node node = (Node) session.getItem(path);
+			if (!node.isNodeType("mix:versionable"))
+			{
+				throw new VersionException("The object " + path
+						+ "is not versionable");
+			}
+
+			return new Version(node.getBaseVersion());
+		}
+		catch (RepositoryException e)
+		{
+			throw new PersistenceException(
+					"Impossible to get the base version for the object " + path,
+					e);
+		}
+
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#lock(java.lang.String, java.lang.Object, boolean, boolean)
+	 */
+	public String lock(final String absPath, final boolean isDeep, final boolean isSessionScoped) throws LockedException
+	{
+		try
+		{
+
+			// Calling this method will throw exception if node is locked
+			// and this operation cant be done (exception translation)
+			checkIfNodeLocked(absPath);
+
+			Node node = getNode(absPath);
+			Lock lock = node.lock(isDeep, isSessionScoped);
+			return lock.getLockToken();
+		}
+		catch (LockException e)
+		{
+			// Only one case with LockException remains: if node is not mix:lockable, propably error in custom node types definitions
+			throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Node of type is not type mix:lockable", e);
+		}
+		catch (RepositoryException e)
+		{
+			throw new org.apache.portals.graffito.jcr.exception.RepositoryException(e.getMessage(), e);
+		}
+	}
+
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#unlock(java.lang.String, java.lang.Object, java.lang.String)
+	 */
+	public void unlock(final String absPath, final String lockToken) throws JcrMappingException, CannotUnlockException
+	{
+		Node node;
+		Lock lock;
+		String lockOwner = null;
+		try
+		{
+			maybeAddLockToken(lockToken);
+
+			node = getNode(absPath);
+
+			if (node.isLocked() == false)
+			{
+				// Safe - if not locked return
+				return;
+			}
+
+			lock = node.getLock();
+			lockOwner = lock.getLockOwner();
+
+			node.unlock();
+		}
+		catch (LockException e)
+		{
+			// LockException if this node does not currently hold a lock (see upper code)
+			// or holds a lock for which this Session does not have the correct lock token
+			log
+					.error("Cannot unlock path: "
+							+ absPath
+							+ " Jcr user: "
+							+ session.getUserID()
+							+ " has no lock token to do this. Lock was placed with user: "
+							+ lockOwner);
+			throw new CannotUnlockException(lockOwner, absPath);
+		}
+		catch (RepositoryException e)
+		{
+			// This also catch UnsupportedRepositoryOperationException - we assume that implementation supports it (jackrabbit does)
+			throw new org.apache.portals.graffito.jcr.exception.RepositoryException(
+					e.getMessage(), e);
+		}
+	}
+	
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#isLocked(java.lang.String)
+	 */
+	public boolean isLocked(final String absPath)
+	{
+		try
+		{
+			final Node node = getNode(absPath);
+			return node.isLocked();
+		}
+		catch (RepositoryException e)
+		{
+			// node.isLocked() RepositoryException if an error occurs.
+			throw new org.apache.portals.graffito.jcr.exception.RepositoryException(
+					"General error with JCR", e);
+		}
+	}
+	
+
+	/**
+	 * Throws {@link LockedException} id node is locked so alter nopde cannot be done
+	 * 
+	 * @param absPath
+	 *            abs path to node
+	 * @throws RepositoryException
+	 * @throws LockedException
+	 *             if node is locked
+	 */
+	protected void checkIfNodeLocked(final String absPath) 	throws RepositoryException, LockedException
+	{
+		Node node = getNode(absPath);
+		// Node can hold nock or can be locked with precedencor
+		if (node.isLocked())
+		{
+			Lock lock = node.getLock();
+			String lockOwner = lock.getLockOwner();
+			final String path = lock.getNode().getPath();
+			throw new LockedException(lockOwner, path);
+		}
+	}
+
+	protected void maybeAddLockToken(final String lockToken)
+	{
+		if (lockToken != null)
+		{
+			// This user (this instance of PM) potentionally placed lock so
+			// session already has lock token
+			final String[] lockTokens = getSession().getLockTokens();
+			if (ArrayUtils.contains(lockTokens, lockToken))
+			{
+				// Ok = this session can unlock
+			}
+			else
+			{
+				getSession().addLockToken(lockToken);
+			}
+		}
+	}
+
+	protected Node getNode(final String absPath) throws PathNotFoundException,
+			RepositoryException
+	{
+
+		if (!getSession().itemExists(absPath))
+		{
+			throw new org.apache.portals.graffito.jcr.exception.PersistenceException(
+					"No object stored on path: " + absPath);
+		}
+		Item item = getSession().getItem(absPath);
+		if (!item.isNode())
+		{
+			throw new org.apache.portals.graffito.jcr.exception.PersistenceException(
+					"No object stored on path: " + absPath
+							+ " on absPath is item (leaf)");
+		}
+		Node node = (Node) item;
+		return node;
+	}
+
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#logout()
+	 */
+	public void logout()
+	{
+		try
+		{
+			session.save();
+			session.logout();
+		}
+		catch (Exception e)
+		{
+			throw new PersistenceException("Impossible to logout", e);
+		}
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#save()
+	 */
+	public void save()
+	{
+		try
+		{
+			session.save();
+		}
+		catch (Exception e)
+		{
+			throw new PersistenceException("Impossible to save", e);
+		}
+	}
+
+	/**
+	 * @return The JCR Session
+	 */
+	public Session getSession()
+	{
+		return this.session;
+	}
+
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java?rev=354166&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java Mon Dec  5 12:35:57 2005
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2000-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.jcr.persistence.objectconverter;
+
+import javax.jcr.Node;
+import javax.jcr.Session;
+
+import org.apache.portals.graffito.jcr.exception.PersistenceException;
+
+
+/**
+ * Convert any kind of beans into JCR nodes & properties
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * @version $Id: Exp $
+ */
+public interface ObjectConverter
+{
+	/**
+	 * Insert the object 
+	 * 
+	 * @param session the JCR session  
+	 * @param object the object to insert
+	 * @throws PersistenceException when it is not possible to insert the object
+	 * 
+	 */
+    public void insert(Session session, Object object) throws PersistenceException;
+    
+	/**
+	 * Update the object 
+	 * 
+	 * @param session the JCR session 
+	 * @param object the object to update
+	 * @throws PersistenceException when it is not possible to update the object
+	 */    
+    public void update(Session session, Object object) throws PersistenceException;
+    
+    /**
+     * Retrieve an object from the JCR repo
+     * 
+     * @param session The JCR session 
+     * @param clazz The class assigned to the object to retrieve
+     * @param path the JCR path
+     * @return The object found or null
+     * 
+     * @throws PersistenceException when it is not possible to retrieve the object
+     */
+    public Object getObject(Session session, Class clazz, String path) throws PersistenceException;
+    
+    
+	/**
+	 * Insert the object 
+	 * 
+	 * @param session the JCR session 
+	 * @param parentNode The parent node used to store the new JCR element (object) 
+	 * @param nodeName The node name used to store the object
+	 * @param object the object to insert
+	 * @throws PersistenceException when it is not possible to insert the object
+	 */
+    public void insert(Session session, Node parentNode, String nodeName, Object object) throws PersistenceException;
+    
+	/**
+	 * Update the object 
+	 * 
+	 * @param session the JCR session 
+	 * @param parentNode The parent node used to store the new JCR element (object) 
+	 * @param nodeName The node name used to store the object
+	 * @param object the object to update
+	 * @throws PersistenceException when it is not possible to update the object
+	 */    
+    public void update(Session session, Node parentNode, String nodeName, Object object) throws PersistenceException;
+    
+   
+    /**
+     * Get the object JCR path 
+     * 
+     * @param session the JCR session 
+     * @param object the object for which the path has to be retrieve 
+     * @return the object JCR path 
+     * @throws PersistenceException when it is not possible to retrieve the object path
+     */
+    public String getPath(Session session , Object object)  throws PersistenceException;
+
+}



Mime
View raw message