incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r795098 - /sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
Date Fri, 17 Jul 2009 14:27:57 GMT
Author: cziegeler
Date: Fri Jul 17 14:27:57 2009
New Revision: 795098

URL: http://svn.apache.org/viewvc?rev=795098&view=rev
Log:
Add new method which explicitly gets a class loader for loading serialized java objects.

Modified:
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java?rev=795098&r1=795097&r2=795098&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
Fri Jul 17 14:27:57 2009
@@ -415,12 +415,29 @@
                                                     final String binPropertyName,
                                                     final String[] ignorePrefixes)
     throws RepositoryException, ClassNotFoundException {
+        return readProperties(node, binPropertyName, ignorePrefixes, Thread.currentThread().getContextClassLoader());
+    }
+
+    /**
+     * Read properties from a repository node and create a property map.
+     * As the properties might contain serialized java objects, a class loader can be specified
+     * for loading classes of the serialized java objects.
+     * @throws RepositoryException
+     * @throws ClassNotFoundException
+     * @since 2.0.6
+     */
+    public static EventPropertiesMap readProperties(final Node node,
+                                                    final String binPropertyName,
+                                                    final String[] ignorePrefixes,
+                                                    final ClassLoader objectClassLoader)
+    throws RepositoryException, ClassNotFoundException {
         final Map<String, Object> properties = new HashMap<String, Object>();
 
         // check the properties blob
         if ( node.hasProperty(binPropertyName) ) {
             try {
-                final ObjectInputStream ois = new ObjectInputStream(node.getProperty(binPropertyName).getStream());
+                final ObjectInputStream ois = new ObjectInputStream(node.getProperty(binPropertyName).getStream(),
+                        objectClassLoader);
                 int length = ois.readInt();
                 for(int i=0;i<length;i++) {
                     final String key = (String)ois.readObject();
@@ -623,9 +640,9 @@
 
         private ClassLoader classloader;
 
-        public ObjectInputStream(InputStream in) throws IOException {
+        public ObjectInputStream(final InputStream in, final ClassLoader classLoader) throws
IOException {
             super(in);
-            this.classloader = Thread.currentThread().getContextClassLoader();
+            this.classloader = classLoader;
         }
 
         /**



Mime
View raw message