Search in sources :

Example 1 with InputStreamDummy

use of org.jowidgets.cap.remoting.common.InputStreamDummy in project jo-client-platform by jo-source.

the class RemoteMethodInvocationHandler method getFilteredArgs.

/**
 * Filter the callback arguments
 *
 * @param args The args to filter
 * @param parameterTypes
 * @return the filtered args
 */
@SuppressWarnings("unchecked")
private Object[] getFilteredArgs(final Object[] args, final Class<?>[] parameterTypes) {
    if (args != null) {
        final Object[] result = new Object[args.length];
        for (int i = 0; i < args.length; i++) {
            final Object object = args[i];
            if (object instanceof IResultCallback<?>) {
                result[i] = null;
            } else if (object instanceof IExecutionCallback) {
                result[i] = null;
            } else if (object instanceof InputStream) {
                result[i] = new InputStreamDummy();
            } else if (InputStream[].class.isAssignableFrom(parameterTypes[i])) {
                final InputStream[] inputStreams = (InputStream[]) object;
                if (inputStreams != null) {
                    final InputStreamDummy[] inputStreamDummies = new InputStreamDummy[inputStreams.length];
                    for (int j = 0; j < inputStreams.length; j++) {
                        if (inputStreams[j] != null) {
                            inputStreamDummies[j] = new InputStreamDummy();
                        } else {
                            inputStreamDummies[j] = null;
                        }
                    }
                    result[i] = inputStreamDummies;
                } else {
                    result[i] = null;
                }
            } else if (Iterable.class.isAssignableFrom(parameterTypes[i])) {
                final Iterable<?> iterable = (Iterable<?>) object;
                if (iterable != null && isIterableOfType(iterable, InputStream.class)) {
                    if (!Collection.class.isAssignableFrom(parameterTypes[i])) {
                        throw new IllegalArgumentException("Iterables that hold InputStreams must be Collections");
                    }
                    final Collection<InputStreamDummy> inputStreamDummies;
                    try {
                        inputStreamDummies = (Collection<InputStreamDummy>) iterable.getClass().newInstance();
                    } catch (final Exception e) {
                        throw new IllegalArgumentException("Collections that holds input streams must have a public default constructor", e);
                    }
                    for (final Object element : iterable) {
                        if (element instanceof InputStream) {
                            inputStreamDummies.add(new InputStreamDummy());
                        } else if (element != null) {
                            throw new IllegalArgumentException("Collections with mixed types must not contain InputStreams");
                        } else {
                            inputStreamDummies.add(null);
                        }
                    }
                    result[i] = inputStreamDummies;
                } else {
                    result[i] = object;
                }
            } else {
                result[i] = object;
            }
        }
        return result;
    } else {
        return new Object[0];
    }
}
Also used : InputStream(java.io.InputStream) InputStreamDummy(org.jowidgets.cap.remoting.common.InputStreamDummy) IExecutionCallback(org.jowidgets.cap.common.api.execution.IExecutionCallback) Collection(java.util.Collection) IResultCallback(org.jowidgets.cap.common.api.execution.IResultCallback)

Aggregations

InputStream (java.io.InputStream)1 Collection (java.util.Collection)1 IExecutionCallback (org.jowidgets.cap.common.api.execution.IExecutionCallback)1 IResultCallback (org.jowidgets.cap.common.api.execution.IResultCallback)1 InputStreamDummy (org.jowidgets.cap.remoting.common.InputStreamDummy)1