incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r442330 - in /incubator/graffito/trunk/jcr/jcr-mapping/src: java/org/apache/portals/graffito/jcr/mapper/model/ java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ java/org/apache/portals/graffito/jcr/persistence/objectconv...
Date Mon, 11 Sep 2006 20:23:31 GMT
Author: clombart
Date: Mon Sep 11 13:23:30 2006
New Revision: 442330

URL: http://svn.apache.org/viewvc?view=rev&rev=442330
Log:
Apply patch provided by Felix Meschberger for issue GRFT-100

Modified:
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/reflection/ReflectionUtils.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java?view=diff&rev=442330&r1=442329&r2=442330
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java
Mon Sep 11 13:23:30 2006
@@ -15,6 +15,9 @@
  */
 package org.apache.portals.graffito.jcr.mapper.model;
 
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.reflection.ReflectionUtils;
+
 
 /**
  *
@@ -278,9 +281,9 @@
         }
         else {
             try {
-                return Class.forName(this.fieldType);
+                return ReflectionUtils.forName(this.fieldType);
             }
-            catch (ClassNotFoundException cnfe) {
+            catch (JcrMappingException jme) {
                 ; // nothing to do; it will be dynamically determined
             }
         }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java?view=diff&rev=442330&r1=442329&r2=442330
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java
Mon Sep 11 13:23:30 2006
@@ -28,6 +28,7 @@
 import org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.ManageableArrayList;
 import org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.ManageableSet;
 import org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.ManageableVector;
+import org.apache.portals.graffito.jcr.reflection.ReflectionUtils;
 
 /**
  * Utility class used to instantiate {@link ManageableCollection}
@@ -44,9 +45,7 @@
      */
     public static ManageableCollection getManageableCollection(String manageableCollectionClassName)
{
         try {
-            Class collectionClass = Class.forName(manageableCollectionClassName);
-
-            return (ManageableCollection) collectionClass.newInstance();
+            return (ManageableCollection) ReflectionUtils.newInstance(manageableCollectionClassName);
         }
         catch (Exception e) {
             throw new JcrMappingException("Cannot create manageable collection : "

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java?view=diff&rev=442330&r1=442329&r2=442330
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
Mon Sep 11 13:23:30 2006
@@ -258,7 +258,7 @@
 			Node node = (Node) session.getItem(path);
 			if (node.hasProperty(PersistenceConstant.DISCRIMINATOR_PROPERTY_NAME)) {
 				String className = node.getProperty(PersistenceConstant.DISCRIMINATOR_PROPERTY_NAME).getValue().getString();
-				classDescriptor = mapper.getClassDescriptorByClass(Class.forName(className));
+				classDescriptor = mapper.getClassDescriptorByClass(ReflectionUtils.forName(className));
 			} else {
 				String nodeType = node.getPrimaryNodeType().getName();
 				if (nodeType.equals(PersistenceConstant.FROZEN_NODE_TYPE)) {
@@ -279,8 +279,8 @@
 			retrieveCollectionFields(session, classDescriptor, node, object, false);
 
 			return object;
-		} catch (ClassNotFoundException clnf) {
-			throw new PersistenceException("Impossible to instantiate the object at " + path, clnf);
+//		} catch (ClassNotFoundException clnf) {
+//			throw new PersistenceException("Impossible to instantiate the object at " + path, clnf);
 		} catch (PathNotFoundException pnfe) {
 			// HINT should never get here
 			throw new PersistenceException("Impossible to get the object at " + path, pnfe);
@@ -316,7 +316,7 @@
 				}
 
 				String className = node.getProperty(PersistenceConstant.DISCRIMINATOR_PROPERTY_NAME).getValue().getString();
-				classDescriptor = getClassDescriptor(Class.forName(className));
+				classDescriptor = getClassDescriptor(ReflectionUtils.forName(className));
 				object = ReflectionUtils.newInstance(className);
 			} else {
 				if (classDescriptor.usesNodeTypePerConcreteClassStrategy()) {
@@ -334,8 +334,8 @@
 			retrieveCollectionFields(session, classDescriptor, node, object, false);
 
 			return object;
-		} catch (ClassNotFoundException clnf) {
-			throw new PersistenceException("Impossible to instantiate the object at " + path, clnf);
+//		} catch (ClassNotFoundException clnf) {
+//			throw new PersistenceException("Impossible to instantiate the object at " + path, clnf);
 		} catch (PathNotFoundException pnfe) {
 			// HINT should never get here
 			throw new PersistenceException("Impossible to get the object at " + path, pnfe);

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/reflection/ReflectionUtils.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/reflection/ReflectionUtils.java?view=diff&rev=442330&r1=442329&r2=442330
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/reflection/ReflectionUtils.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/reflection/ReflectionUtils.java
Mon Sep 11 13:23:30 2006
@@ -30,6 +30,36 @@
  * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
  */
 abstract public class ReflectionUtils {
+    
+    // default the class loader to the load of this class
+    private static ClassLoader classLoader = ReflectionUtils.class.getClassLoader();
+    
+    /**
+     * Sets the class loader to use in the {@link #forName(String)} method to
+     * load classes.
+     * <p>
+     * Care must be taken when using this method as when setting an improperly
+     * set up classloader, the mapper will not work again throwing tons of
+     * exceptions.
+     * 
+     * @param newClassLoader The new class loader to use. This may be
+     *      <code>null</code> in which case the system class loader will be used.
+     */
+    public static void setClassLoader(ClassLoader newClassLoader) {
+        classLoader = newClassLoader;
+    }
+    
+    /**
+     * Returns the class loader which is used by the {@link #forName(String)}
+     * method to load classes.
+     * 
+     * @return The class loader used by {@link #forName(String)} or
+     *      <code>null</code> if the system class loader is used.
+     */
+    public static ClassLoader getClassLoader() {
+        return classLoader;
+    }
+    
     public static Object getNestedProperty(Object object, String fieldName) {
         if (null == object) {
             return null;
@@ -84,7 +114,7 @@
      */
     public static Object  invokeConstructor(String className,  Object[] params) {
         try {
-            Class converterClass= Class.forName(className);
+            Class converterClass= forName(className);
     
             return  ConstructorUtils.invokeConstructor(converterClass, params);
         }
@@ -114,7 +144,7 @@
      */
     public static Object newInstance(String clazz) {
         try {
-            return Class.forName(clazz).newInstance();
+            return forName(clazz).newInstance();
         }
         catch(Exception ex) {
             throw new JcrMappingException("Cannot create instance for class "  + clazz, ex);
@@ -127,7 +157,7 @@
      */
     public static Class forName(String clazz) {
         try {
-            return Class.forName(clazz);
+            return Class.forName(clazz, true, getClassLoader());
         }
         catch(Exception ex) {
             throw new JcrMappingException("Cannot load class " + clazz, ex);

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java?view=diff&rev=442330&r1=442329&r2=442330
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
Mon Sep 11 13:23:30 2006
@@ -164,7 +164,7 @@
     protected void registerNodeTypes(Session session) 
     throws InvalidNodeTypeDefException, javax.jcr.RepositoryException, IOException {
         InputStream xml = new FileInputStream(
-                "./src/test-config/repository/repository/nodetypes/custom_nodetypes.xml");
+                "./src/test-config/nodetypes/custom_nodetypes.xml");
 
         // HINT: throws InvalidNodeTypeDefException, IOException
         NodeTypeDef[] types = NodeTypeReader.read(xml);



Mime
View raw message