sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r911943 - /sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
Date Fri, 19 Feb 2010 19:14:14 GMT
Author: cziegeler
Date: Fri Feb 19 19:14:14 2010
New Revision: 911943

URL: http://svn.apache.org/viewvc?rev=911943&view=rev
Log:
SLING-1398 : Remove deprecated stuff from EventUtil

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=911943&r1=911942&r2=911943&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 Feb 19 19:14:14 2010
@@ -18,31 +18,10 @@
  */
 package org.apache.sling.event;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectOutputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
 import java.util.Dictionary;
 import java.util.Enumeration;
-import java.util.HashMap;
 import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.PropertyIterator;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import javax.jcr.ValueFactory;
 
-import org.apache.jackrabbit.util.ISO9075;
 import org.apache.sling.event.EventUtil.JobStatusNotifier.NotifierContext;
 import org.apache.sling.event.impl.AbstractRepositoryEventHandler;
 import org.apache.sling.event.impl.JobEventHandler;
@@ -398,284 +377,6 @@
     }
 
     /**
-     * Add all java properties as properties to the node.
-     * If the name and the value of a map entry can easily converted into
-     * a repository property, it is directly added. All other java
-     * properties are stored in one binary property.
-     *
-     * @param node The node where all properties are added to
-     * @param properties The map of properties.
-     * @param ignoreProps optional list of property which should be ignored
-     * @param binPropertyName The name of the binary property.
-     * @throws RepositoryException
-     * @deprecated
-     */
-    @Deprecated
-    public static void addProperties(final Node node,
-                                     final Map<String, Object> properties,
-                                     final String[] ignoreProps,
-                                     final String binPropertyName)
-    throws RepositoryException {
-        addProperties(node, new EventPropertiesMap(properties), ignoreProps, binPropertyName);
-    }
-
-    /**
-     * Add all java properties as properties to the node.
-     * If the name and the value of a map entry can easily converted into
-     * a repository property, it is directly added. All other java
-     * properties are stored in one binary property.
-     *
-     * @param node The node where all properties are added to
-     * @param properties The map of properties.
-     * @param ignoreProps optional list of property which should be ignored
-     * @param binPropertyName The name of the binary property.
-     * @throws RepositoryException
-     * @deprecated
-     */
-    @Deprecated
-    public static void addProperties(final Node node,
-                                     final EventPropertiesMap properties,
-                                     final String[] ignoreProps,
-                                     final String binPropertyName)
-    throws RepositoryException {
-        if ( properties != null ) {
-            final List<String> ignorePropList = (ignoreProps == null ? null : Arrays.asList(ignoreProps));
-            // check which props we can write directly and
-            // which we need to write as a binary blob
-            final List<String> propsAsBlob = new ArrayList<String>();
-
-            final Iterator<Map.Entry<String, Object>> i = properties.entrySet().iterator();
-            while ( i.hasNext() ) {
-                final Map.Entry<String, Object> current = i.next();
-
-                if (ignorePropList == null || !ignorePropList.contains(current.getKey())
) {
-                    // sanity check
-                    if ( current.getValue() != null ) {
-                        if ( !setProperty(current.getKey(), current.getValue(), node) ) {
-                            propsAsBlob.add(current.getKey());
-                        }
-                    }
-                }
-            }
-            // write the remaining properties as a blob
-            if ( propsAsBlob.size() > 0 ) {
-                try {
-                    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                    final ObjectOutputStream oos = new ObjectOutputStream(baos);
-                    oos.writeInt(propsAsBlob.size());
-                    for(final String propName : propsAsBlob) {
-                        oos.writeObject(propName);
-                        try {
-                            oos.writeObject(properties.get(propName));
-                        } catch (IOException ioe) {
-                            throw new RepositoryException("Unable to serialize property "
+ propName, ioe);
-                        }
-                    }
-                    oos.close();
-                    node.setProperty(binPropertyName, new ByteArrayInputStream(baos.toByteArray()));
-                } catch (IOException ioe) {
-                    throw new RepositoryException("Unable to serialize properties " + properties,
ioe);
-                }
-            }
-        }
-    }
-
-    /**
-     * Read properties from a repository node and create a property map.
-     * As the properties might contain serialized java objects, the thread context class
-     * loader is used to load these objects.
-     * @throws RepositoryException
-     * @throws ClassNotFoundException
-     * @deprecated
-     */
-    @Deprecated
-    public static EventPropertiesMap readProperties(final Node node,
-                                                    final String binPropertyName,
-                                                    final String[] ignorePrefixes)
-    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(),
-                        Thread.currentThread().getContextClassLoader());
-                int length = ois.readInt();
-                for(int i=0;i<length;i++) {
-                    final String key = (String)ois.readObject();
-                    final Object value = ois.readObject();
-                    properties.put(key, value);
-                }
-            } catch (java.io.InvalidClassException ice) {
-                throw new ClassNotFoundException("Found invalid class.", ice);
-            } catch (IOException ioe) {
-                throw new RepositoryException("Unable to deserialize event properties.",
ioe);
-            }
-        }
-        // now all properties that have been set directly
-        final PropertyIterator pI = node.getProperties();
-        while ( pI.hasNext() ) {
-            final Property p = pI.nextProperty();
-            boolean ignore = p.getName().startsWith("jcr:");
-            if ( !ignore && ignorePrefixes != null ) {
-                int index = 0;
-                while ( !ignore && index < ignorePrefixes.length ) {
-                    ignore = p.getName().startsWith(ignorePrefixes[index]);
-                    index++;
-                }
-            }
-            if ( !ignore ) {
-                final String name = ISO9075.decode(p.getName());
-                if ( p.getDefinition().isMultiple() ) {
-                    final Value[] values = p.getValues();
-                    if ( values.length > 0 ) {
-                        // get first value
-                        final Object firstObject = getPropertyValue(values[0]);
-                        final Object[] array;
-                        if ( firstObject instanceof Boolean ) {
-                            array = new Boolean[values.length];
-                        } else if ( firstObject instanceof Calendar ) {
-                            array = new Calendar[values.length];
-                        } else if ( firstObject instanceof Double ) {
-                            array = new Double[values.length];
-                        } else if ( firstObject instanceof Long ) {
-                            array = new Long[values.length];
-                        } else {
-                            array = new String[values.length];
-                        }
-                        array[0] = firstObject;
-                        int index = 1;
-                        while ( index < values.length ) {
-                            array[index] = getPropertyValue(values[index]);
-                            index++;
-                        }
-                        properties.put(name, array);
-                    }
-                } else {
-                    final Value value = p.getValue();
-                    final Object o = getPropertyValue(value);
-                    properties.put(name, o);
-                }
-            }
-        }
-        return new EventPropertiesMap(properties);
-    }
-
-    /**
-     * Return the converted repository property name
-     * @param name The java object property name
-     * @return The converted name or null if not possible.
-     * @deprecated
-     */
-    @Deprecated
-    public static String getNodePropertyName(final String name) {
-        // if name contains a colon, we can't set it as a property
-        if ( name.indexOf(':') != -1 ) {
-            return null;
-        }
-        return ISO9075.encode(name);
-    }
-
-    /**
-     * Return the converted repository property value
-     * @param valueFactory The value factory
-     * @param eventValue The event value
-     * @return The converted value or null if not possible
-     * @deprecated
-     */
-    @Deprecated
-    public static Value getNodePropertyValue(final ValueFactory valueFactory, final Object
eventValue) {
-        final Value val;
-        if (eventValue instanceof Calendar) {
-            val = valueFactory.createValue((Calendar)eventValue);
-        } else if (eventValue instanceof Long) {
-            val = valueFactory.createValue((Long)eventValue);
-        } else if (eventValue instanceof Double) {
-            val = valueFactory.createValue(((Double)eventValue).doubleValue());
-        } else if (eventValue instanceof Boolean) {
-            val = valueFactory.createValue((Boolean) eventValue);
-        } else if (eventValue instanceof String) {
-            val = valueFactory.createValue((String)eventValue);
-        } else {
-            val = null;
-        }
-        return val;
-    }
-
-    /**
-     * Convert the value back to an object.
-     * @param value
-     * @return
-     * @throws RepositoryException
-     * @deprecated
-     */
-    @Deprecated
-    private static Object getPropertyValue(final Value value)
-    throws RepositoryException {
-        final Object o;
-        switch (value.getType()) {
-            case PropertyType.BOOLEAN:
-                o = value.getBoolean(); break;
-            case PropertyType.DATE:
-                o = value.getDate(); break;
-            case PropertyType.DOUBLE:
-                o = value.getDouble(); break;
-            case PropertyType.LONG:
-                o = value.getLong(); break;
-            case PropertyType.STRING:
-                o = value.getString(); break;
-            default: // this should never happen - we convert to a string...
-                o = value.getString();
-        }
-        return o;
-    }
-
-    /**
-     * Try to set the java property as a property of the node.
-     * @param name
-     * @param value
-     * @param node
-     * @return
-     * @throws RepositoryException
-     * @deprecated
-     */
-    @Deprecated
-    private static boolean setProperty(String name, Object value, Node node)
-    throws RepositoryException {
-        final String propName = getNodePropertyName(name);
-        if ( propName == null ) {
-            return false;
-        }
-        final ValueFactory fac = node.getSession().getValueFactory();
-        // check for multi value
-        if ( value.getClass().isArray() ) {
-            final Object[] array = (Object[])value;
-            // now we try to convert each value
-            // and check if all converted values have the same type
-            final Value[] values = new Value[array.length];
-            int index = 0;
-            for(final Object v : array ) {
-                values[index] = getNodePropertyValue(fac, v);
-                if ( values[index] == null ) {
-                    return false;
-                }
-                if ( index > 0 && !values[index-1].getClass().equals(values[index].getClass())
) {
-                    return false;
-                }
-                index++;
-            }
-            node.setProperty(propName, values);
-            return true;
-        }
-        final Value val = getNodePropertyValue(fac, value);
-        if ( val != null ) {
-            node.setProperty(propName, val);
-            return true;
-        }
-        return false;
-    }
-
-    /**
      * Improved toString method for an Event.
      * This method prints out the event topic and all of the properties.
      */
@@ -703,29 +404,4 @@
         buffer.append("]");
         return buffer.toString();
     }
-
-    /**
-     * This is an extended version of the object input stream which uses the
-     * thread context class loader.
-     */
-    private static class ObjectInputStream extends java.io.ObjectInputStream {
-
-        private ClassLoader classloader;
-
-        public ObjectInputStream(final InputStream in, final ClassLoader classLoader) throws
IOException {
-            super(in);
-            this.classloader = classLoader;
-        }
-
-        /**
-         * @see java.io.ObjectInputStream#resolveClass(java.io.ObjectStreamClass)
-         */
-        @Override
-        protected Class<?> resolveClass(java.io.ObjectStreamClass classDesc) throws
IOException, ClassNotFoundException {
-            if ( this.classloader != null ) {
-                return Class.forName(classDesc.getName(), true, this.classloader);
-            }
-            return super.resolveClass(classDesc);
-        }
-    }
 }
\ No newline at end of file



Mime
View raw message