001package co.codewizards.cloudstore.ls.core.invoke.filter;
002
003import java.beans.PropertyChangeListener;
004import java.util.Collection;
005import java.util.Iterator;
006import java.util.Map;
007
008import co.codewizards.cloudstore.core.io.ByteArrayInputStream;
009import co.codewizards.cloudstore.core.io.ByteArrayOutputStream;
010
011public class AllowJavaInvocationFilter extends AbstractInvocationFilter {
012
013        @Override
014        public Boolean canInvoke(final ExtMethodInvocationRequest extMethodInvocationRequest) {
015                final Class<?> targetClass = extMethodInvocationRequest.getTargetClass();
016                if (Collection.class.isAssignableFrom(targetClass)
017                                || Map.class.isAssignableFrom(targetClass)
018                                || Iterator.class.isAssignableFrom(targetClass)
019                                || PropertyChangeListener.class.isAssignableFrom(targetClass))
020                        return true;
021
022                final String methodName = extMethodInvocationRequest.getMethodInvocationRequest().getMethodName();
023
024                if (System.class.equals(targetClass) && "currentTimeMillis".equals(methodName))
025                        return true;
026
027                if (ByteArrayInputStream.class.equals(targetClass) || ByteArrayOutputStream.class.equals(targetClass))
028                        return true;
029
030                if (java.io.ByteArrayInputStream.class.equals(targetClass) || java.io.ByteArrayOutputStream.class.equals(targetClass))
031                        return true;
032
033                final Object[] arguments = extMethodInvocationRequest.getMethodInvocationRequest().getArguments();
034                if ("hashCode".equals(methodName) && (arguments == null || arguments.length == 0))
035                        return true;
036
037                if ("equals".equals(methodName) && arguments != null && arguments.length == 1)
038                        return true;
039
040                if ("toString".equals(methodName) && (arguments == null || arguments.length == 0))
041                        return true;
042
043                return null;
044        }
045
046}