private FilterChainElement createFromClass(Object next) { try { return (FilterChainElement) ((Class<?>) next).newInstance(); } catch (InstantiationException e) { throw new FilterConfigurationException("Exception when instantiating FilterAction", e); } catch (IllegalAccessException e) { throw new FilterConfigurationException("Exception when instantiating FilterAction", e); } }
private void validateFiltersList() { Iterator<Object> iterator = filters.iterator(); while (iterator.hasNext()) { Object element = iterator.next(); if (element instanceof FilterAction && !(element instanceof FilterChainElement)) { // must be final action break; } validateElement(element); } if (iterator.hasNext()) { throw new FilterConfigurationException("Cannot add more filter-actions after final element"); } }
private void validateElement(Object object) { Class<? extends Object> objClass = object.getClass(); if (objClass.equals(String.class)) { return; } if (object instanceof FilterChainElementFactory) { return; } // Allow FilterAction-classes with proper default-constructors if (Class.class.isAssignableFrom(objClass)) { Class<?> filterClass = (Class<?>) object; if (!FilterAction.class.isAssignableFrom(filterClass)) { throw new FilterConfigurationException(String.format( "Incompatible type: %s, Class must be derived from one of the following: %s", filterClass, FilterAction.class.getName())); } try { filterClass.getConstructor(); } catch (NoSuchMethodException e) { throw new FilterConfigurationException("Filter-class must have a visible default constructor", e); } return; } throw new FilterConfigurationException(String.format("Element %s is not a valid FilterElement", object.toString())); }
protected static final void checkNextInputAndOutputTypes(FilterAction next, Class<?> inputType, Class<?> outputType) throws FilterConfigurationException { if (!next.getSupportedInputType().isAssignableFrom(inputType)) { throw new FilterConfigurationException(String.format("inputTypes are not compatible %s (%s - %s)", next, next.getSupportedInputType(), inputType)); } if (!next.getSupportedOutputType().isAssignableFrom(outputType)) { throw new FilterConfigurationException(String.format("outputTypes are not compatible (%s - %s)", next.getSupportedOutputType(), outputType)); } } }
if (!firstInstance.getSupportedInputType().isAssignableFrom(inputType) || !firstInstance.getSupportedOutputType().isAssignableFrom(outputType)) { throw new FilterConfigurationException(String.format( "incompatible Filtertype (%s) should be (%s->%s) - is (%s->%s)", firstInstance.getClass(), inputType, outputType, firstInstance.getSupportedInputType(),