/** * Transforms the input by ignoring it and returning the stored constant instead. * * @param input the input object which is ignored * @return the stored constant */ public Object transform(Object input) { return iConstant; }
/** * Gets the constant. * * @return the constant * @since Commons Collections 3.1 */ public Object getConstant() { return iConstant; }
/** Serial version UID */ privatestaticfinallongserialVersionUID=3514945074733160196L;
/** The transformers to call in turn */ privatefinal Transformer[] iTransformers;
/** * 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 */ publicstatic Transformer getInstance(Transformer[] transformers) { FunctorUtils.validate(transformers); if (transformers.length == 0) { return NOPTransformer.INSTANCE; } transformers = FunctorUtils.copy(transformers); returnnewChainedTransformer(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 */ publicstatic Transformer getInstance(Collection transformers) { if (transformers == null) { thrownewIllegalArgumentException("Transformer collection must not be null"); } if (transformers.size() == 0) { return NOPTransformer.INSTANCE; } // convert to array like this to guarantee iterator() ordering Transformer[] cmds = newTransformer[transformers.size()]; inti=0; for (Iteratorit= transformers.iterator(); it.hasNext();) { cmds[i++] = (Transformer) it.next(); } FunctorUtils.validate(cmds); returnnewChainedTransformer(cmds); }
/** * 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 */ publicstatic Transformer getInstance(Transformer transformer1, Transformer transformer2) { if (transformer1 == null || transformer2 == null) { thrownewIllegalArgumentException("Transformers must not be null"); } Transformer[] transformers = newTransformer[] { transformer1, transformer2 }; returnnewChainedTransformer(transformers); }
/** * Constructor that performs no validation. * Use <code>getInstance</code> if you want that. * * @param transformers the transformers to chain, not copied, no nulls */ publicChainedTransformer(Transformer[] transformers) { super(); iTransformers = transformers; }
/** * Transforms the input to result via each decorated transformer * * @param object the input object passed to the first transformer * @return the transformed result */ public Object transform(Object object) { for (inti=0; i < iTransformers.length; i++) { object = iTransformers[i].transform(object); } return object; }
/** * Gets the transformers, do not modify the array. * @return the transformers * @since Commons Collections 3.1 */ public Transformer[] getTransformers() { return iTransformers; }
// Check to make sure that types have not evolved incompatibly
AnnotationTypeannotationType=null; try { annotationType = AnnotationType.getInstance(type); } catch(IllegalArgumentException e) { // Class is no longer an annotation type; time to punch out thrownewjava.io.InvalidObjectException("Non-annotation type in annotation serial stream"); }
// If there are annotation members without values, that // situation is handled by the invoke method. for (Map.Entry<String, Object> memberValue : memberValues.entrySet()) { Stringname= memberValue.getKey(); Class<?> memberType = memberTypes.get(name); if (memberType != null) { // i.e. member still exists Objectvalue= memberValue.getValue(); if (!(memberType.isInstance(value) || value instanceof ExceptionProxy)) { memberValue.setValue( newAnnotationTypeMismatchExceptionProxy( value.getClass() + "[" + value + "]").setMember( annotationType.members().get(name))); } } } }
/** * Transforms the input to result via each decorated transformer * * @param object the input object passed to the first transformer * @return the transformed result */ public Object transform(Object object) { for (inti=0; i < iTransformers.length; i++) { object = iTransformers[i].transform(object); } return object; }
publicclassCC1Test { publicstaticvoidmain(String[] args)throws Exception{ // Runtime.getRuntime().exec("calc"); // Runtime r = Runtime.getRuntime(); // Class c = Runtime.class; // Method execMethod = c.getMethod("exec",String.class); // execMethod.invoke(r,"calc"); // InvokerTransformer invokerTransformer = new InvokerTransformer("exec", new Class[]{String.class}, new Object[]{"calc"}); // //invokerTransformer.transform(r)
// Method getRuntimeMethod = (Method) new InvokerTransformer("getMethod",new Class[]{String.class,Class[].class},new Object[]{"getRuntime",null}).transform(Runtime.class); // Runtime r = (Runtime) new InvokerTransformer("invoke", new Class[]{Object.class, Object[].class}, new Object[]{null, null}).transform(getRuntimeMethod); // new InvokerTransformer("exec", new Class[]{String.class}, new Object[]{"calc"}).transform(r);