You are viewing a plain text version of this content. The canonical link for it is here.
Posted to graffito-commits@incubator.apache.org by cl...@apache.org on 2005/09/08 21:28:11 UTC

svn commit: r279634 - in /incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter: ManageableCollection.java ManageableCollectionUtil.java impl/ManageableArrayList.java impl/ManageableVector.java

Author: clombart
Date: Thu Sep  8 14:28:05 2005
New Revision: 279634

URL: http://svn.apache.org/viewcvs?rev=279634&view=rev
Log:
Work on the CollectionDescriptor. 

Added:
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollection.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableArrayList.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableVector.java

Added: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollection.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollection.java?rev=279634&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollection.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollection.java Thu Sep  8 14:28:05 2005
@@ -0,0 +1,34 @@
+/*
+ * 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
+{
+    public void addObject(Object anObject);
+   
+    public Iterator getIterator();
+    
+    
+}

Added: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java?rev=279634&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java Thu Sep  8 14:28:05 2005
@@ -0,0 +1,116 @@
+/*
+ * 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.awt.List;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Vector;
+
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.ManageableArrayList;
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.ManageableVector;
+
+/**
+ *  
+ *
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ *
+ */
+public class ManageableCollectionUtil
+{
+    public static ManageableCollection getManageableCollection(String manageableCollectionName) throws JcrMappingException
+    {
+        try
+        {
+            Class collectionClass = Class.forName(manageableCollectionName);
+            return (ManageableCollection) collectionClass.newInstance();
+        }
+        catch (Exception e)
+        {
+            throw new JcrMappingException("Impossible to create the manageable collection", e);
+        }
+    }
+
+    public static ManageableCollection getManageableCollection(Class collectionClass) throws JcrMappingException
+    {
+        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();
+            }
+
+            throw new JcrMappingException("Unsupported collection type :" + collectionClass.getName());
+        }
+        catch (Exception e)
+        {
+            throw new JcrMappingException("Impossible to create the manageable collection", e);
+        }
+    }
+
+    public static ManageableCollection getManageableCollection(Object object) throws JcrMappingException
+    {
+        try
+        {
+
+
+            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 JcrMappingException("Unsupported collection type :" + object.getClass().getName());
+        }
+        catch (Exception e)
+        {
+            throw new JcrMappingException("Impossible to create the manageable collection", e);
+        }
+    }
+}

Added: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableArrayList.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableArrayList.java?rev=279634&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableArrayList.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableArrayList.java Thu Sep  8 14:28:05 2005
@@ -0,0 +1,45 @@
+/*
+ * 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.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection;
+
+/** 
+ *
+ * {@link ManageableCollection} implementation for ArrayList
+ * 
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ * 
+ */
+public class ManageableArrayList extends ArrayList implements ManageableCollection
+{
+
+    public void addObject(Object object)
+    {
+        this.add(object);
+     
+    }
+
+    public Iterator getIterator()
+    {
+        return this.iterator();
+    }
+
+}

Added: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableVector.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableVector.java?rev=279634&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableVector.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableVector.java Thu Sep  8 14:28:05 2005
@@ -0,0 +1,43 @@
+/*
+ * 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.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection;
+
+/** 
+ *
+ * {@link ManageableCollection} implementation for ArrayList
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ * 
+ */
+public class ManageableVector extends ArrayList implements ManageableCollection
+{
+
+    public void addObject(Object object)
+    {
+        this.add(object);
+    }
+
+    public Iterator getIterator()
+    {
+        return this.iterator();
+    }
+
+}